gtest-printers.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. // Copyright 2007, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Google Test - The Google C++ Testing and Mocking Framework
  30. //
  31. // This file implements a universal value printer that can print a
  32. // value of any type T:
  33. //
  34. // void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
  35. //
  36. // A user can teach this function how to print a class type T by
  37. // defining either operator<<() or PrintTo() in the namespace that
  38. // defines T. More specifically, the FIRST defined function in the
  39. // following list will be used (assuming T is defined in namespace
  40. // foo):
  41. //
  42. // 1. foo::PrintTo(const T&, ostream*)
  43. // 2. operator<<(ostream&, const T&) defined in either foo or the
  44. // global namespace.
  45. //
  46. // However if T is an STL-style container then it is printed element-wise
  47. // unless foo::PrintTo(const T&, ostream*) is defined. Note that
  48. // operator<<() is ignored for container types.
  49. //
  50. // If none of the above is defined, it will print the debug string of
  51. // the value if it is a protocol buffer, or print the raw bytes in the
  52. // value otherwise.
  53. //
  54. // To aid debugging: when T is a reference type, the address of the
  55. // value is also printed; when T is a (const) char pointer, both the
  56. // pointer value and the NUL-terminated string it points to are
  57. // printed.
  58. //
  59. // We also provide some convenient wrappers:
  60. //
  61. // // Prints a value to a string. For a (const or not) char
  62. // // pointer, the NUL-terminated string (but not the pointer) is
  63. // // printed.
  64. // std::string ::testing::PrintToString(const T& value);
  65. //
  66. // // Prints a value tersely: for a reference type, the referenced
  67. // // value (but not the address) is printed; for a (const or not) char
  68. // // pointer, the NUL-terminated string (but not the pointer) is
  69. // // printed.
  70. // void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
  71. //
  72. // // Prints value using the type inferred by the compiler. The difference
  73. // // from UniversalTersePrint() is that this function prints both the
  74. // // pointer and the NUL-terminated string for a (const or not) char pointer.
  75. // void ::testing::internal::UniversalPrint(const T& value, ostream*);
  76. //
  77. // // Prints the fields of a tuple tersely to a string vector, one
  78. // // element for each field. Tuple support must be enabled in
  79. // // gtest-port.h.
  80. // std::vector<string> UniversalTersePrintTupleFieldsToStrings(
  81. // const Tuple& value);
  82. //
  83. // Known limitation:
  84. //
  85. // The print primitives print the elements of an STL-style container
  86. // using the compiler-inferred type of *iter where iter is a
  87. // const_iterator of the container. When const_iterator is an input
  88. // iterator but not a forward iterator, this inferred type may not
  89. // match value_type, and the print output may be incorrect. In
  90. // practice, this is rarely a problem as for most containers
  91. // const_iterator is a forward iterator. We'll fix this if there's an
  92. // actual need for it. Note that this fix cannot rely on value_type
  93. // being defined as many user-defined container types don't have
  94. // value_type.
  95. // IWYU pragma: private, include "gtest/gtest.h"
  96. // IWYU pragma: friend gtest/.*
  97. // IWYU pragma: friend gmock/.*
  98. #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
  99. #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
  100. #include <functional>
  101. #include <memory>
  102. #include <ostream> // NOLINT
  103. #include <sstream>
  104. #include <string>
  105. #include <tuple>
  106. #include <type_traits>
  107. #include <typeinfo>
  108. #include <utility>
  109. #include <vector>
  110. #include "gtest/internal/gtest-internal.h"
  111. #include "gtest/internal/gtest-port.h"
  112. namespace testing {
  113. // Definitions in the internal* namespaces are subject to change without notice.
  114. // DO NOT USE THEM IN USER CODE!
  115. namespace internal {
  116. template <typename T>
  117. void UniversalPrint(const T& value, ::std::ostream* os);
  118. // Used to print an STL-style container when the user doesn't define
  119. // a PrintTo() for it.
  120. struct ContainerPrinter {
  121. template <typename T,
  122. typename = typename std::enable_if<
  123. (sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
  124. !IsRecursiveContainer<T>::value>::type>
  125. static void PrintValue(const T& container, std::ostream* os) {
  126. const size_t kMaxCount = 32; // The maximum number of elements to print.
  127. *os << '{';
  128. size_t count = 0;
  129. for (auto&& elem : container) {
  130. if (count > 0) {
  131. *os << ',';
  132. if (count == kMaxCount) { // Enough has been printed.
  133. *os << " ...";
  134. break;
  135. }
  136. }
  137. *os << ' ';
  138. // We cannot call PrintTo(elem, os) here as PrintTo() doesn't
  139. // handle `elem` being a native array.
  140. internal::UniversalPrint(elem, os);
  141. ++count;
  142. }
  143. if (count > 0) {
  144. *os << ' ';
  145. }
  146. *os << '}';
  147. }
  148. };
  149. // Used to print a pointer that is neither a char pointer nor a member
  150. // pointer, when the user doesn't define PrintTo() for it. (A member
  151. // variable pointer or member function pointer doesn't really point to
  152. // a location in the address space. Their representation is
  153. // implementation-defined. Therefore they will be printed as raw
  154. // bytes.)
  155. struct FunctionPointerPrinter {
  156. template <typename T, typename = typename std::enable_if<
  157. std::is_function<T>::value>::type>
  158. static void PrintValue(T* p, ::std::ostream* os) {
  159. if (p == nullptr) {
  160. *os << "NULL";
  161. } else {
  162. // T is a function type, so '*os << p' doesn't do what we want
  163. // (it just prints p as bool). We want to print p as a const
  164. // void*.
  165. *os << reinterpret_cast<const void*>(p);
  166. }
  167. }
  168. };
  169. struct PointerPrinter {
  170. template <typename T>
  171. static void PrintValue(T* p, ::std::ostream* os) {
  172. if (p == nullptr) {
  173. *os << "NULL";
  174. } else {
  175. // T is not a function type. We just call << to print p,
  176. // relying on ADL to pick up user-defined << for their pointer
  177. // types, if any.
  178. *os << p;
  179. }
  180. }
  181. };
  182. namespace internal_stream_operator_without_lexical_name_lookup {
  183. // The presence of an operator<< here will terminate lexical scope lookup
  184. // straight away (even though it cannot be a match because of its argument
  185. // types). Thus, the two operator<< calls in StreamPrinter will find only ADL
  186. // candidates.
  187. struct LookupBlocker {};
  188. void operator<<(LookupBlocker, LookupBlocker);
  189. struct StreamPrinter {
  190. template <typename T,
  191. // Don't accept member pointers here. We'd print them via implicit
  192. // conversion to bool, which isn't useful.
  193. typename = typename std::enable_if<
  194. !std::is_member_pointer<T>::value>::type,
  195. // Only accept types for which we can find a streaming operator via
  196. // ADL (possibly involving implicit conversions).
  197. typename = decltype(std::declval<std::ostream&>()
  198. << std::declval<const T&>())>
  199. static void PrintValue(const T& value, ::std::ostream* os) {
  200. // Call streaming operator found by ADL, possibly with implicit conversions
  201. // of the arguments.
  202. *os << value;
  203. }
  204. };
  205. } // namespace internal_stream_operator_without_lexical_name_lookup
  206. struct ProtobufPrinter {
  207. // We print a protobuf using its ShortDebugString() when the string
  208. // doesn't exceed this many characters; otherwise we print it using
  209. // DebugString() for better readability.
  210. static const size_t kProtobufOneLinerMaxLength = 50;
  211. template <typename T,
  212. typename = typename std::enable_if<
  213. internal::HasDebugStringAndShortDebugString<T>::value>::type>
  214. static void PrintValue(const T& value, ::std::ostream* os) {
  215. std::string pretty_str = value.ShortDebugString();
  216. if (pretty_str.length() > kProtobufOneLinerMaxLength) {
  217. pretty_str = "\n" + value.DebugString();
  218. }
  219. *os << ("<" + pretty_str + ">");
  220. }
  221. };
  222. struct ConvertibleToIntegerPrinter {
  223. // Since T has no << operator or PrintTo() but can be implicitly
  224. // converted to BiggestInt, we print it as a BiggestInt.
  225. //
  226. // Most likely T is an enum type (either named or unnamed), in which
  227. // case printing it as an integer is the desired behavior. In case
  228. // T is not an enum, printing it as an integer is the best we can do
  229. // given that it has no user-defined printer.
  230. static void PrintValue(internal::BiggestInt value, ::std::ostream* os) {
  231. *os << value;
  232. }
  233. };
  234. struct ConvertibleToStringViewPrinter {
  235. #if GTEST_INTERNAL_HAS_STRING_VIEW
  236. static void PrintValue(internal::StringView value, ::std::ostream* os) {
  237. internal::UniversalPrint(value, os);
  238. }
  239. #endif
  240. };
  241. // Prints the given number of bytes in the given object to the given
  242. // ostream.
  243. GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
  244. size_t count, ::std::ostream* os);
  245. struct RawBytesPrinter {
  246. // SFINAE on `sizeof` to make sure we have a complete type.
  247. template <typename T, size_t = sizeof(T)>
  248. static void PrintValue(const T& value, ::std::ostream* os) {
  249. PrintBytesInObjectTo(
  250. static_cast<const unsigned char*>(
  251. // Load bearing cast to void* to support iOS
  252. reinterpret_cast<const void*>(std::addressof(value))),
  253. sizeof(value), os);
  254. }
  255. };
  256. struct FallbackPrinter {
  257. template <typename T>
  258. static void PrintValue(const T&, ::std::ostream* os) {
  259. *os << "(incomplete type)";
  260. }
  261. };
  262. // Try every printer in order and return the first one that works.
  263. template <typename T, typename E, typename Printer, typename... Printers>
  264. struct FindFirstPrinter : FindFirstPrinter<T, E, Printers...> {};
  265. template <typename T, typename Printer, typename... Printers>
  266. struct FindFirstPrinter<
  267. T, decltype(Printer::PrintValue(std::declval<const T&>(), nullptr)),
  268. Printer, Printers...> {
  269. using type = Printer;
  270. };
  271. // Select the best printer in the following order:
  272. // - Print containers (they have begin/end/etc).
  273. // - Print function pointers.
  274. // - Print object pointers.
  275. // - Use the stream operator, if available.
  276. // - Print protocol buffers.
  277. // - Print types convertible to BiggestInt.
  278. // - Print types convertible to StringView, if available.
  279. // - Fallback to printing the raw bytes of the object.
  280. template <typename T>
  281. void PrintWithFallback(const T& value, ::std::ostream* os) {
  282. using Printer = typename FindFirstPrinter<
  283. T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter,
  284. internal_stream_operator_without_lexical_name_lookup::StreamPrinter,
  285. ProtobufPrinter, ConvertibleToIntegerPrinter,
  286. ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type;
  287. Printer::PrintValue(value, os);
  288. }
  289. // FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
  290. // value of type ToPrint that is an operand of a comparison assertion
  291. // (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
  292. // the comparison, and is used to help determine the best way to
  293. // format the value. In particular, when the value is a C string
  294. // (char pointer) and the other operand is an STL string object, we
  295. // want to format the C string as a string, since we know it is
  296. // compared by value with the string object. If the value is a char
  297. // pointer but the other operand is not an STL string object, we don't
  298. // know whether the pointer is supposed to point to a NUL-terminated
  299. // string, and thus want to print it as a pointer to be safe.
  300. //
  301. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
  302. // The default case.
  303. template <typename ToPrint, typename OtherOperand>
  304. class FormatForComparison {
  305. public:
  306. static ::std::string Format(const ToPrint& value) {
  307. return ::testing::PrintToString(value);
  308. }
  309. };
  310. // Array.
  311. template <typename ToPrint, size_t N, typename OtherOperand>
  312. class FormatForComparison<ToPrint[N], OtherOperand> {
  313. public:
  314. static ::std::string Format(const ToPrint* value) {
  315. return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
  316. }
  317. };
  318. // By default, print C string as pointers to be safe, as we don't know
  319. // whether they actually point to a NUL-terminated string.
  320. #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
  321. template <typename OtherOperand> \
  322. class FormatForComparison<CharType*, OtherOperand> { \
  323. public: \
  324. static ::std::string Format(CharType* value) { \
  325. return ::testing::PrintToString(static_cast<const void*>(value)); \
  326. } \
  327. }
  328. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
  329. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
  330. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
  331. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
  332. #ifdef __cpp_lib_char8_t
  333. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char8_t);
  334. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char8_t);
  335. #endif
  336. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char16_t);
  337. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char16_t);
  338. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char32_t);
  339. GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t);
  340. #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
  341. // If a C string is compared with an STL string object, we know it's meant
  342. // to point to a NUL-terminated string, and thus can print it as a string.
  343. #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
  344. template <> \
  345. class FormatForComparison<CharType*, OtherStringType> { \
  346. public: \
  347. static ::std::string Format(CharType* value) { \
  348. return ::testing::PrintToString(value); \
  349. } \
  350. }
  351. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
  352. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
  353. #ifdef __cpp_lib_char8_t
  354. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string);
  355. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string);
  356. #endif
  357. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char16_t, ::std::u16string);
  358. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char16_t, ::std::u16string);
  359. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char32_t, ::std::u32string);
  360. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char32_t, ::std::u32string);
  361. #if GTEST_HAS_STD_WSTRING
  362. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
  363. GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
  364. #endif
  365. #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
  366. // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
  367. // operand to be used in a failure message. The type (but not value)
  368. // of the other operand may affect the format. This allows us to
  369. // print a char* as a raw pointer when it is compared against another
  370. // char* or void*, and print it as a C string when it is compared
  371. // against an std::string object, for example.
  372. //
  373. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
  374. template <typename T1, typename T2>
  375. std::string FormatForComparisonFailureMessage(const T1& value,
  376. const T2& /* other_operand */) {
  377. return FormatForComparison<T1, T2>::Format(value);
  378. }
  379. // UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
  380. // value to the given ostream. The caller must ensure that
  381. // 'ostream_ptr' is not NULL, or the behavior is undefined.
  382. //
  383. // We define UniversalPrinter as a class template (as opposed to a
  384. // function template), as we need to partially specialize it for
  385. // reference types, which cannot be done with function templates.
  386. template <typename T>
  387. class UniversalPrinter;
  388. // Prints the given value using the << operator if it has one;
  389. // otherwise prints the bytes in it. This is what
  390. // UniversalPrinter<T>::Print() does when PrintTo() is not specialized
  391. // or overloaded for type T.
  392. //
  393. // A user can override this behavior for a class type Foo by defining
  394. // an overload of PrintTo() in the namespace where Foo is defined. We
  395. // give the user this option as sometimes defining a << operator for
  396. // Foo is not desirable (e.g. the coding style may prevent doing it,
  397. // or there is already a << operator but it doesn't do what the user
  398. // wants).
  399. template <typename T>
  400. void PrintTo(const T& value, ::std::ostream* os) {
  401. internal::PrintWithFallback(value, os);
  402. }
  403. // The following list of PrintTo() overloads tells
  404. // UniversalPrinter<T>::Print() how to print standard types (built-in
  405. // types, strings, plain arrays, and pointers).
  406. // Overloads for various char types.
  407. GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
  408. GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
  409. inline void PrintTo(char c, ::std::ostream* os) {
  410. // When printing a plain char, we always treat it as unsigned. This
  411. // way, the output won't be affected by whether the compiler thinks
  412. // char is signed or not.
  413. PrintTo(static_cast<unsigned char>(c), os);
  414. }
  415. // Overloads for other simple built-in types.
  416. inline void PrintTo(bool x, ::std::ostream* os) {
  417. *os << (x ? "true" : "false");
  418. }
  419. // Overload for wchar_t type.
  420. // Prints a wchar_t as a symbol if it is printable or as its internal
  421. // code otherwise and also as its decimal code (except for L'\0').
  422. // The L'\0' char is printed as "L'\\0'". The decimal code is printed
  423. // as signed integer when wchar_t is implemented by the compiler
  424. // as a signed type and is printed as an unsigned integer when wchar_t
  425. // is implemented as an unsigned type.
  426. GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
  427. GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os);
  428. inline void PrintTo(char16_t c, ::std::ostream* os) {
  429. PrintTo(ImplicitCast_<char32_t>(c), os);
  430. }
  431. #ifdef __cpp_char8_t
  432. inline void PrintTo(char8_t c, ::std::ostream* os) {
  433. PrintTo(ImplicitCast_<char32_t>(c), os);
  434. }
  435. #endif
  436. // gcc/clang __{u,}int128_t
  437. #if defined(__SIZEOF_INT128__)
  438. GTEST_API_ void PrintTo(__uint128_t v, ::std::ostream* os);
  439. GTEST_API_ void PrintTo(__int128_t v, ::std::ostream* os);
  440. #endif // __SIZEOF_INT128__
  441. // The default resolution used to print floating-point values uses only
  442. // 6 digits, which can be confusing if a test compares two values whose
  443. // difference lies in the 7th digit. So we'd like to print out numbers
  444. // in full precision.
  445. // However if the value is something simple like 1.1, full will print a
  446. // long string like 1.100000001 due to floating-point numbers not using
  447. // a base of 10. This routiune returns an appropriate resolution for a
  448. // given floating-point number, that is, 6 if it will be accurate, or a
  449. // max_digits10 value (full precision) if it won't, for values between
  450. // 0.0001 and one million.
  451. // It does this by computing what those digits would be (by multiplying
  452. // by an appropriate power of 10), then dividing by that power again to
  453. // see if gets the original value back.
  454. // A similar algorithm applies for values larger than one million; note
  455. // that for those values, we must divide to get a six-digit number, and
  456. // then multiply to possibly get the original value again.
  457. template <typename FloatType>
  458. int AppropriateResolution(FloatType val) {
  459. int full = std::numeric_limits<FloatType>::max_digits10;
  460. if (val < 0) val = -val;
  461. if (val < 1000000) {
  462. FloatType mulfor6 = 1e10;
  463. if (val >= 100000.0) { // 100,000 to 999,999
  464. mulfor6 = 1.0;
  465. } else if (val >= 10000.0) {
  466. mulfor6 = 1e1;
  467. } else if (val >= 1000.0) {
  468. mulfor6 = 1e2;
  469. } else if (val >= 100.0) {
  470. mulfor6 = 1e3;
  471. } else if (val >= 10.0) {
  472. mulfor6 = 1e4;
  473. } else if (val >= 1.0) {
  474. mulfor6 = 1e5;
  475. } else if (val >= 0.1) {
  476. mulfor6 = 1e6;
  477. } else if (val >= 0.01) {
  478. mulfor6 = 1e7;
  479. } else if (val >= 0.001) {
  480. mulfor6 = 1e8;
  481. } else if (val >= 0.0001) {
  482. mulfor6 = 1e9;
  483. }
  484. if (static_cast<int32_t>(val * mulfor6 + 0.5) / mulfor6 == val) return 6;
  485. } else if (val < 1e10) {
  486. FloatType divfor6 = 1.0;
  487. if (val >= 1e9) { // 1,000,000,000 to 9,999,999,999
  488. divfor6 = 10000;
  489. } else if (val >= 1e8) { // 100,000,000 to 999,999,999
  490. divfor6 = 1000;
  491. } else if (val >= 1e7) { // 10,000,000 to 99,999,999
  492. divfor6 = 100;
  493. } else if (val >= 1e6) { // 1,000,000 to 9,999,999
  494. divfor6 = 10;
  495. }
  496. if (static_cast<int32_t>(val / divfor6 + 0.5) * divfor6 == val) return 6;
  497. }
  498. return full;
  499. }
  500. inline void PrintTo(float f, ::std::ostream* os) {
  501. auto old_precision = os->precision();
  502. os->precision(AppropriateResolution(f));
  503. *os << f;
  504. os->precision(old_precision);
  505. }
  506. inline void PrintTo(double d, ::std::ostream* os) {
  507. auto old_precision = os->precision();
  508. os->precision(AppropriateResolution(d));
  509. *os << d;
  510. os->precision(old_precision);
  511. }
  512. // Overloads for C strings.
  513. GTEST_API_ void PrintTo(const char* s, ::std::ostream* os);
  514. inline void PrintTo(char* s, ::std::ostream* os) {
  515. PrintTo(ImplicitCast_<const char*>(s), os);
  516. }
  517. // signed/unsigned char is often used for representing binary data, so
  518. // we print pointers to it as void* to be safe.
  519. inline void PrintTo(const signed char* s, ::std::ostream* os) {
  520. PrintTo(ImplicitCast_<const void*>(s), os);
  521. }
  522. inline void PrintTo(signed char* s, ::std::ostream* os) {
  523. PrintTo(ImplicitCast_<const void*>(s), os);
  524. }
  525. inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
  526. PrintTo(ImplicitCast_<const void*>(s), os);
  527. }
  528. inline void PrintTo(unsigned char* s, ::std::ostream* os) {
  529. PrintTo(ImplicitCast_<const void*>(s), os);
  530. }
  531. #ifdef __cpp_char8_t
  532. // Overloads for u8 strings.
  533. GTEST_API_ void PrintTo(const char8_t* s, ::std::ostream* os);
  534. inline void PrintTo(char8_t* s, ::std::ostream* os) {
  535. PrintTo(ImplicitCast_<const char8_t*>(s), os);
  536. }
  537. #endif
  538. // Overloads for u16 strings.
  539. GTEST_API_ void PrintTo(const char16_t* s, ::std::ostream* os);
  540. inline void PrintTo(char16_t* s, ::std::ostream* os) {
  541. PrintTo(ImplicitCast_<const char16_t*>(s), os);
  542. }
  543. // Overloads for u32 strings.
  544. GTEST_API_ void PrintTo(const char32_t* s, ::std::ostream* os);
  545. inline void PrintTo(char32_t* s, ::std::ostream* os) {
  546. PrintTo(ImplicitCast_<const char32_t*>(s), os);
  547. }
  548. // MSVC can be configured to define wchar_t as a typedef of unsigned
  549. // short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
  550. // type. When wchar_t is a typedef, defining an overload for const
  551. // wchar_t* would cause unsigned short* be printed as a wide string,
  552. // possibly causing invalid memory accesses.
  553. #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
  554. // Overloads for wide C strings
  555. GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
  556. inline void PrintTo(wchar_t* s, ::std::ostream* os) {
  557. PrintTo(ImplicitCast_<const wchar_t*>(s), os);
  558. }
  559. #endif
  560. // Overload for C arrays. Multi-dimensional arrays are printed
  561. // properly.
  562. // Prints the given number of elements in an array, without printing
  563. // the curly braces.
  564. template <typename T>
  565. void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
  566. UniversalPrint(a[0], os);
  567. for (size_t i = 1; i != count; i++) {
  568. *os << ", ";
  569. UniversalPrint(a[i], os);
  570. }
  571. }
  572. // Overloads for ::std::string.
  573. GTEST_API_ void PrintStringTo(const ::std::string& s, ::std::ostream* os);
  574. inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
  575. PrintStringTo(s, os);
  576. }
  577. // Overloads for ::std::u8string
  578. #ifdef __cpp_lib_char8_t
  579. GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os);
  580. inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) {
  581. PrintU8StringTo(s, os);
  582. }
  583. #endif
  584. // Overloads for ::std::u16string
  585. GTEST_API_ void PrintU16StringTo(const ::std::u16string& s, ::std::ostream* os);
  586. inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) {
  587. PrintU16StringTo(s, os);
  588. }
  589. // Overloads for ::std::u32string
  590. GTEST_API_ void PrintU32StringTo(const ::std::u32string& s, ::std::ostream* os);
  591. inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
  592. PrintU32StringTo(s, os);
  593. }
  594. // Overloads for ::std::wstring.
  595. #if GTEST_HAS_STD_WSTRING
  596. GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os);
  597. inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
  598. PrintWideStringTo(s, os);
  599. }
  600. #endif // GTEST_HAS_STD_WSTRING
  601. #if GTEST_INTERNAL_HAS_STRING_VIEW
  602. // Overload for internal::StringView.
  603. inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
  604. PrintTo(::std::string(sp), os);
  605. }
  606. #endif // GTEST_INTERNAL_HAS_STRING_VIEW
  607. inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
  608. #if GTEST_HAS_RTTI
  609. inline void PrintTo(const std::type_info& info, std::ostream* os) {
  610. *os << internal::GetTypeName(info);
  611. }
  612. #endif // GTEST_HAS_RTTI
  613. template <typename T>
  614. void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
  615. UniversalPrinter<T&>::Print(ref.get(), os);
  616. }
  617. inline const void* VoidifyPointer(const void* p) { return p; }
  618. inline const void* VoidifyPointer(volatile const void* p) {
  619. return const_cast<const void*>(p);
  620. }
  621. template <typename T, typename Ptr>
  622. void PrintSmartPointer(const Ptr& ptr, std::ostream* os, char) {
  623. if (ptr == nullptr) {
  624. *os << "(nullptr)";
  625. } else {
  626. // We can't print the value. Just print the pointer..
  627. *os << "(" << (VoidifyPointer)(ptr.get()) << ")";
  628. }
  629. }
  630. template <typename T, typename Ptr,
  631. typename = typename std::enable_if<!std::is_void<T>::value &&
  632. !std::is_array<T>::value>::type>
  633. void PrintSmartPointer(const Ptr& ptr, std::ostream* os, int) {
  634. if (ptr == nullptr) {
  635. *os << "(nullptr)";
  636. } else {
  637. *os << "(ptr = " << (VoidifyPointer)(ptr.get()) << ", value = ";
  638. UniversalPrinter<T>::Print(*ptr, os);
  639. *os << ")";
  640. }
  641. }
  642. template <typename T, typename D>
  643. void PrintTo(const std::unique_ptr<T, D>& ptr, std::ostream* os) {
  644. (PrintSmartPointer<T>)(ptr, os, 0);
  645. }
  646. template <typename T>
  647. void PrintTo(const std::shared_ptr<T>& ptr, std::ostream* os) {
  648. (PrintSmartPointer<T>)(ptr, os, 0);
  649. }
  650. // Helper function for printing a tuple. T must be instantiated with
  651. // a tuple type.
  652. template <typename T>
  653. void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
  654. ::std::ostream*) {}
  655. template <typename T, size_t I>
  656. void PrintTupleTo(const T& t, std::integral_constant<size_t, I>,
  657. ::std::ostream* os) {
  658. PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
  659. GTEST_INTENTIONAL_CONST_COND_PUSH_()
  660. if (I > 1) {
  661. GTEST_INTENTIONAL_CONST_COND_POP_()
  662. *os << ", ";
  663. }
  664. UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print(
  665. std::get<I - 1>(t), os);
  666. }
  667. template <typename... Types>
  668. void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
  669. *os << "(";
  670. PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os);
  671. *os << ")";
  672. }
  673. // Overload for std::pair.
  674. template <typename T1, typename T2>
  675. void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
  676. *os << '(';
  677. // We cannot use UniversalPrint(value.first, os) here, as T1 may be
  678. // a reference type. The same for printing value.second.
  679. UniversalPrinter<T1>::Print(value.first, os);
  680. *os << ", ";
  681. UniversalPrinter<T2>::Print(value.second, os);
  682. *os << ')';
  683. }
  684. // Implements printing a non-reference type T by letting the compiler
  685. // pick the right overload of PrintTo() for T.
  686. template <typename T>
  687. class UniversalPrinter {
  688. public:
  689. // MSVC warns about adding const to a function type, so we want to
  690. // disable the warning.
  691. GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
  692. // Note: we deliberately don't call this PrintTo(), as that name
  693. // conflicts with ::testing::internal::PrintTo in the body of the
  694. // function.
  695. static void Print(const T& value, ::std::ostream* os) {
  696. // By default, ::testing::internal::PrintTo() is used for printing
  697. // the value.
  698. //
  699. // Thanks to Koenig look-up, if T is a class and has its own
  700. // PrintTo() function defined in its namespace, that function will
  701. // be visible here. Since it is more specific than the generic ones
  702. // in ::testing::internal, it will be picked by the compiler in the
  703. // following statement - exactly what we want.
  704. PrintTo(value, os);
  705. }
  706. GTEST_DISABLE_MSC_WARNINGS_POP_()
  707. };
  708. // Remove any const-qualifiers before passing a type to UniversalPrinter.
  709. template <typename T>
  710. class UniversalPrinter<const T> : public UniversalPrinter<T> {};
  711. #if GTEST_INTERNAL_HAS_ANY
  712. // Printer for std::any / absl::any
  713. template <>
  714. class UniversalPrinter<Any> {
  715. public:
  716. static void Print(const Any& value, ::std::ostream* os) {
  717. if (value.has_value()) {
  718. *os << "value of type " << GetTypeName(value);
  719. } else {
  720. *os << "no value";
  721. }
  722. }
  723. private:
  724. static std::string GetTypeName(const Any& value) {
  725. #if GTEST_HAS_RTTI
  726. return internal::GetTypeName(value.type());
  727. #else
  728. static_cast<void>(value); // possibly unused
  729. return "<unknown_type>";
  730. #endif // GTEST_HAS_RTTI
  731. }
  732. };
  733. #endif // GTEST_INTERNAL_HAS_ANY
  734. #if GTEST_INTERNAL_HAS_OPTIONAL
  735. // Printer for std::optional / absl::optional
  736. template <typename T>
  737. class UniversalPrinter<Optional<T>> {
  738. public:
  739. static void Print(const Optional<T>& value, ::std::ostream* os) {
  740. *os << '(';
  741. if (!value) {
  742. *os << "nullopt";
  743. } else {
  744. UniversalPrint(*value, os);
  745. }
  746. *os << ')';
  747. }
  748. };
  749. template <>
  750. class UniversalPrinter<decltype(Nullopt())> {
  751. public:
  752. static void Print(decltype(Nullopt()), ::std::ostream* os) {
  753. *os << "(nullopt)";
  754. }
  755. };
  756. #endif // GTEST_INTERNAL_HAS_OPTIONAL
  757. #if GTEST_INTERNAL_HAS_VARIANT
  758. // Printer for std::variant / absl::variant
  759. template <typename... T>
  760. class UniversalPrinter<Variant<T...>> {
  761. public:
  762. static void Print(const Variant<T...>& value, ::std::ostream* os) {
  763. *os << '(';
  764. #if GTEST_HAS_ABSL
  765. absl::visit(Visitor{os, value.index()}, value);
  766. #else
  767. std::visit(Visitor{os, value.index()}, value);
  768. #endif // GTEST_HAS_ABSL
  769. *os << ')';
  770. }
  771. private:
  772. struct Visitor {
  773. template <typename U>
  774. void operator()(const U& u) const {
  775. *os << "'" << GetTypeName<U>() << "(index = " << index
  776. << ")' with value ";
  777. UniversalPrint(u, os);
  778. }
  779. ::std::ostream* os;
  780. std::size_t index;
  781. };
  782. };
  783. #endif // GTEST_INTERNAL_HAS_VARIANT
  784. // UniversalPrintArray(begin, len, os) prints an array of 'len'
  785. // elements, starting at address 'begin'.
  786. template <typename T>
  787. void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
  788. if (len == 0) {
  789. *os << "{}";
  790. } else {
  791. *os << "{ ";
  792. const size_t kThreshold = 18;
  793. const size_t kChunkSize = 8;
  794. // If the array has more than kThreshold elements, we'll have to
  795. // omit some details by printing only the first and the last
  796. // kChunkSize elements.
  797. if (len <= kThreshold) {
  798. PrintRawArrayTo(begin, len, os);
  799. } else {
  800. PrintRawArrayTo(begin, kChunkSize, os);
  801. *os << ", ..., ";
  802. PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
  803. }
  804. *os << " }";
  805. }
  806. }
  807. // This overload prints a (const) char array compactly.
  808. GTEST_API_ void UniversalPrintArray(const char* begin, size_t len,
  809. ::std::ostream* os);
  810. #ifdef __cpp_char8_t
  811. // This overload prints a (const) char8_t array compactly.
  812. GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len,
  813. ::std::ostream* os);
  814. #endif
  815. // This overload prints a (const) char16_t array compactly.
  816. GTEST_API_ void UniversalPrintArray(const char16_t* begin, size_t len,
  817. ::std::ostream* os);
  818. // This overload prints a (const) char32_t array compactly.
  819. GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len,
  820. ::std::ostream* os);
  821. // This overload prints a (const) wchar_t array compactly.
  822. GTEST_API_ void UniversalPrintArray(const wchar_t* begin, size_t len,
  823. ::std::ostream* os);
  824. // Implements printing an array type T[N].
  825. template <typename T, size_t N>
  826. class UniversalPrinter<T[N]> {
  827. public:
  828. // Prints the given array, omitting some elements when there are too
  829. // many.
  830. static void Print(const T (&a)[N], ::std::ostream* os) {
  831. UniversalPrintArray(a, N, os);
  832. }
  833. };
  834. // Implements printing a reference type T&.
  835. template <typename T>
  836. class UniversalPrinter<T&> {
  837. public:
  838. // MSVC warns about adding const to a function type, so we want to
  839. // disable the warning.
  840. GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
  841. static void Print(const T& value, ::std::ostream* os) {
  842. // Prints the address of the value. We use reinterpret_cast here
  843. // as static_cast doesn't compile when T is a function type.
  844. *os << "@" << reinterpret_cast<const void*>(&value) << " ";
  845. // Then prints the value itself.
  846. UniversalPrint(value, os);
  847. }
  848. GTEST_DISABLE_MSC_WARNINGS_POP_()
  849. };
  850. // Prints a value tersely: for a reference type, the referenced value
  851. // (but not the address) is printed; for a (const) char pointer, the
  852. // NUL-terminated string (but not the pointer) is printed.
  853. template <typename T>
  854. class UniversalTersePrinter {
  855. public:
  856. static void Print(const T& value, ::std::ostream* os) {
  857. UniversalPrint(value, os);
  858. }
  859. };
  860. template <typename T>
  861. class UniversalTersePrinter<T&> {
  862. public:
  863. static void Print(const T& value, ::std::ostream* os) {
  864. UniversalPrint(value, os);
  865. }
  866. };
  867. template <typename T>
  868. class UniversalTersePrinter<std::reference_wrapper<T>> {
  869. public:
  870. static void Print(std::reference_wrapper<T> value, ::std::ostream* os) {
  871. UniversalTersePrinter<T>::Print(value.get(), os);
  872. }
  873. };
  874. template <typename T, size_t N>
  875. class UniversalTersePrinter<T[N]> {
  876. public:
  877. static void Print(const T (&value)[N], ::std::ostream* os) {
  878. UniversalPrinter<T[N]>::Print(value, os);
  879. }
  880. };
  881. template <>
  882. class UniversalTersePrinter<const char*> {
  883. public:
  884. static void Print(const char* str, ::std::ostream* os) {
  885. if (str == nullptr) {
  886. *os << "NULL";
  887. } else {
  888. UniversalPrint(std::string(str), os);
  889. }
  890. }
  891. };
  892. template <>
  893. class UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> {
  894. };
  895. #ifdef __cpp_char8_t
  896. template <>
  897. class UniversalTersePrinter<const char8_t*> {
  898. public:
  899. static void Print(const char8_t* str, ::std::ostream* os) {
  900. if (str == nullptr) {
  901. *os << "NULL";
  902. } else {
  903. UniversalPrint(::std::u8string(str), os);
  904. }
  905. }
  906. };
  907. template <>
  908. class UniversalTersePrinter<char8_t*>
  909. : public UniversalTersePrinter<const char8_t*> {};
  910. #endif
  911. template <>
  912. class UniversalTersePrinter<const char16_t*> {
  913. public:
  914. static void Print(const char16_t* str, ::std::ostream* os) {
  915. if (str == nullptr) {
  916. *os << "NULL";
  917. } else {
  918. UniversalPrint(::std::u16string(str), os);
  919. }
  920. }
  921. };
  922. template <>
  923. class UniversalTersePrinter<char16_t*>
  924. : public UniversalTersePrinter<const char16_t*> {};
  925. template <>
  926. class UniversalTersePrinter<const char32_t*> {
  927. public:
  928. static void Print(const char32_t* str, ::std::ostream* os) {
  929. if (str == nullptr) {
  930. *os << "NULL";
  931. } else {
  932. UniversalPrint(::std::u32string(str), os);
  933. }
  934. }
  935. };
  936. template <>
  937. class UniversalTersePrinter<char32_t*>
  938. : public UniversalTersePrinter<const char32_t*> {};
  939. #if GTEST_HAS_STD_WSTRING
  940. template <>
  941. class UniversalTersePrinter<const wchar_t*> {
  942. public:
  943. static void Print(const wchar_t* str, ::std::ostream* os) {
  944. if (str == nullptr) {
  945. *os << "NULL";
  946. } else {
  947. UniversalPrint(::std::wstring(str), os);
  948. }
  949. }
  950. };
  951. #endif
  952. template <>
  953. class UniversalTersePrinter<wchar_t*> {
  954. public:
  955. static void Print(wchar_t* str, ::std::ostream* os) {
  956. UniversalTersePrinter<const wchar_t*>::Print(str, os);
  957. }
  958. };
  959. template <typename T>
  960. void UniversalTersePrint(const T& value, ::std::ostream* os) {
  961. UniversalTersePrinter<T>::Print(value, os);
  962. }
  963. // Prints a value using the type inferred by the compiler. The
  964. // difference between this and UniversalTersePrint() is that for a
  965. // (const) char pointer, this prints both the pointer and the
  966. // NUL-terminated string.
  967. template <typename T>
  968. void UniversalPrint(const T& value, ::std::ostream* os) {
  969. // A workarond for the bug in VC++ 7.1 that prevents us from instantiating
  970. // UniversalPrinter with T directly.
  971. typedef T T1;
  972. UniversalPrinter<T1>::Print(value, os);
  973. }
  974. typedef ::std::vector<::std::string> Strings;
  975. // Tersely prints the first N fields of a tuple to a string vector,
  976. // one element for each field.
  977. template <typename Tuple>
  978. void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
  979. Strings*) {}
  980. template <typename Tuple, size_t I>
  981. void TersePrintPrefixToStrings(const Tuple& t,
  982. std::integral_constant<size_t, I>,
  983. Strings* strings) {
  984. TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(),
  985. strings);
  986. ::std::stringstream ss;
  987. UniversalTersePrint(std::get<I - 1>(t), &ss);
  988. strings->push_back(ss.str());
  989. }
  990. // Prints the fields of a tuple tersely to a string vector, one
  991. // element for each field. See the comment before
  992. // UniversalTersePrint() for how we define "tersely".
  993. template <typename Tuple>
  994. Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
  995. Strings result;
  996. TersePrintPrefixToStrings(
  997. value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(),
  998. &result);
  999. return result;
  1000. }
  1001. } // namespace internal
  1002. template <typename T>
  1003. ::std::string PrintToString(const T& value) {
  1004. ::std::stringstream ss;
  1005. internal::UniversalTersePrinter<T>::Print(value, &ss);
  1006. return ss.str();
  1007. }
  1008. } // namespace testing
  1009. // Include any custom printer added by the local installation.
  1010. // We must include this header at the end to make sure it can use the
  1011. // declarations from this file.
  1012. #include "gtest/internal/custom/gtest-printers.h"
  1013. #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_