36 #include "gtest/gtest-printers.h" 51 #include "gtest/gtest.h" 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*";
129 class UnprintableInFoo {
132 double z()
const {
return z_; }
145 *os <<
"PrintableViaPrintTo: " << x.
value;
152 ::std::ostream&
operator<<(::std::ostream& os,
154 return os <<
"PointerPrintable*";
158 template <
typename T>
163 const T&
value()
const {
return value_; }
168 template <
typename T>
170 *os <<
"PrintableViaPrintToTemplate: " << x.
value();
174 template <
typename T>
179 const T&
value()
const {
return value_; }
184 template <
typename T>
185 inline ::std::ostream&
operator<<(::std::ostream& os,
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 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
220 #ifdef _STLP_HASH_MAP // We got <hash_map> from STLport. 221 using ::std::hash_map;
222 using ::std::hash_set;
223 using ::std::hash_multimap;
224 using ::std::hash_multiset;
226 using ::stdext::hash_map;
227 using ::stdext::hash_set;
228 using ::stdext::hash_multimap;
229 using ::stdext::hash_multiset;
234 template <
typename T>
236 ::std::stringstream ss;
244 template <
typename T>
246 ::std::stringstream ss;
282 TEST(PrintCharTest, PlainChar) {
302 TEST(PrintCharTest, SignedChar) {
305 Print(static_cast<signed char>(-50)));
309 TEST(PrintCharTest, UnsignedChar) {
312 Print(static_cast<unsigned char>(
'b')));
324 TEST(PrintBuiltInTypeTest, Wchar_t) {
341 EXPECT_EQ(
"L'\\x576' (1398)",
Print(static_cast<wchar_t>(0x576)));
342 EXPECT_EQ(
"L'\\xC74D' (51021)",
Print(static_cast<wchar_t>(0xC74D)));
346 TEST(PrintTypeSizeTest, Wchar_t) {
352 EXPECT_EQ(
"'\\xFF' (255)",
Print(static_cast<unsigned char>(255)));
353 EXPECT_EQ(
"'\\x80' (-128)",
Print(static_cast<signed char>(-128)));
359 Print(static_cast<testing::internal::UInt64>(-1)));
361 Print(static_cast<testing::internal::Int64>(1) << 63));
365 TEST(PrintBuiltInTypeTest, Size_t) {
367 #if !GTEST_OS_WINDOWS 370 #endif // !GTEST_OS_WINDOWS 374 TEST(PrintBuiltInTypeTest, FloatingPoints) {
383 ::std::stringstream expected_result_stream;
384 expected_result_stream << p;
385 return expected_result_stream.str();
392 const char* p =
"World";
397 TEST(PrintCStringTest, NonConst) {
400 Print(static_cast<char*>(p)));
404 TEST(PrintCStringTest, Null) {
405 const char* p = NULL;
410 TEST(PrintCStringTest, EscapesProperly) {
411 const char* p =
"'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
413 "\\n\\r\\t\\v\\x7F\\xFF a\"",
423 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 427 const wchar_t* p = L
"World";
432 TEST(PrintWideCStringTest, NonConst) {
435 Print(static_cast<wchar_t*>(p)));
439 TEST(PrintWideCStringTest, Null) {
440 const wchar_t* p = NULL;
445 TEST(PrintWideCStringTest, EscapesProperly) {
446 const wchar_t s[] = {
'\'',
'"',
'?',
'\\',
'\a',
'\b',
'\f',
'\n',
'\r',
447 '\t',
'\v', 0xD3, 0x576, 0x8D3, 0xC74D,
' ',
'a',
'\0'};
449 "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
450 Print(static_cast<const wchar_t*>(s)));
452 #endif // native wchar_t 457 TEST(PrintCharPointerTest, SignedChar) {
458 signed char* p =
reinterpret_cast<signed char*
>(0x1234);
465 TEST(PrintCharPointerTest, ConstSignedChar) {
466 signed char* p =
reinterpret_cast<signed char*
>(0x1234);
473 TEST(PrintCharPointerTest, UnsignedChar) {
474 unsigned char* p =
reinterpret_cast<unsigned char*
>(0x1234);
481 TEST(PrintCharPointerTest, ConstUnsignedChar) {
482 const unsigned char* p =
reinterpret_cast<const unsigned char*
>(0x1234);
491 TEST(PrintPointerToBuiltInTypeTest,
Bool) {
492 bool* p =
reinterpret_cast<bool*
>(0xABCD);
499 TEST(PrintPointerToBuiltInTypeTest, Void) {
500 void* p =
reinterpret_cast<void*
>(0xABCD);
507 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
508 const void* p =
reinterpret_cast<const void*
>(0xABCD);
515 TEST(PrintPointerToPointerTest, IntPointerPointer) {
516 int** p =
reinterpret_cast<int**
>(0xABCD);
526 TEST(PrintPointerTest, NonMemberFunctionPointer) {
533 reinterpret_cast<internal::BiggestInt>(&
MyFunction))),
535 int (*p)(bool) = NULL;
541 template <
typename StringType>
543 if (str.find(prefix, 0) == 0)
546 const bool is_wide_string =
sizeof(prefix[0]) > 1;
547 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
549 << begin_string_quote << prefix <<
"\" is not a prefix of " 550 << begin_string_quote << str <<
"\"\n";
567 TEST(PrintPointerTest, MemberVariablePointer) {
570 int (
Foo::*p) = NULL;
572 Print(
sizeof(p)) +
"-byte object "));
579 TEST(PrintPointerTest, MemberFunctionPointer) {
581 Print(
sizeof(&Foo::MyMethod)) +
"-byte object "));
584 Print(
sizeof((&Foo::MyVirtualMethod))) +
"-byte object "));
585 int (
Foo::*p)(char) = NULL;
587 Print(
sizeof(p)) +
"-byte object "));
594 template <
typename T,
size_t N>
600 TEST(PrintArrayTest, OneDimensionalArray) {
601 int a[5] = { 1, 2, 3, 4, 5 };
606 TEST(PrintArrayTest, TwoDimensionalArray) {
611 EXPECT_EQ(
"{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }",
PrintArrayHelper(a));
615 TEST(PrintArrayTest, ConstArray) {
616 const bool a[1] = {
false };
621 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
623 char a[] = {
'H',
'\0',
'i' };
628 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
629 const char a[] =
"\0Hi";
634 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
636 const wchar_t a[] = { L
'H', L
'\0', L
'i' };
641 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
642 const wchar_t a[] = L
"\0Hi";
647 TEST(PrintArrayTest, ObjectArray) {
648 string a[3] = {
"Hi",
"Hello",
"Ni hao" };
653 TEST(PrintArrayTest, BigArray) {
654 int a[100] = { 1, 2, 3 };
655 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
661 #if GTEST_HAS_GLOBAL_STRING 663 TEST(PrintStringTest, StringInGlobalNamespace) {
664 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
666 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
669 #endif // GTEST_HAS_GLOBAL_STRING 672 TEST(PrintStringTest, StringInStdNamespace) {
673 const char s[] =
"'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
675 EXPECT_EQ(
"\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
679 TEST(PrintStringTest, StringAmbiguousHex) {
695 #if GTEST_HAS_GLOBAL_WSTRING 697 TEST(PrintWideStringTest, StringInGlobalNamespace) {
698 const wchar_t s[] = L
"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
700 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" 701 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
704 #endif // GTEST_HAS_GLOBAL_WSTRING 706 #if GTEST_HAS_STD_WSTRING 708 TEST(PrintWideStringTest, StringInStdNamespace) {
709 const wchar_t s[] = L
"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
711 EXPECT_EQ(
"L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" 712 "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
716 TEST(PrintWideStringTest, StringAmbiguousHex) {
725 #endif // GTEST_HAS_STD_WSTRING 735 template <
typename Char,
typename CharTraits>
736 std::basic_ostream<Char, CharTraits>&
operator<<(
737 std::basic_ostream<Char, CharTraits>& os,
739 return os <<
"AllowsGenericStreaming";
742 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
749 template <
typename T>
752 template <
typename Char,
typename CharTraits,
typename T>
753 std::basic_ostream<Char, CharTraits>&
operator<<(
754 std::basic_ostream<Char, CharTraits>& os,
756 return os <<
"AllowsGenericStreamingTemplate";
759 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
767 template <
typename T>
770 operator bool()
const {
return false; }
773 template <
typename Char,
typename CharTraits,
typename T>
774 std::basic_ostream<Char, CharTraits>&
operator<<(
775 std::basic_ostream<Char, CharTraits>& os,
777 return os <<
"AllowsGenericStreamingAndImplicitConversionTemplate";
780 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
782 EXPECT_EQ(
"AllowsGenericStreamingAndImplicitConversionTemplate",
Print(a));
785 #if GTEST_HAS_STRING_PIECE_ 789 TEST(PrintStringPieceTest, SimpleStringPiece) {
794 TEST(PrintStringPieceTest, UnprintableCharacters) {
795 const char str[] =
"NUL (\0) and \r\t";
800 #endif // GTEST_HAS_STRING_PIECE_ 804 TEST(PrintStlContainerTest, EmptyDeque) {
809 TEST(PrintStlContainerTest, NonEmptyDeque) {
811 non_empty.push_back(1);
812 non_empty.push_back(3);
816 #if GTEST_HAS_HASH_MAP_ 818 TEST(PrintStlContainerTest, OneElementHashMap) {
819 hash_map<int, char> map1;
824 TEST(PrintStlContainerTest, HashMultiMap) {
825 hash_multimap<int, bool> map1;
826 map1.insert(make_pair(5,
true));
827 map1.insert(make_pair(5,
false));
830 const string result =
Print(map1);
831 EXPECT_TRUE(result ==
"{ (5, true), (5, false) }" ||
832 result ==
"{ (5, false), (5, true) }")
833 <<
" where Print(map1) returns \"" << result <<
"\".";
836 #endif // GTEST_HAS_HASH_MAP_ 838 #if GTEST_HAS_HASH_SET_ 840 TEST(PrintStlContainerTest, HashSet) {
841 hash_set<string> set1;
842 set1.insert(
"hello");
846 TEST(PrintStlContainerTest, HashMultiSet) {
848 int a[kSize] = { 1, 1, 2, 5, 1 };
849 hash_multiset<int> set1(a, a + kSize);
852 const string result =
Print(set1);
853 const string expected_pattern =
"{ d, d, d, d, d }";
857 ASSERT_EQ(expected_pattern.length(), result.length());
858 std::vector<int> numbers;
859 for (
size_t i = 0;
i != result.length();
i++) {
860 if (expected_pattern[
i] ==
'd') {
861 ASSERT_NE(isdigit(static_cast<unsigned char>(result[
i])), 0);
862 numbers.push_back(result[i] -
'0');
864 EXPECT_EQ(expected_pattern[
i], result[i]) <<
" where result is " 870 std::sort(numbers.begin(), numbers.end());
871 std::sort(a, a + kSize);
872 EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
875 #endif // GTEST_HAS_HASH_SET_ 882 const list<string>
strings(a, a + 2);
886 TEST(PrintStlContainerTest,
Map) {
894 TEST(PrintStlContainerTest, MultiMap) {
895 multimap<bool, int> map1;
908 TEST(PrintStlContainerTest, Set) {
909 const unsigned int a[] = { 3, 0, 5 };
914 TEST(PrintStlContainerTest, MultiSet) {
915 const int a[] = { 1, 1, 2, 5, 1 };
916 multiset<int> set1(a, a + 5);
920 #if GTEST_HAS_STD_FORWARD_LIST_ 924 TEST(PrintStlContainerTest, SinglyLinkedList) {
925 int a[] = { 9, 2, 8 };
926 const std::forward_list<int> ints(a, a + 3);
929 #endif // GTEST_HAS_STD_FORWARD_LIST_ 936 TEST(PrintStlContainerTest, Vector) {
943 TEST(PrintStlContainerTest, LongSequence) {
944 const int a[100] = { 1, 2, 3 };
946 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, " 947 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(v));
950 TEST(PrintStlContainerTest, NestedContainer) {
951 const int a1[] = { 1, 2 };
952 const int a2[] = { 3, 4, 5 };
953 const list<int> l1(a1, a1 + 2);
954 const list<int> l2(a2, a2 + 3);
962 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
963 const int a[3] = { 1, 2, 3 };
964 NativeArray<int>
b(a, 3, RelationToSourceReference());
968 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
969 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
970 NativeArray<int[3]>
b(a, 2, RelationToSourceReference());
980 TEST(PrintStlContainerTest, Iterator) {
991 TEST(PrintStlContainerTest, ConstIterator) {
996 #if GTEST_HAS_TR1_TUPLE 1000 TEST(PrintTr1TupleTest, VariousSizes) {
1019 ::std::tr1::tuple<bool, int, int, int, bool, int> t6(
false, 2, 3, 4,
true, 6);
1023 false, 2, 3, 4,
true, 6, 7);
1027 false, 2, 3, 4,
true, 6, 7,
true);
1031 false, 2, 3, 4,
true, 6, 7,
true, 9);
1034 const char*
const str =
"8";
1039 t10(
false,
'a', 3, 4, 5, 1.5F, -2.5, str,
1040 ImplicitCast_<void*>(NULL),
"10");
1042 " pointing to \"8\", NULL, \"10\")",
1047 TEST(PrintTr1TupleTest, NestedTuple) {
1053 #endif // GTEST_HAS_TR1_TUPLE 1055 #if GTEST_HAS_STD_TUPLE_ 1059 TEST(PrintStdTupleTest, VariousSizes) {
1063 ::std::tuple<int> t1(5);
1066 ::std::tuple<char, bool> t2(
'a',
true);
1069 ::std::tuple<bool, int, int> t3(
false, 2, 3);
1072 ::std::tuple<bool, int, int, int> t4(
false, 2, 3, 4);
1075 ::std::tuple<bool, int, int, int, bool> t5(
false, 2, 3, 4,
true);
1078 ::std::tuple<bool, int, int, int, bool, int> t6(
false, 2, 3, 4,
true, 6);
1081 ::std::tuple<bool, int, int, int, bool, int, int> t7(
1082 false, 2, 3, 4,
true, 6, 7);
1085 ::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
1086 false, 2, 3, 4,
true, 6, 7,
true);
1089 ::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
1090 false, 2, 3, 4,
true, 6, 7,
true, 9);
1093 const char*
const str =
"8";
1098 t10(
false,
'a', 3, 4, 5, 1.5F, -2.5, str,
1099 ImplicitCast_<void*>(NULL),
"10");
1101 " pointing to \"8\", NULL, \"10\")",
1106 TEST(PrintStdTupleTest, NestedTuple) {
1107 ::std::tuple< ::std::tuple<int, bool>,
char> nested(
1112 #endif // GTEST_LANG_CXX11 1117 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1123 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1124 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1131 Big() { memset(array, 0,
sizeof(array)); }
1135 TEST(PrintUnpritableTypeTest, BigObject) {
1136 EXPECT_EQ(
"257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 " 1137 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 " 1138 "00-00 00-00 00-00 00-00 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 " 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 00-00 " 1142 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1149 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1156 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1162 TEST(PrintPrintableTypeTest, InUserNamespace) {
1169 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1170 ::foo::PointerPrintable
x;
1175 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1176 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1182 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1193 const ::foo::UnprintableInFoo
x;
1195 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1201 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1203 const string fp_pointer_string =
1209 const string fp_string =
PrintPointer(reinterpret_cast<const void*>(
1210 reinterpret_cast<internal::BiggestInt>(fp)));
1211 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1217 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1218 int (
Foo::*p)(
char ch) = &Foo::MyMethod;
1221 "@" +
PrintPointer(reinterpret_cast<const void*>(&p)) +
" " +
1222 Print(
sizeof(p)) +
"-byte object "));
1224 char (
Foo::*p2)(
int n) = &Foo::MyVirtualMethod;
1227 "@" +
PrintPointer(reinterpret_cast<const void*>(&p2)) +
" " +
1228 Print(
sizeof(p2)) +
"-byte object "));
1233 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1245 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1251 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1258 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1261 int n[] = { 1, 2, 3 };
1271 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1278 const char*
s =
"hello";
1289 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1296 const wchar_t*
s = L
"hello";
1309 #if GTEST_HAS_GLOBAL_STRING 1311 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
1312 const char*
s =
"hello \"world";
1317 char str[] =
"hi\1";
1325 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1326 const char*
s =
"hello \"world";
1331 char str[] =
"hi\1";
1337 #if GTEST_HAS_GLOBAL_WSTRING 1339 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
1340 const wchar_t*
s = L
"hi \"world";
1345 wchar_t str[] = L
"hi\1";
1352 #if GTEST_HAS_STD_WSTRING 1354 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1355 const wchar_t*
s = L
"hi \"world";
1360 wchar_t str[] = L
"hi\1";
1372 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1373 char str[] =
"hi \"world\"";
1380 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1381 const char str[] =
"hi \"world\"";
1387 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1388 wchar_t str[] = L
"hi \"world\"";
1395 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1396 const wchar_t str[] = L
"hi \"world\"";
1404 #if GTEST_HAS_GLOBAL_STRING 1406 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
1407 const char str[] =
"hi \"w\0rld\"";
1415 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1416 const char str[] =
"hi \"world\"";
1421 #if GTEST_HAS_GLOBAL_WSTRING 1423 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
1424 const wchar_t str[] = L
"hi \"world\"";
1430 #if GTEST_HAS_STD_WSTRING 1432 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1433 const wchar_t str[] = L
"hi \"w\0rld\"";
1444 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \ 1445 EXPECT_TRUE(PrintToString(value) == (expected_string)) \ 1446 << " where " #value " prints as " << (PrintToString(value)) 1448 TEST(PrintToStringTest, WorksForScalar) {
1452 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1453 const char* p =
"hello";
1457 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1463 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1464 const char* p =
"hello\n";
1468 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1469 char s[] =
"hello\1";
1474 TEST(PrintToStringTest, WorksForArray) {
1475 int n[3] = { 1, 2, 3 };
1479 TEST(PrintToStringTest, WorksForCharArray) {
1484 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1485 const char str_with_nul[] =
"hello\0 world";
1488 char mutable_str_with_nul[] =
"hello\0 world";
1492 #undef EXPECT_PRINT_TO_STRING_ 1494 TEST(UniversalTersePrintTest, WorksForNonReference) {
1495 ::std::stringstream ss;
1500 TEST(UniversalTersePrintTest, WorksForReference) {
1502 ::std::stringstream ss;
1507 TEST(UniversalTersePrintTest, WorksForCString) {
1508 const char* s1 =
"abc";
1509 ::std::stringstream ss1;
1513 char* s2 =
const_cast<char*
>(s1);
1514 ::std::stringstream ss2;
1518 const char* s3 = NULL;
1519 ::std::stringstream ss3;
1524 TEST(UniversalPrintTest, WorksForNonReference) {
1525 ::std::stringstream ss;
1530 TEST(UniversalPrintTest, WorksForReference) {
1532 ::std::stringstream ss;
1537 TEST(UniversalPrintTest, WorksForCString) {
1538 const char* s1 =
"abc";
1539 ::std::stringstream ss1;
1543 char* s2 =
const_cast<char*
>(s1);
1544 ::std::stringstream ss2;
1548 const char* s3 = NULL;
1549 ::std::stringstream ss3;
1554 TEST(UniversalPrintTest, WorksForCharArray) {
1555 const char str[] =
"\"Line\0 1\"\nLine 2";
1556 ::std::stringstream ss1;
1558 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1560 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1561 ::std::stringstream ss2;
1563 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1566 #if GTEST_HAS_TR1_TUPLE 1568 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
1569 Strings result = UniversalTersePrintTupleFieldsToStrings(
1574 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
1575 Strings result = UniversalTersePrintTupleFieldsToStrings(
1581 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
1582 Strings result = UniversalTersePrintTupleFieldsToStrings(
1589 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
1591 Strings result = UniversalTersePrintTupleFieldsToStrings(
1598 #endif // GTEST_HAS_TR1_TUPLE 1600 #if GTEST_HAS_STD_TUPLE_ 1602 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
1607 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
1608 Strings result = UniversalTersePrintTupleFieldsToStrings(
1614 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
1615 Strings result = UniversalTersePrintTupleFieldsToStrings(
1622 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
1624 Strings result = UniversalTersePrintTupleFieldsToStrings(
1625 ::std::tuple<const int&, const char*>(n,
"a"));
1631 #endif // GTEST_HAS_STD_TUPLE_
TypeWithSize< 8 >::Int Int64
GTEST_API_ AssertionResult AssertionFailure()
#define ASSERT_EQ(val1, val2)
::std::string PrintToString(const T &value)
TypeWithSize< 4 >::Int Int32
UnprintableTemplateInGlobal()
void UniversalTersePrint(const T &value,::std::ostream *os)
#define EXPECT_EQ(val1, val2)
static string PrintPointer(const void *p)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
std::ostream & operator<<(std::ostream &os, EnumWithStreaming e)
bool prefix(Cursor &c, uint32_t expected)
std::unordered_map< int64_t, VecT > Map
string PrintArrayHelper(T(&a)[N])
#define EXPECT_STREQ(s1, s2)
GTEST_API_ AssertionResult AssertionSuccess()
constexpr auto empty(C const &c) -> decltype(c.empty())
string Print(const T &value)
internal::PairMatcher< FirstMatcher, SecondMatcher > Pair(FirstMatcher first_matcher, SecondMatcher second_matcher)
string PrintByRef(const T &value)
void UniversalPrint(const T &value,::std::ostream *os)
Encoder::MutableCompressedList list
PrintableViaPrintToTemplate(const T &a_value)
static const char *const value
void PrintTo(EnumWithPrintTo e, std::ostream *os)
virtual ~StreamableInGlobal()
#define EXPECT_TRUE(condition)
AssertionResult HasPrefix(const StringType &str, const StringType &prefix)
virtual char MyVirtualMethod(int)
::std::vector< string > Strings
StreamableTemplateInFoo()
TEST(UniversalPrintTest, WorksForCharArray)
#define ASSERT_NE(val1, val2)
Range< const char * > StringPiece
#define EXPECT_LT(val1, val2)
static vector< fbstring > strings
#define EXPECT_PRINT_TO_STRING_(value, expected_string)