100#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
101#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
109#include <type_traits>
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<
174 *os << reinterpret_cast<const void*>(
p);
180 template <
typename T>
193namespace internal_stream_operator_without_lexical_name_lookup {
203 template <
typename T,
206 typename =
typename std::enable_if<
210 typename =
decltype(std::declval<std::ostream&>()
211 << std::declval<const T&>())>
225 static const size_t kProtobufOneLinerMaxLength = 50;
227 template <
typename T,
228 typename =
typename std::enable_if<
231 std::string pretty_str =
value.ShortDebugString();
232 if (pretty_str.length() > kProtobufOneLinerMaxLength) {
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)";
286template <
typename T,
typename E,
typename Printer,
typename... Printers>
289template <
typename T,
typename Printer,
typename... Printers>
291 T, decltype(Printer::
PrintValue(std::declval<const T&>(), nullptr)),
292 Printer, Printers...> {
330template <
typename ToPr
int,
typename OtherOperand>
339template <
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_
412template <
typename T1,
typename T2>
426class UniversalPrinter;
451inline void PrintTo(
char c, ::std::ostream* os) {
455 PrintTo(
static_cast<unsigned char>(c), os);
460 *os << (
x ?
"true" :
"false");
473inline void PrintTo(
char16_t c, ::std::ostream* os) {
474 PrintTo(ImplicitCast_<char32_t>(c), os);
477inline void PrintTo(
char8_t c, ::std::ostream* os) {
478 PrintTo(ImplicitCast_<char32_t>(c), os);
484inline void PrintTo(
char* s, ::std::ostream* os) {
485 PrintTo(ImplicitCast_<const char*>(s), os);
490inline void PrintTo(
const signed char* s, ::std::ostream* os) {
491 PrintTo(ImplicitCast_<const void*>(s), os);
493inline void PrintTo(
signed char* s, ::std::ostream* os) {
494 PrintTo(ImplicitCast_<const void*>(s), os);
496inline void PrintTo(
const unsigned char* s, ::std::ostream* os) {
497 PrintTo(ImplicitCast_<const void*>(s), os);
499inline void PrintTo(
unsigned char* s, ::std::ostream* os) {
500 PrintTo(ImplicitCast_<const void*>(s), os);
505inline void PrintTo(
char8_t* s, ::std::ostream* os) {
506 PrintTo(ImplicitCast_<const char8_t*>(s), os);
511inline void PrintTo(
char16_t* s, ::std::ostream* os) {
512 PrintTo(ImplicitCast_<const char16_t*>(s), os);
516inline void PrintTo(
char32_t* s, ::std::ostream* os) {
517 PrintTo(ImplicitCast_<const char32_t*>(s), os);
525#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
528inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
529 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
541 for (
size_t i = 1;
i !=
count;
i++) {
549inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
555GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os);
556inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) {
557 PrintU8StringTo(s, os);
563inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) {
569inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
574#if GTEST_HAS_STD_WSTRING
575GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
576inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
577 PrintWideStringTo(s, os);
581#if GTEST_INTERNAL_HAS_STRING_VIEW
583inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
584 PrintTo(::std::string(sp), os);
588inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os <<
"(nullptr)"; }
591void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
597 return const_cast<const void*
>(
p);
600template <
typename T,
typename Ptr>
602 if (ptr ==
nullptr) {
609template <
typename T,
typename Ptr,
613 if (ptr ==
nullptr) {
622template <
typename T,
typename D>
623void PrintTo(
const std::unique_ptr<T, D>& ptr, std::ostream* os) {
624 (PrintSmartPointer<T>)(ptr, os, 0);
628void PrintTo(
const std::shared_ptr<T>& ptr, std::ostream* os) {
629 (PrintSmartPointer<T>)(ptr, os, 0);
638template <
typename T,
size_t I>
640 ::std::ostream* os) {
641 PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
648 std::get<I - 1>(t), os);
651template <
typename...
Types>
652void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
659template <
typename T1,
typename T2>
701#if GTEST_INTERNAL_HAS_ANY
708 static void Print(
const Any&
value, ::std::ostream* os) {
709 if (
value.has_value()) {
721 static_cast<void>(
value);
722 return "<unknown_type>";
729#if GTEST_INTERNAL_HAS_OPTIONAL
734class UniversalPrinter<Optional<T>> {
736 static void Print(
const Optional<T>&
value, ::std::ostream* os) {
749#if GTEST_INTERNAL_HAS_VARIANT
753template <
typename... T>
754class UniversalPrinter<Variant<T...>> {
756 static void Print(
const Variant<T...>&
value, ::std::ostream* os) {
759 absl::visit(Visitor{os,
value.index()},
value);
761 std::visit(Visitor{os,
value.index()},
value);
768 template <
typename U>
769 void operator()(
const U& u)
const {
770 *os <<
"'" << GetTypeName<U>() <<
"(index = " << index
789 const size_t kThreshold = 18;
790 const size_t kChunkSize = 8;
794 if (len <= kThreshold) {
806 const char* begin,
size_t len, ::std::ostream* os);
824 const wchar_t* begin,
size_t len, ::std::ostream* os);
827template <
typename T,
size_t N>
832 static void Print(
const T (&a)[N], ::std::ostream* os) {
848 *os <<
"@" <<
reinterpret_cast<const void*
>(&
value) <<
" ";
875template <
typename T,
size_t N>
885 static void Print(
const char* str, ::std::ostream* os) {
886 if (str ==
nullptr) {
901 static void Print(
const char8_t* str, ::std::ostream* os) {
902 if (str ==
nullptr) {
910class UniversalTersePrinter<char8_t*>
911 :
public UniversalTersePrinter<const char8_t*> {};
917 static void Print(
const char16_t* str, ::std::ostream* os) {
918 if (str ==
nullptr) {
932 static void Print(
const char32_t* str, ::std::ostream* os) {
933 if (str ==
nullptr) {
944#if GTEST_HAS_STD_WSTRING
948 static void Print(
const wchar_t* str, ::std::ostream* os) {
949 if (str ==
nullptr) {
961 static void Print(
wchar_t* str, ::std::ostream* os) {
987template <
typename Tuple>
990template <
typename Tuple,
size_t I>
992 std::integral_constant<size_t, I>,
996 ::std::stringstream ss;
998 strings->push_back(ss.str());
1004template <
typename Tuple>
1015template <
typename T>
1017 ::std::stringstream ss;
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_INTENTIONAL_CONST_COND_POP_()
::std::string PrintValue(const T &value)
::std::string PrintToString(const T &value)
GTEST_API_ void PrintU32StringTo(const ::std::u32string &s, ::std::ostream *os)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) class GTEST_API_ TypedTestSuitePState
void UniversalPrint(const T &value, ::std::ostream *os)
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char)
::std::vector< ::std::string > Strings
void PrintSmartPointer(const Ptr &ptr, std::ostream *os, char)
void PrintWithFallback(const T &value, ::std::ostream *os)
void TersePrintPrefixToStrings(const Tuple &, std::integral_constant< size_t, 0 >, Strings *)
std::string GetTypeName()
const void * VoidifyPointer(const void *p)
void PrintTupleTo(const T &, std::integral_constant< size_t, 0 >, ::std::ostream *)
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
GTEST_API_ void PrintStringTo(const ::std::string &s, ::std::ostream *os)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
GTEST_API_ void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count, ::std::ostream *os)
GTEST_API_ void PrintU16StringTo(const ::std::u16string &s, ::std::ostream *os)
GTEST_DISABLE_MSC_WARNINGS_POP_() inline const char *SkipComma(const char *str)
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream *os)
void UniversalPrintArray(const T *begin, size_t len, ::std::ostream *os)
void PrintTo(const T &value, ::std::ostream *os)
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string)
void UniversalTersePrint(const T &value, ::std::ostream *os)
void operator<<(LookupBlocker, LookupBlocker)
std::string Print(const T &value)
static void PrintValue(const T &container, std::ostream *os)
static void PrintValue(T *p, ::std::ostream *os)
static void PrintValue(T *p, ::std::ostream *os)
static void PrintValue(const T &value, ::std::ostream *os)
static void PrintValue(const T &value, ::std::ostream *os)
static void PrintValue(internal::BiggestInt value, ::std::ostream *os)
static void PrintValue(const T &value, ::std::ostream *os)
static void PrintValue(const T &, ::std::ostream *os)
::std::string Format(const ToPrint &value)
::std::string Format(const ToPrint *value)
static void Print(const T &value, ::std::ostream *os)
static void Print(const T(&a)[N], ::std::ostream *os)
static void Print(const T &value, ::std::ostream *os)
static void Print(const T &value, ::std::ostream *os)
static void Print(const T(&value)[N], ::std::ostream *os)
static void Print(const char *str, ::std::ostream *os)
static void Print(const char16_t *str, ::std::ostream *os)
static void Print(const char32_t *str, ::std::ostream *os)
static void Print(wchar_t *str, ::std::ostream *os)