gtest-printers.h (googletest-release-1.11.0) | : | gtest-printers.h (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 97 | skipping to change at line 97 | |||
// using the compiler-inferred type of *iter where iter is a | // using the compiler-inferred type of *iter where iter is a | |||
// const_iterator of the container. When const_iterator is an input | // const_iterator of the container. When const_iterator is an input | |||
// iterator but not a forward iterator, this inferred type may not | // iterator but not a forward iterator, this inferred type may not | |||
// match value_type, and the print output may be incorrect. In | // match value_type, and the print output may be incorrect. In | |||
// practice, this is rarely a problem as for most containers | // practice, this is rarely a problem as for most containers | |||
// const_iterator is a forward iterator. We'll fix this if there's an | // const_iterator is a forward iterator. We'll fix this if there's an | |||
// actual need for it. Note that this fix cannot rely on value_type | // actual need for it. Note that this fix cannot rely on value_type | |||
// being defined as many user-defined container types don't have | // being defined as many user-defined container types don't have | |||
// value_type. | // value_type. | |||
// GOOGLETEST_CM0001 DO NOT DELETE | // IWYU pragma: private, include "gtest/gtest.h" | |||
// IWYU pragma: friend gtest/.* | ||||
// IWYU pragma: friend gmock/.* | ||||
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ | |||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ | #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ | |||
#include <functional> | #include <functional> | |||
#include <memory> | #include <memory> | |||
#include <ostream> // NOLINT | #include <ostream> // NOLINT | |||
#include <sstream> | #include <sstream> | |||
#include <string> | #include <string> | |||
#include <tuple> | #include <tuple> | |||
skipping to change at line 262 | skipping to change at line 264 | |||
#if GTEST_INTERNAL_HAS_STRING_VIEW | #if GTEST_INTERNAL_HAS_STRING_VIEW | |||
static void PrintValue(internal::StringView value, ::std::ostream* os) { | static void PrintValue(internal::StringView value, ::std::ostream* os) { | |||
internal::UniversalPrint(value, os); | internal::UniversalPrint(value, os); | |||
} | } | |||
#endif | #endif | |||
}; | }; | |||
// Prints the given number of bytes in the given object to the given | // Prints the given number of bytes in the given object to the given | |||
// ostream. | // ostream. | |||
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 RawBytesPrinter { | struct RawBytesPrinter { | |||
// SFINAE on `sizeof` to make sure we have a complete type. | // SFINAE on `sizeof` to make sure we have a complete type. | |||
template <typename T, size_t = sizeof(T)> | 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*>( | static_cast<const unsigned char*>( | |||
// Load bearing cast to void* to support iOS | // Load bearing cast to void* to support iOS | |||
reinterpret_cast<const void*>(std::addressof(value))), | reinterpret_cast<const void*>(std::addressof(value))), | |||
sizeof(value), os); | sizeof(value), os); | |||
} | } | |||
skipping to change at line 361 | skipping to change at line 362 | |||
public: \ | public: \ | |||
static ::std::string Format(CharType* value) { \ | static ::std::string Format(CharType* value) { \ | |||
return ::testing::PrintToString(static_cast<const void*>(value)); \ | return ::testing::PrintToString(static_cast<const void*>(value)); \ | |||
} \ | } \ | |||
} | } | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); | |||
#ifdef __cpp_char8_t | #ifdef __cpp_lib_char8_t | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char8_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char8_t); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char8_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char8_t); | |||
#endif | #endif | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char16_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char16_t); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char16_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char16_t); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char32_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char32_t); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); | GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); | |||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ | #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ | |||
// If a C string is compared with an STL string object, we know it's meant | // If a C string is compared with an STL string object, we know it's meant | |||
// to point to a NUL-terminated string, and thus can print it as a string. | // to point to a NUL-terminated string, and thus can print it as a string. | |||
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ | #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ | |||
template <> \ | template <> \ | |||
class FormatForComparison<CharType*, OtherStringType> { \ | class FormatForComparison<CharType*, OtherStringType> { \ | |||
public: \ | public: \ | |||
static ::std::string Format(CharType* value) { \ | static ::std::string Format(CharType* value) { \ | |||
return ::testing::PrintToString(value); \ | return ::testing::PrintToString(value); \ | |||
} \ | } \ | |||
} | } | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); | |||
#ifdef __cpp_char8_t | #ifdef __cpp_char8_t | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); | |||
#endif | #endif | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char16_t, ::std::u16string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char16_t, ::std::u16string); | |||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char16_t, ::std::u16string); | GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char16_t, ::std::u16string); | |||
skipping to change at line 411 | skipping to change at line 412 | |||
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) | // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) | |||
// operand to be used in a failure message. The type (but not value) | // operand to be used in a failure message. The type (but not value) | |||
// of the other operand may affect the format. This allows us to | // of the other operand may affect the format. This allows us to | |||
// print a char* as a raw pointer when it is compared against another | // print a char* as a raw pointer when it is compared against another | |||
// char* or void*, and print it as a C string when it is compared | // char* or void*, and print it as a C string when it is compared | |||
// against an std::string object, for example. | // against an std::string object, for example. | |||
// | // | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | |||
template <typename T1, typename T2> | template <typename T1, typename T2> | |||
std::string FormatForComparisonFailureMessage( | std::string FormatForComparisonFailureMessage(const T1& value, | |||
const T1& value, const T2& /* other_operand */) { | const T2& /* other_operand */) { | |||
return FormatForComparison<T1, T2>::Format(value); | return FormatForComparison<T1, T2>::Format(value); | |||
} | } | |||
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given | // UniversalPrinter<T>::Print(value, ostream_ptr) prints the given | |||
// value to the given ostream. The caller must ensure that | // value to the given ostream. The caller must ensure that | |||
// 'ostream_ptr' is not NULL, or the behavior is undefined. | // 'ostream_ptr' is not NULL, or the behavior is undefined. | |||
// | // | |||
// We define UniversalPrinter as a class template (as opposed to a | // We define UniversalPrinter as a class template (as opposed to a | |||
// function template), as we need to partially specialize it for | // function template), as we need to partially specialize it for | |||
// reference types, which cannot be done with function templates. | // reference types, which cannot be done with function templates. | |||
skipping to change at line 480 | skipping to change at line 481 | |||
GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); | GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); | |||
inline void PrintTo(char16_t c, ::std::ostream* os) { | inline void PrintTo(char16_t c, ::std::ostream* os) { | |||
PrintTo(ImplicitCast_<char32_t>(c), os); | PrintTo(ImplicitCast_<char32_t>(c), os); | |||
} | } | |||
#ifdef __cpp_char8_t | #ifdef __cpp_char8_t | |||
inline void PrintTo(char8_t c, ::std::ostream* os) { | inline void PrintTo(char8_t c, ::std::ostream* os) { | |||
PrintTo(ImplicitCast_<char32_t>(c), os); | PrintTo(ImplicitCast_<char32_t>(c), os); | |||
} | } | |||
#endif | #endif | |||
// gcc/clang __{u,}int128_t | ||||
#if defined(__SIZEOF_INT128__) | ||||
GTEST_API_ void PrintTo(__uint128_t v, ::std::ostream* os); | ||||
GTEST_API_ void PrintTo(__int128_t v, ::std::ostream* os); | ||||
#endif // __SIZEOF_INT128__ | ||||
// Overloads for C strings. | // Overloads for C strings. | |||
GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); | GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); | |||
inline void PrintTo(char* s, ::std::ostream* os) { | inline void PrintTo(char* s, ::std::ostream* os) { | |||
PrintTo(ImplicitCast_<const char*>(s), os); | PrintTo(ImplicitCast_<const char*>(s), os); | |||
} | } | |||
// signed/unsigned char is often used for representing binary data, so | // signed/unsigned char is often used for representing binary data, so | |||
// we print pointers to it as void* to be safe. | // we print pointers to it as void* to be safe. | |||
inline void PrintTo(const signed char* s, ::std::ostream* os) { | inline void PrintTo(const signed char* s, ::std::ostream* os) { | |||
PrintTo(ImplicitCast_<const void*>(s), os); | PrintTo(ImplicitCast_<const void*>(s), os); | |||
skipping to change at line 546 | skipping to change at line 553 | |||
template <typename T> | template <typename T> | |||
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { | void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { | |||
UniversalPrint(a[0], os); | UniversalPrint(a[0], os); | |||
for (size_t i = 1; i != count; i++) { | for (size_t i = 1; i != count; i++) { | |||
*os << ", "; | *os << ", "; | |||
UniversalPrint(a[i], os); | UniversalPrint(a[i], os); | |||
} | } | |||
} | } | |||
// Overloads for ::std::string. | // Overloads for ::std::string. | |||
GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os); | GTEST_API_ void PrintStringTo(const ::std::string& s, ::std::ostream* os); | |||
inline void PrintTo(const ::std::string& s, ::std::ostream* os) { | inline void PrintTo(const ::std::string& s, ::std::ostream* os) { | |||
PrintStringTo(s, os); | PrintStringTo(s, os); | |||
} | } | |||
// Overloads for ::std::u8string | // Overloads for ::std::u8string | |||
#ifdef __cpp_char8_t | #ifdef __cpp_char8_t | |||
GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); | GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); | |||
inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { | inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { | |||
PrintU8StringTo(s, os); | PrintU8StringTo(s, os); | |||
} | } | |||
skipping to change at line 573 | skipping to change at line 580 | |||
} | } | |||
// Overloads for ::std::u32string | // Overloads for ::std::u32string | |||
GTEST_API_ void PrintU32StringTo(const ::std::u32string& s, ::std::ostream* os); | GTEST_API_ void PrintU32StringTo(const ::std::u32string& s, ::std::ostream* os); | |||
inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { | inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { | |||
PrintU32StringTo(s, os); | PrintU32StringTo(s, os); | |||
} | } | |||
// Overloads for ::std::wstring. | // Overloads for ::std::wstring. | |||
#if GTEST_HAS_STD_WSTRING | #if GTEST_HAS_STD_WSTRING | |||
GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); | GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os); | |||
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { | inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { | |||
PrintWideStringTo(s, os); | PrintWideStringTo(s, os); | |||
} | } | |||
#endif // GTEST_HAS_STD_WSTRING | #endif // GTEST_HAS_STD_WSTRING | |||
#if GTEST_INTERNAL_HAS_STRING_VIEW | #if GTEST_INTERNAL_HAS_STRING_VIEW | |||
// Overload for internal::StringView. | // Overload for internal::StringView. | |||
inline void PrintTo(internal::StringView sp, ::std::ostream* os) { | inline void PrintTo(internal::StringView sp, ::std::ostream* os) { | |||
PrintTo(::std::string(sp), os); | PrintTo(::std::string(sp), os); | |||
} | } | |||
#endif // GTEST_INTERNAL_HAS_STRING_VIEW | #endif // GTEST_INTERNAL_HAS_STRING_VIEW | |||
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } | inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } | |||
#if GTEST_HAS_RTTI | ||||
inline void PrintTo(const std::type_info& info, std::ostream* os) { | ||||
*os << internal::GetTypeName(info); | ||||
} | ||||
#endif // GTEST_HAS_RTTI | ||||
template <typename T> | template <typename T> | |||
void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) { | void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) { | |||
UniversalPrinter<T&>::Print(ref.get(), os); | UniversalPrinter<T&>::Print(ref.get(), os); | |||
} | } | |||
inline const void* VoidifyPointer(const void* p) { return p; } | inline const void* VoidifyPointer(const void* p) { return p; } | |||
inline const void* VoidifyPointer(volatile const void* p) { | inline const void* VoidifyPointer(volatile const void* p) { | |||
return const_cast<const void*>(p); | return const_cast<const void*>(p); | |||
} | } | |||
skipping to change at line 745 | skipping to change at line 758 | |||
*os << '('; | *os << '('; | |||
if (!value) { | if (!value) { | |||
*os << "nullopt"; | *os << "nullopt"; | |||
} else { | } else { | |||
UniversalPrint(*value, os); | UniversalPrint(*value, os); | |||
} | } | |||
*os << ')'; | *os << ')'; | |||
} | } | |||
}; | }; | |||
template <> | ||||
class UniversalPrinter<decltype(Nullopt())> { | ||||
public: | ||||
static void Print(decltype(Nullopt()), ::std::ostream* os) { | ||||
*os << "(nullopt)"; | ||||
} | ||||
}; | ||||
#endif // GTEST_INTERNAL_HAS_OPTIONAL | #endif // GTEST_INTERNAL_HAS_OPTIONAL | |||
#if GTEST_INTERNAL_HAS_VARIANT | #if GTEST_INTERNAL_HAS_VARIANT | |||
// Printer for std::variant / absl::variant | // Printer for std::variant / absl::variant | |||
template <typename... T> | template <typename... T> | |||
class UniversalPrinter<Variant<T...>> { | class UniversalPrinter<Variant<T...>> { | |||
public: | public: | |||
static void Print(const Variant<T...>& value, ::std::ostream* os) { | static void Print(const Variant<T...>& value, ::std::ostream* os) { | |||
skipping to change at line 803 | skipping to change at line 824 | |||
PrintRawArrayTo(begin, len, os); | PrintRawArrayTo(begin, len, os); | |||
} else { | } else { | |||
PrintRawArrayTo(begin, kChunkSize, os); | PrintRawArrayTo(begin, kChunkSize, os); | |||
*os << ", ..., "; | *os << ", ..., "; | |||
PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os); | PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os); | |||
} | } | |||
*os << " }"; | *os << " }"; | |||
} | } | |||
} | } | |||
// This overload prints a (const) char array compactly. | // This overload prints a (const) char array compactly. | |||
GTEST_API_ void UniversalPrintArray( | GTEST_API_ void UniversalPrintArray(const char* begin, size_t len, | |||
const char* begin, size_t len, ::std::ostream* os); | ::std::ostream* os); | |||
#ifdef __cpp_char8_t | #ifdef __cpp_char8_t | |||
// This overload prints a (const) char8_t array compactly. | // This overload prints a (const) char8_t array compactly. | |||
GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, | GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, | |||
::std::ostream* os); | ::std::ostream* os); | |||
#endif | #endif | |||
// This overload prints a (const) char16_t array compactly. | // This overload prints a (const) char16_t array compactly. | |||
GTEST_API_ void UniversalPrintArray(const char16_t* begin, size_t len, | GTEST_API_ void UniversalPrintArray(const char16_t* begin, size_t len, | |||
::std::ostream* os); | ::std::ostream* os); | |||
// This overload prints a (const) char32_t array compactly. | // This overload prints a (const) char32_t array compactly. | |||
GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len, | GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len, | |||
::std::ostream* os); | ::std::ostream* os); | |||
// This overload prints a (const) wchar_t array compactly. | // This overload prints a (const) wchar_t array compactly. | |||
GTEST_API_ void UniversalPrintArray( | GTEST_API_ void UniversalPrintArray(const wchar_t* begin, size_t len, | |||
const wchar_t* begin, size_t len, ::std::ostream* os); | ::std::ostream* os); | |||
// Implements printing an array type T[N]. | // Implements printing an array type T[N]. | |||
template <typename T, size_t N> | template <typename T, size_t N> | |||
class UniversalPrinter<T[N]> { | class UniversalPrinter<T[N]> { | |||
public: | public: | |||
// Prints the given array, omitting some elements when there are too | // Prints the given array, omitting some elements when there are too | |||
// many. | // many. | |||
static void Print(const T (&a)[N], ::std::ostream* os) { | static void Print(const T (&a)[N], ::std::ostream* os) { | |||
UniversalPrintArray(a, N, os); | UniversalPrintArray(a, N, os); | |||
} | } | |||
skipping to change at line 981 | skipping to change at line 1002 | |||
// (const) char pointer, this prints both the pointer and the | // (const) char pointer, this prints both the pointer and the | |||
// NUL-terminated string. | // NUL-terminated string. | |||
template <typename T> | template <typename T> | |||
void UniversalPrint(const T& value, ::std::ostream* os) { | void UniversalPrint(const T& value, ::std::ostream* os) { | |||
// A workarond for the bug in VC++ 7.1 that prevents us from instantiating | // A workarond for the bug in VC++ 7.1 that prevents us from instantiating | |||
// UniversalPrinter with T directly. | // UniversalPrinter with T directly. | |||
typedef T T1; | typedef T T1; | |||
UniversalPrinter<T1>::Print(value, os); | UniversalPrinter<T1>::Print(value, os); | |||
} | } | |||
typedef ::std::vector< ::std::string> Strings; | typedef ::std::vector<::std::string> Strings; | |||
// Tersely prints the first N fields of a tuple to a string vector, | // Tersely prints the first N fields of a tuple to a string vector, | |||
// one element for each field. | // one element for each field. | |||
template <typename Tuple> | template <typename Tuple> | |||
void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>, | void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>, | |||
Strings*) {} | Strings*) {} | |||
template <typename Tuple, size_t I> | template <typename Tuple, size_t I> | |||
void TersePrintPrefixToStrings(const Tuple& t, | void TersePrintPrefixToStrings(const Tuple& t, | |||
std::integral_constant<size_t, I>, | std::integral_constant<size_t, I>, | |||
Strings* strings) { | Strings* strings) { | |||
TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(), | TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(), | |||
strings); | strings); | |||
::std::stringstream ss; | ::std::stringstream ss; | |||
End of changes. 14 change blocks. | ||||
21 lines changed or deleted | 42 lines changed or added |