diff options
author | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-08-06 21:44:19 (GMT) |
---|---|---|
committer | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-08-06 21:44:19 (GMT) |
commit | d5f13d4a257b6bfc43068f3a918989cf89af75ec (patch) | |
tree | fae369ee214062805989e6506d40f297c85b22c9 /include/gtest/internal/gtest-internal.h | |
parent | 9b093c1779eb48a55db026cfd525f4cf1bbd4749 (diff) | |
download | googletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.zip googletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.tar.gz googletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.tar.bz2 |
Changes test creation functions to factories. By Vlad Losev.
Diffstat (limited to 'include/gtest/internal/gtest-internal.h')
-rw-r--r-- | include/gtest/internal/gtest-internal.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 2eefc7b..dc6154b 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -98,6 +98,7 @@ namespace testing { // Forward declaration of classes. class Message; // Represents a failure message. +class Test; // Represents a test. class TestCase; // A collection of related tests. class TestPartResult; // Result of a test part. class TestInfo; // Information about a test. @@ -484,6 +485,31 @@ inline TypeId GetTypeId() { return &dummy; } +// Defines the abstract factory interface that creates instances +// of a Test object. +class TestFactoryBase { + public: + virtual ~TestFactoryBase() {} + + // Creates a test instance to run. The instance is both created and destroyed + // within TestInfoImpl::Run() + virtual Test* CreateTest() = 0; + + protected: + TestFactoryBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN(TestFactoryBase); +}; + +// This class provides implementation of TeastFactoryBase interface. +// It is used in TEST and TEST_F macros. +template <class TestClass> +class TestFactoryImpl : public TestFactoryBase { + public: + virtual Test* CreateTest() { return new TestClass; } +}; + #ifdef GTEST_OS_WINDOWS // Predicate-formatters for implementing the HRESULT checking macros @@ -523,9 +549,6 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT class test_case_name##_##test_name##_Test : public parent_class {\ public:\ test_case_name##_##test_name##_Test() {}\ - static ::testing::Test* NewTest() {\ - return new test_case_name##_##test_name##_Test;\ - }\ private:\ virtual void TestBody();\ static ::testing::TestInfo* const test_info_;\ @@ -533,13 +556,14 @@ class test_case_name##_##test_name##_Test : public parent_class {\ };\ \ ::testing::TestInfo* const test_case_name##_##test_name##_Test::test_info_ =\ - ::testing::TestInfo::MakeAndRegisterInstance(\ - #test_case_name, \ - #test_name, \ - ::testing::internal::GetTypeId< parent_class >(), \ - parent_class::SetUpTestCase, \ - parent_class::TearDownTestCase, \ - test_case_name##_##test_name##_Test::NewTest);\ + ::testing::TestInfo::MakeAndRegisterInstance(\ + #test_case_name, \ + #test_name, \ + ::testing::internal::GetTypeId< parent_class >(), \ + parent_class::SetUpTestCase, \ + parent_class::TearDownTestCase, \ + new ::testing::internal::TestFactoryImpl<\ + test_case_name##_##test_name##_Test>);\ void test_case_name##_##test_name##_Test::TestBody() |