54 #if GTEST_HAS_HASH_MAP_
56 #endif // GTEST_HAS_HASH_MAP_
57 #if GTEST_HAS_HASH_SET_
59 #endif // GTEST_HAS_HASH_SET_
61 #if GTEST_HAS_STD_FORWARD_LIST_
62 # include <forward_list>
63 #endif // GTEST_HAS_STD_FORWARD_LIST_
85 return os << (e ==
kEWS1 ?
"kEWS1" :
"invalid");
94 *os << (e ==
kEWPT1 ?
"kEWPT1" :
"invalid");
104 template <
typename T>
119 os <<
"StreamableInGlobal";
123 os <<
"StreamableInGlobal*";
132 double z()
const {
return z_; }
145 *os <<
"PrintableViaPrintTo: " << x.
value;
154 return os <<
"PointerPrintable*";
158 template <
typename T>
168 template <
typename T>
170 *os <<
"PrintableViaPrintToTemplate: " << x.
value();
174 template <
typename T>
184 template <
typename T>
187 return os <<
"StreamableTemplateInFoo: " << x.
value();
193 namespace gtest_printers_test {
197 using ::std::make_pair;
199 using ::std::multimap;
200 using ::std::multiset;
207 using ::testing::internal::NativeArray;
208 using ::testing::internal::RE;
209 using ::testing::internal::RelationToSourceReference;
212 using ::testing::internal::UniversalPrinter;
214 #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
215 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
222 #ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
223 using ::std::hash_map;
224 using ::std::hash_set;
225 using ::std::hash_multimap;
226 using ::std::hash_multiset;
228 using ::stdext::hash_map;
229 using ::stdext::hash_set;
230 using ::stdext::hash_multimap;
231 using ::stdext::hash_multiset;
236 template <
typename T>
238 ::std::stringstream ss;
246 template <
typename T>
248 ::std::stringstream ss;
284 TEST(PrintCharTest, PlainChar) {
304 TEST(PrintCharTest, SignedChar) {
307 Print(static_cast<signed char>(-50)));
311 TEST(PrintCharTest, UnsignedChar) {
314 Print(static_cast<unsigned char>(
'b')));
326 TEST(PrintBuiltInTypeTest, Wchar_t) {
343 EXPECT_EQ(
"L'\\x576' (1398)",
Print(static_cast<wchar_t>(0x576)));
344 EXPECT_EQ(
"L'\\xC74D' (51021)",
Print(static_cast<wchar_t>(0xC74D)));
348 TEST(PrintTypeSizeTest, Wchar_t) {
353 TEST(PrintBuiltInTypeTest, Integer) {
354 EXPECT_EQ(
"'\\xFF' (255)",
Print(static_cast<unsigned char>(255)));
355 EXPECT_EQ(
"'\\x80' (-128)",
Print(static_cast<signed char>(-128)));
361 Print(static_cast<testing::internal::UInt64>(-1)));
363 Print(static_cast<testing::internal::Int64>(1) << 63));
367 TEST(PrintBuiltInTypeTest, Size_t) {
369 #if !GTEST_OS_WINDOWS
372 #endif // !GTEST_OS_WINDOWS
376 TEST(PrintBuiltInTypeTest, FloatingPoints) {
385 ::std::stringstream expected_result_stream;
386 expected_result_stream <<
p;
387 return expected_result_stream.str();
394 const char*
p =
"World";
399 TEST(PrintCStringTest, NonConst) {
402 Print(static_cast<char*>(p)));
407 const char*
p = NULL;
412 TEST(PrintCStringTest, EscapesProperly) {
413 const char*
p =
"'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
415 "\\n\\r\\t\\v\\x7F\\xFF a\"",
425 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
429 const wchar_t*
p =
L"World";
434 TEST(PrintWideCStringTest, NonConst) {
437 Print(static_cast<wchar_t*>(p)));
441 TEST(PrintWideCStringTest, Null) {
442 const wchar_t*
p = NULL;
447 TEST(PrintWideCStringTest, EscapesProperly) {
448 const wchar_t s[] = {
'\'',
'"',
'?',
'\\',
'\a',
'\b',
'\f',
'\n',
'\r',
449 '\t',
'\v', 0xD3, 0x576, 0x8D3, 0xC74D,
' ',
'a',
'\0'};
451 "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
452 Print(static_cast<const wchar_t*>(s)));
454 #endif // native wchar_t
459 TEST(PrintCharPointerTest, SignedChar) {
460 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
467 TEST(PrintCharPointerTest, ConstSignedChar) {
468 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
475 TEST(PrintCharPointerTest, UnsignedChar) {
476 unsigned char*
p =
reinterpret_cast<unsigned char*
>(0x1234);
483 TEST(PrintCharPointerTest, ConstUnsignedChar) {
484 const unsigned char*
p =
reinterpret_cast<const unsigned char*
>(0x1234);
494 bool*
p =
reinterpret_cast<bool*
>(0xABCD);
501 TEST(PrintPointerToBuiltInTypeTest, Void) {
502 void*
p =
reinterpret_cast<void*
>(0xABCD);
509 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
510 const void*
p =
reinterpret_cast<const void*
>(0xABCD);
517 TEST(PrintPointerToPointerTest, IntPointerPointer) {
518 int**
p =
reinterpret_cast<int**
>(0xABCD);
528 TEST(PrintPointerTest, NonMemberFunctionPointer) {
535 reinterpret_cast<internal::BiggestInt>(&
MyFunction))),
537 int (*
p)(bool) = NULL;
543 template <
typename StringType>
545 if (str.find(prefix, 0) == 0)
548 const bool is_wide_string =
sizeof(prefix[0]) > 1;
549 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
551 << begin_string_quote << prefix <<
"\" is not a prefix of "
552 << begin_string_quote << str <<
"\"\n";
569 TEST(PrintPointerTest, MemberVariablePointer) {
572 int (
Foo::*
p) = NULL;
574 Print(
sizeof(p)) +
"-byte object "));
581 TEST(PrintPointerTest, MemberFunctionPointer) {
587 int (
Foo::*
p)(char) = NULL;
589 Print(
sizeof(p)) +
"-byte object "));
596 template <
typename T,
size_t N>
602 TEST(PrintArrayTest, OneDimensionalArray) {
603 int a[5] = { 1, 2, 3, 4, 5 };
608 TEST(PrintArrayTest, TwoDimensionalArray) {
613 EXPECT_EQ(
"{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }",
PrintArrayHelper(a));
617 TEST(PrintArrayTest, ConstArray) {
618 const bool a[1] = {
false };
623 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
625 char a[] = {
'H',
'\0',
'i' };
630 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
631 const char a[] =
"\0Hi";
636 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
638 const wchar_t a[] = {
L'H',
L'\0', L
'i' };
643 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
644 const wchar_t a[] =
L"\0Hi";
649 TEST(PrintArrayTest, ObjectArray) {
650 string a[3] = {
"Hi",
"Hello",
"Ni hao" };
655 TEST(PrintArrayTest, BigArray) {
656 int a[100] = { 1, 2, 3 };
657 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
663 #if GTEST_HAS_GLOBAL_STRING
665 TEST(PrintStringTest, StringInGlobalNamespace) {
666 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
668 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
671 #endif // GTEST_HAS_GLOBAL_STRING
674 TEST(PrintStringTest, StringInStdNamespace) {
675 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
677 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
681 TEST(PrintStringTest, StringAmbiguousHex) {
697 #if GTEST_HAS_GLOBAL_WSTRING
699 TEST(PrintWideStringTest, StringInGlobalNamespace) {
700 const wchar_t s[] =
L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
702 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
703 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
706 #endif // GTEST_HAS_GLOBAL_WSTRING
708 #if GTEST_HAS_STD_WSTRING
710 TEST(PrintWideStringTest, StringInStdNamespace) {
711 const wchar_t s[] =
L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
713 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
714 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
718 TEST(PrintWideStringTest, StringAmbiguousHex) {
727 #endif // GTEST_HAS_STD_WSTRING
737 template <
typename Char,
typename CharTraits>
739 std::basic_ostream<Char, CharTraits>&
os,
741 return os <<
"AllowsGenericStreaming";
744 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
751 template <
typename T>
754 template <
typename Char,
typename CharTraits,
typename T>
756 std::basic_ostream<Char, CharTraits>&
os,
758 return os <<
"AllowsGenericStreamingTemplate";
761 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
769 template <
typename T>
772 operator bool()
const {
return false; }
775 template <
typename Char,
typename CharTraits,
typename T>
777 std::basic_ostream<Char, CharTraits>&
os,
779 return os <<
"AllowsGenericStreamingAndImplicitConversionTemplate";
782 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
784 EXPECT_EQ(
"AllowsGenericStreamingAndImplicitConversionTemplate",
Print(a));
787 #if GTEST_HAS_STRING_PIECE_
791 TEST(PrintStringPieceTest, SimpleStringPiece) {
792 const StringPiece sp =
"Hello";
796 TEST(PrintStringPieceTest, UnprintableCharacters) {
797 const char str[] =
"NUL (\0) and \r\t";
798 const StringPiece sp(str,
sizeof(str) - 1);
802 #endif // GTEST_HAS_STRING_PIECE_
806 TEST(PrintStlContainerTest, EmptyDeque) {
811 TEST(PrintStlContainerTest, NonEmptyDeque) {
812 deque<int> non_empty;
813 non_empty.push_back(1);
814 non_empty.push_back(3);
818 #if GTEST_HAS_HASH_MAP_
820 TEST(PrintStlContainerTest, OneElementHashMap) {
821 hash_map<int, char> map1;
826 TEST(PrintStlContainerTest, HashMultiMap) {
827 hash_multimap<int, bool> map1;
828 map1.insert(make_pair(5,
true));
829 map1.insert(make_pair(5,
false));
832 const string result =
Print(map1);
833 EXPECT_TRUE(result ==
"{ (5, true), (5, false) }" ||
834 result ==
"{ (5, false), (5, true) }")
835 <<
" where Print(map1) returns \"" << result <<
"\".";
838 #endif // GTEST_HAS_HASH_MAP_
840 #if GTEST_HAS_HASH_SET_
842 TEST(PrintStlContainerTest, HashSet) {
843 hash_set<string> set1;
844 set1.insert(
"hello");
848 TEST(PrintStlContainerTest, HashMultiSet) {
850 int a[kSize] = { 1, 1, 2, 5, 1 };
851 hash_multiset<int> set1(a, a + kSize);
854 const string result =
Print(set1);
855 const string expected_pattern =
"{ d, d, d, d, d }";
859 ASSERT_EQ(expected_pattern.length(), result.length());
860 std::vector<int> numbers;
861 for (
size_t i = 0;
i != result.length();
i++) {
862 if (expected_pattern[
i] ==
'd') {
863 ASSERT_NE(isdigit(static_cast<unsigned char>(result[
i])), 0);
864 numbers.push_back(result[
i] -
'0');
866 EXPECT_EQ(expected_pattern[
i], result[i]) <<
" where result is "
872 std::sort(numbers.begin(), numbers.end());
874 EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
877 #endif // GTEST_HAS_HASH_SET_
879 TEST(PrintStlContainerTest, List) {
884 const list<string> strings(a, a + 2);
888 TEST(PrintStlContainerTest, Map) {
896 TEST(PrintStlContainerTest, MultiMap) {
897 multimap<bool, int> map1;
904 map1.insert(pair<const bool, int>(
true, 0));
905 map1.insert(pair<const bool, int>(
true, 1));
906 map1.insert(pair<const bool, int>(
false, 2));
911 const unsigned int a[] = { 3, 0, 5 };
912 set<unsigned int> set1(a, a + 3);
916 TEST(PrintStlContainerTest, MultiSet) {
917 const int a[] = { 1, 1, 2, 5, 1 };
918 multiset<int> set1(a, a + 5);
922 #if GTEST_HAS_STD_FORWARD_LIST_
926 TEST(PrintStlContainerTest, SinglyLinkedList) {
927 int a[] = { 9, 2, 8 };
928 const std::forward_list<int> ints(a, a + 3);
931 #endif // GTEST_HAS_STD_FORWARD_LIST_
934 pair<const bool, int>
p(
true, 5);
945 TEST(PrintStlContainerTest, LongSequence) {
946 const int a[100] = { 1, 2, 3 };
947 const vector<int>
v(a, a + 100);
948 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
949 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(v));
952 TEST(PrintStlContainerTest, NestedContainer) {
953 const int a1[] = { 1, 2 };
954 const int a2[] = { 3, 4, 5 };
955 const list<int>
l1(a1, a1 + 2);
956 const list<int>
l2(a2, a2 + 3);
958 vector<list<int> >
v;
964 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
965 const int a[3] = { 1, 2, 3 };
966 NativeArray<int>
b(a, 3, RelationToSourceReference());
970 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
971 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
972 NativeArray<int[3]>
b(a, 2, RelationToSourceReference());
982 TEST(PrintStlContainerTest, Iterator) {
993 TEST(PrintStlContainerTest, ConstIterator) {
998 #if GTEST_HAS_TR1_TUPLE
1002 TEST(PrintTr1TupleTest, VariousSizes) {
1021 ::std::tr1::tuple<bool, int, int, int, bool, int> t6(
false, 2, 3, 4,
true, 6);
1025 false, 2, 3, 4,
true, 6, 7);
1029 false, 2, 3, 4,
true, 6, 7,
true);
1033 false, 2, 3, 4,
true, 6, 7,
true, 9);
1036 const char*
const str =
"8";
1041 t10(
false,
'a', 3, 4, 5, 1.5F, -2.5, str,
1042 ImplicitCast_<void*>(NULL),
"10");
1044 " pointing to \"8\", NULL, \"10\")",
1049 TEST(PrintTr1TupleTest, NestedTuple) {
1055 #endif // GTEST_HAS_TR1_TUPLE
1057 #if GTEST_HAS_STD_TUPLE_
1061 TEST(PrintStdTupleTest, VariousSizes) {
1065 ::std::tuple<int>
t1(5);
1068 ::std::tuple<char, bool>
t2(
'a',
true);
1071 ::std::tuple<bool, int, int>
t3(
false, 2, 3);
1074 ::std::tuple<bool, int, int, int>
t4(
false, 2, 3, 4);
1077 ::std::tuple<bool, int, int, int, bool> t5(
false, 2, 3, 4,
true);
1080 ::std::tuple<bool, int, int, int, bool, int> t6(
false, 2, 3, 4,
true, 6);
1083 ::std::tuple<bool, int, int, int, bool, int, int> t7(
1084 false, 2, 3, 4,
true, 6, 7);
1087 ::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
1088 false, 2, 3, 4,
true, 6, 7,
true);
1091 ::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
1092 false, 2, 3, 4,
true, 6, 7,
true, 9);
1095 const char*
const str =
"8";
1100 t10(
false,
'a', 3, 4, 5, 1.5F, -2.5, str,
1101 ImplicitCast_<void*>(NULL),
"10");
1103 " pointing to \"8\", NULL, \"10\")",
1108 TEST(PrintStdTupleTest, NestedTuple) {
1109 ::std::tuple< ::std::tuple<int, bool>,
char>
nested(
1114 #endif // GTEST_LANG_CXX11
1119 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1125 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1126 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1137 TEST(PrintUnpritableTypeTest, BigObject) {
1138 EXPECT_EQ(
"257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
1139 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1140 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1141 "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
1142 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1143 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1144 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1151 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1158 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1164 TEST(PrintPrintableTypeTest, InUserNamespace) {
1171 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1177 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1178 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1184 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1195 const ::foo::UnprintableInFoo
x;
1197 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1203 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1205 const string fp_pointer_string =
1211 const string fp_string =
PrintPointer(reinterpret_cast<const void*>(
1212 reinterpret_cast<internal::BiggestInt>(fp)));
1213 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1219 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1223 "@" +
PrintPointer(reinterpret_cast<const void*>(&p)) +
" " +
1224 Print(
sizeof(p)) +
"-byte object "));
1229 "@" +
PrintPointer(reinterpret_cast<const void*>(&p2)) +
" " +
1230 Print(
sizeof(p2)) +
"-byte object "));
1235 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1247 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1253 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1260 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1263 int n[] = { 1, 2, 3 };
1273 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1280 const char* s =
"hello";
1291 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1298 const wchar_t* s =
L"hello";
1311 #if GTEST_HAS_GLOBAL_STRING
1313 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
1314 const char* s =
"hello \"world";
1319 char str[] =
"hi\1";
1327 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1328 const char* s =
"hello \"world";
1333 char str[] =
"hi\1";
1339 #if GTEST_HAS_GLOBAL_WSTRING
1341 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
1342 const wchar_t* s =
L"hi \"world";
1347 wchar_t str[] =
L"hi\1";
1354 #if GTEST_HAS_STD_WSTRING
1356 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1357 const wchar_t* s =
L"hi \"world";
1362 wchar_t str[] =
L"hi\1";
1374 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1375 char str[] =
"hi \"world\"";
1382 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1383 const char str[] =
"hi \"world\"";
1389 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1390 wchar_t str[] =
L"hi \"world\"";
1397 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1398 const wchar_t str[] =
L"hi \"world\"";
1406 #if GTEST_HAS_GLOBAL_STRING
1408 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
1409 const char str[] =
"hi \"w\0rld\"";
1417 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1418 const char str[] =
"hi \"world\"";
1423 #if GTEST_HAS_GLOBAL_WSTRING
1425 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
1426 const wchar_t str[] =
L"hi \"world\"";
1432 #if GTEST_HAS_STD_WSTRING
1434 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1435 const wchar_t str[] =
L"hi \"w\0rld\"";
1446 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \
1447 EXPECT_TRUE(PrintToString(value) == (expected_string)) \
1448 << " where " #value " prints as " << (PrintToString(value))
1450 TEST(PrintToStringTest, WorksForScalar) {
1454 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1455 const char* p =
"hello";
1459 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1465 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1466 const char* p =
"hello\n";
1470 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1471 char s[] =
"hello\1";
1476 TEST(PrintToStringTest, WorksForArray) {
1477 int n[3] = { 1, 2, 3 };
1481 TEST(PrintToStringTest, WorksForCharArray) {
1486 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1487 const char str_with_nul[] =
"hello\0 world";
1490 char mutable_str_with_nul[] =
"hello\0 world";
1494 #undef EXPECT_PRINT_TO_STRING_
1496 TEST(UniversalTersePrintTest, WorksForNonReference) {
1497 ::std::stringstream ss;
1502 TEST(UniversalTersePrintTest, WorksForReference) {
1504 ::std::stringstream ss;
1509 TEST(UniversalTersePrintTest, WorksForCString) {
1510 const char* s1 =
"abc";
1511 ::std::stringstream ss1;
1515 char* s2 =
const_cast<char*
>(s1);
1516 ::std::stringstream ss2;
1520 const char* s3 = NULL;
1521 ::std::stringstream ss3;
1526 TEST(UniversalPrintTest, WorksForNonReference) {
1527 ::std::stringstream ss;
1532 TEST(UniversalPrintTest, WorksForReference) {
1534 ::std::stringstream ss;
1539 TEST(UniversalPrintTest, WorksForCString) {
1540 const char* s1 =
"abc";
1541 ::std::stringstream ss1;
1545 char* s2 =
const_cast<char*
>(s1);
1546 ::std::stringstream ss2;
1550 const char* s3 = NULL;
1551 ::std::stringstream ss3;
1556 TEST(UniversalPrintTest, WorksForCharArray) {
1557 const char str[] =
"\"Line\0 1\"\nLine 2";
1558 ::std::stringstream ss1;
1560 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1562 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1563 ::std::stringstream ss2;
1565 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1568 #if GTEST_HAS_TR1_TUPLE
1570 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
1571 Strings result = UniversalTersePrintTupleFieldsToStrings(
1576 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
1577 Strings result = UniversalTersePrintTupleFieldsToStrings(
1583 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
1584 Strings result = UniversalTersePrintTupleFieldsToStrings(
1591 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
1593 Strings result = UniversalTersePrintTupleFieldsToStrings(
1600 #endif // GTEST_HAS_TR1_TUPLE
1602 #if GTEST_HAS_STD_TUPLE_
1604 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1609 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1610 Strings result = UniversalTersePrintTupleFieldsToStrings(
1616 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1617 Strings result = UniversalTersePrintTupleFieldsToStrings(
1624 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1626 Strings result = UniversalTersePrintTupleFieldsToStrings(
1627 ::std::tuple<const int&, const char*>(n,
"a"));
1633 #endif // GTEST_HAS_STD_TUPLE_