summaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2021-02-09 16:37:05 (GMT)
committerAndy Soffer <asoffer@google.com>2021-02-11 17:49:00 (GMT)
commitaf058521adb3a12c0e2d69a219f81a133b244ee6 (patch)
tree5f357d380ec69b59575cc643312c270fd1c13ad9 /googletest/test
parent9c2293af064504f1a7296a2397211be8809452d9 (diff)
downloadgoogletest-af058521adb3a12c0e2d69a219f81a133b244ee6.zip
googletest-af058521adb3a12c0e2d69a219f81a133b244ee6.tar.gz
googletest-af058521adb3a12c0e2d69a219f81a133b244ee6.tar.bz2
Googletest export
Fix #2987 Removing const before passing any types through UniversalPrinter. PiperOrigin-RevId: 356508875
Diffstat (limited to 'googletest/test')
-rw-r--r--googletest/test/googletest-printers-test.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index 0653d9e..8247d4e 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -229,6 +229,33 @@ class PathLike {
} // namespace foo
namespace testing {
+namespace {
+template <typename T>
+class Wrapper {
+ public:
+ explicit Wrapper(T&& value) : value_(std::forward<T>(value)) {}
+
+ const T& value() const { return value_; }
+
+ private:
+ T value_;
+};
+
+} // namespace
+
+namespace internal {
+template <typename T>
+class UniversalPrinter<Wrapper<T>> {
+ public:
+ static void Print(const Wrapper<T>& w, ::std::ostream* os) {
+ *os << "Wrapper(";
+ UniversalPrint(w.value(), os);
+ *os << ')';
+ }
+};
+} // namespace internal
+
+
namespace gtest_printers_test {
using ::std::deque;
@@ -1667,6 +1694,13 @@ TEST(UniversalPrintTest, WorksForReference) {
EXPECT_EQ("123", ss.str());
}
+TEST(UniversalPrintTest, WorksForPairWithConst) {
+ std::pair<const Wrapper<std::string>, int> p(Wrapper<std::string>("abc"), 1);
+ ::std::stringstream ss;
+ UniversalPrint(p, &ss);
+ EXPECT_EQ("(Wrapper(\"abc\"), 1)", ss.str());
+}
+
TEST(UniversalPrintTest, WorksForCString) {
const char* s1 = "abc";
::std::stringstream ss1;