| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ |
| #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ |
|
|
| #include <functional> |
| #include <memory> |
| #include <ostream> |
| #include <sstream> |
| #include <string> |
| #include <tuple> |
| #include <type_traits> |
| #include <utility> |
| #include <vector> |
|
|
| #include "gtest/internal/gtest-internal.h" |
| #include "gtest/internal/gtest-port.h" |
|
|
| namespace testing { |
|
|
| |
| |
| namespace internal { |
|
|
| template <typename T> |
| void UniversalPrint(const T& value, ::std::ostream* os); |
|
|
| |
| |
| struct ContainerPrinter { |
| template <typename T, |
| typename = typename std::enable_if< |
| (sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) && |
| !IsRecursiveContainer<T>::value>::type> |
| static void PrintValue(const T& container, std::ostream* os) { |
| const size_t kMaxCount = 32; |
| *os << '{'; |
| size_t count = 0; |
| for (auto&& elem : container) { |
| if (count > 0) { |
| *os << ','; |
| if (count == kMaxCount) { |
| *os << " ..."; |
| break; |
| } |
| } |
| *os << ' '; |
| |
| |
| internal::UniversalPrint(elem, os); |
| ++count; |
| } |
|
|
| if (count > 0) { |
| *os << ' '; |
| } |
| *os << '}'; |
| } |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| struct FunctionPointerPrinter { |
| template <typename T, typename = typename std::enable_if< |
| std::is_function<T>::value>::type> |
| static void PrintValue(T* p, ::std::ostream* os) { |
| if (p == nullptr) { |
| *os << "NULL"; |
| } else { |
| |
| |
| |
| *os << reinterpret_cast<const void*>(p); |
| } |
| } |
| }; |
|
|
| struct PointerPrinter { |
| template <typename T> |
| static void PrintValue(T* p, ::std::ostream* os) { |
| if (p == nullptr) { |
| *os << "NULL"; |
| } else { |
| |
| |
| |
| *os << p; |
| } |
| } |
| }; |
|
|
| namespace internal_stream_operator_without_lexical_name_lookup { |
|
|
| |
| |
| |
| |
| struct LookupBlocker {}; |
| void operator<<(LookupBlocker, LookupBlocker); |
|
|
| struct StreamPrinter { |
| template <typename T, |
| |
| |
| typename = typename std::enable_if< |
| !std::is_member_pointer<T>::value>::type, |
| |
| |
| typename = decltype(std::declval<std::ostream&>() |
| << std::declval<const T&>())> |
| static void PrintValue(const T& value, ::std::ostream* os) { |
| |
| |
| *os << value; |
| } |
| }; |
|
|
| } |
|
|
| struct ProtobufPrinter { |
| |
| |
| |
| static const size_t kProtobufOneLinerMaxLength = 50; |
|
|
| template <typename T, |
| typename = typename std::enable_if< |
| internal::HasDebugStringAndShortDebugString<T>::value>::type> |
| static void PrintValue(const T& value, ::std::ostream* os) { |
| std::string pretty_str = value.ShortDebugString(); |
| if (pretty_str.length() > kProtobufOneLinerMaxLength) { |
| pretty_str = "\n" + value.DebugString(); |
| } |
| *os << ("<" + pretty_str + ">"); |
| } |
| }; |
|
|
| struct ConvertibleToIntegerPrinter { |
| |
| |
| |
| |
| |
| |
| |
| static void PrintValue(internal::BiggestInt value, ::std::ostream* os) { |
| *os << value; |
| } |
| }; |
|
|
| struct ConvertibleToStringViewPrinter { |
| #if GTEST_INTERNAL_HAS_STRING_VIEW |
| static void PrintValue(internal::StringView value, ::std::ostream* os) { |
| internal::UniversalPrint(value, os); |
| } |
| #endif |
| }; |
|
|
|
|
| |
| |
| GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, |
| size_t count, |
| ::std::ostream* os); |
| struct RawBytesPrinter { |
| |
| template <typename T, size_t = sizeof(T)> |
| static void PrintValue(const T& value, ::std::ostream* os) { |
| PrintBytesInObjectTo( |
| static_cast<const unsigned char*>( |
| |
| reinterpret_cast<const void*>(std::addressof(value))), |
| sizeof(value), os); |
| } |
| }; |
|
|
| struct FallbackPrinter { |
| template <typename T> |
| static void PrintValue(const T&, ::std::ostream* os) { |
| *os << "(incomplete type)"; |
| } |
| }; |
|
|
| |
| template <typename T, typename E, typename Printer, typename... Printers> |
| struct FindFirstPrinter : FindFirstPrinter<T, E, Printers...> {}; |
|
|
| template <typename T, typename Printer, typename... Printers> |
| struct FindFirstPrinter< |
| T, decltype(Printer::PrintValue(std::declval<const T&>(), nullptr)), |
| Printer, Printers...> { |
| using type = Printer; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename T> |
| void PrintWithFallback(const T& value, ::std::ostream* os) { |
| using Printer = typename FindFirstPrinter< |
| T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, |
| internal_stream_operator_without_lexical_name_lookup::StreamPrinter, |
| ProtobufPrinter, ConvertibleToIntegerPrinter, |
| ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; |
| Printer::PrintValue(value, os); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| template <typename ToPrint, typename OtherOperand> |
| class FormatForComparison { |
| public: |
| static ::std::string Format(const ToPrint& value) { |
| return ::testing::PrintToString(value); |
| } |
| }; |
|
|
| |
| template <typename ToPrint, size_t N, typename OtherOperand> |
| class FormatForComparison<ToPrint[N], OtherOperand> { |
| public: |
| static ::std::string Format(const ToPrint* value) { |
| return FormatForComparison<const ToPrint*, OtherOperand>::Format(value); |
| } |
| }; |
|
|
| |
| |
|
|
| #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \ |
| template <typename OtherOperand> \ |
| class FormatForComparison<CharType*, OtherOperand> { \ |
| public: \ |
| static ::std::string Format(CharType* value) { \ |
| return ::testing::PrintToString(static_cast<const void*>(value)); \ |
| } \ |
| } |
|
|
| GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(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_(const wchar_t); |
| #ifdef __cpp_char8_t |
| GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char8_t); |
| GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char8_t); |
| #endif |
| 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_(char32_t); |
| GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); |
|
|
| #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ |
|
|
| |
| |
|
|
| #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ |
| template <> \ |
| class FormatForComparison<CharType*, OtherStringType> { \ |
| public: \ |
| static ::std::string Format(CharType* value) { \ |
| return ::testing::PrintToString(value); \ |
| } \ |
| } |
|
|
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); |
| #ifdef __cpp_char8_t |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); |
| #endif |
| 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_(char32_t, ::std::u32string); |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char32_t, ::std::u32string); |
|
|
| #if GTEST_HAS_STD_WSTRING |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring); |
| GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring); |
| #endif |
|
|
| #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_ |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename T1, typename T2> |
| std::string FormatForComparisonFailureMessage( |
| const T1& value, const T2& ) { |
| return FormatForComparison<T1, T2>::Format(value); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| template <typename T> |
| class UniversalPrinter; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename T> |
| void PrintTo(const T& value, ::std::ostream* os) { |
| internal::PrintWithFallback(value, os); |
| } |
|
|
| |
| |
| |
|
|
| |
| GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os); |
| GTEST_API_ void PrintTo(signed char c, ::std::ostream* os); |
| inline void PrintTo(char c, ::std::ostream* os) { |
| |
| |
| |
| PrintTo(static_cast<unsigned char>(c), os); |
| } |
|
|
| |
| inline void PrintTo(bool x, ::std::ostream* os) { |
| *os << (x ? "true" : "false"); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os); |
|
|
| GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); |
| inline void PrintTo(char16_t c, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<char32_t>(c), os); |
| } |
| #ifdef __cpp_char8_t |
| inline void PrintTo(char8_t c, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<char32_t>(c), os); |
| } |
| #endif |
|
|
| |
| GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); |
| inline void PrintTo(char* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const char*>(s), os); |
| } |
|
|
| |
| |
| inline void PrintTo(const signed char* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const void*>(s), os); |
| } |
| inline void PrintTo(signed char* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const void*>(s), os); |
| } |
| inline void PrintTo(const unsigned char* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const void*>(s), os); |
| } |
| inline void PrintTo(unsigned char* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const void*>(s), os); |
| } |
| #ifdef __cpp_char8_t |
| |
| GTEST_API_ void PrintTo(const char8_t* s, ::std::ostream* os); |
| inline void PrintTo(char8_t* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const char8_t*>(s), os); |
| } |
| #endif |
| |
| GTEST_API_ void PrintTo(const char16_t* s, ::std::ostream* os); |
| inline void PrintTo(char16_t* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const char16_t*>(s), os); |
| } |
| |
| GTEST_API_ void PrintTo(const char32_t* s, ::std::ostream* os); |
| inline void PrintTo(char32_t* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const char32_t*>(s), os); |
| } |
|
|
| |
| |
| |
| |
| |
| #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) |
| |
| GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os); |
| inline void PrintTo(wchar_t* s, ::std::ostream* os) { |
| PrintTo(ImplicitCast_<const wchar_t*>(s), os); |
| } |
| #endif |
|
|
| |
| |
|
|
| |
| |
| template <typename T> |
| void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { |
| UniversalPrint(a[0], os); |
| for (size_t i = 1; i != count; i++) { |
| *os << ", "; |
| UniversalPrint(a[i], os); |
| } |
| } |
|
|
| |
| GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os); |
| inline void PrintTo(const ::std::string& s, ::std::ostream* os) { |
| PrintStringTo(s, os); |
| } |
|
|
| |
| #ifdef __cpp_char8_t |
| GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); |
| inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { |
| PrintU8StringTo(s, os); |
| } |
| #endif |
|
|
| |
| GTEST_API_ void PrintU16StringTo(const ::std::u16string& s, ::std::ostream* os); |
| inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) { |
| PrintU16StringTo(s, os); |
| } |
|
|
| |
| GTEST_API_ void PrintU32StringTo(const ::std::u32string& s, ::std::ostream* os); |
| inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { |
| PrintU32StringTo(s, os); |
| } |
|
|
| |
| #if GTEST_HAS_STD_WSTRING |
| GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); |
| inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { |
| PrintWideStringTo(s, os); |
| } |
| #endif |
|
|
| #if GTEST_INTERNAL_HAS_STRING_VIEW |
| |
| inline void PrintTo(internal::StringView sp, ::std::ostream* os) { |
| PrintTo(::std::string(sp), os); |
| } |
| #endif |
|
|
| inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } |
|
|
| template <typename T> |
| void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) { |
| UniversalPrinter<T&>::Print(ref.get(), os); |
| } |
|
|
| inline const void* VoidifyPointer(const void* p) { return p; } |
| inline const void* VoidifyPointer(volatile const void* p) { |
| return const_cast<const void*>(p); |
| } |
|
|
| template <typename T, typename Ptr> |
| void PrintSmartPointer(const Ptr& ptr, std::ostream* os, char) { |
| if (ptr == nullptr) { |
| *os << "(nullptr)"; |
| } else { |
| |
| *os << "(" << (VoidifyPointer)(ptr.get()) << ")"; |
| } |
| } |
| template <typename T, typename Ptr, |
| typename = typename std::enable_if<!std::is_void<T>::value && |
| !std::is_array<T>::value>::type> |
| void PrintSmartPointer(const Ptr& ptr, std::ostream* os, int) { |
| if (ptr == nullptr) { |
| *os << "(nullptr)"; |
| } else { |
| *os << "(ptr = " << (VoidifyPointer)(ptr.get()) << ", value = "; |
| UniversalPrinter<T>::Print(*ptr, os); |
| *os << ")"; |
| } |
| } |
|
|
| template <typename T, typename D> |
| void PrintTo(const std::unique_ptr<T, D>& ptr, std::ostream* os) { |
| (PrintSmartPointer<T>)(ptr, os, 0); |
| } |
|
|
| template <typename T> |
| void PrintTo(const std::shared_ptr<T>& ptr, std::ostream* os) { |
| (PrintSmartPointer<T>)(ptr, os, 0); |
| } |
|
|
| |
| |
| template <typename T> |
| void PrintTupleTo(const T&, std::integral_constant<size_t, 0>, |
| ::std::ostream*) {} |
|
|
| template <typename T, size_t I> |
| void PrintTupleTo(const T& t, std::integral_constant<size_t, I>, |
| ::std::ostream* os) { |
| PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os); |
| GTEST_INTENTIONAL_CONST_COND_PUSH_() |
| if (I > 1) { |
| GTEST_INTENTIONAL_CONST_COND_POP_() |
| *os << ", "; |
| } |
| UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print( |
| std::get<I - 1>(t), os); |
| } |
|
|
| template <typename... Types> |
| void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) { |
| *os << "("; |
| PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os); |
| *os << ")"; |
| } |
|
|
| |
| template <typename T1, typename T2> |
| void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) { |
| *os << '('; |
| |
| |
| UniversalPrinter<T1>::Print(value.first, os); |
| *os << ", "; |
| UniversalPrinter<T2>::Print(value.second, os); |
| *os << ')'; |
| } |
|
|
| |
| |
| template <typename T> |
| class UniversalPrinter { |
| public: |
| |
| |
| GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180) |
|
|
| |
| |
| |
| static void Print(const T& value, ::std::ostream* os) { |
| |
| |
| |
| |
| |
| |
| |
| |
| PrintTo(value, os); |
| } |
|
|
| GTEST_DISABLE_MSC_WARNINGS_POP_() |
| }; |
|
|
| |
| template <typename T> |
| class UniversalPrinter<const T> : public UniversalPrinter<T> {}; |
|
|
| #if GTEST_INTERNAL_HAS_ANY |
|
|
| |
|
|
| template <> |
| class UniversalPrinter<Any> { |
| public: |
| static void Print(const Any& value, ::std::ostream* os) { |
| if (value.has_value()) { |
| *os << "value of type " << GetTypeName(value); |
| } else { |
| *os << "no value"; |
| } |
| } |
|
|
| private: |
| static std::string GetTypeName(const Any& value) { |
| #if GTEST_HAS_RTTI |
| return internal::GetTypeName(value.type()); |
| #else |
| static_cast<void>(value); |
| return "<unknown_type>"; |
| #endif |
| } |
| }; |
|
|
| #endif |
|
|
| #if GTEST_INTERNAL_HAS_OPTIONAL |
|
|
| |
|
|
| template <typename T> |
| class UniversalPrinter<Optional<T>> { |
| public: |
| static void Print(const Optional<T>& value, ::std::ostream* os) { |
| *os << '('; |
| if (!value) { |
| *os << "nullopt"; |
| } else { |
| UniversalPrint(*value, os); |
| } |
| *os << ')'; |
| } |
| }; |
|
|
| #endif |
|
|
| #if GTEST_INTERNAL_HAS_VARIANT |
|
|
| |
|
|
| template <typename... T> |
| class UniversalPrinter<Variant<T...>> { |
| public: |
| static void Print(const Variant<T...>& value, ::std::ostream* os) { |
| *os << '('; |
| #if GTEST_HAS_ABSL |
| absl::visit(Visitor{os, value.index()}, value); |
| #else |
| std::visit(Visitor{os, value.index()}, value); |
| #endif |
| *os << ')'; |
| } |
|
|
| private: |
| struct Visitor { |
| template <typename U> |
| void operator()(const U& u) const { |
| *os << "'" << GetTypeName<U>() << "(index = " << index |
| << ")' with value "; |
| UniversalPrint(u, os); |
| } |
| ::std::ostream* os; |
| std::size_t index; |
| }; |
| }; |
|
|
| #endif |
|
|
| |
| |
| template <typename T> |
| void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { |
| if (len == 0) { |
| *os << "{}"; |
| } else { |
| *os << "{ "; |
| const size_t kThreshold = 18; |
| const size_t kChunkSize = 8; |
| |
| |
| |
| if (len <= kThreshold) { |
| PrintRawArrayTo(begin, len, os); |
| } else { |
| PrintRawArrayTo(begin, kChunkSize, os); |
| *os << ", ..., "; |
| PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os); |
| } |
| *os << " }"; |
| } |
| } |
| |
| GTEST_API_ void UniversalPrintArray( |
| const char* begin, size_t len, ::std::ostream* os); |
|
|
| #ifdef __cpp_char8_t |
| |
| GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, |
| ::std::ostream* os); |
| #endif |
|
|
| |
| GTEST_API_ void UniversalPrintArray(const char16_t* begin, size_t len, |
| ::std::ostream* os); |
|
|
| |
| GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len, |
| ::std::ostream* os); |
|
|
| |
| GTEST_API_ void UniversalPrintArray( |
| const wchar_t* begin, size_t len, ::std::ostream* os); |
|
|
| |
| template <typename T, size_t N> |
| class UniversalPrinter<T[N]> { |
| public: |
| |
| |
| static void Print(const T (&a)[N], ::std::ostream* os) { |
| UniversalPrintArray(a, N, os); |
| } |
| }; |
|
|
| |
| template <typename T> |
| class UniversalPrinter<T&> { |
| public: |
| |
| |
| GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180) |
|
|
| static void Print(const T& value, ::std::ostream* os) { |
| |
| |
| *os << "@" << reinterpret_cast<const void*>(&value) << " "; |
|
|
| |
| UniversalPrint(value, os); |
| } |
|
|
| GTEST_DISABLE_MSC_WARNINGS_POP_() |
| }; |
|
|
| |
| |
| |
|
|
| template <typename T> |
| class UniversalTersePrinter { |
| public: |
| static void Print(const T& value, ::std::ostream* os) { |
| UniversalPrint(value, os); |
| } |
| }; |
| template <typename T> |
| class UniversalTersePrinter<T&> { |
| public: |
| static void Print(const T& value, ::std::ostream* os) { |
| UniversalPrint(value, os); |
| } |
| }; |
| template <typename T, size_t N> |
| class UniversalTersePrinter<T[N]> { |
| public: |
| static void Print(const T (&value)[N], ::std::ostream* os) { |
| UniversalPrinter<T[N]>::Print(value, os); |
| } |
| }; |
| template <> |
| class UniversalTersePrinter<const char*> { |
| public: |
| static void Print(const char* str, ::std::ostream* os) { |
| if (str == nullptr) { |
| *os << "NULL"; |
| } else { |
| UniversalPrint(std::string(str), os); |
| } |
| } |
| }; |
| template <> |
| class UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> { |
| }; |
|
|
| #ifdef __cpp_char8_t |
| template <> |
| class UniversalTersePrinter<const char8_t*> { |
| public: |
| static void Print(const char8_t* str, ::std::ostream* os) { |
| if (str == nullptr) { |
| *os << "NULL"; |
| } else { |
| UniversalPrint(::std::u8string(str), os); |
| } |
| } |
| }; |
| template <> |
| class UniversalTersePrinter<char8_t*> |
| : public UniversalTersePrinter<const char8_t*> {}; |
| #endif |
|
|
| template <> |
| class UniversalTersePrinter<const char16_t*> { |
| public: |
| static void Print(const char16_t* str, ::std::ostream* os) { |
| if (str == nullptr) { |
| *os << "NULL"; |
| } else { |
| UniversalPrint(::std::u16string(str), os); |
| } |
| } |
| }; |
| template <> |
| class UniversalTersePrinter<char16_t*> |
| : public UniversalTersePrinter<const char16_t*> {}; |
|
|
| template <> |
| class UniversalTersePrinter<const char32_t*> { |
| public: |
| static void Print(const char32_t* str, ::std::ostream* os) { |
| if (str == nullptr) { |
| *os << "NULL"; |
| } else { |
| UniversalPrint(::std::u32string(str), os); |
| } |
| } |
| }; |
| template <> |
| class UniversalTersePrinter<char32_t*> |
| : public UniversalTersePrinter<const char32_t*> {}; |
|
|
| #if GTEST_HAS_STD_WSTRING |
| template <> |
| class UniversalTersePrinter<const wchar_t*> { |
| public: |
| static void Print(const wchar_t* str, ::std::ostream* os) { |
| if (str == nullptr) { |
| *os << "NULL"; |
| } else { |
| UniversalPrint(::std::wstring(str), os); |
| } |
| } |
| }; |
| #endif |
|
|
| template <> |
| class UniversalTersePrinter<wchar_t*> { |
| public: |
| static void Print(wchar_t* str, ::std::ostream* os) { |
| UniversalTersePrinter<const wchar_t*>::Print(str, os); |
| } |
| }; |
|
|
| template <typename T> |
| void UniversalTersePrint(const T& value, ::std::ostream* os) { |
| UniversalTersePrinter<T>::Print(value, os); |
| } |
|
|
| |
| |
| |
| |
| template <typename T> |
| void UniversalPrint(const T& value, ::std::ostream* os) { |
| |
| |
| typedef T T1; |
| UniversalPrinter<T1>::Print(value, os); |
| } |
|
|
| typedef ::std::vector< ::std::string> Strings; |
|
|
| |
| |
| template <typename Tuple> |
| void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>, |
| Strings*) {} |
| template <typename Tuple, size_t I> |
| void TersePrintPrefixToStrings(const Tuple& t, |
| std::integral_constant<size_t, I>, |
| Strings* strings) { |
| TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(), |
| strings); |
| ::std::stringstream ss; |
| UniversalTersePrint(std::get<I - 1>(t), &ss); |
| strings->push_back(ss.str()); |
| } |
|
|
| |
| |
| |
| template <typename Tuple> |
| Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { |
| Strings result; |
| TersePrintPrefixToStrings( |
| value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(), |
| &result); |
| return result; |
| } |
|
|
| } |
|
|
| template <typename T> |
| ::std::string PrintToString(const T& value) { |
| ::std::stringstream ss; |
| internal::UniversalTersePrinter<T>::Print(value, &ss); |
| return ss.str(); |
| } |
|
|
| } |
|
|
| |
| |
| |
| #include "gtest/internal/custom/gtest-printers.h" |
|
|
| #endif |
|
|