104#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
105#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
113#include <type_traits>
119#include "absl/strings/internal/has_absl_stringify.h"
120#include "absl/strings/str_cat.h"
137 template <
typename T,
138 typename =
typename std::enable_if<
142 const size_t kMaxCount = 32;
145 for (
auto&& elem : container) {
148 if (
count == kMaxCount) {
174 template <
typename T,
typename =
typename std::enable_if<
175 std::is_function<T>::value>::type>
183 *os << reinterpret_cast<const void*>(
p);
189 template <
typename T>
202namespace internal_stream_operator_without_lexical_name_lookup {
212 template <
typename T,
215 typename =
typename std::enable_if<
216 !std::is_member_pointer<T>::value>::type>
222 ->
decltype((void)(*os <<
value)) {
237 template <
typename T,
238 typename =
typename std::enable_if<
241 std::string pretty_str =
value.ShortDebugString();
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) {
271struct ConvertibleToAbslStringifyPrinter {
274 typename =
typename std::enable_if<
275 absl::strings_internal::HasAbslStringify<T>::value>::type>
277 *os << absl::StrCat(
value);
285 size_t count, ::std::ostream* os);
288 template <
typename T,
size_t = sizeof(T)>
291 static_cast<const unsigned char*
>(
293 reinterpret_cast<const void*
>(std::addressof(
value))),
299 template <
typename T>
301 *os <<
"(incomplete type)";
306template <
typename T,
typename E,
typename Printer,
typename... Printers>
309template <
typename T,
typename Printer,
typename... Printers>
311 T, decltype(Printer::
PrintValue(std::declval<const T&>(), nullptr)),
312 Printer, Printers...> {
331 ConvertibleToAbslStringifyPrinter,
336 Printer::PrintValue(
value, os);
354template <
typename ToPr
int,
typename OtherOperand>
358 return ::testing::PrintToString(
value);
363template <
typename ToPr
int,
size_t N,
typename OtherOperand>
374#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
375 template <typename OtherOperand> \
376 class FormatForComparison<CharType*, OtherOperand> { \
378 static ::std::string Format(CharType* value) { \
379 return ::testing::PrintToString(static_cast<const void*>(value)); \
387#ifdef __cpp_lib_char8_t
396#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
401#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
403 class FormatForComparison<CharType*, OtherStringType> { \
405 static ::std::string Format(CharType* value) { \
406 return ::testing::PrintToString(value); \
412#ifdef __cpp_lib_char8_t
421#if GTEST_HAS_STD_WSTRING
426#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
436template <
typename T1,
typename T2>
450class UniversalPrinter;
475inline void PrintTo(
char c, ::std::ostream* os) {
479 PrintTo(
static_cast<unsigned char>(c), os);
484 *os << (
x ?
"true" :
"false");
497inline void PrintTo(
char16_t c, ::std::ostream* os) {
500#ifdef __cpp_lib_char8_t
501inline void PrintTo(
char8_t c, ::std::ostream* os) {
507#if defined(__SIZEOF_INT128__)
528template <
typename FloatType>
530 int full = std::numeric_limits<FloatType>::max_digits10;
531 if (val < 0) val = -val;
534 FloatType mulfor6 = 1e10;
535 if (val >= 100000.0) {
537 }
else if (val >= 10000.0) {
539 }
else if (val >= 1000.0) {
541 }
else if (val >= 100.0) {
543 }
else if (val >= 10.0) {
545 }
else if (val >= 1.0) {
547 }
else if (val >= 0.1) {
549 }
else if (val >= 0.01) {
551 }
else if (val >= 0.001) {
553 }
else if (val >= 0.0001) {
556 if (
static_cast<FloatType
>(
static_cast<int32_t
>(val * mulfor6 + 0.5)) /
560 }
else if (val < 1e10) {
561 FloatType divfor6 = 1.0;
564 }
else if (val >= 1e8) {
566 }
else if (val >= 1e7) {
568 }
else if (val >= 1e6) {
571 if (
static_cast<FloatType
>(
static_cast<int32_t
>(val / divfor6 + 0.5)) *
579inline void PrintTo(
float f, ::std::ostream* os) {
580 auto old_precision = os->precision();
583 os->precision(old_precision);
586inline void PrintTo(
double d, ::std::ostream* os) {
587 auto old_precision = os->precision();
590 os->precision(old_precision);
595inline void PrintTo(
char* s, ::std::ostream* os) {
601inline void PrintTo(
const signed char* s, ::std::ostream* os) {
604inline void PrintTo(
signed char* s, ::std::ostream* os) {
607inline void PrintTo(
const unsigned char* s, ::std::ostream* os) {
610inline void PrintTo(
unsigned char* s, ::std::ostream* os) {
613#ifdef __cpp_lib_char8_t
616inline void PrintTo(
char8_t* s, ::std::ostream* os) {
622inline void PrintTo(
char16_t* s, ::std::ostream* os) {
627inline void PrintTo(
char32_t* s, ::std::ostream* os) {
636#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
639inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
652 for (
size_t i = 1;
i !=
count;
i++) {
660inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
665#ifdef __cpp_lib_char8_t
666GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os);
667inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) {
668 PrintU8StringTo(s, os);
674inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) {
680inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
685#if GTEST_HAS_STD_WSTRING
686GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os);
687inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
688 PrintWideStringTo(s, os);
692#if GTEST_INTERNAL_HAS_STRING_VIEW
694inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
695 PrintTo(::std::string(sp), os);
699inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os <<
"(nullptr)"; }
702inline void PrintTo(
const std::type_info& info, std::ostream* os) {
708void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
714 return const_cast<const void*
>(
p);
717template <
typename T,
typename Ptr>
719 if (ptr ==
nullptr) {
726template <
typename T,
typename Ptr,
727 typename =
typename std::enable_if<!std::is_void<T>::value &&
728 !std::is_array<T>::value>::type>
730 if (ptr ==
nullptr) {
739template <
typename T,
typename D>
740void PrintTo(
const std::unique_ptr<T, D>& ptr, std::ostream* os) {
745void PrintTo(
const std::shared_ptr<T>& ptr, std::ostream* os) {
755template <
typename T,
size_t I>
757 ::std::ostream* os) {
758 PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
765 std::get<I - 1>(t), os);
768template <
typename...
Types>
769void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
776template <
typename T1,
typename T2>
818#if GTEST_INTERNAL_HAS_ANY
825 static void Print(
const Any&
value, ::std::ostream* os) {
826 if (
value.has_value()) {
838 static_cast<void>(
value);
839 return "<unknown_type>";
846#if GTEST_INTERNAL_HAS_OPTIONAL
851class UniversalPrinter<Optional<
T>> {
853 static void Print(
const Optional<T>&
value, ::std::ostream* os) {
865class UniversalPrinter<decltype(Nullopt())> {
867 static void Print(
decltype(Nullopt()), ::std::ostream* os) {
874#if GTEST_INTERNAL_HAS_VARIANT
878template <
typename...
T>
879class UniversalPrinter<Variant<
T...>> {
881 static void Print(
const Variant<T...>&
value, ::std::ostream* os) {
884 absl::visit(Visitor{os,
value.index()},
value);
886 std::visit(Visitor{os,
value.index()},
value);
893 template <
typename U>
894 void operator()(
const U& u)
const {
895 *os <<
"'" << GetTypeName<U>() <<
"(index = " << index
914 const size_t kThreshold = 18;
915 const size_t kChunkSize = 8;
919 if (len <= kThreshold) {
933#ifdef __cpp_lib_char8_t
952template <
typename T,
size_t N>
957 static void Print(
const T (&a)[N], ::std::ostream* os) {
973 *os <<
"@" <<
reinterpret_cast<const void*
>(&
value) <<
" ";
1000template <
typename T>
1003 static void Print(std::reference_wrapper<T>
value, ::std::ostream* os) {
1007template <
typename T,
size_t N>
1017 static void Print(
const char* str, ::std::ostream* os) {
1018 if (str ==
nullptr) {
1029#ifdef __cpp_lib_char8_t
1033 static void Print(
const char8_t* str, ::std::ostream* os) {
1034 if (str ==
nullptr) {
1042class UniversalTersePrinter<char8_t*>
1043 :
public UniversalTersePrinter<const char8_t*> {};
1049 static void Print(
const char16_t* str, ::std::ostream* os) {
1050 if (str ==
nullptr) {
1064 static void Print(
const char32_t* str, ::std::ostream* os) {
1065 if (str ==
nullptr) {
1076#if GTEST_HAS_STD_WSTRING
1080 static void Print(
const wchar_t* str, ::std::ostream* os) {
1081 if (str ==
nullptr) {
1093 static void Print(
wchar_t* str, ::std::ostream* os) {
1098template <
typename T>
1107template <
typename T>
1119template <
typename Tuple>
1122template <
typename Tuple,
size_t I>
1124 std::integral_constant<size_t, I>,
1128 ::std::stringstream ss;
1130 strings->push_back(ss.str());
1136template <
typename Tuple>
1140 value, std::integral_constant<
size_t, std::tuple_size<Tuple>::value>(),
1147template <
typename T>
1149 ::std::stringstream ss;
Definition gtest-internal.h:881
static void Print(const T(&a)[N], ::std::ostream *os)
Definition gtest-printers.h:957
Definition gtest-printers.h:790
static void Print(const T &value, ::std::ostream *os)
Definition gtest-printers.h:799
static void Print(const T &value, ::std::ostream *os)
Definition gtest-printers.h:996
static void Print(const T(&value)[N], ::std::ostream *os)
Definition gtest-printers.h:1010
static void Print(const char16_t *str, ::std::ostream *os)
Definition gtest-printers.h:1049
static void Print(const char32_t *str, ::std::ostream *os)
Definition gtest-printers.h:1064
static void Print(const char *str, ::std::ostream *os)
Definition gtest-printers.h:1017
static void Print(std::reference_wrapper< T > value, ::std::ostream *os)
Definition gtest-printers.h:1003
static void Print(wchar_t *str, ::std::ostream *os)
Definition gtest-printers.h:1093
Definition gtest-printers.h:987
static void Print(const T &value, ::std::ostream *os)
Definition gtest-printers.h:989
pRC::Float<> T
Definition externs_nonTT.hpp:1
int value
Definition gmock-actions_test.cc:1714
int i
Definition gmock-matchers-comparisons_test.cc:603
int x
Definition gmock-matchers-containers_test.cc:376
const char * p
Definition gmock-matchers-containers_test.cc:379
int * count
Definition gmock_stress_test.cc:90
::std::string PrintValue(const T &value)
Definition googletest-param-test-test.cc:72
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
Definition gtest-port.h:787
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition gtest-port.h:360
#define GTEST_API_
Definition gtest-port.h:842
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition gtest-port.h:361
#define GTEST_INTENTIONAL_CONST_COND_POP_()
Definition gtest-port.h:789
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType)
Definition gtest-printers.h:374
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType)
Definition gtest-printers.h:401
void operator<<(LookupBlocker, LookupBlocker)
::std::vector<::std::string > Strings
Definition gtest-printers.h:1115
long long BiggestInt
Definition gtest-port.h:2171
GTEST_API_ void PrintU32StringTo(const ::std::u32string &s, ::std::ostream *os)
void UniversalPrint(const T &value, ::std::ostream *os)
Definition gtest-printers.h:1108
void PrintSmartPointer(const Ptr &ptr, std::ostream *os, char)
Definition gtest-printers.h:718
void PrintWithFallback(const T &value, ::std::ostream *os)
Definition gtest-printers.h:326
void TersePrintPrefixToStrings(const Tuple &, std::integral_constant< size_t, 0 >, Strings *)
Definition gtest-printers.h:1120
std::string GetTypeName()
Definition gtest-type-util.h:129
const void * VoidifyPointer(const void *p)
Definition gtest-printers.h:712
void PrintTupleTo(const T &, std::integral_constant< size_t, 0 >, ::std::ostream *)
Definition gtest-printers.h:752
IsContainer IsContainerTest(int)
Definition gtest-internal.h:939
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
Definition gtest-printers.h:1137
GTEST_API_ void PrintStringTo(const ::std::string &s, ::std::ostream *os)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
Definition gtest-printers.h:437
To ImplicitCast_(To x)
Definition gtest-port.h:1140
int AppropriateResolution(FloatType val)
Definition gtest-printers.h:529
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)
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream *os)
Definition gtest-printers.h:650
void UniversalPrintArray(const T *begin, size_t len, ::std::ostream *os)
Definition gtest-printers.h:909
int IsContainer
Definition gtest-internal.h:932
void PrintTo(const T &value, ::std::ostream *os)
Definition gtest-printers.h:464
void UniversalTersePrint(const T &value, ::std::ostream *os)
Definition gtest-printers.h:1099
Definition gmock-actions.h:151
::std::string PrintToString(const T &value)
Definition gtest-printers.h:1148
Definition gtest-printers.h:136
static void PrintValue(const T &container, std::ostream *os)
Definition gtest-printers.h:141
Definition gtest-printers.h:249
static void PrintValue(internal::BiggestInt value, ::std::ostream *os)
Definition gtest-printers.h:257
Definition gtest-printers.h:262
Definition gtest-printers.h:298
static void PrintValue(const T &, ::std::ostream *os)
Definition gtest-printers.h:300
Printer type
Definition gtest-printers.h:313
Definition gtest-printers.h:307
Definition gtest-printers.h:173
static void PrintValue(T *p, ::std::ostream *os)
Definition gtest-printers.h:176
Definition gtest-internal.h:997
Definition gtest-printers.h:188
static void PrintValue(T *p, ::std::ostream *os)
Definition gtest-printers.h:190
Definition gtest-printers.h:231
static const size_t kProtobufOneLinerMaxLength
Definition gtest-printers.h:235
static void PrintValue(const T &value, ::std::ostream *os)
Definition gtest-printers.h:240
Definition gtest-type-util.h:190
Definition gtest-printers.h:286
static void PrintValue(const T &value, ::std::ostream *os)
Definition gtest-printers.h:289
Definition gtest-type-util.h:176
Definition gtest-printers.h:208
Definition gtest-printers.h:211
static auto PrintValue(const T &value, ::std::ostream *os) -> decltype((void)(*os<< value))
Definition gtest-printers.h:221