123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029 |
- #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
- #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
- #include <functional>
- #include <memory>
- #include <ostream> // NOLINT
- #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
|