Changes test creation functions to factories. By Vlad Losev.
This commit is contained in:
@@ -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_;
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user