diff options
Diffstat (limited to 'googletest/test/gtest-typed-test_test.cc')
-rw-r--r-- | googletest/test/gtest-typed-test_test.cc | 135 |
1 files changed, 68 insertions, 67 deletions
diff --git a/googletest/test/gtest-typed-test_test.cc b/googletest/test/gtest-typed-test_test.cc index de6cc53..5411832 100644 --- a/googletest/test/gtest-typed-test_test.cc +++ b/googletest/test/gtest-typed-test_test.cc @@ -31,6 +31,7 @@ #include "test/gtest-typed-test_test.h" #include <set> +#include <type_traits> #include <vector> #include "gtest/gtest.h" @@ -41,19 +42,19 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */) using testing::Test; -// Used for testing that SetUpTestCase()/TearDownTestCase(), fixture +// Used for testing that SetUpTestSuite()/TearDownTestSuite(), fixture // ctor/dtor, and SetUp()/TearDown() work correctly in typed tests and // type-parameterized test. template <typename T> class CommonTest : public Test { - // For some technical reason, SetUpTestCase() and TearDownTestCase() + // For some technical reason, SetUpTestSuite() and TearDownTestSuite() // must be public. public: - static void SetUpTestCase() { + static void SetUpTestSuite() { shared_ = new T(5); } - static void TearDownTestCase() { + static void TearDownTestSuite() { delete shared_; shared_ = nullptr; } @@ -92,11 +93,11 @@ T* CommonTest<T>::shared_ = nullptr; using testing::Types; -// Tests that SetUpTestCase()/TearDownTestCase(), fixture ctor/dtor, +// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, // and SetUp()/TearDown() work correctly in typed tests typedef Types<char, int> TwoTypes; -TYPED_TEST_CASE(CommonTest, TwoTypes); +TYPED_TEST_SUITE(CommonTest, TwoTypes); TYPED_TEST(CommonTest, ValuesAreCorrect) { // Static members of the fixture class template can be visited via @@ -128,25 +129,25 @@ TYPED_TEST(CommonTest, ValuesAreStillCorrect) { EXPECT_EQ(static_cast<TypeParam>(2), this->value_); } -// Tests that multiple TYPED_TEST_CASE's can be defined in the same +// Tests that multiple TYPED_TEST_SUITE's can be defined in the same // translation unit. template <typename T> class TypedTest1 : public Test { }; -// Verifies that the second argument of TYPED_TEST_CASE can be a +// Verifies that the second argument of TYPED_TEST_SUITE can be a // single type. -TYPED_TEST_CASE(TypedTest1, int); +TYPED_TEST_SUITE(TypedTest1, int); TYPED_TEST(TypedTest1, A) {} template <typename T> class TypedTest2 : public Test { }; -// Verifies that the second argument of TYPED_TEST_CASE can be a +// Verifies that the second argument of TYPED_TEST_SUITE can be a // Types<...> type list. -TYPED_TEST_CASE(TypedTest2, Types<int>); +TYPED_TEST_SUITE(TypedTest2, Types<int>); // This also verifies that tests from different typed test cases can // share the same name. @@ -161,7 +162,7 @@ class NumericTest : public Test { }; typedef Types<int, long> NumericTypes; -TYPED_TEST_CASE(NumericTest, NumericTypes); +TYPED_TEST_SUITE(NumericTest, NumericTypes); TYPED_TEST(NumericTest, DefaultIsZero) { EXPECT_EQ(0, TypeParam()); @@ -177,25 +178,25 @@ class TypedTestNames { public: template <typename T> static std::string GetName(int i) { - if (testing::internal::IsSame<T, char>::value) { + if (std::is_same<T, char>::value) { return std::string("char") + ::testing::PrintToString(i); } - if (testing::internal::IsSame<T, int>::value) { + if (std::is_same<T, int>::value) { return std::string("int") + ::testing::PrintToString(i); } } }; -TYPED_TEST_CASE(TypedTestWithNames, TwoTypes, TypedTestNames); +TYPED_TEST_SUITE(TypedTestWithNames, TwoTypes, TypedTestNames); -TYPED_TEST(TypedTestWithNames, TestCaseName) { - if (testing::internal::IsSame<TypeParam, char>::value) { +TYPED_TEST(TypedTestWithNames, TestSuiteName) { + if (std::is_same<TypeParam, char>::value) { EXPECT_STREQ(::testing::UnitTest::GetInstance() ->current_test_info() ->test_case_name(), "TypedTestWithNames/char0"); } - if (testing::internal::IsSame<TypeParam, int>::value) { + if (std::is_same<TypeParam, int>::value) { EXPECT_STREQ(::testing::UnitTest::GetInstance() ->current_test_info() ->test_case_name(), @@ -209,11 +210,11 @@ TYPED_TEST(TypedTestWithNames, TestCaseName) { #if GTEST_HAS_TYPED_TEST_P using testing::Types; -using testing::internal::TypedTestCasePState; +using testing::internal::TypedTestSuitePState; -// Tests TypedTestCasePState. +// Tests TypedTestSuitePState. -class TypedTestCasePStateTest : public Test { +class TypedTestSuitePStateTest : public Test { protected: void SetUp() override { state_.AddTestName("foo.cc", 0, "FooTest", "A"); @@ -221,10 +222,10 @@ class TypedTestCasePStateTest : public Test { state_.AddTestName("foo.cc", 0, "FooTest", "C"); } - TypedTestCasePState state_; + TypedTestSuitePState state_; }; -TEST_F(TypedTestCasePStateTest, SucceedsForMatchingList) { +TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) { const char* tests = "A, B, C"; EXPECT_EQ(tests, state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); @@ -232,27 +233,27 @@ TEST_F(TypedTestCasePStateTest, SucceedsForMatchingList) { // Makes sure that the order of the tests and spaces around the names // don't matter. -TEST_F(TypedTestCasePStateTest, IgnoresOrderAndSpaces) { +TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) { const char* tests = "A,C, B"; EXPECT_EQ(tests, state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); } -typedef TypedTestCasePStateTest TypedTestCasePStateDeathTest; +using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest; -TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) { +TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) { EXPECT_DEATH_IF_SUPPORTED( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"), "foo\\.cc.1.?: Test A is listed more than once\\."); } -TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) { +TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) { EXPECT_DEATH_IF_SUPPORTED( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"), - "foo\\.cc.1.?: No test named D can be found in this test case\\."); + "foo\\.cc.1.?: No test named D can be found in this test suite\\."); } -TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) { +TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) { EXPECT_DEATH_IF_SUPPORTED( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"), "foo\\.cc.1.?: You forgot to list test B\\."); @@ -260,22 +261,22 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) { // Tests that defining a test for a parameterized test case generates // a run-time error if the test case has been registered. -TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) { +TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) { state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C"); EXPECT_DEATH_IF_SUPPORTED( state_.AddTestName("foo.cc", 2, "FooTest", "D"), - "foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_CASE_P" + "foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P" "\\(FooTest, \\.\\.\\.\\)\\."); } -// Tests that SetUpTestCase()/TearDownTestCase(), fixture ctor/dtor, +// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, // and SetUp()/TearDown() work correctly in type-parameterized tests. template <typename T> class DerivedTest : public CommonTest<T> { }; -TYPED_TEST_CASE_P(DerivedTest); +TYPED_TEST_SUITE_P(DerivedTest); TYPED_TEST_P(DerivedTest, ValuesAreCorrect) { // Static members of the fixture class template can be visited via @@ -297,27 +298,27 @@ TYPED_TEST_P(DerivedTest, ValuesAreStillCorrect) { EXPECT_EQ(2, this->value_); } -REGISTER_TYPED_TEST_CASE_P(DerivedTest, +REGISTER_TYPED_TEST_SUITE_P(DerivedTest, ValuesAreCorrect, ValuesAreStillCorrect); typedef Types<short, long> MyTwoTypes; -INSTANTIATE_TYPED_TEST_CASE_P(My, DerivedTest, MyTwoTypes); +INSTANTIATE_TYPED_TEST_SUITE_P(My, DerivedTest, MyTwoTypes); // Tests that custom names work with type parametrized tests. We reuse the // TwoTypes from above here. template <typename T> class TypeParametrizedTestWithNames : public Test {}; -TYPED_TEST_CASE_P(TypeParametrizedTestWithNames); +TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames); -TYPED_TEST_P(TypeParametrizedTestWithNames, TestCaseName) { - if (testing::internal::IsSame<TypeParam, char>::value) { +TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) { + if (std::is_same<TypeParam, char>::value) { EXPECT_STREQ(::testing::UnitTest::GetInstance() ->current_test_info() ->test_case_name(), "CustomName/TypeParametrizedTestWithNames/parChar0"); } - if (testing::internal::IsSame<TypeParam, int>::value) { + if (std::is_same<TypeParam, int>::value) { EXPECT_STREQ(::testing::UnitTest::GetInstance() ->current_test_info() ->test_case_name(), @@ -325,77 +326,77 @@ TYPED_TEST_P(TypeParametrizedTestWithNames, TestCaseName) { } } -REGISTER_TYPED_TEST_CASE_P(TypeParametrizedTestWithNames, TestCaseName); +REGISTER_TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames, TestSuiteName); class TypeParametrizedTestNames { public: template <typename T> static std::string GetName(int i) { - if (testing::internal::IsSame<T, char>::value) { + if (std::is_same<T, char>::value) { return std::string("parChar") + ::testing::PrintToString(i); } - if (testing::internal::IsSame<T, int>::value) { + if (std::is_same<T, int>::value) { return std::string("parInt") + ::testing::PrintToString(i); } } }; -INSTANTIATE_TYPED_TEST_CASE_P(CustomName, TypeParametrizedTestWithNames, +INSTANTIATE_TYPED_TEST_SUITE_P(CustomName, TypeParametrizedTestWithNames, TwoTypes, TypeParametrizedTestNames); -// Tests that multiple TYPED_TEST_CASE_P's can be defined in the same +// Tests that multiple TYPED_TEST_SUITE_P's can be defined in the same // translation unit. template <typename T> class TypedTestP1 : public Test { }; -TYPED_TEST_CASE_P(TypedTestP1); +TYPED_TEST_SUITE_P(TypedTestP1); -// For testing that the code between TYPED_TEST_CASE_P() and +// For testing that the code between TYPED_TEST_SUITE_P() and // TYPED_TEST_P() is not enclosed in a namespace. -typedef int IntAfterTypedTestCaseP; +using IntAfterTypedTestSuiteP = int; TYPED_TEST_P(TypedTestP1, A) {} TYPED_TEST_P(TypedTestP1, B) {} // For testing that the code between TYPED_TEST_P() and -// REGISTER_TYPED_TEST_CASE_P() is not enclosed in a namespace. -typedef int IntBeforeRegisterTypedTestCaseP; +// REGISTER_TYPED_TEST_SUITE_P() is not enclosed in a namespace. +using IntBeforeRegisterTypedTestSuiteP = int; -REGISTER_TYPED_TEST_CASE_P(TypedTestP1, A, B); +REGISTER_TYPED_TEST_SUITE_P(TypedTestP1, A, B); template <typename T> class TypedTestP2 : public Test { }; -TYPED_TEST_CASE_P(TypedTestP2); +TYPED_TEST_SUITE_P(TypedTestP2); // This also verifies that tests from different type-parameterized // test cases can share the same name. TYPED_TEST_P(TypedTestP2, A) {} -REGISTER_TYPED_TEST_CASE_P(TypedTestP2, A); +REGISTER_TYPED_TEST_SUITE_P(TypedTestP2, A); -// Verifies that the code between TYPED_TEST_CASE_P() and -// REGISTER_TYPED_TEST_CASE_P() is not enclosed in a namespace. -IntAfterTypedTestCaseP after = 0; -IntBeforeRegisterTypedTestCaseP before = 0; +// Verifies that the code between TYPED_TEST_SUITE_P() and +// REGISTER_TYPED_TEST_SUITE_P() is not enclosed in a namespace. +IntAfterTypedTestSuiteP after = 0; +IntBeforeRegisterTypedTestSuiteP before = 0; -// Verifies that the last argument of INSTANTIATE_TYPED_TEST_CASE_P() +// Verifies that the last argument of INSTANTIATE_TYPED_TEST_SUITE_P() // can be either a single type or a Types<...> type list. -INSTANTIATE_TYPED_TEST_CASE_P(Int, TypedTestP1, int); -INSTANTIATE_TYPED_TEST_CASE_P(Int, TypedTestP2, Types<int>); +INSTANTIATE_TYPED_TEST_SUITE_P(Int, TypedTestP1, int); +INSTANTIATE_TYPED_TEST_SUITE_P(Int, TypedTestP2, Types<int>); // Tests that the same type-parameterized test case can be // instantiated more than once in the same translation unit. -INSTANTIATE_TYPED_TEST_CASE_P(Double, TypedTestP2, Types<double>); +INSTANTIATE_TYPED_TEST_SUITE_P(Double, TypedTestP2, Types<double>); // Tests that the same type-parameterized test case can be // instantiated in different translation units linked together. // (ContainerTest is also instantiated in gtest-typed-test_test.cc.) typedef Types<std::vector<double>, std::set<char> > MyContainers; -INSTANTIATE_TYPED_TEST_CASE_P(My, ContainerTest, MyContainers); +INSTANTIATE_TYPED_TEST_SUITE_P(My, ContainerTest, MyContainers); // Tests that a type-parameterized test case can be defined and // instantiated in a namespace. @@ -406,7 +407,7 @@ template <typename T> class NumericTest : public Test { }; -TYPED_TEST_CASE_P(NumericTest); +TYPED_TEST_SUITE_P(NumericTest); TYPED_TEST_P(NumericTest, DefaultIsZero) { EXPECT_EQ(0, TypeParam()); @@ -416,29 +417,29 @@ TYPED_TEST_P(NumericTest, ZeroIsLessThanOne) { EXPECT_LT(TypeParam(0), TypeParam(1)); } -REGISTER_TYPED_TEST_CASE_P(NumericTest, +REGISTER_TYPED_TEST_SUITE_P(NumericTest, DefaultIsZero, ZeroIsLessThanOne); typedef Types<int, double> NumericTypes; -INSTANTIATE_TYPED_TEST_CASE_P(My, NumericTest, NumericTypes); +INSTANTIATE_TYPED_TEST_SUITE_P(My, NumericTest, NumericTypes); static const char* GetTestName() { return testing::UnitTest::GetInstance()->current_test_info()->name(); } // Test the stripping of space from test names template <typename T> class TrimmedTest : public Test { }; -TYPED_TEST_CASE_P(TrimmedTest); +TYPED_TEST_SUITE_P(TrimmedTest); TYPED_TEST_P(TrimmedTest, Test1) { EXPECT_STREQ("Test1", GetTestName()); } TYPED_TEST_P(TrimmedTest, Test2) { EXPECT_STREQ("Test2", GetTestName()); } TYPED_TEST_P(TrimmedTest, Test3) { EXPECT_STREQ("Test3", GetTestName()); } TYPED_TEST_P(TrimmedTest, Test4) { EXPECT_STREQ("Test4", GetTestName()); } TYPED_TEST_P(TrimmedTest, Test5) { EXPECT_STREQ("Test5", GetTestName()); } -REGISTER_TYPED_TEST_CASE_P( +REGISTER_TYPED_TEST_SUITE_P( TrimmedTest, Test1, Test2,Test3 , Test4 ,Test5 ); // NOLINT template <typename T1, typename T2> struct MyPair {}; // 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; -INSTANTIATE_TYPED_TEST_CASE_P(My, TrimmedTest, TrimTypes); +INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes); } // namespace library2 |