summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorGennadiy Civil <gennadiycivil@users.noreply.github.com>2018-05-22 13:01:05 (GMT)
committerGitHub <noreply@github.com>2018-05-22 13:01:05 (GMT)
commit32c84be0fc3a417a938ce93275461f2cf960ef1c (patch)
tree1e44c78c0653048fc4847f1ab424f4af7b20e67c /googletest
parentf91bf75cf97f70cfc3814bd12cc7d505c62269e2 (diff)
parent8276dbae6fb1016cf9829f2e790fade17967a6d4 (diff)
downloadgoogletest-32c84be0fc3a417a938ce93275461f2cf960ef1c.zip
googletest-32c84be0fc3a417a938ce93275461f2cf960ef1c.tar.gz
googletest-32c84be0fc3a417a938ce93275461f2cf960ef1c.tar.bz2
Merge branch 'master' into unused-variable-fuchsiarefs/pull/1603/head
Diffstat (limited to 'googletest')
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h18
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h.pump18
-rw-r--r--googletest/test/gtest_unittest.cc25
3 files changed, 59 insertions, 2 deletions
diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h
index e46f7cf..d778131 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h
+++ b/googletest/include/gtest/internal/gtest-type-util.h
@@ -56,6 +56,22 @@
namespace testing {
namespace internal {
+
+// Canonicalizes a given name with respect to the Standard C++ Library.
+// This handles removing the inline namespace within `std` that is
+// used by various standard libraries (e.g., `std::__1`). Names outside
+// of namespace std are returned unmodified.
+inline std::string CanonicalizeForStdLibVersioning(std::string s) {
+ static const char prefix[] = "std::__";
+ if (s.compare(0, strlen(prefix), prefix) == 0) {
+ std::string::size_type end = s.find("::", strlen(prefix));
+ if (end != s.npos) {
+ // Erase everything between the initial `std` and the second `::`.
+ s.erase(strlen("std"), end - strlen("std"));
+ }
+ }
+ return s;
+}
// GetTypeName<T>() returns a human-readable name of type T.
// NB: This function is also used in Google Mock, so don't move it inside of
@@ -75,7 +91,7 @@ std::string GetTypeName() {
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const std::string name_str(status == 0 ? readable_name : name);
free(readable_name);
- return name_str;
+ return CanonicalizeForStdLibVersioning(name_str);
# else
return name;
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
diff --git a/googletest/include/gtest/internal/gtest-type-util.h.pump b/googletest/include/gtest/internal/gtest-type-util.h.pump
index 251fdf0..eb4df2c 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h.pump
+++ b/googletest/include/gtest/internal/gtest-type-util.h.pump
@@ -54,6 +54,22 @@ $var n = 50 $$ Maximum length of type lists we want to support.
namespace testing {
namespace internal {
+
+// Canonicalizes a given name with respect to the Standard C++ Library.
+// This handles removing the inline namespace within `std` that is
+// used by various standard libraries (e.g., `std::__1`). Names outside
+// of namespace std are returned unmodified.
+inline std::string CanonicalizeForStdLibVersioning(std::string s) {
+ static const char prefix[] = "std::__";
+ if (s.compare(0, strlen(prefix), prefix) == 0) {
+ std::string::size_type end = s.find("::", strlen(prefix));
+ if (end != s.npos) {
+ // Erase everything between the initial `std` and the second `::`.
+ s.erase(strlen("std"), end - strlen("std"));
+ }
+ }
+ return s;
+}
// GetTypeName<T>() returns a human-readable name of type T.
// NB: This function is also used in Google Mock, so don't move it inside of
@@ -73,7 +89,7 @@ std::string GetTypeName() {
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const std::string name_str(status == 0 ? readable_name : name);
free(readable_name);
- return name_str;
+ return CanonicalizeForStdLibVersioning(name_str);
# else
return name;
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 8dc8932..662a8ab 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -380,6 +380,31 @@ TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
EXPECT_EQ(kTestTypeIdInGoogleTest, GetTestTypeId());
}
+// Tests CanonicalizeForStdLibVersioning.
+
+using ::testing::internal::CanonicalizeForStdLibVersioning;
+
+TEST(CanonicalizeForStdLibVersioning, LeavesUnversionedNamesUnchanged) {
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::_"));
+ EXPECT_EQ("std::__foo", CanonicalizeForStdLibVersioning("std::__foo"));
+ EXPECT_EQ("gtl::__1::x", CanonicalizeForStdLibVersioning("gtl::__1::x"));
+ EXPECT_EQ("__1::x", CanonicalizeForStdLibVersioning("__1::x"));
+ EXPECT_EQ("::__1::x", CanonicalizeForStdLibVersioning("::__1::x"));
+}
+
+TEST(CanonicalizeForStdLibVersioning, ElidesDoubleUnderNames) {
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__1::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__1::_"));
+
+ EXPECT_EQ("std::bind", CanonicalizeForStdLibVersioning("std::__g::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__g::_"));
+
+ EXPECT_EQ("std::bind",
+ CanonicalizeForStdLibVersioning("std::__google::bind"));
+ EXPECT_EQ("std::_", CanonicalizeForStdLibVersioning("std::__google::_"));
+}
+
// Tests FormatTimeInMillisAsSeconds().
TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {