1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <memory> 8 #include <utility> 9 10 #include <zxtest/base/test-driver.h> 11 #include <zxtest/base/test-internal.h> 12 13 namespace zxtest { 14 15 // Instance of a test to be executed. 16 class Test : private internal::TestInternal { 17 public: 18 // Default factory function for tests. 19 template <typename Derived> Create(internal::TestDriver * driver)20 static std::unique_ptr<Derived> Create(internal::TestDriver* driver) { 21 static_assert(std::is_base_of<Test, Derived>::value, 22 "Must inherit from zxtest::TestInternal."); 23 std::unique_ptr<Derived> derived = std::make_unique<Derived>(); 24 derived->driver_ = driver; 25 return std::move(derived); 26 } 27 28 virtual ~Test() = default; 29 30 // Dummy implementation for TestCase SetUp functions. SetUpTestCase()31 static void SetUpTestCase() {} 32 33 // Dummy implementation for TestCase TearDown functions. TearDownTestCase()34 static void TearDownTestCase() {} 35 36 // Dummy SetUp method. SetUp()37 virtual void SetUp() {} 38 39 // Dummy TearDown method. TearDown()40 virtual void TearDown() {} 41 42 // Executed the current test instance. 43 void Run(); 44 45 private: 46 // Actual test implementation. 47 virtual void TestBody() = 0; 48 }; 49 50 } // namespace zxtest 51