Index: ext/googletest/googletest/test/gtest-typed-test_test.cc =================================================================== diff -u -r4a481bbe77043e0bda2435c6d62a02700b3e46c5 -r2e4eacb299f21d06196fe13140b4b0d095abdca9 --- ext/googletest/googletest/test/gtest-typed-test_test.cc (.../gtest-typed-test_test.cc) (revision 4a481bbe77043e0bda2435c6d62a02700b3e46c5) +++ ext/googletest/googletest/test/gtest-typed-test_test.cc (.../gtest-typed-test_test.cc) (revision 2e4eacb299f21d06196fe13140b4b0d095abdca9) @@ -26,16 +26,19 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + #include "test/gtest-typed-test_test.h" #include #include #include "gtest/gtest.h" +#if _MSC_VER +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */) +#endif // _MSC_VER + using testing::Test; // Used for testing that SetUpTestCase()/TearDownTestCase(), fixture @@ -166,6 +169,40 @@ } // namespace library1 +// Tests that custom names work. +template +class TypedTestWithNames : public Test {}; + +class TypedTestNames { + public: + template + static std::string GetName(int i) { + if (testing::internal::IsSame::value) { + return std::string("char") + ::testing::PrintToString(i); + } + if (testing::internal::IsSame::value) { + return std::string("int") + ::testing::PrintToString(i); + } + } +}; + +TYPED_TEST_CASE(TypedTestWithNames, TwoTypes, TypedTestNames); + +TYPED_TEST(TypedTestWithNames, TestCaseName) { + if (testing::internal::IsSame::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "TypedTestWithNames/char0"); + } + if (testing::internal::IsSame::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "TypedTestWithNames/int1"); + } +} + #endif // GTEST_HAS_TYPED_TEST // This #ifdef block tests type-parameterized tests. @@ -266,6 +303,46 @@ typedef Types MyTwoTypes; INSTANTIATE_TYPED_TEST_CASE_P(My, DerivedTest, MyTwoTypes); +// Tests that custom names work with type parametrized tests. We reuse the +// TwoTypes from above here. +template +class TypeParametrizedTestWithNames : public Test {}; + +TYPED_TEST_CASE_P(TypeParametrizedTestWithNames); + +TYPED_TEST_P(TypeParametrizedTestWithNames, TestCaseName) { + if (testing::internal::IsSame::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "CustomName/TypeParametrizedTestWithNames/parChar0"); + } + if (testing::internal::IsSame::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "CustomName/TypeParametrizedTestWithNames/parInt1"); + } +} + +REGISTER_TYPED_TEST_CASE_P(TypeParametrizedTestWithNames, TestCaseName); + +class TypeParametrizedTestNames { + public: + template + static std::string GetName(int i) { + if (testing::internal::IsSame::value) { + return std::string("parChar") + ::testing::PrintToString(i); + } + if (testing::internal::IsSame::value) { + return std::string("parInt") + ::testing::PrintToString(i); + } + } +}; + +INSTANTIATE_TYPED_TEST_CASE_P(CustomName, TypeParametrizedTestWithNames, + TwoTypes, TypeParametrizedTestNames); + // Tests that multiple TYPED_TEST_CASE_P's can be defined in the same // translation unit. @@ -377,4 +454,8 @@ // 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)