Publishing R3
[platform/upstream/dldt.git] / inference-engine / tests / libs / gtest / googletest / test / gtest-printers_test.cc
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 //
30 // Author: wan@google.com (Zhanyong Wan)
31
32 // Google Test - The Google C++ Testing Framework
33 //
34 // This file tests the universal value printer.
35
36 #include "gtest/gtest-printers.h"
37
38 #include <ctype.h>
39 #include <limits.h>
40 #include <string.h>
41 #include <algorithm>
42 #include <deque>
43 #include <list>
44 #include <map>
45 #include <set>
46 #include <sstream>
47 #include <string>
48 #include <utility>
49 #include <vector>
50
51 #include "gtest/gtest.h"
52
53 // hash_map and hash_set are available under Visual C++, or on Linux.
54 #if GTEST_HAS_HASH_MAP_
55 # include <hash_map>            // NOLINT
56 #endif  // GTEST_HAS_HASH_MAP_
57 #if GTEST_HAS_HASH_SET_
58 # include <hash_set>            // NOLINT
59 #endif  // GTEST_HAS_HASH_SET_
60
61 #if GTEST_HAS_STD_FORWARD_LIST_
62 # include <forward_list> // NOLINT
63 #endif  // GTEST_HAS_STD_FORWARD_LIST_
64
65 // Some user-defined types for testing the universal value printer.
66
67 // An anonymous enum type.
68 enum AnonymousEnum {
69   kAE1 = -1,
70   kAE2 = 1
71 };
72
73 // An enum without a user-defined printer.
74 enum EnumWithoutPrinter {
75   kEWP1 = -2,
76   kEWP2 = 42
77 };
78
79 // An enum with a << operator.
80 enum EnumWithStreaming {
81   kEWS1 = 10
82 };
83
84 std::ostream& operator<<(std::ostream& os, EnumWithStreaming e) {
85   return os << (e == kEWS1 ? "kEWS1" : "invalid");
86 }
87
88 // An enum with a PrintTo() function.
89 enum EnumWithPrintTo {
90   kEWPT1 = 1
91 };
92
93 void PrintTo(EnumWithPrintTo e, std::ostream* os) {
94   *os << (e == kEWPT1 ? "kEWPT1" : "invalid");
95 }
96
97 // A class implicitly convertible to BiggestInt.
98 class BiggestIntConvertible {
99  public:
100   operator ::testing::internal::BiggestInt() const { return 42; }
101 };
102
103 // A user-defined unprintable class template in the global namespace.
104 template <typename T>
105 class UnprintableTemplateInGlobal {
106  public:
107   UnprintableTemplateInGlobal() : value_() {}
108  private:
109   T value_;
110 };
111
112 // A user-defined streamable type in the global namespace.
113 class StreamableInGlobal {
114  public:
115   virtual ~StreamableInGlobal() {}
116 };
117
118 inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
119   os << "StreamableInGlobal";
120 }
121
122 void operator<<(::std::ostream& os, const StreamableInGlobal* /* x */) {
123   os << "StreamableInGlobal*";
124 }
125
126 namespace foo {
127
128 // A user-defined unprintable type in a user namespace.
129 class UnprintableInFoo {
130  public:
131   UnprintableInFoo() : z_(0) { memcpy(xy_, "\xEF\x12\x0\x0\x34\xAB\x0\x0", 8); }
132   double z() const { return z_; }
133  private:
134   char xy_[8];
135   double z_;
136 };
137
138 // A user-defined printable type in a user-chosen namespace.
139 struct PrintableViaPrintTo {
140   PrintableViaPrintTo() : value() {}
141   int value;
142 };
143
144 void PrintTo(const PrintableViaPrintTo& x, ::std::ostream* os) {
145   *os << "PrintableViaPrintTo: " << x.value;
146 }
147
148 // A type with a user-defined << for printing its pointer.
149 struct PointerPrintable {
150 };
151
152 ::std::ostream& operator<<(::std::ostream& os,
153                            const PointerPrintable* /* x */) {
154   return os << "PointerPrintable*";
155 }
156
157 // A user-defined printable class template in a user-chosen namespace.
158 template <typename T>
159 class PrintableViaPrintToTemplate {
160  public:
161   explicit PrintableViaPrintToTemplate(const T& a_value) : value_(a_value) {}
162
163   const T& value() const { return value_; }
164  private:
165   T value_;
166 };
167
168 template <typename T>
169 void PrintTo(const PrintableViaPrintToTemplate<T>& x, ::std::ostream* os) {
170   *os << "PrintableViaPrintToTemplate: " << x.value();
171 }
172
173 // A user-defined streamable class template in a user namespace.
174 template <typename T>
175 class StreamableTemplateInFoo {
176  public:
177   StreamableTemplateInFoo() : value_() {}
178
179   const T& value() const { return value_; }
180  private:
181   T value_;
182 };
183
184 template <typename T>
185 inline ::std::ostream& operator<<(::std::ostream& os,
186                                   const StreamableTemplateInFoo<T>& x) {
187   return os << "StreamableTemplateInFoo: " << x.value();
188 }
189
190 // A user-defined streamable but recursivly-defined container type in 
191 // a user namespace, it mimics therefore std::filesystem::path or
192 // boost::filesystem::path.
193 class PathLike {
194  public:
195   struct iterator
196   {
197     typedef PathLike value_type;
198   };
199   typedef iterator const_iterator;
200
201   PathLike() {}
202
203   iterator begin() const { return iterator(); }
204   iterator end() const { return iterator(); }
205
206   friend 
207   ::std::ostream& operator<<(::std::ostream& os, const PathLike&)
208   {
209     return os << "Streamable-PathLike";
210   }
211 };
212
213 }  // namespace foo
214
215 namespace testing {
216 namespace gtest_printers_test {
217
218 using ::std::deque;
219 using ::std::list;
220 using ::std::make_pair;
221 using ::std::map;
222 using ::std::multimap;
223 using ::std::multiset;
224 using ::std::pair;
225 using ::std::set;
226 using ::std::vector;
227 using ::testing::PrintToString;
228 using ::testing::internal::FormatForComparisonFailureMessage;
229 using ::testing::internal::ImplicitCast_;
230 using ::testing::internal::NativeArray;
231 using ::testing::internal::RE;
232 using ::testing::internal::RelationToSourceReference;
233 using ::testing::internal::Strings;
234 using ::testing::internal::UniversalPrint;
235 using ::testing::internal::UniversalPrinter;
236 using ::testing::internal::UniversalTersePrint;
237 #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
238 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
239 #endif
240 using ::testing::internal::string;
241
242 #if GTEST_HAS_HASH_MAP_
243 // The hash_* classes are not part of the C++ standard.  STLport
244 // defines them in namespace std.  MSVC defines them in ::stdext.  GCC
245 // defines them in ::.
246 #ifdef _STLP_HASH_MAP  // We got <hash_map> from STLport.
247 using ::std::hash_map;
248 using ::std::hash_set;
249 using ::std::hash_multimap;
250 using ::std::hash_multiset;
251 #elif _MSC_VER
252 using ::stdext::hash_map;
253 using ::stdext::hash_set;
254 using ::stdext::hash_multimap;
255 using ::stdext::hash_multiset;
256 #endif
257 #endif
258
259 // Prints a value to a string using the universal value printer.  This
260 // is a helper for testing UniversalPrinter<T>::Print() for various types.
261 template <typename T>
262 std::string Print(const T& value) {
263   ::std::stringstream ss;
264   UniversalPrinter<T>::Print(value, &ss);
265   return ss.str();
266 }
267
268 // Prints a value passed by reference to a string, using the universal
269 // value printer.  This is a helper for testing
270 // UniversalPrinter<T&>::Print() for various types.
271 template <typename T>
272 std::string PrintByRef(const T& value) {
273   ::std::stringstream ss;
274   UniversalPrinter<T&>::Print(value, &ss);
275   return ss.str();
276 }
277
278 // Tests printing various enum types.
279
280 TEST(PrintEnumTest, AnonymousEnum) {
281   EXPECT_EQ("-1", Print(kAE1));
282   EXPECT_EQ("1", Print(kAE2));
283 }
284
285 TEST(PrintEnumTest, EnumWithoutPrinter) {
286   EXPECT_EQ("-2", Print(kEWP1));
287   EXPECT_EQ("42", Print(kEWP2));
288 }
289
290 TEST(PrintEnumTest, EnumWithStreaming) {
291   EXPECT_EQ("kEWS1", Print(kEWS1));
292   EXPECT_EQ("invalid", Print(static_cast<EnumWithStreaming>(0)));
293 }
294
295 TEST(PrintEnumTest, EnumWithPrintTo) {
296   EXPECT_EQ("kEWPT1", Print(kEWPT1));
297   EXPECT_EQ("invalid", Print(static_cast<EnumWithPrintTo>(0)));
298 }
299
300 // Tests printing a class implicitly convertible to BiggestInt.
301
302 TEST(PrintClassTest, BiggestIntConvertible) {
303   EXPECT_EQ("42", Print(BiggestIntConvertible()));
304 }
305
306 // Tests printing various char types.
307
308 // char.
309 TEST(PrintCharTest, PlainChar) {
310   EXPECT_EQ("'\\0'", Print('\0'));
311   EXPECT_EQ("'\\'' (39, 0x27)", Print('\''));
312   EXPECT_EQ("'\"' (34, 0x22)", Print('"'));
313   EXPECT_EQ("'?' (63, 0x3F)", Print('?'));
314   EXPECT_EQ("'\\\\' (92, 0x5C)", Print('\\'));
315   EXPECT_EQ("'\\a' (7)", Print('\a'));
316   EXPECT_EQ("'\\b' (8)", Print('\b'));
317   EXPECT_EQ("'\\f' (12, 0xC)", Print('\f'));
318   EXPECT_EQ("'\\n' (10, 0xA)", Print('\n'));
319   EXPECT_EQ("'\\r' (13, 0xD)", Print('\r'));
320   EXPECT_EQ("'\\t' (9)", Print('\t'));
321   EXPECT_EQ("'\\v' (11, 0xB)", Print('\v'));
322   EXPECT_EQ("'\\x7F' (127)", Print('\x7F'));
323   EXPECT_EQ("'\\xFF' (255)", Print('\xFF'));
324   EXPECT_EQ("' ' (32, 0x20)", Print(' '));
325   EXPECT_EQ("'a' (97, 0x61)", Print('a'));
326 }
327
328 // signed char.
329 TEST(PrintCharTest, SignedChar) {
330   EXPECT_EQ("'\\0'", Print(static_cast<signed char>('\0')));
331   EXPECT_EQ("'\\xCE' (-50)",
332             Print(static_cast<signed char>(-50)));
333 }
334
335 // unsigned char.
336 TEST(PrintCharTest, UnsignedChar) {
337   EXPECT_EQ("'\\0'", Print(static_cast<unsigned char>('\0')));
338   EXPECT_EQ("'b' (98, 0x62)",
339             Print(static_cast<unsigned char>('b')));
340 }
341
342 // Tests printing other simple, built-in types.
343
344 // bool.
345 TEST(PrintBuiltInTypeTest, Bool) {
346   EXPECT_EQ("false", Print(false));
347   EXPECT_EQ("true", Print(true));
348 }
349
350 // wchar_t.
351 TEST(PrintBuiltInTypeTest, Wchar_t) {
352   EXPECT_EQ("L'\\0'", Print(L'\0'));
353   EXPECT_EQ("L'\\'' (39, 0x27)", Print(L'\''));
354   EXPECT_EQ("L'\"' (34, 0x22)", Print(L'"'));
355   EXPECT_EQ("L'?' (63, 0x3F)", Print(L'?'));
356   EXPECT_EQ("L'\\\\' (92, 0x5C)", Print(L'\\'));
357   EXPECT_EQ("L'\\a' (7)", Print(L'\a'));
358   EXPECT_EQ("L'\\b' (8)", Print(L'\b'));
359   EXPECT_EQ("L'\\f' (12, 0xC)", Print(L'\f'));
360   EXPECT_EQ("L'\\n' (10, 0xA)", Print(L'\n'));
361   EXPECT_EQ("L'\\r' (13, 0xD)", Print(L'\r'));
362   EXPECT_EQ("L'\\t' (9)", Print(L'\t'));
363   EXPECT_EQ("L'\\v' (11, 0xB)", Print(L'\v'));
364   EXPECT_EQ("L'\\x7F' (127)", Print(L'\x7F'));
365   EXPECT_EQ("L'\\xFF' (255)", Print(L'\xFF'));
366   EXPECT_EQ("L' ' (32, 0x20)", Print(L' '));
367   EXPECT_EQ("L'a' (97, 0x61)", Print(L'a'));
368   EXPECT_EQ("L'\\x576' (1398)", Print(static_cast<wchar_t>(0x576)));
369   EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D)));
370 }
371
372 // Test that Int64 provides more storage than wchar_t.
373 TEST(PrintTypeSizeTest, Wchar_t) {
374   EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64));
375 }
376
377 // Various integer types.
378 TEST(PrintBuiltInTypeTest, Integer) {
379   EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255)));  // uint8
380   EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128)));  // int8
381   EXPECT_EQ("65535", Print(USHRT_MAX));  // uint16
382   EXPECT_EQ("-32768", Print(SHRT_MIN));  // int16
383   EXPECT_EQ("4294967295", Print(UINT_MAX));  // uint32
384   EXPECT_EQ("-2147483648", Print(INT_MIN));  // int32
385   EXPECT_EQ("18446744073709551615",
386             Print(static_cast<testing::internal::UInt64>(-1)));  // uint64
387   EXPECT_EQ("-9223372036854775808",
388             Print(static_cast<testing::internal::Int64>(1) << 63));  // int64
389 }
390
391 // Size types.
392 TEST(PrintBuiltInTypeTest, Size_t) {
393   EXPECT_EQ("1", Print(sizeof('a')));  // size_t.
394 #if !GTEST_OS_WINDOWS
395   // Windows has no ssize_t type.
396   EXPECT_EQ("-2", Print(static_cast<ssize_t>(-2)));  // ssize_t.
397 #endif  // !GTEST_OS_WINDOWS
398 }
399
400 // Floating-points.
401 TEST(PrintBuiltInTypeTest, FloatingPoints) {
402   EXPECT_EQ("1.5", Print(1.5f));   // float
403   EXPECT_EQ("-2.5", Print(-2.5));  // double
404 }
405
406 // Since ::std::stringstream::operator<<(const void *) formats the pointer
407 // output differently with different compilers, we have to create the expected
408 // output first and use it as our expectation.
409 static std::string PrintPointer(const void* p) {
410   ::std::stringstream expected_result_stream;
411   expected_result_stream << p;
412   return expected_result_stream.str();
413 }
414
415 // Tests printing C strings.
416
417 // const char*.
418 TEST(PrintCStringTest, Const) {
419   const char* p = "World";
420   EXPECT_EQ(PrintPointer(p) + " pointing to \"World\"", Print(p));
421 }
422
423 // char*.
424 TEST(PrintCStringTest, NonConst) {
425   char p[] = "Hi";
426   EXPECT_EQ(PrintPointer(p) + " pointing to \"Hi\"",
427             Print(static_cast<char*>(p)));
428 }
429
430 // NULL C string.
431 TEST(PrintCStringTest, Null) {
432   const char* p = NULL;
433   EXPECT_EQ("NULL", Print(p));
434 }
435
436 // Tests that C strings are escaped properly.
437 TEST(PrintCStringTest, EscapesProperly) {
438   const char* p = "'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
439   EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"?\\\\\\a\\b\\f"
440             "\\n\\r\\t\\v\\x7F\\xFF a\"",
441             Print(p));
442 }
443
444 // MSVC compiler can be configured to define whar_t as a typedef
445 // of unsigned short. Defining an overload for const wchar_t* in that case
446 // would cause pointers to unsigned shorts be printed as wide strings,
447 // possibly accessing more memory than intended and causing invalid
448 // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
449 // wchar_t is implemented as a native type.
450 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
451
452 // const wchar_t*.
453 TEST(PrintWideCStringTest, Const) {
454   const wchar_t* p = L"World";
455   EXPECT_EQ(PrintPointer(p) + " pointing to L\"World\"", Print(p));
456 }
457
458 // wchar_t*.
459 TEST(PrintWideCStringTest, NonConst) {
460   wchar_t p[] = L"Hi";
461   EXPECT_EQ(PrintPointer(p) + " pointing to L\"Hi\"",
462             Print(static_cast<wchar_t*>(p)));
463 }
464
465 // NULL wide C string.
466 TEST(PrintWideCStringTest, Null) {
467   const wchar_t* p = NULL;
468   EXPECT_EQ("NULL", Print(p));
469 }
470
471 // Tests that wide C strings are escaped properly.
472 TEST(PrintWideCStringTest, EscapesProperly) {
473   const wchar_t s[] = {'\'', '"', '?', '\\', '\a', '\b', '\f', '\n', '\r',
474                        '\t', '\v', 0xD3, 0x576, 0x8D3, 0xC74D, ' ', 'a', '\0'};
475   EXPECT_EQ(PrintPointer(s) + " pointing to L\"'\\\"?\\\\\\a\\b\\f"
476             "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
477             Print(static_cast<const wchar_t*>(s)));
478 }
479 #endif  // native wchar_t
480
481 // Tests printing pointers to other char types.
482
483 // signed char*.
484 TEST(PrintCharPointerTest, SignedChar) {
485   signed char* p = reinterpret_cast<signed char*>(0x1234);
486   EXPECT_EQ(PrintPointer(p), Print(p));
487   p = NULL;
488   EXPECT_EQ("NULL", Print(p));
489 }
490
491 // const signed char*.
492 TEST(PrintCharPointerTest, ConstSignedChar) {
493   signed char* p = reinterpret_cast<signed char*>(0x1234);
494   EXPECT_EQ(PrintPointer(p), Print(p));
495   p = NULL;
496   EXPECT_EQ("NULL", Print(p));
497 }
498
499 // unsigned char*.
500 TEST(PrintCharPointerTest, UnsignedChar) {
501   unsigned char* p = reinterpret_cast<unsigned char*>(0x1234);
502   EXPECT_EQ(PrintPointer(p), Print(p));
503   p = NULL;
504   EXPECT_EQ("NULL", Print(p));
505 }
506
507 // const unsigned char*.
508 TEST(PrintCharPointerTest, ConstUnsignedChar) {
509   const unsigned char* p = reinterpret_cast<const unsigned char*>(0x1234);
510   EXPECT_EQ(PrintPointer(p), Print(p));
511   p = NULL;
512   EXPECT_EQ("NULL", Print(p));
513 }
514
515 // Tests printing pointers to simple, built-in types.
516
517 // bool*.
518 TEST(PrintPointerToBuiltInTypeTest, Bool) {
519   bool* p = reinterpret_cast<bool*>(0xABCD);
520   EXPECT_EQ(PrintPointer(p), Print(p));
521   p = NULL;
522   EXPECT_EQ("NULL", Print(p));
523 }
524
525 // void*.
526 TEST(PrintPointerToBuiltInTypeTest, Void) {
527   void* p = reinterpret_cast<void*>(0xABCD);
528   EXPECT_EQ(PrintPointer(p), Print(p));
529   p = NULL;
530   EXPECT_EQ("NULL", Print(p));
531 }
532
533 // const void*.
534 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
535   const void* p = reinterpret_cast<const void*>(0xABCD);
536   EXPECT_EQ(PrintPointer(p), Print(p));
537   p = NULL;
538   EXPECT_EQ("NULL", Print(p));
539 }
540
541 // Tests printing pointers to pointers.
542 TEST(PrintPointerToPointerTest, IntPointerPointer) {
543   int** p = reinterpret_cast<int**>(0xABCD);
544   EXPECT_EQ(PrintPointer(p), Print(p));
545   p = NULL;
546   EXPECT_EQ("NULL", Print(p));
547 }
548
549 // Tests printing (non-member) function pointers.
550
551 void MyFunction(int /* n */) {}
552
553 TEST(PrintPointerTest, NonMemberFunctionPointer) {
554   // We cannot directly cast &MyFunction to const void* because the
555   // standard disallows casting between pointers to functions and
556   // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
557   // this limitation.
558   EXPECT_EQ(
559       PrintPointer(reinterpret_cast<const void*>(
560           reinterpret_cast<internal::BiggestInt>(&MyFunction))),
561       Print(&MyFunction));
562   int (*p)(bool) = NULL;  // NOLINT
563   EXPECT_EQ("NULL", Print(p));
564 }
565
566 // An assertion predicate determining whether a one string is a prefix for
567 // another.
568 template <typename StringType>
569 AssertionResult HasPrefix(const StringType& str, const StringType& prefix) {
570   if (str.find(prefix, 0) == 0)
571     return AssertionSuccess();
572
573   const bool is_wide_string = sizeof(prefix[0]) > 1;
574   const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
575   return AssertionFailure()
576       << begin_string_quote << prefix << "\" is not a prefix of "
577       << begin_string_quote << str << "\"\n";
578 }
579
580 // Tests printing member variable pointers.  Although they are called
581 // pointers, they don't point to a location in the address space.
582 // Their representation is implementation-defined.  Thus they will be
583 // printed as raw bytes.
584
585 struct Foo {
586  public:
587   virtual ~Foo() {}
588   int MyMethod(char x) { return x + 1; }
589   virtual char MyVirtualMethod(int /* n */) { return 'a'; }
590
591   int value;
592 };
593
594 TEST(PrintPointerTest, MemberVariablePointer) {
595   EXPECT_TRUE(HasPrefix(Print(&Foo::value),
596                         Print(sizeof(&Foo::value)) + "-byte object "));
597   int (Foo::*p) = NULL;  // NOLINT
598   EXPECT_TRUE(HasPrefix(Print(p),
599                         Print(sizeof(p)) + "-byte object "));
600 }
601
602 // Tests printing member function pointers.  Although they are called
603 // pointers, they don't point to a location in the address space.
604 // Their representation is implementation-defined.  Thus they will be
605 // printed as raw bytes.
606 TEST(PrintPointerTest, MemberFunctionPointer) {
607   EXPECT_TRUE(HasPrefix(Print(&Foo::MyMethod),
608                         Print(sizeof(&Foo::MyMethod)) + "-byte object "));
609   EXPECT_TRUE(
610       HasPrefix(Print(&Foo::MyVirtualMethod),
611                 Print(sizeof((&Foo::MyVirtualMethod))) + "-byte object "));
612   int (Foo::*p)(char) = NULL;  // NOLINT
613   EXPECT_TRUE(HasPrefix(Print(p),
614                         Print(sizeof(p)) + "-byte object "));
615 }
616
617 // Tests printing C arrays.
618
619 // The difference between this and Print() is that it ensures that the
620 // argument is a reference to an array.
621 template <typename T, size_t N>
622 std::string PrintArrayHelper(T (&a)[N]) {
623   return Print(a);
624 }
625
626 // One-dimensional array.
627 TEST(PrintArrayTest, OneDimensionalArray) {
628   int a[5] = { 1, 2, 3, 4, 5 };
629   EXPECT_EQ("{ 1, 2, 3, 4, 5 }", PrintArrayHelper(a));
630 }
631
632 // Two-dimensional array.
633 TEST(PrintArrayTest, TwoDimensionalArray) {
634   int a[2][5] = {
635     { 1, 2, 3, 4, 5 },
636     { 6, 7, 8, 9, 0 }
637   };
638   EXPECT_EQ("{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }", PrintArrayHelper(a));
639 }
640
641 // Array of const elements.
642 TEST(PrintArrayTest, ConstArray) {
643   const bool a[1] = { false };
644   EXPECT_EQ("{ false }", PrintArrayHelper(a));
645 }
646
647 // char array without terminating NUL.
648 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
649   // Array a contains '\0' in the middle and doesn't end with '\0'.
650   char a[] = { 'H', '\0', 'i' };
651   EXPECT_EQ("\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
652 }
653
654 // const char array with terminating NUL.
655 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
656   const char a[] = "\0Hi";
657   EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a));
658 }
659
660 // const wchar_t array without terminating NUL.
661 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
662   // Array a contains '\0' in the middle and doesn't end with '\0'.
663   const wchar_t a[] = { L'H', L'\0', L'i' };
664   EXPECT_EQ("L\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
665 }
666
667 // wchar_t array with terminating NUL.
668 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
669   const wchar_t a[] = L"\0Hi";
670   EXPECT_EQ("L\"\\0Hi\"", PrintArrayHelper(a));
671 }
672
673 // Array of objects.
674 TEST(PrintArrayTest, ObjectArray) {
675   std::string a[3] = {"Hi", "Hello", "Ni hao"};
676   EXPECT_EQ("{ \"Hi\", \"Hello\", \"Ni hao\" }", PrintArrayHelper(a));
677 }
678
679 // Array with many elements.
680 TEST(PrintArrayTest, BigArray) {
681   int a[100] = { 1, 2, 3 };
682   EXPECT_EQ("{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
683             PrintArrayHelper(a));
684 }
685
686 // Tests printing ::string and ::std::string.
687
688 #if GTEST_HAS_GLOBAL_STRING
689 // ::string.
690 TEST(PrintStringTest, StringInGlobalNamespace) {
691   const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
692   const ::string str(s, sizeof(s));
693   EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
694             Print(str));
695 }
696 #endif  // GTEST_HAS_GLOBAL_STRING
697
698 // ::std::string.
699 TEST(PrintStringTest, StringInStdNamespace) {
700   const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
701   const ::std::string str(s, sizeof(s));
702   EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
703             Print(str));
704 }
705
706 TEST(PrintStringTest, StringAmbiguousHex) {
707   // "\x6BANANA" is ambiguous, it can be interpreted as starting with either of:
708   // '\x6', '\x6B', or '\x6BA'.
709
710   // a hex escaping sequence following by a decimal digit
711   EXPECT_EQ("\"0\\x12\" \"3\"", Print(::std::string("0\x12" "3")));
712   // a hex escaping sequence following by a hex digit (lower-case)
713   EXPECT_EQ("\"mm\\x6\" \"bananas\"", Print(::std::string("mm\x6" "bananas")));
714   // a hex escaping sequence following by a hex digit (upper-case)
715   EXPECT_EQ("\"NOM\\x6\" \"BANANA\"", Print(::std::string("NOM\x6" "BANANA")));
716   // a hex escaping sequence following by a non-xdigit
717   EXPECT_EQ("\"!\\x5-!\"", Print(::std::string("!\x5-!")));
718 }
719
720 // Tests printing ::wstring and ::std::wstring.
721
722 #if GTEST_HAS_GLOBAL_WSTRING
723 // ::wstring.
724 TEST(PrintWideStringTest, StringInGlobalNamespace) {
725   const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
726   const ::wstring str(s, sizeof(s)/sizeof(wchar_t));
727   EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
728             "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
729             Print(str));
730 }
731 #endif  // GTEST_HAS_GLOBAL_WSTRING
732
733 #if GTEST_HAS_STD_WSTRING
734 // ::std::wstring.
735 TEST(PrintWideStringTest, StringInStdNamespace) {
736   const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
737   const ::std::wstring str(s, sizeof(s)/sizeof(wchar_t));
738   EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
739             "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
740             Print(str));
741 }
742
743 TEST(PrintWideStringTest, StringAmbiguousHex) {
744   // same for wide strings.
745   EXPECT_EQ("L\"0\\x12\" L\"3\"", Print(::std::wstring(L"0\x12" L"3")));
746   EXPECT_EQ("L\"mm\\x6\" L\"bananas\"",
747             Print(::std::wstring(L"mm\x6" L"bananas")));
748   EXPECT_EQ("L\"NOM\\x6\" L\"BANANA\"",
749             Print(::std::wstring(L"NOM\x6" L"BANANA")));
750   EXPECT_EQ("L\"!\\x5-!\"", Print(::std::wstring(L"!\x5-!")));
751 }
752 #endif  // GTEST_HAS_STD_WSTRING
753
754 // Tests printing types that support generic streaming (i.e. streaming
755 // to std::basic_ostream<Char, CharTraits> for any valid Char and
756 // CharTraits types).
757
758 // Tests printing a non-template type that supports generic streaming.
759
760 class AllowsGenericStreaming {};
761
762 template <typename Char, typename CharTraits>
763 std::basic_ostream<Char, CharTraits>& operator<<(
764     std::basic_ostream<Char, CharTraits>& os,
765     const AllowsGenericStreaming& /* a */) {
766   return os << "AllowsGenericStreaming";
767 }
768
769 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
770   AllowsGenericStreaming a;
771   EXPECT_EQ("AllowsGenericStreaming", Print(a));
772 }
773
774 // Tests printing a template type that supports generic streaming.
775
776 template <typename T>
777 class AllowsGenericStreamingTemplate {};
778
779 template <typename Char, typename CharTraits, typename T>
780 std::basic_ostream<Char, CharTraits>& operator<<(
781     std::basic_ostream<Char, CharTraits>& os,
782     const AllowsGenericStreamingTemplate<T>& /* a */) {
783   return os << "AllowsGenericStreamingTemplate";
784 }
785
786 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
787   AllowsGenericStreamingTemplate<int> a;
788   EXPECT_EQ("AllowsGenericStreamingTemplate", Print(a));
789 }
790
791 // Tests printing a type that supports generic streaming and can be
792 // implicitly converted to another printable type.
793
794 template <typename T>
795 class AllowsGenericStreamingAndImplicitConversionTemplate {
796  public:
797   operator bool() const { return false; }
798 };
799
800 template <typename Char, typename CharTraits, typename T>
801 std::basic_ostream<Char, CharTraits>& operator<<(
802     std::basic_ostream<Char, CharTraits>& os,
803     const AllowsGenericStreamingAndImplicitConversionTemplate<T>& /* a */) {
804   return os << "AllowsGenericStreamingAndImplicitConversionTemplate";
805 }
806
807 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
808   AllowsGenericStreamingAndImplicitConversionTemplate<int> a;
809   EXPECT_EQ("AllowsGenericStreamingAndImplicitConversionTemplate", Print(a));
810 }
811
812 #if GTEST_HAS_STRING_PIECE_
813
814 // Tests printing StringPiece.
815
816 TEST(PrintStringPieceTest, SimpleStringPiece) {
817   const StringPiece sp = "Hello";
818   EXPECT_EQ("\"Hello\"", Print(sp));
819 }
820
821 TEST(PrintStringPieceTest, UnprintableCharacters) {
822   const char str[] = "NUL (\0) and \r\t";
823   const StringPiece sp(str, sizeof(str) - 1);
824   EXPECT_EQ("\"NUL (\\0) and \\r\\t\"", Print(sp));
825 }
826
827 #endif  // GTEST_HAS_STRING_PIECE_
828
829 // Tests printing STL containers.
830
831 TEST(PrintStlContainerTest, EmptyDeque) {
832   deque<char> empty;
833   EXPECT_EQ("{}", Print(empty));
834 }
835
836 TEST(PrintStlContainerTest, NonEmptyDeque) {
837   deque<int> non_empty;
838   non_empty.push_back(1);
839   non_empty.push_back(3);
840   EXPECT_EQ("{ 1, 3 }", Print(non_empty));
841 }
842
843 #if GTEST_HAS_HASH_MAP_
844
845 TEST(PrintStlContainerTest, OneElementHashMap) {
846   hash_map<int, char> map1;
847   map1[1] = 'a';
848   EXPECT_EQ("{ (1, 'a' (97, 0x61)) }", Print(map1));
849 }
850
851 TEST(PrintStlContainerTest, HashMultiMap) {
852   hash_multimap<int, bool> map1;
853   map1.insert(make_pair(5, true));
854   map1.insert(make_pair(5, false));
855
856   // Elements of hash_multimap can be printed in any order.
857   const std::string result = Print(map1);
858   EXPECT_TRUE(result == "{ (5, true), (5, false) }" ||
859               result == "{ (5, false), (5, true) }")
860                   << " where Print(map1) returns \"" << result << "\".";
861 }
862
863 #endif  // GTEST_HAS_HASH_MAP_
864
865 #if GTEST_HAS_HASH_SET_
866
867 TEST(PrintStlContainerTest, HashSet) {
868   hash_set<int> set1;
869   set1.insert(1);
870   EXPECT_EQ("{ 1 }", Print(set1));
871 }
872
873 TEST(PrintStlContainerTest, HashMultiSet) {
874   const int kSize = 5;
875   int a[kSize] = { 1, 1, 2, 5, 1 };
876   hash_multiset<int> set1(a, a + kSize);
877
878   // Elements of hash_multiset can be printed in any order.
879   const std::string result = Print(set1);
880   const std::string expected_pattern = "{ d, d, d, d, d }";  // d means a digit.
881
882   // Verifies the result matches the expected pattern; also extracts
883   // the numbers in the result.
884   ASSERT_EQ(expected_pattern.length(), result.length());
885   std::vector<int> numbers;
886   for (size_t i = 0; i != result.length(); i++) {
887     if (expected_pattern[i] == 'd') {
888       ASSERT_NE(isdigit(static_cast<unsigned char>(result[i])), 0);
889       numbers.push_back(result[i] - '0');
890     } else {
891       EXPECT_EQ(expected_pattern[i], result[i]) << " where result is "
892                                                 << result;
893     }
894   }
895
896   // Makes sure the result contains the right numbers.
897   std::sort(numbers.begin(), numbers.end());
898   std::sort(a, a + kSize);
899   EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
900 }
901
902 #endif  // GTEST_HAS_HASH_SET_
903
904 TEST(PrintStlContainerTest, List) {
905   const std::string a[] = {"hello", "world"};
906   const list<std::string> strings(a, a + 2);
907   EXPECT_EQ("{ \"hello\", \"world\" }", Print(strings));
908 }
909
910 TEST(PrintStlContainerTest, Map) {
911   map<int, bool> map1;
912   map1[1] = true;
913   map1[5] = false;
914   map1[3] = true;
915   EXPECT_EQ("{ (1, true), (3, true), (5, false) }", Print(map1));
916 }
917
918 TEST(PrintStlContainerTest, MultiMap) {
919   multimap<bool, int> map1;
920   // The make_pair template function would deduce the type as
921   // pair<bool, int> here, and since the key part in a multimap has to
922   // be constant, without a templated ctor in the pair class (as in
923   // libCstd on Solaris), make_pair call would fail to compile as no
924   // implicit conversion is found.  Thus explicit typename is used
925   // here instead.
926   map1.insert(pair<const bool, int>(true, 0));
927   map1.insert(pair<const bool, int>(true, 1));
928   map1.insert(pair<const bool, int>(false, 2));
929   EXPECT_EQ("{ (false, 2), (true, 0), (true, 1) }", Print(map1));
930 }
931
932 TEST(PrintStlContainerTest, Set) {
933   const unsigned int a[] = { 3, 0, 5 };
934   set<unsigned int> set1(a, a + 3);
935   EXPECT_EQ("{ 0, 3, 5 }", Print(set1));
936 }
937
938 TEST(PrintStlContainerTest, MultiSet) {
939   const int a[] = { 1, 1, 2, 5, 1 };
940   multiset<int> set1(a, a + 5);
941   EXPECT_EQ("{ 1, 1, 1, 2, 5 }", Print(set1));
942 }
943
944 #if GTEST_HAS_STD_FORWARD_LIST_
945 // <slist> is available on Linux in the google3 mode, but not on
946 // Windows or Mac OS X.
947
948 TEST(PrintStlContainerTest, SinglyLinkedList) {
949   int a[] = { 9, 2, 8 };
950   const std::forward_list<int> ints(a, a + 3);
951   EXPECT_EQ("{ 9, 2, 8 }", Print(ints));
952 }
953 #endif  // GTEST_HAS_STD_FORWARD_LIST_
954
955 TEST(PrintStlContainerTest, Pair) {
956   pair<const bool, int> p(true, 5);
957   EXPECT_EQ("(true, 5)", Print(p));
958 }
959
960 TEST(PrintStlContainerTest, Vector) {
961   vector<int> v;
962   v.push_back(1);
963   v.push_back(2);
964   EXPECT_EQ("{ 1, 2 }", Print(v));
965 }
966
967 TEST(PrintStlContainerTest, LongSequence) {
968   const int a[100] = { 1, 2, 3 };
969   const vector<int> v(a, a + 100);
970   EXPECT_EQ("{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
971             "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }", Print(v));
972 }
973
974 TEST(PrintStlContainerTest, NestedContainer) {
975   const int a1[] = { 1, 2 };
976   const int a2[] = { 3, 4, 5 };
977   const list<int> l1(a1, a1 + 2);
978   const list<int> l2(a2, a2 + 3);
979
980   vector<list<int> > v;
981   v.push_back(l1);
982   v.push_back(l2);
983   EXPECT_EQ("{ { 1, 2 }, { 3, 4, 5 } }", Print(v));
984 }
985
986 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
987   const int a[3] = { 1, 2, 3 };
988   NativeArray<int> b(a, 3, RelationToSourceReference());
989   EXPECT_EQ("{ 1, 2, 3 }", Print(b));
990 }
991
992 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
993   const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
994   NativeArray<int[3]> b(a, 2, RelationToSourceReference());
995   EXPECT_EQ("{ { 1, 2, 3 }, { 4, 5, 6 } }", Print(b));
996 }
997
998 // Tests that a class named iterator isn't treated as a container.
999
1000 struct iterator {
1001   char x;
1002 };
1003
1004 TEST(PrintStlContainerTest, Iterator) {
1005   iterator it = {};
1006   EXPECT_EQ("1-byte object <00>", Print(it));
1007 }
1008
1009 // Tests that a class named const_iterator isn't treated as a container.
1010
1011 struct const_iterator {
1012   char x;
1013 };
1014
1015 TEST(PrintStlContainerTest, ConstIterator) {
1016   const_iterator it = {};
1017   EXPECT_EQ("1-byte object <00>", Print(it));
1018 }
1019
1020 #if GTEST_HAS_TR1_TUPLE
1021 // Tests printing ::std::tr1::tuples.
1022
1023 // Tuples of various arities.
1024 TEST(PrintTr1TupleTest, VariousSizes) {
1025   ::std::tr1::tuple<> t0;
1026   EXPECT_EQ("()", Print(t0));
1027
1028   ::std::tr1::tuple<int> t1(5);
1029   EXPECT_EQ("(5)", Print(t1));
1030
1031   ::std::tr1::tuple<char, bool> t2('a', true);
1032   EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
1033
1034   ::std::tr1::tuple<bool, int, int> t3(false, 2, 3);
1035   EXPECT_EQ("(false, 2, 3)", Print(t3));
1036
1037   ::std::tr1::tuple<bool, int, int, int> t4(false, 2, 3, 4);
1038   EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
1039
1040   ::std::tr1::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
1041   EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
1042
1043   ::std::tr1::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
1044   EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
1045
1046   ::std::tr1::tuple<bool, int, int, int, bool, int, int> t7(
1047       false, 2, 3, 4, true, 6, 7);
1048   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
1049
1050   ::std::tr1::tuple<bool, int, int, int, bool, int, int, bool> t8(
1051       false, 2, 3, 4, true, 6, 7, true);
1052   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
1053
1054   ::std::tr1::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
1055       false, 2, 3, 4, true, 6, 7, true, 9);
1056   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
1057
1058   const char* const str = "8";
1059   // VC++ 2010's implementation of tuple of C++0x is deficient, requiring
1060   // an explicit type cast of NULL to be used.
1061   ::std::tr1::tuple<bool, char, short, testing::internal::Int32,  // NOLINT
1062                     testing::internal::Int64, float, double, const char*, void*,
1063                     std::string>
1064       t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, ImplicitCast_<void*>(NULL),
1065           "10");
1066   EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
1067             " pointing to \"8\", NULL, \"10\")",
1068             Print(t10));
1069 }
1070
1071 // Nested tuples.
1072 TEST(PrintTr1TupleTest, NestedTuple) {
1073   ::std::tr1::tuple< ::std::tr1::tuple<int, bool>, char> nested(
1074       ::std::tr1::make_tuple(5, true), 'a');
1075   EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
1076 }
1077
1078 #endif  // GTEST_HAS_TR1_TUPLE
1079
1080 #if GTEST_HAS_STD_TUPLE_
1081 // Tests printing ::std::tuples.
1082
1083 // Tuples of various arities.
1084 TEST(PrintStdTupleTest, VariousSizes) {
1085   ::std::tuple<> t0;
1086   EXPECT_EQ("()", Print(t0));
1087
1088   ::std::tuple<int> t1(5);
1089   EXPECT_EQ("(5)", Print(t1));
1090
1091   ::std::tuple<char, bool> t2('a', true);
1092   EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
1093
1094   ::std::tuple<bool, int, int> t3(false, 2, 3);
1095   EXPECT_EQ("(false, 2, 3)", Print(t3));
1096
1097   ::std::tuple<bool, int, int, int> t4(false, 2, 3, 4);
1098   EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
1099
1100   ::std::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
1101   EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
1102
1103   ::std::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
1104   EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
1105
1106   ::std::tuple<bool, int, int, int, bool, int, int> t7(
1107       false, 2, 3, 4, true, 6, 7);
1108   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
1109
1110   ::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
1111       false, 2, 3, 4, true, 6, 7, true);
1112   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
1113
1114   ::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
1115       false, 2, 3, 4, true, 6, 7, true, 9);
1116   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
1117
1118   const char* const str = "8";
1119   // VC++ 2010's implementation of tuple of C++0x is deficient, requiring
1120   // an explicit type cast of NULL to be used.
1121   ::std::tuple<bool, char, short, testing::internal::Int32,  // NOLINT
1122                testing::internal::Int64, float, double, const char*, void*,
1123                std::string>
1124       t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, ImplicitCast_<void*>(NULL),
1125           "10");
1126   EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
1127             " pointing to \"8\", NULL, \"10\")",
1128             Print(t10));
1129 }
1130
1131 // Nested tuples.
1132 TEST(PrintStdTupleTest, NestedTuple) {
1133   ::std::tuple< ::std::tuple<int, bool>, char> nested(
1134       ::std::make_tuple(5, true), 'a');
1135   EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
1136 }
1137
1138 #endif  // GTEST_LANG_CXX11
1139
1140 // Tests printing user-defined unprintable types.
1141
1142 // Unprintable types in the global namespace.
1143 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1144   EXPECT_EQ("1-byte object <00>",
1145             Print(UnprintableTemplateInGlobal<char>()));
1146 }
1147
1148 // Unprintable types in a user namespace.
1149 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1150   EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1151             Print(::foo::UnprintableInFoo()));
1152 }
1153
1154 // Unprintable types are that too big to be printed completely.
1155
1156 struct Big {
1157   Big() { memset(array, 0, sizeof(array)); }
1158   char array[257];
1159 };
1160
1161 TEST(PrintUnpritableTypeTest, BigObject) {
1162   EXPECT_EQ("257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
1163             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1164             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1165             "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
1166             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1167             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1168             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1169             Print(Big()));
1170 }
1171
1172 // Tests printing user-defined streamable types.
1173
1174 // Streamable types in the global namespace.
1175 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1176   StreamableInGlobal x;
1177   EXPECT_EQ("StreamableInGlobal", Print(x));
1178   EXPECT_EQ("StreamableInGlobal*", Print(&x));
1179 }
1180
1181 // Printable template types in a user namespace.
1182 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1183   EXPECT_EQ("StreamableTemplateInFoo: 0",
1184             Print(::foo::StreamableTemplateInFoo<int>()));
1185 }
1186
1187 // Tests printing a user-defined recursive container type that has a <<
1188 // operator.
1189 TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
1190   ::foo::PathLike x;
1191   EXPECT_EQ("Streamable-PathLike", Print(x));
1192   const ::foo::PathLike cx;
1193   EXPECT_EQ("Streamable-PathLike", Print(cx));
1194 }
1195
1196 // Tests printing user-defined types that have a PrintTo() function.
1197 TEST(PrintPrintableTypeTest, InUserNamespace) {
1198   EXPECT_EQ("PrintableViaPrintTo: 0",
1199             Print(::foo::PrintableViaPrintTo()));
1200 }
1201
1202 // Tests printing a pointer to a user-defined type that has a <<
1203 // operator for its pointer.
1204 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1205   ::foo::PointerPrintable x;
1206   EXPECT_EQ("PointerPrintable*", Print(&x));
1207 }
1208
1209 // Tests printing user-defined class template that have a PrintTo() function.
1210 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1211   EXPECT_EQ("PrintableViaPrintToTemplate: 5",
1212             Print(::foo::PrintableViaPrintToTemplate<int>(5)));
1213 }
1214
1215 // Tests that the universal printer prints both the address and the
1216 // value of a reference.
1217 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1218   int n = 5;
1219   EXPECT_EQ("@" + PrintPointer(&n) + " 5", PrintByRef(n));
1220
1221   int a[2][3] = {
1222     { 0, 1, 2 },
1223     { 3, 4, 5 }
1224   };
1225   EXPECT_EQ("@" + PrintPointer(a) + " { { 0, 1, 2 }, { 3, 4, 5 } }",
1226             PrintByRef(a));
1227
1228   const ::foo::UnprintableInFoo x;
1229   EXPECT_EQ("@" + PrintPointer(&x) + " 16-byte object "
1230             "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1231             PrintByRef(x));
1232 }
1233
1234 // Tests that the universal printer prints a function pointer passed by
1235 // reference.
1236 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1237   void (*fp)(int n) = &MyFunction;
1238   const std::string fp_pointer_string =
1239       PrintPointer(reinterpret_cast<const void*>(&fp));
1240   // We cannot directly cast &MyFunction to const void* because the
1241   // standard disallows casting between pointers to functions and
1242   // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
1243   // this limitation.
1244   const std::string fp_string = PrintPointer(reinterpret_cast<const void*>(
1245       reinterpret_cast<internal::BiggestInt>(fp)));
1246   EXPECT_EQ("@" + fp_pointer_string + " " + fp_string,
1247             PrintByRef(fp));
1248 }
1249
1250 // Tests that the universal printer prints a member function pointer
1251 // passed by reference.
1252 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1253   int (Foo::*p)(char ch) = &Foo::MyMethod;
1254   EXPECT_TRUE(HasPrefix(
1255       PrintByRef(p),
1256       "@" + PrintPointer(reinterpret_cast<const void*>(&p)) + " " +
1257           Print(sizeof(p)) + "-byte object "));
1258
1259   char (Foo::*p2)(int n) = &Foo::MyVirtualMethod;
1260   EXPECT_TRUE(HasPrefix(
1261       PrintByRef(p2),
1262       "@" + PrintPointer(reinterpret_cast<const void*>(&p2)) + " " +
1263           Print(sizeof(p2)) + "-byte object "));
1264 }
1265
1266 // Tests that the universal printer prints a member variable pointer
1267 // passed by reference.
1268 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1269   int (Foo::*p) = &Foo::value;  // NOLINT
1270   EXPECT_TRUE(HasPrefix(
1271       PrintByRef(p),
1272       "@" + PrintPointer(&p) + " " + Print(sizeof(p)) + "-byte object "));
1273 }
1274
1275 // Tests that FormatForComparisonFailureMessage(), which is used to print
1276 // an operand in a comparison assertion (e.g. ASSERT_EQ) when the assertion
1277 // fails, formats the operand in the desired way.
1278
1279 // scalar
1280 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1281   EXPECT_STREQ("123",
1282                FormatForComparisonFailureMessage(123, 124).c_str());
1283 }
1284
1285 // non-char pointer
1286 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1287   int n = 0;
1288   EXPECT_EQ(PrintPointer(&n),
1289             FormatForComparisonFailureMessage(&n, &n).c_str());
1290 }
1291
1292 // non-char array
1293 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1294   // In expression 'array == x', 'array' is compared by pointer.
1295   // Therefore we want to print an array operand as a pointer.
1296   int n[] = { 1, 2, 3 };
1297   EXPECT_EQ(PrintPointer(n),
1298             FormatForComparisonFailureMessage(n, n).c_str());
1299 }
1300
1301 // Tests formatting a char pointer when it's compared with another pointer.
1302 // In this case we want to print it as a raw pointer, as the comparision is by
1303 // pointer.
1304
1305 // char pointer vs pointer
1306 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1307   // In expression 'p == x', where 'p' and 'x' are (const or not) char
1308   // pointers, the operands are compared by pointer.  Therefore we
1309   // want to print 'p' as a pointer instead of a C string (we don't
1310   // even know if it's supposed to point to a valid C string).
1311
1312   // const char*
1313   const char* s = "hello";
1314   EXPECT_EQ(PrintPointer(s),
1315             FormatForComparisonFailureMessage(s, s).c_str());
1316
1317   // char*
1318   char ch = 'a';
1319   EXPECT_EQ(PrintPointer(&ch),
1320             FormatForComparisonFailureMessage(&ch, &ch).c_str());
1321 }
1322
1323 // wchar_t pointer vs pointer
1324 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1325   // In expression 'p == x', where 'p' and 'x' are (const or not) char
1326   // pointers, the operands are compared by pointer.  Therefore we
1327   // want to print 'p' as a pointer instead of a wide C string (we don't
1328   // even know if it's supposed to point to a valid wide C string).
1329
1330   // const wchar_t*
1331   const wchar_t* s = L"hello";
1332   EXPECT_EQ(PrintPointer(s),
1333             FormatForComparisonFailureMessage(s, s).c_str());
1334
1335   // wchar_t*
1336   wchar_t ch = L'a';
1337   EXPECT_EQ(PrintPointer(&ch),
1338             FormatForComparisonFailureMessage(&ch, &ch).c_str());
1339 }
1340
1341 // Tests formatting a char pointer when it's compared to a string object.
1342 // In this case we want to print the char pointer as a C string.
1343
1344 #if GTEST_HAS_GLOBAL_STRING
1345 // char pointer vs ::string
1346 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
1347   const char* s = "hello \"world";
1348   EXPECT_STREQ("\"hello \\\"world\"",  // The string content should be escaped.
1349                FormatForComparisonFailureMessage(s, ::string()).c_str());
1350
1351   // char*
1352   char str[] = "hi\1";
1353   char* p = str;
1354   EXPECT_STREQ("\"hi\\x1\"",  // The string content should be escaped.
1355                FormatForComparisonFailureMessage(p, ::string()).c_str());
1356 }
1357 #endif
1358
1359 // char pointer vs std::string
1360 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1361   const char* s = "hello \"world";
1362   EXPECT_STREQ("\"hello \\\"world\"",  // The string content should be escaped.
1363                FormatForComparisonFailureMessage(s, ::std::string()).c_str());
1364
1365   // char*
1366   char str[] = "hi\1";
1367   char* p = str;
1368   EXPECT_STREQ("\"hi\\x1\"",  // The string content should be escaped.
1369                FormatForComparisonFailureMessage(p, ::std::string()).c_str());
1370 }
1371
1372 #if GTEST_HAS_GLOBAL_WSTRING
1373 // wchar_t pointer vs ::wstring
1374 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
1375   const wchar_t* s = L"hi \"world";
1376   EXPECT_STREQ("L\"hi \\\"world\"",  // The string content should be escaped.
1377                FormatForComparisonFailureMessage(s, ::wstring()).c_str());
1378
1379   // wchar_t*
1380   wchar_t str[] = L"hi\1";
1381   wchar_t* p = str;
1382   EXPECT_STREQ("L\"hi\\x1\"",  // The string content should be escaped.
1383                FormatForComparisonFailureMessage(p, ::wstring()).c_str());
1384 }
1385 #endif
1386
1387 #if GTEST_HAS_STD_WSTRING
1388 // wchar_t pointer vs std::wstring
1389 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1390   const wchar_t* s = L"hi \"world";
1391   EXPECT_STREQ("L\"hi \\\"world\"",  // The string content should be escaped.
1392                FormatForComparisonFailureMessage(s, ::std::wstring()).c_str());
1393
1394   // wchar_t*
1395   wchar_t str[] = L"hi\1";
1396   wchar_t* p = str;
1397   EXPECT_STREQ("L\"hi\\x1\"",  // The string content should be escaped.
1398                FormatForComparisonFailureMessage(p, ::std::wstring()).c_str());
1399 }
1400 #endif
1401
1402 // Tests formatting a char array when it's compared with a pointer or array.
1403 // In this case we want to print the array as a row pointer, as the comparison
1404 // is by pointer.
1405
1406 // char array vs pointer
1407 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1408   char str[] = "hi \"world\"";
1409   char* p = NULL;
1410   EXPECT_EQ(PrintPointer(str),
1411             FormatForComparisonFailureMessage(str, p).c_str());
1412 }
1413
1414 // char array vs char array
1415 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1416   const char str[] = "hi \"world\"";
1417   EXPECT_EQ(PrintPointer(str),
1418             FormatForComparisonFailureMessage(str, str).c_str());
1419 }
1420
1421 // wchar_t array vs pointer
1422 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1423   wchar_t str[] = L"hi \"world\"";
1424   wchar_t* p = NULL;
1425   EXPECT_EQ(PrintPointer(str),
1426             FormatForComparisonFailureMessage(str, p).c_str());
1427 }
1428
1429 // wchar_t array vs wchar_t array
1430 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1431   const wchar_t str[] = L"hi \"world\"";
1432   EXPECT_EQ(PrintPointer(str),
1433             FormatForComparisonFailureMessage(str, str).c_str());
1434 }
1435
1436 // Tests formatting a char array when it's compared with a string object.
1437 // In this case we want to print the array as a C string.
1438
1439 #if GTEST_HAS_GLOBAL_STRING
1440 // char array vs string
1441 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
1442   const char str[] = "hi \"w\0rld\"";
1443   EXPECT_STREQ("\"hi \\\"w\"",  // The content should be escaped.
1444                                 // Embedded NUL terminates the string.
1445                FormatForComparisonFailureMessage(str, ::string()).c_str());
1446 }
1447 #endif
1448
1449 // char array vs std::string
1450 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1451   const char str[] = "hi \"world\"";
1452   EXPECT_STREQ("\"hi \\\"world\\\"\"",  // The content should be escaped.
1453                FormatForComparisonFailureMessage(str, ::std::string()).c_str());
1454 }
1455
1456 #if GTEST_HAS_GLOBAL_WSTRING
1457 // wchar_t array vs wstring
1458 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
1459   const wchar_t str[] = L"hi \"world\"";
1460   EXPECT_STREQ("L\"hi \\\"world\\\"\"",  // The content should be escaped.
1461                FormatForComparisonFailureMessage(str, ::wstring()).c_str());
1462 }
1463 #endif
1464
1465 #if GTEST_HAS_STD_WSTRING
1466 // wchar_t array vs std::wstring
1467 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1468   const wchar_t str[] = L"hi \"w\0rld\"";
1469   EXPECT_STREQ(
1470       "L\"hi \\\"w\"",  // The content should be escaped.
1471                         // Embedded NUL terminates the string.
1472       FormatForComparisonFailureMessage(str, ::std::wstring()).c_str());
1473 }
1474 #endif
1475
1476 // Useful for testing PrintToString().  We cannot use EXPECT_EQ()
1477 // there as its implementation uses PrintToString().  The caller must
1478 // ensure that 'value' has no side effect.
1479 #define EXPECT_PRINT_TO_STRING_(value, expected_string)         \
1480   EXPECT_TRUE(PrintToString(value) == (expected_string))        \
1481       << " where " #value " prints as " << (PrintToString(value))
1482
1483 TEST(PrintToStringTest, WorksForScalar) {
1484   EXPECT_PRINT_TO_STRING_(123, "123");
1485 }
1486
1487 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1488   const char* p = "hello";
1489   EXPECT_PRINT_TO_STRING_(p, "\"hello\"");
1490 }
1491
1492 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1493   char s[] = "hello";
1494   char* p = s;
1495   EXPECT_PRINT_TO_STRING_(p, "\"hello\"");
1496 }
1497
1498 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1499   const char* p = "hello\n";
1500   EXPECT_PRINT_TO_STRING_(p, "\"hello\\n\"");
1501 }
1502
1503 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1504   char s[] = "hello\1";
1505   char* p = s;
1506   EXPECT_PRINT_TO_STRING_(p, "\"hello\\x1\"");
1507 }
1508
1509 TEST(PrintToStringTest, WorksForArray) {
1510   int n[3] = { 1, 2, 3 };
1511   EXPECT_PRINT_TO_STRING_(n, "{ 1, 2, 3 }");
1512 }
1513
1514 TEST(PrintToStringTest, WorksForCharArray) {
1515   char s[] = "hello";
1516   EXPECT_PRINT_TO_STRING_(s, "\"hello\"");
1517 }
1518
1519 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1520   const char str_with_nul[] = "hello\0 world";
1521   EXPECT_PRINT_TO_STRING_(str_with_nul, "\"hello\\0 world\"");
1522
1523   char mutable_str_with_nul[] = "hello\0 world";
1524   EXPECT_PRINT_TO_STRING_(mutable_str_with_nul, "\"hello\\0 world\"");
1525 }
1526
1527 #undef EXPECT_PRINT_TO_STRING_
1528
1529 TEST(UniversalTersePrintTest, WorksForNonReference) {
1530   ::std::stringstream ss;
1531   UniversalTersePrint(123, &ss);
1532   EXPECT_EQ("123", ss.str());
1533 }
1534
1535 TEST(UniversalTersePrintTest, WorksForReference) {
1536   const int& n = 123;
1537   ::std::stringstream ss;
1538   UniversalTersePrint(n, &ss);
1539   EXPECT_EQ("123", ss.str());
1540 }
1541
1542 TEST(UniversalTersePrintTest, WorksForCString) {
1543   const char* s1 = "abc";
1544   ::std::stringstream ss1;
1545   UniversalTersePrint(s1, &ss1);
1546   EXPECT_EQ("\"abc\"", ss1.str());
1547
1548   char* s2 = const_cast<char*>(s1);
1549   ::std::stringstream ss2;
1550   UniversalTersePrint(s2, &ss2);
1551   EXPECT_EQ("\"abc\"", ss2.str());
1552
1553   const char* s3 = NULL;
1554   ::std::stringstream ss3;
1555   UniversalTersePrint(s3, &ss3);
1556   EXPECT_EQ("NULL", ss3.str());
1557 }
1558
1559 TEST(UniversalPrintTest, WorksForNonReference) {
1560   ::std::stringstream ss;
1561   UniversalPrint(123, &ss);
1562   EXPECT_EQ("123", ss.str());
1563 }
1564
1565 TEST(UniversalPrintTest, WorksForReference) {
1566   const int& n = 123;
1567   ::std::stringstream ss;
1568   UniversalPrint(n, &ss);
1569   EXPECT_EQ("123", ss.str());
1570 }
1571
1572 TEST(UniversalPrintTest, WorksForCString) {
1573   const char* s1 = "abc";
1574   ::std::stringstream ss1;
1575   UniversalPrint(s1, &ss1);
1576   EXPECT_EQ(PrintPointer(s1) + " pointing to \"abc\"", std::string(ss1.str()));
1577
1578   char* s2 = const_cast<char*>(s1);
1579   ::std::stringstream ss2;
1580   UniversalPrint(s2, &ss2);
1581   EXPECT_EQ(PrintPointer(s2) + " pointing to \"abc\"", std::string(ss2.str()));
1582
1583   const char* s3 = NULL;
1584   ::std::stringstream ss3;
1585   UniversalPrint(s3, &ss3);
1586   EXPECT_EQ("NULL", ss3.str());
1587 }
1588
1589 TEST(UniversalPrintTest, WorksForCharArray) {
1590   const char str[] = "\"Line\0 1\"\nLine 2";
1591   ::std::stringstream ss1;
1592   UniversalPrint(str, &ss1);
1593   EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1594
1595   const char mutable_str[] = "\"Line\0 1\"\nLine 2";
1596   ::std::stringstream ss2;
1597   UniversalPrint(mutable_str, &ss2);
1598   EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1599 }
1600
1601 #if GTEST_HAS_TR1_TUPLE
1602
1603 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
1604   Strings result = UniversalTersePrintTupleFieldsToStrings(
1605       ::std::tr1::make_tuple());
1606   EXPECT_EQ(0u, result.size());
1607 }
1608
1609 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
1610   Strings result = UniversalTersePrintTupleFieldsToStrings(
1611       ::std::tr1::make_tuple(1));
1612   ASSERT_EQ(1u, result.size());
1613   EXPECT_EQ("1", result[0]);
1614 }
1615
1616 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
1617   Strings result = UniversalTersePrintTupleFieldsToStrings(
1618       ::std::tr1::make_tuple(1, 'a'));
1619   ASSERT_EQ(2u, result.size());
1620   EXPECT_EQ("1", result[0]);
1621   EXPECT_EQ("'a' (97, 0x61)", result[1]);
1622 }
1623
1624 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
1625   const int n = 1;
1626   Strings result = UniversalTersePrintTupleFieldsToStrings(
1627       ::std::tr1::tuple<const int&, const char*>(n, "a"));
1628   ASSERT_EQ(2u, result.size());
1629   EXPECT_EQ("1", result[0]);
1630   EXPECT_EQ("\"a\"", result[1]);
1631 }
1632
1633 #endif  // GTEST_HAS_TR1_TUPLE
1634
1635 #if GTEST_HAS_STD_TUPLE_
1636
1637 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1638   Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
1639   EXPECT_EQ(0u, result.size());
1640 }
1641
1642 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1643   Strings result = UniversalTersePrintTupleFieldsToStrings(
1644       ::std::make_tuple(1));
1645   ASSERT_EQ(1u, result.size());
1646   EXPECT_EQ("1", result[0]);
1647 }
1648
1649 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1650   Strings result = UniversalTersePrintTupleFieldsToStrings(
1651       ::std::make_tuple(1, 'a'));
1652   ASSERT_EQ(2u, result.size());
1653   EXPECT_EQ("1", result[0]);
1654   EXPECT_EQ("'a' (97, 0x61)", result[1]);
1655 }
1656
1657 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1658   const int n = 1;
1659   Strings result = UniversalTersePrintTupleFieldsToStrings(
1660       ::std::tuple<const int&, const char*>(n, "a"));
1661   ASSERT_EQ(2u, result.size());
1662   EXPECT_EQ("1", result[0]);
1663   EXPECT_EQ("\"a\"", result[1]);
1664 }
1665
1666 #endif  // GTEST_HAS_STD_TUPLE_
1667
1668 }  // namespace gtest_printers_test
1669 }  // namespace testing