100 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
101 #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
103 #include <functional>
108 #include <type_traits>
115 #include "absl/strings/string_view.h"
116 #endif // GTEST_HAS_ABSL
124 template <
typename T>
130 template <
typename T,
131 typename =
typename std::enable_if<
132 (
sizeof(IsContainerTest<T>(0)) ==
sizeof(
IsContainer)) &&
135 const size_t kMaxCount = 32;
138 for (
auto&& elem : container) {
141 if (count == kMaxCount) {
167 template <
typename T,
typename =
typename std::enable_if<
176 *os << reinterpret_cast<const void*>(
p);
182 template <
typename T>
195 namespace internal_stream {
198 template <
typename Char,
typename CharTraits,
typename T>
199 Sentinel* operator<<(::std::basic_ostream<Char, CharTraits>& os,
const T&
x);
215 template <
typename T>
217 return !std::is_same<decltype(std::declval<std::ostream&>()
218 << std::declval<const T&>()),
225 template <
typename T,
typename =
typename std::enable_if<
226 internal_stream::UseStreamOperator<T>()>::type>
236 static const size_t kProtobufOneLinerMaxLength = 50;
238 template <
typename T,
typename =
typename std::enable_if<
241 std::string pretty_str = value.ShortDebugString();
242 if (pretty_str.length() > kProtobufOneLinerMaxLength) {
243 pretty_str =
"\n" + value.DebugString();
245 *os << (
"<" + pretty_str +
">");
263 #if GTEST_INTERNAL_HAS_STRING_VIEW
264 static void PrintValue(internal::StringView
value, ::std::ostream* os) {
277 template <
typename T>
280 static_cast<const unsigned char*>(
281 reinterpret_cast<const void*>(std::addressof(value))),
287 template <
typename T,
typename E,
typename Printer,
typename... Printers>
290 template <
typename T,
typename Printer,
typename... Printers>
292 T, decltype(Printer::
PrintValue(std::declval<const T&>(), nullptr)),
293 Printer, Printers...> {
306 template <
typename T>
330 template <
typename ToPr
int,
typename OtherOperand>
339 template <
typename ToPr
int,
size_t N,
typename OtherOperand>
350 #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
351 template <typename OtherOperand> \
352 class FormatForComparison<CharType*, OtherOperand> { \
354 static ::std::string Format(CharType* value) { \
355 return ::testing::PrintToString(static_cast<const void*>(value)); \
372 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
377 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
379 class FormatForComparison<CharType*, OtherStringType> { \
381 static ::std::string Format(CharType* value) { \
382 return ::testing::PrintToString(value); \
397 #if GTEST_HAS_STD_WSTRING
402 #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
412 template <
typename T1,
typename T2>
425 template <
typename T>
439 template <
typename T>
455 PrintTo(static_cast<unsigned char>(c), os);
460 *os << (x ?
"true" :
"false");
473 inline void PrintTo(char16_t
c, ::std::ostream* os) {
474 PrintTo(ImplicitCast_<char32_t>(c), os);
477 inline void PrintTo(char8_t
c, ::std::ostream* os) {
478 PrintTo(ImplicitCast_<char32_t>(c), os);
484 inline void PrintTo(
char* s, ::std::ostream* os) {
485 PrintTo(ImplicitCast_<const char*>(s), os);
490 inline void PrintTo(
const signed char* s, ::std::ostream* os) {
491 PrintTo(ImplicitCast_<const void*>(s), os);
493 inline void PrintTo(
signed char* s, ::std::ostream* os) {
494 PrintTo(ImplicitCast_<const void*>(s), os);
496 inline void PrintTo(
const unsigned char* s, ::std::ostream* os) {
497 PrintTo(ImplicitCast_<const void*>(s), os);
499 inline void PrintTo(
unsigned char* s, ::std::ostream* os) {
500 PrintTo(ImplicitCast_<const void*>(s), os);
503 inline void PrintTo(
const char8_t* s, ::std::ostream* os) {
504 PrintTo(ImplicitCast_<const void*>(s), os);
506 inline void PrintTo(char8_t* s, ::std::ostream* os) {
507 PrintTo(ImplicitCast_<const void*>(s), os);
510 inline void PrintTo(
const char16_t* s, ::std::ostream* os) {
511 PrintTo(ImplicitCast_<const void*>(s), os);
513 inline void PrintTo(char16_t* s, ::std::ostream* os) {
514 PrintTo(ImplicitCast_<const void*>(s), os);
516 inline void PrintTo(
const char32_t* s, ::std::ostream* os) {
517 PrintTo(ImplicitCast_<const void*>(s), os);
519 inline void PrintTo(char32_t* s, ::std::ostream* os) {
520 PrintTo(ImplicitCast_<const void*>(s), os);
528 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
531 inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
532 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
541 template <
typename T>
544 for (
size_t i = 1;
i !=
count;
i++) {
552 inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
557 #if GTEST_HAS_STD_WSTRING
558 GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
559 inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
560 PrintWideStringTo(s, os);
562 #endif // GTEST_HAS_STD_WSTRING
564 #if GTEST_INTERNAL_HAS_STRING_VIEW
566 inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
567 PrintTo(::std::string(sp), os);
569 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
571 inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os <<
"(nullptr)"; }
573 template <
typename T>
574 void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
580 template <
typename T>
584 template <
typename T,
size_t I>
586 ::std::ostream* os) {
587 PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
594 std::get<I - 1>(t), os);
597 template <
typename...
Types>
598 void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
605 template <
typename T1,
typename T2>
618 template <
typename T>
619 class UniversalPrinter {
643 #if GTEST_INTERNAL_HAS_ANY
648 class UniversalPrinter<Any> {
650 static void Print(
const Any&
value, ::std::ostream* os) {
651 if (value.has_value()) {
663 static_cast<void>(
value);
664 return "<unknown_type>";
665 #endif // GTEST_HAS_RTTI
669 #endif // GTEST_INTERNAL_HAS_ANY
671 #if GTEST_INTERNAL_HAS_OPTIONAL
675 template <
typename T>
676 class UniversalPrinter<Optional<
T>> {
678 static void Print(
const Optional<T>& value, ::std::ostream* os) {
689 #endif // GTEST_INTERNAL_HAS_OPTIONAL
691 #if GTEST_INTERNAL_HAS_VARIANT
695 template <
typename...
T>
696 class UniversalPrinter<Variant<
T...>> {
698 static void Print(
const Variant<T...>& value, ::std::ostream* os) {
701 absl::visit(Visitor{os, value.index()},
value);
703 std::visit(Visitor{os, value.index()},
value);
704 #endif // GTEST_HAS_ABSL
710 template <
typename U>
711 void operator()(
const U& u)
const {
712 *os <<
"'" << GetTypeName<U>() <<
"(index = " << index
721 #endif // GTEST_INTERNAL_HAS_VARIANT
725 template <
typename T>
731 const size_t kThreshold = 18;
732 const size_t kChunkSize = 8;
736 if (len <= kThreshold) {
748 const char* begin,
size_t len, ::std::ostream* os);
752 const wchar_t* begin,
size_t len, ::std::ostream* os);
755 template <
typename T,
size_t N>
760 static void Print(
const T (&
a)[
N], ::std::ostream* os) {
766 template <
typename T>
773 static
void Print(const
T& value, ::std::ostream* os) {
776 *os <<
"@" <<
reinterpret_cast<const void*
>(&
value) <<
" ";
789 template <
typename T>
792 static void Print(
const T& value, ::std::ostream* os) {
796 template <
typename T>
799 static void Print(
const T& value, ::std::ostream* os) {
803 template <
typename T,
size_t N>
806 static void Print(
const T (&value)[
N], ::std::ostream* os) {
813 static void Print(
const char* str, ::std::ostream* os) {
814 if (str ==
nullptr) {
824 static void Print(
char* str, ::std::ostream* os) {
829 #if GTEST_HAS_STD_WSTRING
831 class UniversalTersePrinter<const wchar_t*> {
833 static void Print(
const wchar_t* str, ::std::ostream* os) {
834 if (str ==
nullptr) {
846 static void Print(
wchar_t* str, ::std::ostream* os) {
851 template <
typename T>
860 template <
typename T>
868 typedef ::std::vector< ::std::string>
Strings;
872 template <
typename Tuple>
875 template <
typename Tuple,
size_t I>
877 std::integral_constant<size_t, I>,
881 ::std::stringstream ss;
883 strings->push_back(ss.str());
889 template <
typename Tuple>
900 template <
typename T>
902 ::std::stringstream ss;
914 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
static void Print(const T &value,::std::ostream *os)
void PrintRawArrayTo(const T a[], size_t count,::std::ostream *os)
::std::string PrintValue(const T &value)
static void Print(wchar_t *str,::std::ostream *os)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
static void Print(const T &value,::std::ostream *os)
GTEST_API_ void PrintStringTo(const ::std::string &s,::std::ostream *os)
::std::string PrintToString(const T &value)
static void Print(const T(&value)[N],::std::ostream *os)
void UniversalTersePrint(const T &value,::std::ostream *os)
std::string Print(const T &value)
::std::vector< ::std::string > Strings
static void Print(const T(&a)[N],::std::ostream *os)
constexpr bool UseStreamOperator()
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char,::std::string)
static void Print(const char *str,::std::ostream *os)
internal::ProxyTypeList< Ts...> Types
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
std::string GetTypeName()
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
GTEST_API_ void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count,::std::ostream *os)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
void UniversalPrint(const T &value,::std::ostream *os)
static void PrintValue(const T &container, std::ostream *os)
static void PrintValue(const T &value,::std::ostream *os)
static void PrintValue(T *p,::std::ostream *os)
void PrintTo(const T &value,::std::ostream *os)
void PrintWithFallback(const T &value,::std::ostream *os)
void PrintTupleTo(const T &, std::integral_constant< size_t, 0 >,::std::ostream *)
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
static void PrintValue(T *p,::std::ostream *os)
static void Print(char *str,::std::ostream *os)
void UniversalPrintArray(const T *begin, size_t len,::std::ostream *os)
static void PrintValue(const T &value,::std::ostream *os)
void TersePrintPrefixToStrings(const Tuple &, std::integral_constant< size_t, 0 >, Strings *)
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char)
static void Print(const T &value,::std::ostream *os)
static void PrintValue(internal::BiggestInt value,::std::ostream *os)
#define GTEST_INTENTIONAL_CONST_COND_POP_()
static void PrintValue(const T &value,::std::ostream *os)