aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorshiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-08-06 21:44:19 +0000
committershiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-08-06 21:44:19 +0000
commitd5f13d4a257b6bfc43068f3a918989cf89af75ec (patch)
treefae369ee214062805989e6506d40f297c85b22c9 /include
parent9b093c1779eb48a55db026cfd525f4cf1bbd4749 (diff)
downloadgoogletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.tar.gz
googletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.tar.bz2
googletest-d5f13d4a257b6bfc43068f3a918989cf89af75ec.zip
Changes test creation functions to factories. By Vlad Losev.
Diffstat (limited to 'include')
-rw-r--r--include/gtest/gtest.h17
-rw-r--r--include/gtest/internal/gtest-internal.h44
2 files changed, 42 insertions, 19 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h
index 2464f725..1f5d7640 100644
--- a/include/gtest/gtest.h
+++ b/include/gtest/gtest.h
@@ -310,11 +310,6 @@ class Test {
};
-// Defines the type of a function pointer that creates a Test object
-// when invoked.
-typedef Test* (*TestMaker)();
-
-
// A TestInfo object stores the following information about a test:
//
// Test case name
@@ -342,7 +337,9 @@ class TestInfo {
// fixture_class_id: ID of the test fixture class
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
- // maker: pointer to the function that creates a test object
+ // factory: Pointer to the factory that creates a test object.
+ // The newly created TestInfo instance will assume
+ // ownershi pof the factory object.
//
// This is public only because it's needed by the TEST and TEST_F macros.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
@@ -352,7 +349,7 @@ class TestInfo {
internal::TypeId fixture_class_id,
Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc,
- TestMaker maker);
+ internal::TestFactoryBase* factory);
// Returns the test case name.
const char* test_case_name() const;
@@ -395,9 +392,11 @@ class TestInfo {
internal::TestInfoImpl* impl() { return impl_; }
const internal::TestInfoImpl* impl() const { return impl_; }
- // Constructs a TestInfo object.
+ // Constructs a TestInfo object. The newly constructed instance assumes
+ // ownership of the factory object.
TestInfo(const char* test_case_name, const char* name,
- internal::TypeId fixture_class_id, TestMaker maker);
+ internal::TypeId fixture_class_id,
+ internal::TestFactoryBase* factory);
// An opaque implementation object.
internal::TestInfoImpl* impl_;
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h
index 2eefc7bf..dc6154b6 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()