aboutsummaryrefslogtreecommitdiffstats
path: root/googletest/test/googletest-output-test_.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-08-28 09:40:18 -0400
committerGennadiy Civil <misterg@google.com>2018-08-28 16:53:45 -0400
commit03867b5389516a0f185af52672cf5472fa0c159c (patch)
treefd9829743c961c67920d1eeb80ed7486148d63da /googletest/test/googletest-output-test_.cc
parent52f8183e7f3620cf03f321a2624eb0d4f7649f4c (diff)
downloadgoogletest-03867b5389516a0f185af52672cf5472fa0c159c.tar.gz
googletest-03867b5389516a0f185af52672cf5472fa0c159c.tar.bz2
googletest-03867b5389516a0f185af52672cf5472fa0c159c.zip
Googletest export
Add the possibility of specifying the name in type parameterized tests. Similar to how the last parameter of INSTANTIATE_TEST_CASE_P allows to override the name for (non-type) parametrized tests, this adds the possibility of adding a parameter to INSTANTIATE_TYPED_TEST_CASE_P. The argument has to be a class, which contains a static templated function GetName<T>(int), returning the name for type T. PiperOrigin-RevId: 210532231
Diffstat (limited to 'googletest/test/googletest-output-test_.cc')
-rw-r--r--googletest/test/googletest-output-test_.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc
index 3860cf45..d6f7e0ba 100644
--- a/googletest/test/googletest-output-test_.cc
+++ b/googletest/test/googletest-output-test_.cc
@@ -801,6 +801,28 @@ TYPED_TEST(TypedTest, Failure) {
EXPECT_EQ(1, TypeParam()) << "Expected failure";
}
+typedef testing::Types<char, int> TypesForTestWithNames;
+
+template <typename T>
+class TypedTestWithNames : public testing::Test {};
+
+class TypedTestNames {
+ public:
+ template <typename T>
+ static std::string GetName(int i) {
+ if (testing::internal::IsSame<T, char>::value)
+ return std::string("char_") + ::testing::PrintToString(i);
+ if (testing::internal::IsSame<T, int>::value)
+ return std::string("int_") + ::testing::PrintToString(i);
+ }
+};
+
+TYPED_TEST_CASE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames);
+
+TYPED_TEST(TypedTestWithNames, Success) {}
+
+TYPED_TEST(TypedTestWithNames, Failure) { FAIL(); }
+
#endif // GTEST_HAS_TYPED_TEST
// This #ifdef block tests the output of type-parameterized tests.
@@ -825,6 +847,22 @@ REGISTER_TYPED_TEST_CASE_P(TypedTestP, Success, Failure);
typedef testing::Types<unsigned char, unsigned int> UnsignedTypes;
INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes);
+class TypedTestPNames {
+ public:
+ template <typename T>
+ static std::string GetName(int i) {
+ if (testing::internal::IsSame<T, unsigned char>::value) {
+ return std::string("unsigned_char_") + ::testing::PrintToString(i);
+ }
+ if (testing::internal::IsSame<T, unsigned int>::value) {
+ return std::string("unsigned_int_") + ::testing::PrintToString(i);
+ }
+ }
+};
+
+INSTANTIATE_TYPED_TEST_CASE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
+ TypedTestPNames);
+
#endif // GTEST_HAS_TYPED_TEST_P
#if GTEST_HAS_DEATH_TEST