40 #include <forward_list>
47 #include <unordered_map>
48 #include <unordered_set>
52 #include "gtest/gtest-printers.h"
53 #include "gtest/gtest.h"
75 return os << (e ==
kEWS1 ?
"kEWS1" :
"invalid");
84 *os << (e ==
kEWPT1 ?
"kEWPT1" :
"invalid");
102 os <<
"ChildClassWithStreamOperator";
106 template <
typename T>
121 os <<
"StreamableInGlobal";
125 os <<
"StreamableInGlobal*";
131 class UnprintableInFoo {
134 double z()
const {
return z_; }
141 struct PrintableViaPrintTo {
146 void PrintTo(
const PrintableViaPrintTo& x, ::std::ostream* os) {
147 *os <<
"PrintableViaPrintTo: " <<
x.value;
151 struct PointerPrintable {
154 ::std::ostream&
operator<<(::std::ostream& os,
155 const PointerPrintable* ) {
156 return os <<
"PointerPrintable*";
160 template <
typename T>
161 class PrintableViaPrintToTemplate {
170 template <
typename T>
171 void PrintTo(
const PrintableViaPrintToTemplate<T>& x, ::std::ostream* os) {
172 *os <<
"PrintableViaPrintToTemplate: " <<
x.value();
176 template <
typename T>
177 class StreamableTemplateInFoo {
186 template <
typename T>
187 inline ::std::ostream&
operator<<(::std::ostream& os,
188 const StreamableTemplateInFoo<T>& x) {
189 return os <<
"StreamableTemplateInFoo: " <<
x.value();
196 template <
typename OutputStream>
198 const TemplatedStreamableInFoo& ) {
199 os <<
"TemplatedStreamableInFoo";
224 return os <<
"Streamable-PathLike";
231 namespace gtest_printers_test {
235 using ::std::make_pair;
237 using ::std::multimap;
238 using ::std::multiset;
245 using ::testing::internal::NativeArray;
246 using ::testing::internal::RelationToSourceReference;
249 using ::testing::internal::UniversalPrinter;
255 template <
typename T>
257 ::std::stringstream ss;
265 template <
typename T>
267 ::std::stringstream ss;
303 TEST(PrintCharTest, PlainChar) {
323 TEST(PrintCharTest, SignedChar) {
326 Print(
static_cast<signed char>(-50)));
330 TEST(PrintCharTest, UnsignedChar) {
333 Print(
static_cast<unsigned char>(
'b')));
345 TEST(PrintCharTest, Char8) {
359 TEST(PrintBuiltInTypeTest, Wchar_t) {
376 EXPECT_EQ(
"L'\\x576' (1398)",
Print(
static_cast<wchar_t>(0x576)));
377 EXPECT_EQ(
"L'\\xC74D' (51021)",
Print(
static_cast<wchar_t>(0xC74D)));
381 TEST(PrintTypeSizeTest, Wchar_t) {
386 TEST(PrintBuiltInTypeTest, Integer) {
387 EXPECT_EQ(
"'\\xFF' (255)",
Print(
static_cast<unsigned char>(255)));
388 EXPECT_EQ(
"'\\x80' (-128)",
Print(
static_cast<signed char>(-128)));
416 TEST(PrintBuiltInTypeTest, Size_t) {
418 #if !GTEST_OS_WINDOWS
421 #endif // !GTEST_OS_WINDOWS
425 TEST(PrintBuiltInTypeTest, FloatingPoints) {
434 ::std::stringstream expected_result_stream;
435 expected_result_stream << p;
436 return expected_result_stream.str();
443 const char* p =
"World";
448 TEST(PrintCStringTest, NonConst) {
451 Print(
static_cast<char*
>(p)));
455 TEST(PrintCStringTest, Null) {
456 const char*
p =
nullptr;
461 TEST(PrintCStringTest, EscapesProperly) {
462 const char*
p =
"'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
464 "\\n\\r\\t\\v\\x7F\\xFF a\"",
474 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
478 const wchar_t*
p =
L"World";
483 TEST(PrintWideCStringTest, NonConst) {
486 Print(
static_cast<wchar_t*
>(p)));
490 TEST(PrintWideCStringTest, Null) {
491 const wchar_t*
p =
nullptr;
496 TEST(PrintWideCStringTest, EscapesProperly) {
497 const wchar_t s[] = {
'\'',
'"',
'?',
'\\',
'\a',
'\b',
'\f',
'\n',
'\r',
498 '\t',
'\v', 0xD3, 0x576, 0x8D3, 0xC74D,
' ',
'a',
'\0'};
500 "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
501 Print(
static_cast<const wchar_t*
>(s)));
503 #endif // native wchar_t
508 TEST(PrintCharPointerTest, SignedChar) {
509 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
516 TEST(PrintCharPointerTest, ConstSignedChar) {
517 signed char*
p =
reinterpret_cast<signed char*
>(0x1234);
524 TEST(PrintCharPointerTest, UnsignedChar) {
525 unsigned char*
p =
reinterpret_cast<unsigned char*
>(0x1234);
532 TEST(PrintCharPointerTest, ConstUnsignedChar) {
533 const unsigned char*
p =
reinterpret_cast<const unsigned char*
>(0x1234);
541 TEST(PrintCharPointerTest, Char8) {
542 char8_t*
p =
reinterpret_cast<char8_t*
>(0x1234);
549 TEST(PrintCharPointerTest, ConstChar8) {
550 const char8_t*
p =
reinterpret_cast<const char8_t*
>(0x1234);
558 TEST(PrintCharPointerTest, Char16) {
559 char16_t* p =
reinterpret_cast<char16_t*
>(0x1234);
566 TEST(PrintCharPointerTest, ConstChar16) {
567 const char16_t* p =
reinterpret_cast<const char16_t*
>(0x1234);
574 TEST(PrintCharPointerTest, Char32) {
575 char32_t* p =
reinterpret_cast<char32_t*
>(0x1234);
582 TEST(PrintCharPointerTest, ConstChar32) {
583 const char32_t* p =
reinterpret_cast<const char32_t*
>(0x1234);
592 TEST(PrintPointerToBuiltInTypeTest,
Bool) {
593 bool* p =
reinterpret_cast<bool*
>(0xABCD);
600 TEST(PrintPointerToBuiltInTypeTest, Void) {
601 void* p =
reinterpret_cast<void*
>(0xABCD);
608 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
609 const void*
p =
reinterpret_cast<const void*
>(0xABCD);
616 TEST(PrintPointerToPointerTest, IntPointerPointer) {
617 int**
p =
reinterpret_cast<int**
>(0xABCD);
627 TEST(PrintPointerTest, NonMemberFunctionPointer) {
642 template <
typename StringType>
647 const bool is_wide_string =
sizeof(
prefix[0]) > 1;
648 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
650 << begin_string_quote <<
prefix <<
"\" is not a prefix of "
651 << begin_string_quote <<
str <<
"\"\n";
668 TEST(PrintPointerTest, MemberVariablePointer) {
673 Print(
sizeof(p)) +
"-byte object "));
680 TEST(PrintPointerTest, MemberFunctionPointer) {
686 int (
Foo::*p)(char) = NULL;
688 Print(
sizeof(p)) +
"-byte object "));
695 template <
typename T,
size_t N>
701 TEST(PrintArrayTest, OneDimensionalArray) {
702 int a[5] = { 1, 2, 3, 4, 5 };
707 TEST(PrintArrayTest, TwoDimensionalArray) {
712 EXPECT_EQ(
"{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }",
PrintArrayHelper(a));
716 TEST(PrintArrayTest, ConstArray) {
717 const bool a[1] = {
false };
722 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
724 char a[] = {
'H',
'\0',
'i' };
729 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
730 const char a[] =
"\0Hi";
735 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
737 const wchar_t a[] = {
L'H',
L'\0',
L'i' };
742 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
743 const wchar_t a[] =
L"\0Hi";
749 TEST(PrintArrayTest, Char8Array) {
750 const char8_t
a[] = u8
"Hello, world!";
752 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+0077, "
753 "U+006F, U+0072, U+006C, U+0064, U+0021, U+0000 }",
761 TEST(PrintArrayTest, DISABLED_Char16Array) {
763 TEST(PrintArrayTest, Char16Array) {
765 const char16_t
a[] =
u"Hello, 世界";
767 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
775 TEST(PrintArrayTest, DISABLED_Char32Array) {
777 TEST(PrintArrayTest, Char32Array) {
779 const char32_t
a[] = U
"Hello, 世界";
781 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
787 TEST(PrintArrayTest, ObjectArray) {
793 TEST(PrintArrayTest, BigArray) {
794 int a[100] = { 1, 2, 3 };
795 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
802 TEST(PrintStringTest, StringInStdNamespace) {
803 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
805 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
809 TEST(PrintStringTest, StringAmbiguousHex) {
824 #if GTEST_HAS_STD_WSTRING
826 TEST(PrintWideStringTest, StringInStdNamespace) {
827 const wchar_t s[] =
L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
829 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
830 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
834 TEST(PrintWideStringTest, StringAmbiguousHex) {
843 #endif // GTEST_HAS_STD_WSTRING
846 TEST(PrintStringTest, U8String) {
847 std::u8string
str = u8
"Hello, world!";
850 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+0077, "
851 "U+006F, U+0072, U+006C, U+0064, U+0021 }",
858 TEST(PrintStringTest, DISABLED_U16String) {
860 TEST(PrintStringTest, U16String) {
862 std::u16string
str =
u"Hello, 世界";
865 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
872 TEST(PrintStringTest, DISABLED_U32String) {
874 TEST(PrintStringTest, U32String) {
876 std::u32string
str = U
"Hello, 世界";
879 "{ U+0048, U+0065, U+006C, U+006C, U+006F, U+002C, U+0020, U+4E16, "
890 class AllowsGenericStreaming {};
892 template <
typename Char,
typename CharTraits>
893 std::basic_ostream<Char, CharTraits>&
operator<<(
894 std::basic_ostream<Char, CharTraits>& os,
895 const AllowsGenericStreaming& ) {
896 return os <<
"AllowsGenericStreaming";
899 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
900 AllowsGenericStreaming
a;
906 template <
typename T>
907 class AllowsGenericStreamingTemplate {};
909 template <
typename Char,
typename CharTraits,
typename T>
910 std::basic_ostream<Char, CharTraits>&
operator<<(
911 std::basic_ostream<Char, CharTraits>& os,
912 const AllowsGenericStreamingTemplate<T>& ) {
913 return os <<
"AllowsGenericStreamingTemplate";
916 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
917 AllowsGenericStreamingTemplate<int>
a;
924 template <
typename T>
925 class AllowsGenericStreamingAndImplicitConversionTemplate {
927 operator bool()
const {
return false; }
930 template <
typename Char,
typename CharTraits,
typename T>
931 std::basic_ostream<Char, CharTraits>&
operator<<(
932 std::basic_ostream<Char, CharTraits>& os,
933 const AllowsGenericStreamingAndImplicitConversionTemplate<T>& ) {
934 return os <<
"AllowsGenericStreamingAndImplicitConversionTemplate";
937 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
938 AllowsGenericStreamingAndImplicitConversionTemplate<int>
a;
939 EXPECT_EQ(
"AllowsGenericStreamingAndImplicitConversionTemplate",
Print(a));
942 #if GTEST_INTERNAL_HAS_STRING_VIEW
946 TEST(PrintStringViewTest, SimpleStringView) {
947 const internal::StringView sp =
"Hello";
951 TEST(PrintStringViewTest, UnprintableCharacters) {
952 const char str[] =
"NUL (\0) and \r\t";
953 const internal::StringView sp(
str,
sizeof(
str) - 1);
957 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
961 TEST(PrintStlContainerTest, EmptyDeque) {
966 TEST(PrintStlContainerTest, NonEmptyDeque) {
967 deque<int> non_empty;
968 non_empty.push_back(1);
969 non_empty.push_back(3);
974 TEST(PrintStlContainerTest, OneElementHashMap) {
975 ::std::unordered_map<int, char> map1;
980 TEST(PrintStlContainerTest, HashMultiMap) {
981 ::std::unordered_multimap<int, bool> map1;
982 map1.insert(make_pair(5,
true));
983 map1.insert(make_pair(5,
false));
988 result ==
"{ (5, false), (5, true) }")
989 <<
" where Print(map1) returns \"" <<
result <<
"\".";
994 TEST(PrintStlContainerTest, HashSet) {
995 ::std::unordered_set<int> set1;
1000 TEST(PrintStlContainerTest, HashMultiSet) {
1001 const int kSize = 5;
1002 int a[
kSize] = { 1, 1, 2, 5, 1 };
1003 ::std::unordered_multiset<int> set1(a, a + kSize);
1007 const std::string expected_pattern =
"{ d, d, d, d, d }";
1012 std::vector<int> numbers;
1013 for (
size_t i = 0;
i !=
result.length();
i++) {
1014 if (expected_pattern[i] ==
'd') {
1016 numbers.push_back(
result[i] -
'0');
1024 std::sort(numbers.begin(), numbers.end());
1025 std::sort(a, a + kSize);
1026 EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
1030 TEST(PrintStlContainerTest, List) {
1032 const list<std::string> strings(a, a + 2);
1036 TEST(PrintStlContainerTest,
Map) {
1037 map<int, bool> map1;
1044 TEST(PrintStlContainerTest, MultiMap) {
1045 multimap<bool, int> map1;
1052 map1.insert(pair<const bool, int>(
true, 0));
1053 map1.insert(pair<const bool, int>(
true, 1));
1054 map1.insert(pair<const bool, int>(
false, 2));
1058 TEST(PrintStlContainerTest, Set) {
1059 const unsigned int a[] = { 3, 0, 5 };
1060 set<unsigned int> set1(a, a + 3);
1064 TEST(PrintStlContainerTest, MultiSet) {
1065 const int a[] = { 1, 1, 2, 5, 1 };
1066 multiset<int> set1(a, a + 5);
1071 TEST(PrintStlContainerTest, SinglyLinkedList) {
1072 int a[] = { 9, 2, 8 };
1073 const std::forward_list<int> ints(a, a + 3);
1077 TEST(PrintStlContainerTest,
Pair) {
1078 pair<const bool, int>
p(
true, 5);
1089 TEST(PrintStlContainerTest, LongSequence) {
1090 const int a[100] = { 1, 2, 3 };
1091 const vector<int>
v(a, a + 100);
1092 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
1093 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(
v));
1096 TEST(PrintStlContainerTest, NestedContainer) {
1097 const int a1[] = { 1, 2 };
1098 const int a2[] = { 3, 4, 5 };
1099 const list<int> l1(
a1,
a1 + 2);
1100 const list<int> l2(
a2,
a2 + 3);
1102 vector<list<int> >
v;
1108 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
1109 const int a[3] = { 1, 2, 3 };
1110 NativeArray<int>
b(a, 3, RelationToSourceReference());
1114 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
1115 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
1116 NativeArray<int[3]>
b(a, 2, RelationToSourceReference());
1133 struct const_iterator {
1138 const_iterator
it = {};
1145 TEST(PrintStdTupleTest, VariousSizes) {
1149 ::std::tuple<int>
t1(5);
1152 ::std::tuple<char, bool> t2(
'a',
true);
1155 ::std::tuple<bool, int, int> t3(
false, 2, 3);
1158 ::std::tuple<bool, int, int, int> t4(
false, 2, 3, 4);
1161 const char*
const str =
"8";
1164 t10(
false,
'a',
static_cast<short>(3), 4, 5, 1.5F, -2.5,
str,
1167 " pointing to \"8\", NULL, \"10\")",
1172 TEST(PrintStdTupleTest, NestedTuple) {
1173 ::std::tuple< ::std::tuple<int, bool>,
char>
nested(
1178 TEST(PrintNullptrT, Basic) {
1182 TEST(PrintReferenceWrapper, Printable) {
1188 TEST(PrintReferenceWrapper, Unprintable) {
1192 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1196 " 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1197 Print(std::cref(up)));
1203 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1209 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1210 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1221 TEST(PrintUnpritableTypeTest, BigObject) {
1222 EXPECT_EQ(
"257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
1223 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1224 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1225 "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
1226 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1227 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
1228 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1235 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1242 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1247 TEST(PrintStreamableTypeTest, TypeInUserNamespaceWithTemplatedStreamOperator) {
1252 TEST(PrintStreamableTypeTest, SubclassUsesSuperclassStreamOperator) {
1263 TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
1266 const ::foo::PathLike cx;
1271 TEST(PrintPrintableTypeTest, InUserNamespace) {
1278 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1284 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1285 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1291 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1302 const ::foo::UnprintableInFoo
x;
1304 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1310 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1320 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1326 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1330 "@" +
PrintPointer(
reinterpret_cast<const void*
>(&p)) +
" " +
1331 Print(
sizeof(p)) +
"-byte object "));
1336 "@" +
PrintPointer(
reinterpret_cast<const void*
>(&p2)) +
" " +
1337 Print(
sizeof(p2)) +
"-byte object "));
1342 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1354 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1360 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1367 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1370 int n[] = { 1, 2, 3 };
1380 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1387 const char*
s =
"hello";
1398 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1405 const wchar_t*
s =
L"hello";
1419 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1420 const char*
s =
"hello \"world";
1425 char str[] =
"hi\1";
1431 #if GTEST_HAS_STD_WSTRING
1433 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1434 const wchar_t*
s =
L"hi \"world";
1439 wchar_t str[] =
L"hi\1";
1451 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1452 char str[] =
"hi \"world\"";
1459 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1460 const char str[] =
"hi \"world\"";
1466 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1467 wchar_t str[] =
L"hi \"world\"";
1468 wchar_t*
p =
nullptr;
1474 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1475 const wchar_t str[] =
L"hi \"world\"";
1484 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1485 const char str[] =
"hi \"world\"";
1490 #if GTEST_HAS_STD_WSTRING
1492 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1493 const wchar_t str[] =
L"hi \"w\0rld\"";
1504 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \
1505 EXPECT_TRUE(PrintToString(value) == (expected_string)) \
1506 << " where " #value " prints as " << (PrintToString(value))
1508 TEST(PrintToStringTest, WorksForScalar) {
1512 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1513 const char*
p =
"hello";
1517 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1523 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1524 const char*
p =
"hello\n";
1528 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1529 char s[] =
"hello\1";
1534 TEST(PrintToStringTest, WorksForArray) {
1535 int n[3] = { 1, 2, 3 };
1539 TEST(PrintToStringTest, WorksForCharArray) {
1544 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1545 const char str_with_nul[] =
"hello\0 world";
1548 char mutable_str_with_nul[] =
"hello\0 world";
1552 TEST(PrintToStringTest, ContainsNonLatin) {
1556 "\"\\xEC\\x98\\xA4\\xEC\\xA0\\x84 4:30\"\n"
1557 " As Text: \"ì˜¤ì „ 4:30\"");
1560 "\"From \\xC3\\xA4 \\xE2\\x80\\x94 \\xE1\\xBA\\x91\""
1561 "\n As Text: \"From ä — ẑ\"");
1564 TEST(IsValidUTF8Test, IllFormedUTF8) {
1569 static const char *
const kTestdata[][2] = {
1571 {
"\xC3\x74",
"\"\\xC3t\""},
1573 {
"\xC3\x84\xA4",
"\"\\xC3\\x84\\xA4\""},
1575 {
"abc\xC3",
"\"abc\\xC3\""},
1577 {
"x\xE2\x70\x94",
"\"x\\xE2p\\x94\""},
1579 {
"\xE2\x80",
"\"\\xE2\\x80\""},
1581 {
"\xE2\x80\xC3\x84",
"\"\\xE2\\x80\\xC3\\x84\""},
1583 {
"\xE2\x80\x7A",
"\"\\xE2\\x80z\""},
1585 {
"\xE2\xE2\x80\x94",
"\"\\xE2\\xE2\\x80\\x94\""},
1587 {
"\xF0\xE2\x80\x94",
"\"\\xF0\\xE2\\x80\\x94\""},
1589 {
"\xF0\xE2\x80",
"\"\\xF0\\xE2\\x80\""},
1591 {
"abc\xE2\x80\x94\xC3\x74xyc",
"\"abc\\xE2\\x80\\x94\\xC3txyc\""},
1592 {
"abc\xC3\x84\xE2\x80\xC3\x84xyz",
1593 "\"abc\\xC3\\x84\\xE2\\x80\\xC3\\x84xyz\""},
1596 {
"\xC0\x80",
"\"\\xC0\\x80\""},
1597 {
"\xC1\x81",
"\"\\xC1\\x81\""},
1599 {
"\xE0\x80\x80",
"\"\\xE0\\x80\\x80\""},
1600 {
"\xf0\x80\x80\x80",
"\"\\xF0\\x80\\x80\\x80\""},
1603 {
"\xED\x9F\xBF",
"\"\\xED\\x9F\\xBF\"\n As Text: \"퟿\""},
1605 {
"\xED\xA0\x80",
"\"\\xED\\xA0\\x80\""},
1607 {
"\xED\xAD\xBF",
"\"\\xED\\xAD\\xBF\""},
1609 {
"\xED\xAE\x80",
"\"\\xED\\xAE\\x80\""},
1611 {
"\xED\xAF\xBF",
"\"\\xED\\xAF\\xBF\""},
1613 {
"\xED\xB3\xBF",
"\"\\xED\\xB3\\xBF\""},
1616 {
"\xEE\x80\x80",
"\"\\xEE\\x80\\x80\"\n As Text: \"\""}
1619 for (
int i = 0;
i <
int(
sizeof(kTestdata)/
sizeof(kTestdata[0])); ++
i) {
1624 #undef EXPECT_PRINT_TO_STRING_
1626 TEST(UniversalTersePrintTest, WorksForNonReference) {
1627 ::std::stringstream ss;
1632 TEST(UniversalTersePrintTest, WorksForReference) {
1634 ::std::stringstream ss;
1639 TEST(UniversalTersePrintTest, WorksForCString) {
1640 const char* s1 =
"abc";
1641 ::std::stringstream ss1;
1645 char* s2 =
const_cast<char*
>(s1);
1646 ::std::stringstream ss2;
1650 const char* s3 =
nullptr;
1651 ::std::stringstream ss3;
1656 TEST(UniversalPrintTest, WorksForNonReference) {
1657 ::std::stringstream ss;
1662 TEST(UniversalPrintTest, WorksForReference) {
1664 ::std::stringstream ss;
1669 TEST(UniversalPrintTest, WorksForCString) {
1670 const char* s1 =
"abc";
1671 ::std::stringstream ss1;
1675 char* s2 =
const_cast<char*
>(s1);
1676 ::std::stringstream ss2;
1680 const char* s3 =
nullptr;
1681 ::std::stringstream ss3;
1686 TEST(UniversalPrintTest, WorksForCharArray) {
1687 const char str[] =
"\"Line\0 1\"\nLine 2";
1688 ::std::stringstream ss1;
1690 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1692 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1693 ::std::stringstream ss2;
1695 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1698 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1703 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1710 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1718 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1721 ::std::tuple<const int&, const char*>(n,
"a"));
1727 #if GTEST_INTERNAL_HAS_ANY
1730 template <
typename T>
1733 return internal::GetTypeName<T>();
1735 return "<unknown_type>";
1736 #endif // GTEST_HAS_RTTI
1745 TEST_F(PrintAnyTest, NonEmpty) {
1747 constexpr
int val1 = 10;
1754 EXPECT_EQ(
"value of type " + ExpectedTypeName<std::string>(),
1757 #endif // GTEST_INTERNAL_HAS_ANY
1759 #if GTEST_INTERNAL_HAS_OPTIONAL
1760 TEST(PrintOptionalTest, Basic) {
1761 internal::Optional<int>
value;
1768 #endif // GTEST_INTERNAL_HAS_OPTIONAL
1770 #if GTEST_INTERNAL_HAS_VARIANT
1771 struct NonPrintable {
1775 TEST(PrintOneofTest, Basic) {
1776 using Type = internal::Variant<int, StreamableInGlobal, NonPrintable>;
1778 EXPECT_EQ(
"('StreamableInGlobal(index = 1)' with value StreamableInGlobal)",
1781 "('testing::gtest_printers_test::NonPrintable(index = 2)' with value "
1782 "1-byte object <11>)",
1785 #endif // GTEST_INTERNAL_HAS_VARIANT
1817 bool operator==(
const char* s)
const noexcept {
1833 const char*
s =
"alex\0davidjohn\0";
1834 string_ptr
ptr(s, 5);