100 #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
101 #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
103 #include <functional>
109 #include <type_traits>
113 #include "gtest/internal/gtest-internal.h"
114 #include "gtest/internal/gtest-port.h"
122 template <
typename T>
128 template <
typename T,
129 typename =
typename std::enable_if<
130 (
sizeof(IsContainerTest<T>(0)) ==
sizeof(
IsContainer)) &&
132 static void PrintValue(
const T& container, std::ostream* os) {
133 const size_t kMaxCount = 32;
136 for (
auto&& elem : container) {
139 if (count == kMaxCount) {
165 template <
typename T,
typename =
typename std::enable_if<
166 std::is_function<T>::value>::type>
174 *os << reinterpret_cast<const void*>(p);
180 template <
typename T>
193 namespace internal_stream_operator_without_lexical_name_lookup {
203 template <
typename T,
206 typename =
typename std::enable_if<
207 !std::is_member_pointer<T>::value>::type,
210 typename = decltype(std::declval<std::ostream&>()
211 << std::declval<const T&>())>
227 template <
typename T,
228 typename =
typename std::enable_if<
231 std::string pretty_str = value.ShortDebugString();
233 pretty_str =
"\n" + value.DebugString();
235 *os << (
"<" + pretty_str +
">");
253 #if GTEST_INTERNAL_HAS_STRING_VIEW
254 static void PrintValue(internal::StringView value, ::std::ostream* os) {
268 template <
typename T,
size_t = sizeof(T)>
271 static_cast<const unsigned char*
>(
273 reinterpret_cast<const void*
>(std::addressof(value))),
279 template <
typename T>
281 *os <<
"(incomplete type)";
286 template <
typename T,
typename E,
typename Printer,
typename... Printers>
289 template <
typename T,
typename Printer,
typename... Printers>
291 T, decltype(Printer::PrintValue(std::declval<const T&>(), nullptr)),
292 Printer, Printers...> {
305 template <
typename T>
312 Printer::PrintValue(value, os);
330 template <
typename ToPr
int,
typename OtherOperand>
333 static ::std::string
Format(
const ToPrint& value) {
339 template <
typename ToPr
int,
size_t N,
typename OtherOperand>
342 static ::std::string
Format(
const ToPrint* value) {
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>
414 const T1& value,
const T2& ) {
425 template <
typename T>
426 class UniversalPrinter;
439 template <
typename T>
440 void PrintTo(
const T& value, ::std::ostream* os) {
451 inline void PrintTo(
char c, ::std::ostream* os) {
455 PrintTo(
static_cast<unsigned char>(c), os);
459 inline void PrintTo(
bool x, ::std::ostream* 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);
564 #if GTEST_INTERNAL_HAS_STRING_VIEW
566 inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
567 PrintTo(::std::string(sp), os);
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 return const_cast<const void*
>(p);
583 template <
typename T,
typename Ptr>
585 if (ptr ==
nullptr) {
592 template <
typename T,
typename Ptr,
593 typename =
typename std::enable_if<!std::is_void<T>::value &&
594 !std::is_array<T>::value>::type>
596 if (ptr ==
nullptr) {
605 template <
typename T,
typename D>
606 void PrintTo(
const std::unique_ptr<T, D>& ptr, std::ostream* os) {
607 (PrintSmartPointer<T>)(ptr, os, 0);
610 template <
typename T>
611 void PrintTo(
const std::shared_ptr<T>& ptr, std::ostream* os) {
612 (PrintSmartPointer<T>)(ptr, os, 0);
617 template <
typename T>
621 template <
typename T,
size_t I>
623 ::std::ostream* os) {
624 PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
631 std::get<I - 1>(t), os);
634 template <
typename...
Types>
635 void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
642 template <
typename T1,
typename T2>
643 void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
655 template <
typename T>
656 class UniversalPrinter {
665 static
void Print(const T& value, ::std::ostream* os) {
681 template <
typename T>
684 #if GTEST_INTERNAL_HAS_ANY
691 static void Print(
const Any& value, ::std::ostream* os) {
692 if (value.has_value()) {
704 static_cast<void>(value);
705 return "<unknown_type>";
712 #if GTEST_INTERNAL_HAS_OPTIONAL
716 template <
typename T>
717 class UniversalPrinter<Optional<T>> {
719 static void Print(
const Optional<T>& value, ::std::ostream* os) {
732 #if GTEST_INTERNAL_HAS_VARIANT
736 template <
typename... T>
737 class UniversalPrinter<Variant<T...>> {
739 static void Print(
const Variant<T...>& value, ::std::ostream* os) {
742 absl::visit(Visitor{os, value.index()}, value);
744 std::visit(Visitor{os, value.index()}, value);
751 template <
typename U>
752 void operator()(
const U& u)
const {
753 *os <<
"'" << GetTypeName<U>() <<
"(index = " << index
766 template <
typename T>
772 const size_t kThreshold = 18;
773 const size_t kChunkSize = 8;
777 if (len <= kThreshold) {
789 const char* begin,
size_t len, ::std::ostream* os);
793 const wchar_t* begin,
size_t len, ::std::ostream* os);
796 template <
typename T,
size_t N>
801 static void Print(
const T (&a)[N], ::std::ostream* os) {
807 template <
typename T>
814 static
void Print(const T& value, ::std::ostream* os) {
817 *os <<
"@" <<
reinterpret_cast<const void*
>(&value) <<
" ";
830 template <
typename T>
833 static void Print(
const T& value, ::std::ostream* os) {
837 template <
typename T>
840 static void Print(
const T& value, ::std::ostream* os) {
844 template <
typename T,
size_t N>
847 static void Print(
const T (&value)[N], ::std::ostream* os) {
854 static void Print(
const char* str, ::std::ostream* os) {
855 if (str ==
nullptr) {
865 static void Print(
char* str, ::std::ostream* os) {
870 #if GTEST_HAS_STD_WSTRING
872 class UniversalTersePrinter<const wchar_t*> {
874 static void Print(
const wchar_t* str, ::std::ostream* os) {
875 if (str ==
nullptr) {
887 static void Print(
wchar_t* str, ::std::ostream* os) {
892 template <
typename T>
901 template <
typename T>
909 typedef ::std::vector< ::std::string>
Strings;
913 template <
typename Tuple>
916 template <
typename Tuple,
size_t I>
918 std::integral_constant<size_t, I>,
922 ::std::stringstream ss;
924 strings->push_back(ss.str());
930 template <
typename Tuple>
934 value, std::integral_constant<
size_t, std::tuple_size<Tuple>::value>(),
941 template <
typename T>
943 ::std::stringstream ss;
953 #include "gtest/internal/custom/gtest-printers.h"
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:895
static void Print(const T(&a)[N], ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:801
Definition: cmake-build-release/googletest-src/googletest/include/gtest/gtest-printers.h:656
static void Print(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:665
static void Print(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:840
static void Print(const T(&value)[N], ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:847
static void Print(char *str, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:865
static void Print(const char *str, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:854
static void Print(wchar_t *str, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:887
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:831
static void Print(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:833
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:727
#define GTEST_API_
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:775
#define GTEST_INTENTIONAL_CONST_COND_POP_()
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:729
void operator<<(LookupBlocker, LookupBlocker)
long long BiggestInt
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:2133
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) class GTEST_API_ TypedTestSuitePState
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:593
void UniversalPrint(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:902
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char)
::std::vector< ::std::string > Strings
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:909
void PrintSmartPointer(const Ptr &ptr, std::ostream *os, char)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:584
void PrintWithFallback(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:306
void TersePrintPrefixToStrings(const Tuple &, std::integral_constant< size_t, 0 >, Strings *)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:914
std::string GetTypeName()
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-type-util.h:93
const void * VoidifyPointer(const void *p)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:578
void PrintTupleTo(const T &, std::integral_constant< size_t, 0 >, ::std::ostream *)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:618
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:931
GTEST_API_ void PrintStringTo(const ::std::string &s, ::std::ostream *os)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:413
GTEST_API_ void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count, ::std::ostream *os)
GTEST_DISABLE_MSC_WARNINGS_POP_() inline const char *SkipComma(const char *str)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:648
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:542
void UniversalPrintArray(const T *begin, size_t len, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:767
int IsContainer
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:944
void PrintTo(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:440
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string)
void UniversalTersePrint(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:893
Definition: cmake-build-debug/googletest-src/googlemock/include/gmock/gmock-actions.h:154
::std::string PrintToString(const T &value)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:942
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:127
static void PrintValue(const T &container, std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:132
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:239
static void PrintValue(internal::BiggestInt value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:247
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:252
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:278
static void PrintValue(const T &, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:280
Printer type
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:293
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:287
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:164
static void PrintValue(T *p, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:167
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:1007
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:179
static void PrintValue(T *p, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:181
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:221
static const size_t kProtobufOneLinerMaxLength
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:225
static void PrintValue(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:230
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-type-util.h:153
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:266
static void PrintValue(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:269
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-type-util.h:139
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:199
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:202
static void PrintValue(const T &value, ::std::ostream *os)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/gtest-printers.h:212