99#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
100#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
110#if GTEST_HAS_STD_TUPLE_
115#include "absl/strings/string_view.h"
116#include "absl/types/optional.h"
138 kConvertibleToStringView,
148template <
typename T, TypeKind kTypeKind>
154 reinterpret_cast<const void*
>(&
value)),
168 std::string pretty_str =
value.ShortDebugString();
170 pretty_str =
"\n" +
value.DebugString();
172 *
os << (
"<" + pretty_str +
">");
194class TypeWithoutFormatter<
T, kConvertibleToStringView> {
229template <
typename Char,
typename CharTraits,
typename T>
230::std::basic_ostream<Char, CharTraits>&
operator<<(
231 ::std::basic_ostream<Char, CharTraits>&
os,
const T& x) {
234 : internal::ImplicitlyConvertible<
239 internal::ImplicitlyConvertible<
241 ? kConvertibleToStringView
308template <
typename ToPr
int,
typename OtherOperand>
312 return ::testing::PrintToString(
value);
317template <
typename ToPr
int,
size_t N,
typename OtherOperand>
328#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
329 template <typename OtherOperand> \
330 class FormatForComparison<CharType*, OtherOperand> { \
332 static ::std::string Format(CharType* value) { \
333 return ::testing::PrintToString(static_cast<const void*>(value)); \
342#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
347#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
349 class FormatForComparison<CharType*, OtherStringType> { \
351 static ::std::string Format(CharType* value) { \
352 return ::testing::PrintToString(value); \
359#if GTEST_HAS_GLOBAL_STRING
364#if GTEST_HAS_GLOBAL_WSTRING
369#if GTEST_HAS_STD_WSTRING
374#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
384template <
typename T1,
typename T2>
386 const T1&
value,
const T2& ) {
398class UniversalPrinter;
415 const C& container, ::std::ostream*
os) {
416 const size_t kMaxCount = 32;
419 for (
typename C::const_iterator it = container.begin();
420 it != container.end(); ++it, ++
count) {
423 if (
count == kMaxCount) {
448 T*
p, ::std::ostream*
os) {
460 T*
p, ::std::ostream*
os) {
475 const T&
value, ::std::ostream*
os) {
513 (
sizeof(IsContainerTest<T>(0)) ==
sizeof(
IsContainer)) &&
519 : std::is_function<
typename std::remove_pointer<T>::type>
::value
539 PrintTo(
static_cast<unsigned char>(c),
os);
544 *
os << (x ?
"true" :
"false");
564inline void PrintTo(
const signed char*
s, ::std::ostream*
os) {
570inline void PrintTo(
const unsigned char*
s, ::std::ostream*
os) {
582#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
598 for (
size_t i = 1; i !=
count; i++) {
605#if GTEST_HAS_GLOBAL_STRING
607inline void PrintTo(const ::string&
s, ::std::ostream*
os) {
613inline void PrintTo(const ::std::string&
s, ::std::ostream*
os) {
618#if GTEST_HAS_GLOBAL_WSTRING
619GTEST_API_ void PrintWideStringTo(const ::wstring&
s, ::std::ostream*
os);
620inline void PrintTo(const ::wstring&
s, ::std::ostream*
os) {
621 PrintWideStringTo(
s,
os);
625#if GTEST_HAS_STD_WSTRING
626GTEST_API_ void PrintWideStringTo(const ::std::wstring&
s, ::std::ostream*
os);
627inline void PrintTo(const ::std::wstring&
s, ::std::ostream*
os) {
628 PrintWideStringTo(
s,
os);
634inline void PrintTo(absl::string_view sp, ::std::ostream*
os) {
640inline void PrintTo(std::nullptr_t, ::std::ostream*
os) { *
os <<
"(nullptr)"; }
643#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
647void PrintTupleTo(
const T& t, ::std::ostream*
os);
650#if GTEST_HAS_TR1_TUPLE
659inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream*
os) {
663template <
typename T1>
664void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream*
os) {
668template <
typename T1,
typename T2>
669void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream*
os) {
673template <
typename T1,
typename T2,
typename T3>
674void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream*
os) {
678template <
typename T1,
typename T2,
typename T3,
typename T4>
679void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream*
os) {
683template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
684void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
685 ::std::ostream*
os) {
689template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
691void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
692 ::std::ostream*
os) {
696template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
697 typename T6,
typename T7>
698void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
699 ::std::ostream*
os) {
703template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
704 typename T6,
typename T7,
typename T8>
705void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
706 ::std::ostream*
os) {
710template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
711 typename T6,
typename T7,
typename T8,
typename T9>
712void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
713 ::std::ostream*
os) {
717template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
718 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
720 const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
721 ::std::ostream*
os) {
726#if GTEST_HAS_STD_TUPLE_
727template <
typename... Types>
728void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream*
os) {
734template <
typename T1,
typename T2>
777class UniversalPrinter<::absl::optional<T>> {
779 static void Print(const ::absl::optional<T>&
value, ::std::ostream*
os) {
800 const size_t kThreshold = 18;
801 const size_t kChunkSize = 8;
806 if (
len <= kThreshold) {
818 const char* begin,
size_t len, ::std::ostream*
os);
822 const wchar_t* begin,
size_t len, ::std::ostream*
os);
825template <
typename T,
size_t N>
846 *
os <<
"@" <<
reinterpret_cast<const void*
>(&
value) <<
" ";
873template <
typename T,
size_t N>
883 static void Print(
const char* str, ::std::ostream*
os) {
894 static void Print(
char* str, ::std::ostream*
os) {
899#if GTEST_HAS_STD_WSTRING
901class UniversalTersePrinter<const wchar_t*> {
903 static void Print(
const wchar_t* str, ::std::ostream*
os) {
916 static void Print(
wchar_t* str, ::std::ostream*
os) {
947template <
typename TupleT>
950#if GTEST_HAS_TR1_TUPLE
951template <
typename TupleT>
953 typedef TupleT Tuple;
961 const typename ::std::tr1::tuple_element<I, Tuple>::type>::type get(
962 const Tuple& tuple) {
963 return ::std::tr1::get<I>(tuple);
966template <
typename TupleT>
967const size_t TuplePolicy<TupleT>::tuple_size;
970#if GTEST_HAS_STD_TUPLE_
971template <
typename... Types>
972struct TuplePolicy< ::std::tuple<Types...> > {
973 typedef ::std::tuple<Types...> Tuple;
974 static const size_t tuple_size = ::std::tuple_size<Tuple>::value;
977 struct tuple_element : ::std::tuple_element<I, Tuple> {};
980 static const typename ::std::tuple_element<I, Tuple>::type& get(
981 const Tuple& tuple) {
982 return ::std::get<I>(tuple);
985template <
typename... Types>
986const size_t TuplePolicy< ::std::tuple<Types...> >::tuple_size;
989#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
999struct TuplePrefixPrinter {
1001 template <
typename Tuple>
1002 static void PrintPrefixTo(
const Tuple& t, ::std::ostream*
os) {
1003 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t,
os);
1010 typename TuplePolicy<Tuple>::template tuple_element<
N - 1>::type>
1011 ::Print(TuplePolicy<Tuple>::template get<N - 1>(t),
os);
1016 template <
typename Tuple>
1017 static void TersePrintPrefixToStrings(
const Tuple& t, Strings* strings) {
1018 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
1019 ::std::stringstream
ss;
1021 strings->push_back(
ss.str());
1027struct TuplePrefixPrinter<0> {
1028 template <
typename Tuple>
1029 static void PrintPrefixTo(
const Tuple&, ::std::ostream*) {}
1031 template <
typename Tuple>
1032 static void TersePrintPrefixToStrings(
const Tuple&, Strings*) {}
1037template <
typename Tuple>
1038void PrintTupleTo(
const Tuple& t, ::std::ostream*
os) {
1040 TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::PrintPrefixTo(t,
os);
1047template <
typename Tuple>
1048Strings UniversalTersePrintTupleFieldsToStrings(
const Tuple&
value) {
1050 TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::
1051 TersePrintPrefixToStrings(
value, &result);
1059namespace internal2 {
1060template <
typename T>
1062 const T&
value, ::std::ostream*
os) {
1068template <
typename T>
1070 ::std::stringstream ss;
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)
static const Segment ss(Segment::ss)
const size_t kProtobufOneLinerMaxLength
GTEST_API_ void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count, ::std::ostream *os)
::std::basic_ostream< Char, CharTraits > & operator<<(::std::basic_ostream< Char, CharTraits > &os, const T &x)
void DefaultPrintTo(WrapPrinterType< kPrintContainer >, const C &container, ::std::ostream *os)
void UniversalPrint(const T &value, ::std::ostream *os)
::std::vector< ::std::string > Strings
GTEST_API_ void PrintStringTo(const ::std::string &s, ::std::ostream *os)
void PrintTo(const ReferenceWrapper< T > &ref, ::std::ostream *os)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream *os)
void UniversalPrintArray(const T *begin, size_t len, ::std::ostream *os)
void UniversalTersePrint(const T &value, ::std::ostream *os)
void DefaultPrintNonContainerTo(const T &value, ::std::ostream *os)
::std::string PrintToString(const T &value)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define T(meth, val, expected)