40 #include <forward_list>
47 #include <unordered_map>
48 #include <unordered_set>
75 return os << (e ==
kEWS1 ?
"kEWS1" :
"invalid");
84 *os << (e ==
kEWPT1 ?
"kEWPT1" :
"invalid");
109 os <<
"StreamableInGlobal";
113 os <<
"StreamableInGlobal*";
122 double z()
const {
return z_; }
135 *os <<
"PrintableViaPrintTo: " << x.
value;
144 return os <<
"PointerPrintable*";
148 template <
typename T>
158 template <
typename T>
160 *os <<
"PrintableViaPrintToTemplate: " << x.
value();
164 template <
typename T>
174 template <
typename T>
177 return os <<
"StreamableTemplateInFoo: " << x.
value();
201 return os <<
"Streamable-PathLike";
208 namespace gtest_printers_test {
212 using ::std::make_pair;
214 using ::std::multimap;
215 using ::std::multiset;
222 using ::testing::internal::NativeArray;
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(PrintCharTest, Char8) {
336 TEST(PrintBuiltInTypeTest, Wchar_t) {
353 EXPECT_EQ(
"L'\\x576' (1398)",
Print(static_cast<wchar_t>(0x576)));
354 EXPECT_EQ(
"L'\\xC74D' (51021)",
Print(static_cast<wchar_t>(0xC74D)));
358 TEST(PrintTypeSizeTest, Wchar_t) {
359 EXPECT_LT(
sizeof(
wchar_t),
sizeof(int64_t));
363 TEST(PrintBuiltInTypeTest, Integer) {
364 EXPECT_EQ(
"'\\xFF' (255)",
Print(static_cast<unsigned char>(255)));
365 EXPECT_EQ(
"'\\x80' (-128)",
Print(static_cast<signed char>(-128)));
393 TEST(PrintBuiltInTypeTest, Size_t) {
395 #if !GTEST_OS_WINDOWS
398 #endif // !GTEST_OS_WINDOWS
402 TEST(PrintBuiltInTypeTest, FloatingPoints) {
411 ::std::stringstream expected_result_stream;
412 expected_result_stream <<
p;
413 return expected_result_stream.str();
419 TEST(PrintCStringTest, Const) {
420 const char*
p =
"World";
425 TEST(PrintCStringTest, NonConst) {
428 Print(static_cast<char*>(p)));
433 const char*
p =
nullptr;
438 TEST(PrintCStringTest, EscapesProperly) {
439 const char*
p =
"'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
441 "\\n\\r\\t\\v\\x7F\\xFF a\"",
451 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
454 TEST(PrintWideCStringTest, Const) {
455 const wchar_t*
p = L
"World";
460 TEST(PrintWideCStringTest, NonConst) {
463 Print(static_cast<wchar_t*>(p)));
467 TEST(PrintWideCStringTest, Null) {
468 const wchar_t*
p =
nullptr;
473 TEST(PrintWideCStringTest, EscapesProperly) {
474 const wchar_t s[] = {
'\'',
'"',
'?',
'\\',
'\a',
'\b',
'\f',
'\n',
'\r',
475 '\t',
'\v', 0xD3, 0x576, 0x8D3, 0xC74D,
' ',
'a',
'\0'};
477 "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
478 Print(static_cast<const wchar_t*>(s)));
480 #endif // native wchar_t
485 TEST(PrintCharPointerTest, SignedChar) {
486 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
493 TEST(PrintCharPointerTest, ConstSignedChar) {
494 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
501 TEST(PrintCharPointerTest, UnsignedChar) {
502 unsigned char*
p =
reinterpret_cast<unsigned char*
>(0x1234);
509 TEST(PrintCharPointerTest, ConstUnsignedChar) {
510 const unsigned char*
p =
reinterpret_cast<const unsigned char*
>(0x1234);
518 TEST(PrintCharPointerTest, Char8) {
519 char8_t*
p =
reinterpret_cast<char8_t*
>(0x1234);
526 TEST(PrintCharPointerTest, ConstChar8) {
527 const char8_t* p =
reinterpret_cast<const char8_t*
>(0x1234);
535 TEST(PrintCharPointerTest, Char16) {
536 char16_t* p =
reinterpret_cast<char16_t*
>(0x1234);
543 TEST(PrintCharPointerTest, ConstChar16) {
544 const char16_t* p =
reinterpret_cast<const char16_t*
>(0x1234);
551 TEST(PrintCharPointerTest, Char32) {
552 char32_t* p =
reinterpret_cast<char32_t*
>(0x1234);
559 TEST(PrintCharPointerTest, ConstChar32) {
560 const char32_t* p =
reinterpret_cast<const char32_t*
>(0x1234);
570 bool* p =
reinterpret_cast<bool*
>(0xABCD);
578 void* p =
reinterpret_cast<void*
>(0xABCD);
585 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
586 const void* p =
reinterpret_cast<const void*
>(0xABCD);
593 TEST(PrintPointerToPointerTest, IntPointerPointer) {
594 int** p =
reinterpret_cast<int**
>(0xABCD);
604 TEST(PrintPointerTest, NonMemberFunctionPointer) {
611 reinterpret_cast<internal::BiggestInt>(&
MyFunction))),
613 int (*p)(bool) = NULL;
619 template <
typename StringType>
620 AssertionResult
HasPrefix(
const StringType& str,
const StringType& prefix) {
621 if (str.find(prefix, 0) == 0)
624 const bool is_wide_string =
sizeof(prefix[0]) > 1;
625 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
627 << begin_string_quote << prefix <<
"\" is not a prefix of "
628 << begin_string_quote << str <<
"\"\n";
645 TEST(PrintPointerTest, MemberVariablePointer) {
650 Print(
sizeof(p)) +
"-byte object "));
657 TEST(PrintPointerTest, MemberFunctionPointer) {
663 int (
Foo::*p)(char) = NULL;
665 Print(
sizeof(p)) +
"-byte object "));
672 template <
typename T,
size_t N>
678 TEST(PrintArrayTest, OneDimensionalArray) {
679 int a[5] = { 1, 2, 3, 4, 5 };
684 TEST(PrintArrayTest, TwoDimensionalArray) {
689 EXPECT_EQ(
"{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }",
PrintArrayHelper(a));
693 TEST(PrintArrayTest, ConstArray) {
694 const bool a[1] = {
false };
699 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
701 char a[] = {
'H',
'\0',
'i' };
706 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
707 const char a[] =
"\0Hi";
712 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
714 const wchar_t a[] = { L
'H', L
'\0', L
'i' };
719 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
720 const wchar_t a[] = L
"\0Hi";
726 TEST(PrintArrayTest, Char8Array) {
727 const char8_t
a[] = u8
"Hello, world!";
729 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+0077, "
730 "U+006F, U+0072, U+006C, U+0064, U+0021, U+0000 }",
736 TEST(PrintArrayTest, Char16Array) {
737 const char16_t a[] = u
"Hello, 世界";
739 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
745 TEST(PrintArrayTest, Char32Array) {
746 const char32_t a[] = U
"Hello, 世界";
748 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
754 TEST(PrintArrayTest, ObjectArray) {
755 std::string a[3] = {
"Hi",
"Hello",
"Ni hao"};
760 TEST(PrintArrayTest, BigArray) {
761 int a[100] = { 1, 2, 3 };
762 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
769 TEST(PrintStringTest, StringInStdNamespace) {
770 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
771 const ::std::string str(s,
sizeof(s));
772 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
776 TEST(PrintStringTest, StringAmbiguousHex) {
783 EXPECT_EQ(
"\"mm\\x6\" \"bananas\"",
Print(::std::string(
"mm\x6" "bananas")));
785 EXPECT_EQ(
"\"NOM\\x6\" \"BANANA\"",
Print(::std::string(
"NOM\x6" "BANANA")));
791 #if GTEST_HAS_STD_WSTRING
793 TEST(PrintWideStringTest, StringInStdNamespace) {
794 const wchar_t s[] = L
"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
795 const ::std::wstring str(s,
sizeof(s)/
sizeof(
wchar_t));
796 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
797 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
801 TEST(PrintWideStringTest, StringAmbiguousHex) {
803 EXPECT_EQ(
"L\"0\\x12\" L\"3\"",
Print(::std::wstring(L
"0\x12" L
"3")));
805 Print(::std::wstring(L
"mm\x6" L
"bananas")));
807 Print(::std::wstring(L
"NOM\x6" L
"BANANA")));
810 #endif // GTEST_HAS_STD_WSTRING
813 TEST(PrintStringTest, U8String) {
814 std::u8string str = u8
"Hello, world!";
817 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+0077, "
818 "U+006F, U+0072, U+006C, U+0064, U+0021 }",
823 TEST(PrintStringTest, U16String) {
824 std::u16string str = u
"Hello, 世界";
827 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
832 TEST(PrintStringTest, U32String) {
833 std::u32string str = U
"Hello, 世界";
836 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
849 template <
typename Char,
typename CharTraits>
851 std::basic_ostream<Char, CharTraits>& os,
853 return os <<
"AllowsGenericStreaming";
856 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
863 template <
typename T>
866 template <
typename Char,
typename CharTraits,
typename T>
868 std::basic_ostream<Char, CharTraits>& os,
870 return os <<
"AllowsGenericStreamingTemplate";
873 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
881 template <
typename T>
884 operator bool()
const {
return false; }
887 template <
typename Char,
typename CharTraits,
typename T>
889 std::basic_ostream<Char, CharTraits>& os,
891 return os <<
"AllowsGenericStreamingAndImplicitConversionTemplate";
894 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
896 EXPECT_EQ(
"AllowsGenericStreamingAndImplicitConversionTemplate",
Print(a));
899 #if GTEST_INTERNAL_HAS_STRING_VIEW
903 TEST(PrintStringViewTest, SimpleStringView) {
904 const internal::StringView sp =
"Hello";
908 TEST(PrintStringViewTest, UnprintableCharacters) {
909 const char str[] =
"NUL (\0) and \r\t";
910 const internal::StringView sp(str,
sizeof(str) - 1);
914 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
918 TEST(PrintStlContainerTest, EmptyDeque) {
923 TEST(PrintStlContainerTest, NonEmptyDeque) {
924 deque<int> non_empty;
925 non_empty.push_back(1);
926 non_empty.push_back(3);
931 TEST(PrintStlContainerTest, OneElementHashMap) {
932 ::std::unordered_map<int, char> map1;
937 TEST(PrintStlContainerTest, HashMultiMap) {
938 ::std::unordered_multimap<int, bool> map1;
939 map1.insert(make_pair(5,
true));
940 map1.insert(make_pair(5,
false));
943 const std::string result =
Print(map1);
944 EXPECT_TRUE(result ==
"{ (5, true), (5, false) }" ||
945 result ==
"{ (5, false), (5, true) }")
946 <<
" where Print(map1) returns \"" << result <<
"\".";
951 TEST(PrintStlContainerTest, HashSet) {
952 ::std::unordered_set<int> set1;
957 TEST(PrintStlContainerTest, HashMultiSet) {
959 int a[kSize] = { 1, 1, 2, 5, 1 };
960 ::std::unordered_multiset<int> set1(a, a + kSize);
963 const std::string result =
Print(set1);
964 const std::string expected_pattern =
"{ d, d, d, d, d }";
968 ASSERT_EQ(expected_pattern.length(), result.length());
969 std::vector<int> numbers;
970 for (
size_t i = 0;
i != result.length();
i++) {
971 if (expected_pattern[
i] ==
'd') {
972 ASSERT_NE(isdigit(static_cast<unsigned char>(result[
i])), 0);
973 numbers.push_back(result[i] -
'0');
975 EXPECT_EQ(expected_pattern[
i], result[i]) <<
" where result is "
981 std::sort(numbers.begin(), numbers.end());
982 std::sort(a, a + kSize);
983 EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
987 TEST(PrintStlContainerTest, List) {
988 const std::string a[] = {
"hello",
"world"};
989 const list<std::string> strings(a, a + 2);
993 TEST(PrintStlContainerTest, Map) {
1001 TEST(PrintStlContainerTest, MultiMap) {
1002 multimap<bool, int> map1;
1009 map1.insert(pair<const bool, int>(
true, 0));
1010 map1.insert(pair<const bool, int>(
true, 1));
1011 map1.insert(pair<const bool, int>(
false, 2));
1016 const unsigned int a[] = { 3, 0, 5 };
1017 set<unsigned int> set1(a, a + 3);
1021 TEST(PrintStlContainerTest, MultiSet) {
1022 const int a[] = { 1, 1, 2, 5, 1 };
1023 multiset<int> set1(a, a + 5);
1028 TEST(PrintStlContainerTest, SinglyLinkedList) {
1029 int a[] = { 9, 2, 8 };
1030 const std::forward_list<int> ints(a, a + 3);
1034 TEST(PrintStlContainerTest, Pair) {
1035 pair<const bool, int>
p(
true, 5);
1039 TEST(PrintStlContainerTest, Vector) {
1046 TEST(PrintStlContainerTest, LongSequence) {
1047 const int a[100] = { 1, 2, 3 };
1048 const vector<int> v(a, a + 100);
1049 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
1050 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(v));
1053 TEST(PrintStlContainerTest, NestedContainer) {
1054 const int a1[] = { 1, 2 };
1055 const int a2[] = { 3, 4, 5 };
1056 const list<int> l1(a1, a1 + 2);
1057 const list<int> l2(a2, a2 + 3);
1059 vector<list<int> > v;
1065 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
1066 const int a[3] = { 1, 2, 3 };
1067 NativeArray<int> b(a, 3, RelationToSourceReference());
1071 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
1072 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
1073 NativeArray<int[3]> b(a, 2, RelationToSourceReference());
1083 TEST(PrintStlContainerTest, Iterator) {
1094 TEST(PrintStlContainerTest, ConstIterator) {
1102 TEST(PrintStdTupleTest, VariousSizes) {
1106 ::std::tuple<int> t1(5);
1109 ::std::tuple<char, bool> t2(
'a',
true);
1112 ::std::tuple<bool, int, int> t3(
false, 2, 3);
1115 ::std::tuple<bool, int, int, int> t4(
false, 2, 3, 4);
1118 const char*
const str =
"8";
1119 ::std::tuple<bool, char, short, int32_t, int64_t, float, double,
1120 const char*,
void*, std::string>
1121 t10(
false,
'a', static_cast<short>(3), 4, 5, 1.5
F, -2.5, str,
1124 " pointing to \"8\", NULL, \"10\")",
1129 TEST(PrintStdTupleTest, NestedTuple) {
1130 ::std::tuple< ::std::tuple<int, bool>,
char> nested(
1131 ::std::make_tuple(5,
true),
'a');
1139 TEST(PrintReferenceWrapper, Printable) {
1145 TEST(PrintReferenceWrapper, Unprintable) {
1149 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1150 Print(std::ref(up)));
1153 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1154 Print(std::cref(up)));
1160 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1166 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1167 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1178 TEST(PrintUnpritableTypeTest, BigObject) {
1179 EXPECT_EQ(
"257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
1180 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1181 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1182 "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
1183 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1184 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1185 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1192 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1199 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1206 TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
1209 const ::foo::PathLike cx;
1214 TEST(PrintPrintableTypeTest, InUserNamespace) {
1221 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1227 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1228 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1234 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1245 const ::foo::UnprintableInFoo
x;
1247 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1253 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1255 const std::string fp_pointer_string =
1261 const std::string fp_string =
PrintPointer(reinterpret_cast<const void*>(
1262 reinterpret_cast<internal::BiggestInt>(fp)));
1263 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1269 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1273 "@" +
PrintPointer(reinterpret_cast<const void*>(&p)) +
" " +
1274 Print(
sizeof(p)) +
"-byte object "));
1279 "@" +
PrintPointer(reinterpret_cast<const void*>(&p2)) +
" " +
1280 Print(
sizeof(p2)) +
"-byte object "));
1285 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1297 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1303 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1310 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1313 int n[] = { 1, 2, 3 };
1323 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1330 const char* s =
"hello";
1341 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1348 const wchar_t* s = L
"hello";
1362 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1363 const char* s =
"hello \"world";
1368 char str[] =
"hi\1";
1374 #if GTEST_HAS_STD_WSTRING
1376 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1377 const wchar_t* s = L
"hi \"world";
1382 wchar_t str[] = L
"hi\1";
1394 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1395 char str[] =
"hi \"world\"";
1402 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1403 const char str[] =
"hi \"world\"";
1409 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1410 wchar_t str[] = L
"hi \"world\"";
1411 wchar_t* p =
nullptr;
1417 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1418 const wchar_t str[] = L
"hi \"world\"";
1427 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1428 const char str[] =
"hi \"world\"";
1433 #if GTEST_HAS_STD_WSTRING
1435 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1436 const wchar_t str[] = L
"hi \"w\0rld\"";
1447 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \
1448 EXPECT_TRUE(PrintToString(value) == (expected_string)) \
1449 << " where " #value " prints as " << (PrintToString(value))
1451 TEST(PrintToStringTest, WorksForScalar) {
1455 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1456 const char* p =
"hello";
1460 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1466 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1467 const char* p =
"hello\n";
1471 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1472 char s[] =
"hello\1";
1477 TEST(PrintToStringTest, WorksForArray) {
1478 int n[3] = { 1, 2, 3 };
1482 TEST(PrintToStringTest, WorksForCharArray) {
1487 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1488 const char str_with_nul[] =
"hello\0 world";
1491 char mutable_str_with_nul[] =
"hello\0 world";
1495 TEST(PrintToStringTest, ContainsNonLatin) {
1497 std::string non_ascii_str = ::std::string(
"ì˜¤ì „ 4:30");
1499 "\"\\xEC\\x98\\xA4\\xEC\\xA0\\x84 4:30\"\n"
1500 " As Text: \"ì˜¤ì „ 4:30\"");
1501 non_ascii_str = ::std::string(
"From ä — ẑ");
1503 "\"From \\xC3\\xA4 \\xE2\\x80\\x94 \\xE1\\xBA\\x91\""
1504 "\n As Text: \"From ä — ẑ\"");
1507 TEST(IsValidUTF8Test, IllFormedUTF8) {
1512 static const char *
const kTestdata[][2] = {
1514 {
"\xC3\x74",
"\"\\xC3t\""},
1516 {
"\xC3\x84\xA4",
"\"\\xC3\\x84\\xA4\""},
1518 {
"abc\xC3",
"\"abc\\xC3\""},
1520 {
"x\xE2\x70\x94",
"\"x\\xE2p\\x94\""},
1522 {
"\xE2\x80",
"\"\\xE2\\x80\""},
1524 {
"\xE2\x80\xC3\x84",
"\"\\xE2\\x80\\xC3\\x84\""},
1526 {
"\xE2\x80\x7A",
"\"\\xE2\\x80z\""},
1528 {
"\xE2\xE2\x80\x94",
"\"\\xE2\\xE2\\x80\\x94\""},
1530 {
"\xF0\xE2\x80\x94",
"\"\\xF0\\xE2\\x80\\x94\""},
1532 {
"\xF0\xE2\x80",
"\"\\xF0\\xE2\\x80\""},
1534 {
"abc\xE2\x80\x94\xC3\x74xyc",
"\"abc\\xE2\\x80\\x94\\xC3txyc\""},
1535 {
"abc\xC3\x84\xE2\x80\xC3\x84xyz",
1536 "\"abc\\xC3\\x84\\xE2\\x80\\xC3\\x84xyz\""},
1539 {
"\xC0\x80",
"\"\\xC0\\x80\""},
1540 {
"\xC1\x81",
"\"\\xC1\\x81\""},
1542 {
"\xE0\x80\x80",
"\"\\xE0\\x80\\x80\""},
1543 {
"\xf0\x80\x80\x80",
"\"\\xF0\\x80\\x80\\x80\""},
1546 {
"\xED\x9F\xBF",
"\"\\xED\\x9F\\xBF\"\n As Text: \"퟿\""},
1548 {
"\xED\xA0\x80",
"\"\\xED\\xA0\\x80\""},
1550 {
"\xED\xAD\xBF",
"\"\\xED\\xAD\\xBF\""},
1552 {
"\xED\xAE\x80",
"\"\\xED\\xAE\\x80\""},
1554 {
"\xED\xAF\xBF",
"\"\\xED\\xAF\\xBF\""},
1556 {
"\xED\xB3\xBF",
"\"\\xED\\xB3\\xBF\""},
1559 {
"\xEE\x80\x80",
"\"\\xEE\\x80\\x80\"\n As Text: \"\""}
1562 for (
int i = 0;
i < int(
sizeof(kTestdata)/
sizeof(kTestdata[0])); ++
i) {
1567 #undef EXPECT_PRINT_TO_STRING_
1569 TEST(UniversalTersePrintTest, WorksForNonReference) {
1570 ::std::stringstream ss;
1575 TEST(UniversalTersePrintTest, WorksForReference) {
1577 ::std::stringstream ss;
1582 TEST(UniversalTersePrintTest, WorksForCString) {
1583 const char* s1 =
"abc";
1584 ::std::stringstream ss1;
1588 char* s2 =
const_cast<char*
>(s1);
1589 ::std::stringstream ss2;
1593 const char* s3 =
nullptr;
1594 ::std::stringstream ss3;
1599 TEST(UniversalPrintTest, WorksForNonReference) {
1600 ::std::stringstream ss;
1605 TEST(UniversalPrintTest, WorksForReference) {
1607 ::std::stringstream ss;
1612 TEST(UniversalPrintTest, WorksForCString) {
1613 const char* s1 =
"abc";
1614 ::std::stringstream ss1;
1618 char* s2 =
const_cast<char*
>(s1);
1619 ::std::stringstream ss2;
1623 const char* s3 =
nullptr;
1624 ::std::stringstream ss3;
1629 TEST(UniversalPrintTest, WorksForCharArray) {
1630 const char str[] =
"\"Line\0 1\"\nLine 2";
1631 ::std::stringstream ss1;
1633 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1635 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1636 ::std::stringstream ss2;
1638 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1641 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1646 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1648 ::std::make_tuple(1));
1653 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1655 ::std::make_tuple(1,
'a'));
1661 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1664 ::std::tuple<const int&, const char*>(n,
"a"));
1670 #if GTEST_INTERNAL_HAS_ANY
1673 template <
typename T>
1674 static std::string ExpectedTypeName() {
1676 return internal::GetTypeName<T>();
1678 return "<unknown_type>";
1679 #endif // GTEST_HAS_RTTI
1683 TEST_F(PrintAnyTest, Empty) {
1688 TEST_F(PrintAnyTest, NonEmpty) {
1690 constexpr
int val1 = 10;
1691 const std::string val2 =
"content";
1697 EXPECT_EQ(
"value of type " + ExpectedTypeName<std::string>(),
1700 #endif // GTEST_INTERNAL_HAS_ANY
1702 #if GTEST_INTERNAL_HAS_OPTIONAL
1703 TEST(PrintOptionalTest, Basic) {
1704 internal::Optional<int>
value;
1711 #endif // GTEST_INTERNAL_HAS_OPTIONAL
1713 #if GTEST_INTERNAL_HAS_VARIANT
1714 struct NonPrintable {
1715 unsigned char contents = 17;
1718 TEST(PrintOneofTest, Basic) {
1719 using Type = internal::Variant<int, StreamableInGlobal, NonPrintable>;
1721 EXPECT_EQ(
"('StreamableInGlobal(index = 1)' with value StreamableInGlobal)",
1724 "('testing::gtest_printers_test::NonPrintable(index = 2)' with value "
1725 "1-byte object <11>)",
1728 #endif // GTEST_INTERNAL_HAS_VARIANT
1737 string_ptr(
const char* data,
size_t size) :
data_(data),
size_(size) {}
1739 string_ptr& operator++() noexcept {
1756 string_ref(
const char* data,
size_t size) :
data_(data),
size_(size) {}
1758 string_ptr operator&()
const noexcept {
return {
data_, size_}; }
1760 bool operator==(
const char* s)
const noexcept {
1761 if (size_ > 0 && data_[size_ - 1] != 0) {
1762 return std::string(data_, size_) == std::string(s);
1764 return std::string(data_) == std::string(s);
1773 string_ref string_ptr::operator*() const noexcept {
return {
data_,
size_}; }
1775 TEST(string_ref, compare) {
1776 const char* s =
"alex\0davidjohn\0";
1777 string_ptr ptr(s, 5);
TEST(PrintEnumTest, AnonymousEnum)
AssertionResult AssertionFailure()
#define EXPECT_PRINT_TO_STRING_(value, expected_string)
#define ASSERT_NE(val1, val2)
::std::string PrintToString(const T &value)
TEST_F(TestInfoTest, Names)
UnprintableTemplateInGlobal()
void UniversalTersePrint(const T &value,::std::ostream *os)
std::basic_ostream< Char, CharTraits > & operator<<(std::basic_ostream< Char, CharTraits > &os, const AllowsGenericStreaming &)
std::string Print(const T &value)
::std::vector< ::std::string > Strings
#define ASSERT_EQ(val1, val2)
::std::ostream & operator<<(::std::ostream &os, const PointerPrintable *)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
std::string PrintArrayHelper(T(&a)[N])
BigUInt< n > operator*(BigUInt< n > const &a, BigUInt< n > const &b)
#define EXPECT_LT(val1, val2)
std::ostream & operator<<(std::ostream &os, const Expr< T > &xx)
AssertionResult AssertionSuccess()
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
void UniversalPrint(const T &value,::std::ostream *os)
ADVar foo(double d, ADVar x, ADVar y)
PrintableViaPrintToTemplate(const T &a_value)
#define EXPECT_STREQ(s1, s2)
void PrintTo(const PrintableViaPrintTo &x,::std::ostream *os)
virtual ~StreamableInGlobal()
void PrintTo(const T &value,::std::ostream *os)
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
AssertionResult HasPrefix(const StringType &str, const StringType &prefix)
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
virtual char MyVirtualMethod(int)
#define EXPECT_EQ(val1, val2)
static std::string PrintPointer(const void *p)
StreamableTemplateInFoo()
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define EXPECT_TRUE(condition)
std::string PrintByRef(const T &value)
friend::std::ostream & operator<<(::std::ostream &os, const PathLike &)