40 #include <forward_list>
46 #include <unordered_map>
47 #include <unordered_set>
74 return os << (e ==
kEWS1 ?
"kEWS1" :
"invalid");
83 *os << (e ==
kEWPT1 ?
"kEWPT1" :
"invalid");
108 os <<
"StreamableInGlobal";
112 os <<
"StreamableInGlobal*";
121 double z()
const {
return z_; }
134 *os <<
"PrintableViaPrintTo: " <<
x.value;
143 return os <<
"PointerPrintable*";
147 template <
typename T>
157 template <
typename T>
159 *os <<
"PrintableViaPrintToTemplate: " <<
x.value();
163 template <
typename T>
173 template <
typename T>
176 return os <<
"StreamableTemplateInFoo: " <<
x.value();
200 return os <<
"Streamable-PathLike";
207 namespace gtest_printers_test {
211 using ::std::make_pair;
213 using ::std::multimap;
214 using ::std::multiset;
221 using ::testing::internal::NativeArray;
222 using ::testing::internal::RE;
223 using ::testing::internal::RelationToSourceReference;
226 using ::testing::internal::UniversalPrinter;
232 template <
typename T>
234 ::std::stringstream ss;
242 template <
typename T>
244 ::std::stringstream ss;
280 TEST(PrintCharTest, PlainChar) {
300 TEST(PrintCharTest, SignedChar) {
303 Print(
static_cast<signed char>(-50)));
307 TEST(PrintCharTest, UnsignedChar) {
310 Print(
static_cast<unsigned char>(
'b')));
322 TEST(PrintBuiltInTypeTest, Wchar_t) {
339 EXPECT_EQ(
"L'\\x576' (1398)",
Print(
static_cast<wchar_t>(0x576)));
340 EXPECT_EQ(
"L'\\xC74D' (51021)",
Print(
static_cast<wchar_t>(0xC74D)));
344 TEST(PrintTypeSizeTest, Wchar_t) {
349 TEST(PrintBuiltInTypeTest, Integer) {
350 EXPECT_EQ(
"'\\xFF' (255)",
Print(
static_cast<unsigned char>(255)));
351 EXPECT_EQ(
"'\\x80' (-128)",
Print(
static_cast<signed char>(-128)));
363 TEST(PrintBuiltInTypeTest, Size_t) {
365 #if !GTEST_OS_WINDOWS
368 #endif // !GTEST_OS_WINDOWS
372 TEST(PrintBuiltInTypeTest, FloatingPoints) {
381 ::std::stringstream expected_result_stream;
382 expected_result_stream <<
p;
383 return expected_result_stream.str();
389 TEST(PrintCStringTest, Const) {
390 const char*
p =
"World";
395 TEST(PrintCStringTest, NonConst) {
398 Print(
static_cast<char*
>(
p)));
403 const char*
p =
nullptr;
408 TEST(PrintCStringTest, EscapesProperly) {
409 const char*
p =
"'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
411 "\\n\\r\\t\\v\\x7F\\xFF a\"",
421 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
424 TEST(PrintWideCStringTest, Const) {
425 const wchar_t*
p = L
"World";
430 TEST(PrintWideCStringTest, NonConst) {
433 Print(
static_cast<wchar_t*
>(
p)));
437 TEST(PrintWideCStringTest, Null) {
438 const wchar_t*
p =
nullptr;
443 TEST(PrintWideCStringTest, EscapesProperly) {
444 const wchar_t s[] = {
'\'',
'"',
'?',
'\\',
'\a',
'\b',
'\f',
'\n',
'\r',
445 '\t',
'\v', 0xD3, 0x576, 0x8D3, 0xC74D,
' ',
'a',
'\0'};
447 "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
448 Print(
static_cast<const wchar_t*
>(
s)));
450 #endif // native wchar_t
455 TEST(PrintCharPointerTest, SignedChar) {
456 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
463 TEST(PrintCharPointerTest, ConstSignedChar) {
464 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
471 TEST(PrintCharPointerTest, UnsignedChar) {
472 unsigned char*
p =
reinterpret_cast<unsigned char*
>(0x1234);
479 TEST(PrintCharPointerTest, ConstUnsignedChar) {
480 const unsigned char*
p =
reinterpret_cast<const unsigned char*
>(0x1234);
490 bool*
p =
reinterpret_cast<bool*
>(0xABCD);
497 TEST(PrintPointerToBuiltInTypeTest, Void) {
498 void*
p =
reinterpret_cast<void*
>(0xABCD);
505 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
506 const void*
p =
reinterpret_cast<const void*
>(0xABCD);
513 TEST(PrintPointerToPointerTest, IntPointerPointer) {
514 int**
p =
reinterpret_cast<int**
>(0xABCD);
524 TEST(PrintPointerTest, NonMemberFunctionPointer) {
533 int (*
p)(bool) =
NULL;
539 template <
typename StringType>
544 const bool is_wide_string =
sizeof(
prefix[0]) > 1;
545 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
547 << begin_string_quote <<
prefix <<
"\" is not a prefix of "
548 << begin_string_quote <<
str <<
"\"\n";
565 TEST(PrintPointerTest, MemberVariablePointer) {
570 Print(
sizeof(
p)) +
"-byte object "));
577 TEST(PrintPointerTest, MemberFunctionPointer) {
585 Print(
sizeof(
p)) +
"-byte object "));
592 template <
typename T,
size_t N>
598 TEST(PrintArrayTest, OneDimensionalArray) {
599 int a[5] = { 1, 2, 3, 4, 5 };
604 TEST(PrintArrayTest, TwoDimensionalArray) {
609 EXPECT_EQ(
"{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }",
PrintArrayHelper(
a));
613 TEST(PrintArrayTest, ConstArray) {
614 const bool a[1] = {
false };
619 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
621 char a[] = {
'H',
'\0',
'i' };
626 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
627 const char a[] =
"\0Hi";
632 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
634 const wchar_t a[] = { L
'H', L
'\0', L
'i' };
639 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
640 const wchar_t a[] = L
"\0Hi";
645 TEST(PrintArrayTest, ObjectArray) {
651 TEST(PrintArrayTest, BigArray) {
652 int a[100] = { 1, 2, 3 };
653 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
659 #if GTEST_HAS_GLOBAL_STRING
661 TEST(PrintStringTest, StringInGlobalNamespace) {
662 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
664 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
667 #endif // GTEST_HAS_GLOBAL_STRING
670 TEST(PrintStringTest, StringInStdNamespace) {
671 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
673 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
677 TEST(PrintStringTest, StringAmbiguousHex) {
693 #if GTEST_HAS_GLOBAL_WSTRING
695 TEST(PrintWideStringTest, StringInGlobalNamespace) {
696 const wchar_t s[] = L
"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
698 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
699 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
702 #endif // GTEST_HAS_GLOBAL_WSTRING
704 #if GTEST_HAS_STD_WSTRING
706 TEST(PrintWideStringTest, StringInStdNamespace) {
707 const wchar_t s[] = L
"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
709 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
710 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
714 TEST(PrintWideStringTest, StringAmbiguousHex) {
723 #endif // GTEST_HAS_STD_WSTRING
733 template <
typename Char,
typename CharTraits>
735 std::basic_ostream<Char, CharTraits>& os,
737 return os <<
"AllowsGenericStreaming";
740 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
747 template <
typename T>
750 template <
typename Char,
typename CharTraits,
typename T>
752 std::basic_ostream<Char, CharTraits>& os,
754 return os <<
"AllowsGenericStreamingTemplate";
757 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
765 template <
typename T>
768 operator bool()
const {
return false; }
771 template <
typename Char,
typename CharTraits,
typename T>
773 std::basic_ostream<Char, CharTraits>& os,
775 return os <<
"AllowsGenericStreamingAndImplicitConversionTemplate";
778 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
780 EXPECT_EQ(
"AllowsGenericStreamingAndImplicitConversionTemplate",
Print(
a));
787 TEST(PrintStringViewTest, SimpleStringView) {
788 const ::absl::string_view sp =
"Hello";
792 TEST(PrintStringViewTest, UnprintableCharacters) {
793 const char str[] =
"NUL (\0) and \r\t";
794 const ::absl::string_view sp(
str,
sizeof(
str) - 1);
798 #endif // GTEST_HAS_ABSL
802 TEST(PrintStlContainerTest, EmptyDeque) {
807 TEST(PrintStlContainerTest, NonEmptyDeque) {
808 deque<int> non_empty;
809 non_empty.push_back(1);
810 non_empty.push_back(3);
815 TEST(PrintStlContainerTest, OneElementHashMap) {
816 ::std::unordered_map<int, char> map1;
821 TEST(PrintStlContainerTest, HashMultiMap) {
822 ::std::unordered_multimap<int, bool> map1;
823 map1.insert(make_pair(5,
true));
824 map1.insert(make_pair(5,
false));
828 EXPECT_TRUE(result ==
"{ (5, true), (5, false) }" ||
829 result ==
"{ (5, false), (5, true) }")
830 <<
" where Print(map1) returns \"" << result <<
"\".";
835 TEST(PrintStlContainerTest, HashSet) {
836 ::std::unordered_set<int> set1;
841 TEST(PrintStlContainerTest, HashMultiSet) {
843 int a[kSize] = { 1, 1, 2, 5, 1 };
844 ::std::unordered_multiset<int> set1(
a,
a + kSize);
848 const std::string expected_pattern =
"{ d, d, d, d, d }";
852 ASSERT_EQ(expected_pattern.length(), result.length());
853 std::vector<int> numbers;
854 for (
size_t i = 0;
i != result.length();
i++) {
855 if (expected_pattern[
i] ==
'd') {
856 ASSERT_NE(isdigit(
static_cast<unsigned char>(result[
i])), 0);
857 numbers.push_back(result[
i] -
'0');
859 EXPECT_EQ(expected_pattern[
i], result[
i]) <<
" where result is "
865 std::sort(numbers.begin(), numbers.end());
866 std::sort(
a,
a + kSize);
871 TEST(PrintStlContainerTest, List) {
873 const list<std::string>
strings(
a,
a + 2);
885 TEST(PrintStlContainerTest, MultiMap) {
886 multimap<bool, int> map1;
893 map1.insert(pair<const bool, int>(
true, 0));
894 map1.insert(pair<const bool, int>(
true, 1));
895 map1.insert(pair<const bool, int>(
false, 2));
899 TEST(PrintStlContainerTest, Set) {
900 const unsigned int a[] = { 3, 0, 5 };
901 set<unsigned int> set1(
a,
a + 3);
905 TEST(PrintStlContainerTest, MultiSet) {
906 const int a[] = { 1, 1, 2, 5, 1 };
907 multiset<int> set1(
a,
a + 5);
912 TEST(PrintStlContainerTest, SinglyLinkedList) {
913 int a[] = { 9, 2, 8 };
914 const std::forward_list<int> ints(
a,
a + 3);
918 TEST(PrintStlContainerTest, Pair) {
919 pair<const bool, int>
p(
true, 5);
923 TEST(PrintStlContainerTest, Vector) {
930 TEST(PrintStlContainerTest, LongSequence) {
931 const int a[100] = { 1, 2, 3 };
932 const vector<int>
v(
a,
a + 100);
933 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
934 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(
v));
937 TEST(PrintStlContainerTest, NestedContainer) {
938 const int a1[] = { 1, 2 };
939 const int a2[] = { 3, 4, 5 };
940 const list<int> l1(a1, a1 + 2);
941 const list<int> l2(a2, a2 + 3);
943 vector<list<int> >
v;
949 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
950 const int a[3] = { 1, 2, 3 };
951 NativeArray<int>
b(
a, 3, RelationToSourceReference());
955 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
956 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
957 NativeArray<int[3]>
b(
a, 2, RelationToSourceReference());
967 TEST(PrintStlContainerTest, Iterator) {
978 TEST(PrintStlContainerTest, ConstIterator) {
986 TEST(PrintStdTupleTest, VariousSizes) {
990 ::std::tuple<int> t1(5);
993 ::std::tuple<char, bool> t2(
'a',
true);
996 ::std::tuple<bool, int, int> t3(
false, 2, 3);
999 ::std::tuple<bool, int, int, int> t4(
false, 2, 3, 4);
1002 const char*
const str =
"8";
1006 t10(
false,
'a',
static_cast<short>(3), 4, 5, 1.5
F, -2.5,
str,
1009 " pointing to \"8\", NULL, \"10\")",
1014 TEST(PrintStdTupleTest, NestedTuple) {
1015 ::std::tuple< ::std::tuple<int, bool>,
char> nested(
1016 ::std::make_tuple(5,
true),
'a');
1024 TEST(PrintReferenceWrapper, Printable) {
1030 TEST(PrintReferenceWrapper, Unprintable) {
1034 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1038 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1039 Print(std::cref(up)));
1045 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1051 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1052 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1063 TEST(PrintUnpritableTypeTest, BigObject) {
1064 EXPECT_EQ(
"257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
1065 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1066 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1067 "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
1068 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1069 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1070 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1077 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1084 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1091 TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
1094 const ::foo::PathLike cx;
1099 TEST(PrintPrintableTypeTest, InUserNamespace) {
1106 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1112 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1113 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1119 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1130 const ::foo::UnprintableInFoo
x;
1132 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1138 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1148 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1154 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1158 "@" +
PrintPointer(
reinterpret_cast<const void*
>(&
p)) +
" " +
1159 Print(
sizeof(
p)) +
"-byte object "));
1164 "@" +
PrintPointer(
reinterpret_cast<const void*
>(&p2)) +
" " +
1165 Print(
sizeof(p2)) +
"-byte object "));
1170 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1182 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1188 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1195 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1198 int n[] = { 1, 2, 3 };
1208 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1215 const char*
s =
"hello";
1226 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1233 const wchar_t*
s = L
"hello";
1246 #if GTEST_HAS_GLOBAL_STRING
1248 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
1249 const char*
s =
"hello \"world";
1254 char str[] =
"hi\1";
1262 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1263 const char*
s =
"hello \"world";
1268 char str[] =
"hi\1";
1274 #if GTEST_HAS_GLOBAL_WSTRING
1276 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
1277 const wchar_t*
s = L
"hi \"world";
1282 wchar_t str[] = L
"hi\1";
1289 #if GTEST_HAS_STD_WSTRING
1291 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1292 const wchar_t*
s = L
"hi \"world";
1297 wchar_t str[] = L
"hi\1";
1309 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1310 char str[] =
"hi \"world\"";
1317 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1318 const char str[] =
"hi \"world\"";
1324 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1325 wchar_t str[] = L
"hi \"world\"";
1326 wchar_t*
p =
nullptr;
1332 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1333 const wchar_t str[] = L
"hi \"world\"";
1341 #if GTEST_HAS_GLOBAL_STRING
1343 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
1344 const char str[] =
"hi \"w\0rld\"";
1352 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1353 const char str[] =
"hi \"world\"";
1358 #if GTEST_HAS_GLOBAL_WSTRING
1360 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
1361 const wchar_t str[] = L
"hi \"world\"";
1367 #if GTEST_HAS_STD_WSTRING
1369 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1370 const wchar_t str[] = L
"hi \"w\0rld\"";
1381 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \
1382 EXPECT_TRUE(PrintToString(value) == (expected_string)) \
1383 << " where " #value " prints as " << (PrintToString(value))
1385 TEST(PrintToStringTest, WorksForScalar) {
1389 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1390 const char*
p =
"hello";
1394 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1400 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1401 const char*
p =
"hello\n";
1405 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1406 char s[] =
"hello\1";
1411 TEST(PrintToStringTest, WorksForArray) {
1412 int n[3] = { 1, 2, 3 };
1416 TEST(PrintToStringTest, WorksForCharArray) {
1421 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1422 const char str_with_nul[] =
"hello\0 world";
1425 char mutable_str_with_nul[] =
"hello\0 world";
1429 TEST(PrintToStringTest, ContainsNonLatin) {
1433 "\"\\xEC\\x98\\xA4\\xEC\\xA0\\x84 4:30\"\n"
1434 " As Text: \"ì˜¤ì „ 4:30\"");
1437 "\"From \\xC3\\xA4 \\xE2\\x80\\x94 \\xE1\\xBA\\x91\""
1438 "\n As Text: \"From ä — ẑ\"");
1441 TEST(IsValidUTF8Test, IllFormedUTF8) {
1446 static const char *
const kTestdata[][2] = {
1448 {
"\xC3\x74",
"\"\\xC3t\""},
1450 {
"\xC3\x84\xA4",
"\"\\xC3\\x84\\xA4\""},
1452 {
"abc\xC3",
"\"abc\\xC3\""},
1454 {
"x\xE2\x70\x94",
"\"x\\xE2p\\x94\""},
1456 {
"\xE2\x80",
"\"\\xE2\\x80\""},
1458 {
"\xE2\x80\xC3\x84",
"\"\\xE2\\x80\\xC3\\x84\""},
1460 {
"\xE2\x80\x7A",
"\"\\xE2\\x80z\""},
1462 {
"\xE2\xE2\x80\x94",
"\"\\xE2\\xE2\\x80\\x94\""},
1464 {
"\xF0\xE2\x80\x94",
"\"\\xF0\\xE2\\x80\\x94\""},
1466 {
"\xF0\xE2\x80",
"\"\\xF0\\xE2\\x80\""},
1468 {
"abc\xE2\x80\x94\xC3\x74xyc",
"\"abc\\xE2\\x80\\x94\\xC3txyc\""},
1469 {
"abc\xC3\x84\xE2\x80\xC3\x84xyz",
1470 "\"abc\\xC3\\x84\\xE2\\x80\\xC3\\x84xyz\""},
1473 {
"\xC0\x80",
"\"\\xC0\\x80\""},
1474 {
"\xC1\x81",
"\"\\xC1\\x81\""},
1476 {
"\xE0\x80\x80",
"\"\\xE0\\x80\\x80\""},
1477 {
"\xf0\x80\x80\x80",
"\"\\xF0\\x80\\x80\\x80\""},
1480 {
"\xED\x9F\xBF",
"\"\\xED\\x9F\\xBF\"\n As Text: \"퟿\""},
1482 {
"\xED\xA0\x80",
"\"\\xED\\xA0\\x80\""},
1484 {
"\xED\xAD\xBF",
"\"\\xED\\xAD\\xBF\""},
1486 {
"\xED\xAE\x80",
"\"\\xED\\xAE\\x80\""},
1488 {
"\xED\xAF\xBF",
"\"\\xED\\xAF\\xBF\""},
1490 {
"\xED\xB3\xBF",
"\"\\xED\\xB3\\xBF\""},
1493 {
"\xEE\x80\x80",
"\"\\xEE\\x80\\x80\"\n As Text: \"\""}
1496 for (
int i = 0;
i < int(
sizeof(kTestdata)/
sizeof(kTestdata[0])); ++
i) {
1501 #undef EXPECT_PRINT_TO_STRING_
1503 TEST(UniversalTersePrintTest, WorksForNonReference) {
1504 ::std::stringstream ss;
1509 TEST(UniversalTersePrintTest, WorksForReference) {
1511 ::std::stringstream ss;
1516 TEST(UniversalTersePrintTest, WorksForCString) {
1517 const char* s1 =
"abc";
1518 ::std::stringstream ss1;
1522 char* s2 =
const_cast<char*
>(s1);
1523 ::std::stringstream ss2;
1527 const char* s3 =
nullptr;
1528 ::std::stringstream ss3;
1533 TEST(UniversalPrintTest, WorksForNonReference) {
1534 ::std::stringstream ss;
1539 TEST(UniversalPrintTest, WorksForReference) {
1541 ::std::stringstream ss;
1546 TEST(UniversalPrintTest, WorksForCString) {
1547 const char* s1 =
"abc";
1548 ::std::stringstream ss1;
1552 char* s2 =
const_cast<char*
>(s1);
1553 ::std::stringstream ss2;
1557 const char* s3 =
nullptr;
1558 ::std::stringstream ss3;
1563 TEST(UniversalPrintTest, WorksForCharArray) {
1564 const char str[] =
"\"Line\0 1\"\nLine 2";
1565 ::std::stringstream ss1;
1567 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1569 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1570 ::std::stringstream ss2;
1572 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1575 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1580 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1582 ::std::make_tuple(1));
1587 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1589 ::std::make_tuple(1,
'a'));
1595 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1598 ::std::tuple<const int&, const char*>(
n,
"a"));
1606 TEST(PrintOptionalTest, Basic) {
1607 absl::optional<int>
value;
1615 struct NonPrintable {
1616 unsigned char contents = 17;
1619 TEST(PrintOneofTest, Basic) {
1620 using Type = absl::variant<int, StreamableInGlobal, NonPrintable>;
1622 EXPECT_EQ(
"('StreamableInGlobal' with value StreamableInGlobal)",
1625 "('testing::gtest_printers_test::NonPrintable' with value 1-byte object "
1629 #endif // GTEST_HAS_ABSL