Googletest export
Fix #2987 Removing const before passing any types through UniversalPrinter. PiperOrigin-RevId: 356508875
This commit is contained in:
parent
9c2293af06
commit
af058521ad
@ -677,6 +677,10 @@ class UniversalPrinter {
|
|||||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Remove any const-qualifiers before passing a type to UniversalPrinter.
|
||||||
|
template <typename T>
|
||||||
|
class UniversalPrinter<const T> : public UniversalPrinter<T> {};
|
||||||
|
|
||||||
#if GTEST_INTERNAL_HAS_ANY
|
#if GTEST_INTERNAL_HAS_ANY
|
||||||
|
|
||||||
// Printer for std::any / absl::any
|
// Printer for std::any / absl::any
|
||||||
|
@ -229,6 +229,33 @@ class PathLike {
|
|||||||
} // namespace foo
|
} // namespace foo
|
||||||
|
|
||||||
namespace testing {
|
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 {
|
namespace gtest_printers_test {
|
||||||
|
|
||||||
using ::std::deque;
|
using ::std::deque;
|
||||||
@ -1667,6 +1694,13 @@ TEST(UniversalPrintTest, WorksForReference) {
|
|||||||
EXPECT_EQ("123", ss.str());
|
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) {
|
TEST(UniversalPrintTest, WorksForCString) {
|
||||||
const char* s1 = "abc";
|
const char* s1 = "abc";
|
||||||
::std::stringstream ss1;
|
::std::stringstream ss1;
|
||||||
|
Loading…
Reference in New Issue
Block a user