100#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
101#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
108#include <type_traits>
115#include "absl/strings/string_view.h"
130 template <
typename T,
131 typename =
typename std::enable_if<
132 (
sizeof(IsContainerTest<T>(0)) ==
sizeof(
IsContainer)) &&
135 const size_t kMaxCount = 32;
141 if (
count == kMaxCount) {
167 template <
typename T,
typename =
typename std::enable_if<
168 std::is_function<T>::value>::type>
176 *os << reinterpret_cast<const void*>(
p);
182 template <
typename T>
195namespace internal_stream {
198template <
typename Char,
typename CharTraits,
typename T>
199Sentinel*
operator<<(::std::basic_ostream<Char, CharTraits>& os,
const T&
x);
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>
238 template <
typename T,
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) {
277 template <
typename T>
280 static_cast<const unsigned char*
>(
281 reinterpret_cast<const void*
>(std::addressof(
value))),
287template <
typename T,
typename E,
typename Printer,
typename... Printers>
290template <
typename T,
typename Printer,
typename... Printers>
292 T, decltype(Printer::
PrintValue(std::declval<const T&>(), nullptr)),
293 Printer, Printers...> {
312 Printer::PrintValue(
value, os);
330template <
typename ToPr
int,
typename OtherOperand>
334 return ::testing::PrintToString(
value);
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;
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);
503inline void PrintTo(
const char8_t* s, ::std::ostream* os) {
504 PrintTo(ImplicitCast_<const void*>(s), os);
506inline void PrintTo(
char8_t* s, ::std::ostream* os) {
507 PrintTo(ImplicitCast_<const void*>(s), os);
510inline void PrintTo(
const char16_t* s, ::std::ostream* os) {
511 PrintTo(ImplicitCast_<const void*>(s), os);
513inline void PrintTo(
char16_t* s, ::std::ostream* os) {
514 PrintTo(ImplicitCast_<const void*>(s), os);
516inline void PrintTo(
const char32_t* s, ::std::ostream* os) {
517 PrintTo(ImplicitCast_<const void*>(s), os);
519inline 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)
531inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
532 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
544 for (
size_t i = 1;
i !=
count;
i++) {
552inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
557#if GTEST_HAS_STD_WSTRING
558GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
559inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
560 PrintWideStringTo(s, os);
564#if GTEST_INTERNAL_HAS_STRING_VIEW
566inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
567 PrintTo(::std::string(sp), os);
571inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os <<
"(nullptr)"; }
574void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
584template <
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);
597template <
typename...
Types>
598void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
605template <
typename T1,
typename T2>
643#if GTEST_INTERNAL_HAS_ANY
648class 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>";
671#if GTEST_INTERNAL_HAS_OPTIONAL
676class UniversalPrinter<Optional<T>> {
678 static void Print(
const Optional<T>&
value, ::std::ostream* os) {
691#if GTEST_INTERNAL_HAS_VARIANT
695template <
typename... T>
696class 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);
710 template <
typename U>
711 void operator()(
const U& u)
const {
712 *os <<
"'" << GetTypeName<U>() <<
"(index = " << index
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);
755template <
typename T,
size_t N>
760 static void Print(
const T (&
a)[
N], ::std::ostream* os) {
773 static
void Print(const T&
value, ::
std::ostream* os) {
776 *os <<
"@" <<
reinterpret_cast<const void*
>(&
value) <<
" ";
803template <
typename T,
size_t N>
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
831class 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) {
872template <
typename Tuple>
875template <
typename Tuple,
size_t I>
877 std::integral_constant<size_t, I>,
881 ::std::stringstream ss;
883 strings->push_back(ss.str());
889template <
typename Tuple>
893 value, std::integral_constant<
size_t, std::tuple_size<Tuple>::value>(),
902 ::std::stringstream ss;
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
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(char *str, ::std::ostream *os)
static void Print(const char *str, ::std::ostream *os)
static void Print(wchar_t *str, ::std::ostream *os)
static void Print(const T &value, ::std::ostream *os)
::std::string PrintValue(const T &value)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_INTENTIONAL_CONST_COND_POP_()
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType)
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType)
constexpr bool UseStreamOperator()
Sentinel * operator<<(::std::basic_ostream< Char, CharTraits > &os, const T &x)
void UniversalPrint(const T &value, ::std::ostream *os)
::std::vector< ::std::string > Strings
void PrintWithFallback(const T &value, ::std::ostream *os)
void TersePrintPrefixToStrings(const Tuple &, std::integral_constant< size_t, 0 >, Strings *)
std::string GetTypeName()
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)
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)
void UniversalTersePrint(const T &value, ::std::ostream *os)
internal::ProxyTypeList< Ts... > Types
::std::string PrintToString(const T &value)
static void PrintValue(const T &container, std::ostream *os)
static void PrintValue(internal::BiggestInt value, ::std::ostream *os)
static void PrintValue(const T &value, ::std::ostream *os)
static void PrintValue(T *p, ::std::ostream *os)
static void PrintValue(T *p, ::std::ostream *os)
static const size_t kProtobufOneLinerMaxLength
static void PrintValue(const T &value, ::std::ostream *os)
static void PrintValue(const T &value, ::std::ostream *os)