"git@developer.sourcefind.cn:yangql/googletest.git" did not exist on "35956659eaaafd4b356acfbabcb48c183d957ff4"
Commit f8304d76 authored by Abseil Team's avatar Abseil Team Committed by Derek Mauro
Browse files

Googletest export

Add support for printing incomplete types in the universal printer.

PiperOrigin-RevId: 350154637
parent 95a9bdd9
...@@ -261,16 +261,23 @@ struct ConvertibleToStringViewPrinter { ...@@ -261,16 +261,23 @@ struct ConvertibleToStringViewPrinter {
GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
size_t count, size_t count,
::std::ostream* os); ::std::ostream* os);
struct FallbackPrinter { struct RawBytesPrinter {
template <typename T> // SFINAE on `sizeof` to make sure we have a complete type.
template <typename T, size_t = sizeof(T)>
static void PrintValue(const T& value, ::std::ostream* os) { static void PrintValue(const T& value, ::std::ostream* os) {
PrintBytesInObjectTo( PrintBytesInObjectTo(
static_cast<const unsigned char*>( reinterpret_cast<const unsigned char*>(std::addressof(value)),
reinterpret_cast<const void*>(std::addressof(value))),
sizeof(value), os); sizeof(value), os);
} }
}; };
struct FallbackPrinter {
template <typename T>
static void PrintValue(const T&, ::std::ostream* os) {
*os << "(incomplete type)";
}
};
// Try every printer in order and return the first one that works. // Try every printer in order and return the first one that works.
template <typename T, typename E, typename Printer, typename... Printers> template <typename T, typename E, typename Printer, typename... Printers>
struct FindFirstPrinter : FindFirstPrinter<T, E, Printers...> {}; struct FindFirstPrinter : FindFirstPrinter<T, E, Printers...> {};
...@@ -297,7 +304,7 @@ void PrintWithFallback(const T& value, ::std::ostream* os) { ...@@ -297,7 +304,7 @@ void PrintWithFallback(const T& value, ::std::ostream* os) {
T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter,
internal_stream_operator_without_lexical_name_lookup::StreamPrinter, internal_stream_operator_without_lexical_name_lookup::StreamPrinter,
ProtobufPrinter, ConvertibleToIntegerPrinter, ProtobufPrinter, ConvertibleToIntegerPrinter,
ConvertibleToStringViewPrinter, FallbackPrinter>::type; ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type;
Printer::PrintValue(value, os); Printer::PrintValue(value, os);
} }
......
...@@ -1695,6 +1695,13 @@ TEST(UniversalPrintTest, WorksForCharArray) { ...@@ -1695,6 +1695,13 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str()); EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
} }
TEST(UniversalPrintTest, IncompleteType) {
struct Incomplete;
char some_object = 0;
EXPECT_EQ("(incomplete type)",
PrintToString(reinterpret_cast<Incomplete&>(some_object)));
}
TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) { TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple()); Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
EXPECT_EQ(0u, result.size()); EXPECT_EQ(0u, result.size());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment