gtest-typed-test_test.cc (googletest-release-1.10.0) | : | gtest-typed-test_test.cc (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 90 | skipping to change at line 90 | |||
value_++; | value_++; | |||
} | } | |||
T value_; | T value_; | |||
static T* shared_; | static T* shared_; | |||
}; | }; | |||
template <typename T> | template <typename T> | |||
T* CommonTest<T>::shared_ = nullptr; | T* CommonTest<T>::shared_ = nullptr; | |||
// This #ifdef block tests typed tests. | ||||
#if GTEST_HAS_TYPED_TEST | ||||
using testing::Types; | using testing::Types; | |||
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, | // Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, | |||
// and SetUp()/TearDown() work correctly in typed tests | // and SetUp()/TearDown() work correctly in typed tests | |||
typedef Types<char, int> TwoTypes; | typedef Types<char, int> TwoTypes; | |||
TYPED_TEST_SUITE(CommonTest, TwoTypes); | TYPED_TEST_SUITE(CommonTest, TwoTypes); | |||
TYPED_TEST(CommonTest, ValuesAreCorrect) { | TYPED_TEST(CommonTest, ValuesAreCorrect) { | |||
// Static members of the fixture class template can be visited via | // Static members of the fixture class template can be visited via | |||
skipping to change at line 195 | skipping to change at line 192 | |||
} | } | |||
} | } | |||
}; | }; | |||
TYPED_TEST_SUITE(TypedTestWithNames, TwoTypes, TypedTestNames); | TYPED_TEST_SUITE(TypedTestWithNames, TwoTypes, TypedTestNames); | |||
TYPED_TEST(TypedTestWithNames, TestSuiteName) { | TYPED_TEST(TypedTestWithNames, TestSuiteName) { | |||
if (std::is_same<TypeParam, char>::value) { | if (std::is_same<TypeParam, char>::value) { | |||
EXPECT_STREQ(::testing::UnitTest::GetInstance() | EXPECT_STREQ(::testing::UnitTest::GetInstance() | |||
->current_test_info() | ->current_test_info() | |||
->test_case_name(), | ->test_suite_name(), | |||
"TypedTestWithNames/char0"); | "TypedTestWithNames/char0"); | |||
} | } | |||
if (std::is_same<TypeParam, int>::value) { | if (std::is_same<TypeParam, int>::value) { | |||
EXPECT_STREQ(::testing::UnitTest::GetInstance() | EXPECT_STREQ(::testing::UnitTest::GetInstance() | |||
->current_test_info() | ->current_test_info() | |||
->test_case_name(), | ->test_suite_name(), | |||
"TypedTestWithNames/int1"); | "TypedTestWithNames/int1"); | |||
} | } | |||
} | } | |||
#endif // GTEST_HAS_TYPED_TEST | ||||
// This #ifdef block tests type-parameterized tests. | ||||
#if GTEST_HAS_TYPED_TEST_P | ||||
using testing::Types; | using testing::Types; | |||
using testing::internal::TypedTestSuitePState; | using testing::internal::TypedTestSuitePState; | |||
// Tests TypedTestSuitePState. | // Tests TypedTestSuitePState. | |||
class TypedTestSuitePStateTest : public Test { | class TypedTestSuitePStateTest : public Test { | |||
protected: | protected: | |||
void SetUp() override { | void SetUp() override { | |||
state_.AddTestName("foo.cc", 0, "FooTest", "A"); | state_.AddTestName("foo.cc", 0, "FooTest", "A"); | |||
state_.AddTestName("foo.cc", 0, "FooTest", "B"); | state_.AddTestName("foo.cc", 0, "FooTest", "B"); | |||
state_.AddTestName("foo.cc", 0, "FooTest", "C"); | state_.AddTestName("foo.cc", 0, "FooTest", "C"); | |||
} | } | |||
TypedTestSuitePState state_; | TypedTestSuitePState state_; | |||
}; | }; | |||
TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) { | TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) { | |||
const char* tests = "A, B, C"; | const char* tests = "A, B, C"; | |||
EXPECT_EQ(tests, | EXPECT_EQ(tests, | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests)); | |||
} | } | |||
// Makes sure that the order of the tests and spaces around the names | // Makes sure that the order of the tests and spaces around the names | |||
// don't matter. | // don't matter. | |||
TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) { | TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) { | |||
const char* tests = "A,C, B"; | const char* tests = "A,C, B"; | |||
EXPECT_EQ(tests, | EXPECT_EQ(tests, | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests)); | |||
} | } | |||
using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest; | using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest; | |||
TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) { | TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) { | |||
EXPECT_DEATH_IF_SUPPORTED( | EXPECT_DEATH_IF_SUPPORTED( | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"), | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, A, C"), | |||
"foo\\.cc.1.?: Test A is listed more than once\\."); | "foo\\.cc.1.?: Test A is listed more than once\\."); | |||
} | } | |||
TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) { | TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) { | |||
EXPECT_DEATH_IF_SUPPORTED( | EXPECT_DEATH_IF_SUPPORTED( | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"), | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C, D"), | |||
"foo\\.cc.1.?: No test named D can be found in this test suite\\."); | "foo\\.cc.1.?: No test named D can be found in this test suite\\."); | |||
} | } | |||
TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) { | TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) { | |||
EXPECT_DEATH_IF_SUPPORTED( | EXPECT_DEATH_IF_SUPPORTED( | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"), | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, C"), | |||
"foo\\.cc.1.?: You forgot to list test B\\."); | "foo\\.cc.1.?: You forgot to list test B\\."); | |||
} | } | |||
// Tests that defining a test for a parameterized test case generates | // Tests that defining a test for a parameterized test case generates | |||
// a run-time error if the test case has been registered. | // a run-time error if the test case has been registered. | |||
TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) { | TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) { | |||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C"); | state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C"); | |||
EXPECT_DEATH_IF_SUPPORTED( | EXPECT_DEATH_IF_SUPPORTED( | |||
state_.AddTestName("foo.cc", 2, "FooTest", "D"), | state_.AddTestName("foo.cc", 2, "FooTest", "D"), | |||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P" | "foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P" | |||
"\\(FooTest, \\.\\.\\.\\)\\."); | "\\(FooTest, \\.\\.\\.\\)\\."); | |||
} | } | |||
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, | // Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, | |||
// and SetUp()/TearDown() work correctly in type-parameterized tests. | // and SetUp()/TearDown() work correctly in type-parameterized tests. | |||
template <typename T> | template <typename T> | |||
skipping to change at line 317 | skipping to change at line 309 | |||
// TwoTypes from above here. | // TwoTypes from above here. | |||
template <typename T> | template <typename T> | |||
class TypeParametrizedTestWithNames : public Test {}; | class TypeParametrizedTestWithNames : public Test {}; | |||
TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames); | TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames); | |||
TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) { | TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) { | |||
if (std::is_same<TypeParam, char>::value) { | if (std::is_same<TypeParam, char>::value) { | |||
EXPECT_STREQ(::testing::UnitTest::GetInstance() | EXPECT_STREQ(::testing::UnitTest::GetInstance() | |||
->current_test_info() | ->current_test_info() | |||
->test_case_name(), | ->test_suite_name(), | |||
"CustomName/TypeParametrizedTestWithNames/parChar0"); | "CustomName/TypeParametrizedTestWithNames/parChar0"); | |||
} | } | |||
if (std::is_same<TypeParam, int>::value) { | if (std::is_same<TypeParam, int>::value) { | |||
EXPECT_STREQ(::testing::UnitTest::GetInstance() | EXPECT_STREQ(::testing::UnitTest::GetInstance() | |||
->current_test_info() | ->current_test_info() | |||
->test_case_name(), | ->test_suite_name(), | |||
"CustomName/TypeParametrizedTestWithNames/parInt1"); | "CustomName/TypeParametrizedTestWithNames/parInt1"); | |||
} | } | |||
} | } | |||
REGISTER_TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames, TestSuiteName); | REGISTER_TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames, TestSuiteName); | |||
class TypeParametrizedTestNames { | class TypeParametrizedTestNames { | |||
public: | public: | |||
template <typename T> | template <typename T> | |||
static std::string GetName(int i) { | static std::string GetName(int i) { | |||
skipping to change at line 444 | skipping to change at line 436 | |||
TYPED_TEST_P(TrimmedTest, Test5) { EXPECT_STREQ("Test5", GetTestName()); } | TYPED_TEST_P(TrimmedTest, Test5) { EXPECT_STREQ("Test5", GetTestName()); } | |||
REGISTER_TYPED_TEST_SUITE_P( | REGISTER_TYPED_TEST_SUITE_P( | |||
TrimmedTest, | TrimmedTest, | |||
Test1, Test2,Test3 , Test4 ,Test5 ); // NOLINT | Test1, Test2,Test3 , Test4 ,Test5 ); // NOLINT | |||
template <typename T1, typename T2> struct MyPair {}; | template <typename T1, typename T2> struct MyPair {}; | |||
// Be sure to try a type with a comma in its name just in case it matters. | // Be sure to try a type with a comma in its name just in case it matters. | |||
typedef Types<int, double, MyPair<int, int> > TrimTypes; | typedef Types<int, double, MyPair<int, int> > TrimTypes; | |||
INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes); | INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes); | |||
} // namespace library2 | } // namespace library2 | |||
#endif // GTEST_HAS_TYPED_TEST_P | ||||
#if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P) | ||||
// Google Test may not support type-parameterized tests with some | ||||
// compilers. If we use conditional compilation to compile out all | ||||
// code referring to the gtest_main library, MSVC linker will not link | ||||
// that library at all and consequently complain about missing entry | ||||
// point defined in that library (fatal error LNK1561: entry point | ||||
// must be defined). This dummy test keeps gtest_main linked in. | ||||
TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {} | ||||
#if _MSC_VER | ||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127 | ||||
#endif // _MSC_VER | ||||
#endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P | ||||
) | ||||
End of changes. 13 change blocks. | ||||
18 lines changed or deleted | 10 lines changed or added |