36 #include "gtest/gtest-printers.h" 51 #include "gtest/gtest.h" 55 # define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available. 57 # define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available. 59 #endif // GTEST_OS_WINDOWS 81 return os << (e ==
kEWS1 ?
"kEWS1" :
"invalid");
90 *os << (e ==
kEWPT1 ?
"kEWPT1" :
"invalid");
100 template <
typename T>
115 os <<
"StreamableInGlobal";
119 os <<
"StreamableInGlobal*";
125 class UnprintableInFoo {
140 *os <<
"PrintableViaPrintTo: " << x.
value;
147 ::std::ostream&
operator<<(::std::ostream& os,
149 return os <<
"PointerPrintable*";
153 template <
typename T>
158 const T&
value()
const {
return value_; }
163 template <
typename T>
165 *os <<
"PrintableViaPrintToTemplate: " << x.
value();
169 template <
typename T>
174 const T&
value()
const {
return value_; }
179 template <
typename T>
180 inline ::std::ostream&
operator<<(::std::ostream& os,
182 return os <<
"StreamableTemplateInFoo: " << x.
value();
188 namespace gtest_printers_test {
192 using ::std::make_pair;
194 using ::std::multimap;
195 using ::std::multiset;
202 using ::testing::internal::NativeArray;
203 using ::testing::internal::RE;
206 using ::testing::internal::UniversalPrinter;
212 #if GTEST_HAS_TR1_TUPLE 214 using ::std::tr1::tuple;
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>
235 string Print(
const T& value) {
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\"",
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);
493 TEST(PrintPointerToBuiltInTypeTest,
Bool) {
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) {
571 Print(
sizeof(&Foo::value)) +
"-byte object "));
572 int (
Foo::*p) = NULL;
574 Print(
sizeof(p)) +
"-byte object "));
581 TEST(PrintPointerTest, MemberFunctionPointer) {
586 Print(
sizeof((&Foo::MyVirtualMethod))) +
"-byte object "));
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>
738 std::basic_ostream<Char, CharTraits>&
operator<<(
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>
755 std::basic_ostream<Char, CharTraits>&
operator<<(
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>
776 std::basic_ostream<Char, CharTraits>&
operator<<(
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());
873 std::sort(a, a + kSize);
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));
910 TEST(PrintStlContainerTest, Set) {
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);
923 pair<const bool, int> p(
true, 5);
927 TEST(PrintStlContainerTest, Vector) {
934 TEST(PrintStlContainerTest, LongSequence) {
935 const int a[100] = { 1, 2, 3 };
936 const vector<int> v(a, a + 100);
937 EXPECT_EQ(
"{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, " 938 "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }",
Print(v));
941 TEST(PrintStlContainerTest, NestedContainer) {
942 const int a1[] = { 1, 2 };
943 const int a2[] = { 3, 4, 5 };
944 const list<int> l1(a1, a1 + 2);
945 const list<int> l2(a2, a2 + 3);
947 vector<list<int> > v;
953 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
954 const int a[3] = { 1, 2, 3 };
959 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
960 const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
971 TEST(PrintStlContainerTest, Iterator) {
982 TEST(PrintStlContainerTest, ConstIterator) {
987 #if GTEST_HAS_TR1_TUPLE 991 TEST(PrintTupleTest, VariousSizes) {
998 tuple<char, bool> t2(
'a',
true);
1001 tuple<bool, int, int> t3(
false, 2, 3);
1004 tuple<bool, int, int, int> t4(
false, 2, 3, 4);
1007 tuple<bool, int, int, int, bool> t5(
false, 2, 3, 4,
true);
1010 tuple<bool, int, int, int, bool, int> t6(
false, 2, 3, 4,
true, 6);
1013 tuple<bool, int, int, int, bool, int, int> t7(
false, 2, 3, 4,
true, 6, 7);
1016 tuple<bool, int, int, int, bool, int, int, bool> t8(
1017 false, 2, 3, 4,
true, 6, 7,
true);
1020 tuple<bool, int, int, int, bool, int, int, bool, int> t9(
1021 false, 2, 3, 4,
true, 6, 7,
true, 9);
1024 const char*
const str =
"8";
1029 t10(
false,
'a', 3, 4, 5, 1.5F, -2.5, str,
1030 ImplicitCast_<void*>(NULL),
"10");
1032 " pointing to \"8\", NULL, \"10\")",
1037 TEST(PrintTupleTest, NestedTuple) {
1038 tuple<tuple<int, bool>,
char> nested(
make_tuple(5,
true),
'a');
1042 #endif // GTEST_HAS_TR1_TUPLE 1047 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
1053 TEST(PrintUnprintableTypeTest, InUserNamespace) {
1054 EXPECT_EQ(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1061 Big() { memset(array, 0,
sizeof(array)); }
1065 TEST(PrintUnpritableTypeTest, BigObject) {
1066 EXPECT_EQ(
"257-byte object <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 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 " 1070 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 " 1071 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 " 1072 "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
1079 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
1086 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
1092 TEST(PrintPrintableTypeTest, InUserNamespace) {
1099 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
1105 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
1106 EXPECT_EQ(
"PrintableViaPrintToTemplate: 5",
1110 #if GTEST_HAS_PROTOBUF_ 1113 TEST(PrintProtocolMessageTest, PrintsShortDebugString) {
1114 testing::internal::TestMessage msg;
1115 msg.set_member(
"yes");
1120 TEST(PrintProto2MessageTest, PrintsShortDebugStringWhenItIsShort) {
1121 testing::internal::FooMessage msg;
1122 msg.set_int_field(2);
1123 msg.set_string_field(
"hello");
1125 "<int_field:\\s*2\\s+string_field:\\s*\"hello\">");
1129 TEST(PrintProto2MessageTest, PrintsDebugStringWhenItIsLong) {
1130 testing::internal::FooMessage msg;
1131 msg.set_int_field(2);
1132 msg.set_string_field(
"hello");
1133 msg.add_names(
"peter");
1134 msg.add_names(
"paul");
1135 msg.add_names(
"mary");
1139 "string_field:\\s*\"hello\"\n" 1140 "names:\\s*\"peter\"\n" 1141 "names:\\s*\"paul\"\n" 1142 "names:\\s*\"mary\"\n" 1146 #endif // GTEST_HAS_PROTOBUF_ 1150 TEST(PrintReferenceTest, PrintsAddressAndValue) {
1161 const ::foo::UnprintableInFoo x;
1163 "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
1169 TEST(PrintReferenceTest, HandlesFunctionPointer) {
1171 const string fp_pointer_string =
1177 const string fp_string =
PrintPointer(reinterpret_cast<const void*>(
1178 reinterpret_cast<internal::BiggestInt>(fp)));
1179 EXPECT_EQ(
"@" + fp_pointer_string +
" " + fp_string,
1185 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
1189 "@" +
PrintPointer(reinterpret_cast<const void*>(&p)) +
" " +
1190 Print(
sizeof(p)) +
"-byte object "));
1192 char (
Foo::*p2)(
int n) = &Foo::MyVirtualMethod;
1195 "@" +
PrintPointer(reinterpret_cast<const void*>(&p2)) +
" " +
1196 Print(
sizeof(p2)) +
"-byte object "));
1201 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
1202 int (
Foo::*p) = &Foo::value;
1213 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
1219 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
1226 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
1229 int n[] = { 1, 2, 3 };
1239 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
1246 const char*
s =
"hello";
1257 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
1264 const wchar_t*
s = L
"hello";
1277 #if GTEST_HAS_GLOBAL_STRING 1279 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
1280 const char*
s =
"hello \"world";
1285 char str[] =
"hi\1";
1293 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
1294 const char*
s =
"hello \"world";
1299 char str[] =
"hi\1";
1305 #if GTEST_HAS_GLOBAL_WSTRING 1307 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
1308 const wchar_t*
s = L
"hi \"world";
1313 wchar_t str[] = L
"hi\1";
1320 #if GTEST_HAS_STD_WSTRING 1322 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
1323 const wchar_t*
s = L
"hi \"world";
1328 wchar_t str[] = L
"hi\1";
1340 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
1341 char str[] =
"hi \"world\"";
1348 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
1349 const char str[] =
"hi \"world\"";
1355 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
1356 wchar_t str[] = L
"hi \"world\"";
1363 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
1364 const wchar_t str[] = L
"hi \"world\"";
1372 #if GTEST_HAS_GLOBAL_STRING 1374 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
1375 const char str[] =
"hi \"w\0rld\"";
1383 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
1384 const char str[] =
"hi \"world\"";
1389 #if GTEST_HAS_GLOBAL_WSTRING 1391 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
1392 const wchar_t str[] = L
"hi \"world\"";
1398 #if GTEST_HAS_STD_WSTRING 1400 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
1401 const wchar_t str[] = L
"hi \"w\0rld\"";
1412 #define EXPECT_PRINT_TO_STRING_(value, expected_string) \ 1413 EXPECT_TRUE(PrintToString(value) == (expected_string)) \ 1414 << " where " #value " prints as " << (PrintToString(value)) 1416 TEST(PrintToStringTest, WorksForScalar) {
1420 TEST(PrintToStringTest, WorksForPointerToConstChar) {
1421 const char* p =
"hello";
1425 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
1431 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
1432 const char* p =
"hello\n";
1436 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
1437 char s[] =
"hello\1";
1442 TEST(PrintToStringTest, WorksForArray) {
1443 int n[3] = { 1, 2, 3 };
1447 TEST(PrintToStringTest, WorksForCharArray) {
1452 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
1453 const char str_with_nul[] =
"hello\0 world";
1456 char mutable_str_with_nul[] =
"hello\0 world";
1460 #undef EXPECT_PRINT_TO_STRING_ 1462 TEST(UniversalTersePrintTest, WorksForNonReference) {
1463 ::std::stringstream ss;
1468 TEST(UniversalTersePrintTest, WorksForReference) {
1470 ::std::stringstream ss;
1475 TEST(UniversalTersePrintTest, WorksForCString) {
1476 const char* s1 =
"abc";
1477 ::std::stringstream ss1;
1481 char* s2 =
const_cast<char*
>(s1);
1482 ::std::stringstream ss2;
1486 const char* s3 = NULL;
1487 ::std::stringstream ss3;
1492 TEST(UniversalPrintTest, WorksForNonReference) {
1493 ::std::stringstream ss;
1498 TEST(UniversalPrintTest, WorksForReference) {
1500 ::std::stringstream ss;
1505 TEST(UniversalPrintTest, WorksForCString) {
1506 const char* s1 =
"abc";
1507 ::std::stringstream ss1;
1511 char* s2 =
const_cast<char*
>(s1);
1512 ::std::stringstream ss2;
1516 const char* s3 = NULL;
1517 ::std::stringstream ss3;
1522 TEST(UniversalPrintTest, WorksForCharArray) {
1523 const char str[] =
"\"Line\0 1\"\nLine 2";
1524 ::std::stringstream ss1;
1526 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
1528 const char mutable_str[] =
"\"Line\0 1\"\nLine 2";
1529 ::std::stringstream ss2;
1531 EXPECT_EQ(
"\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
1534 #if GTEST_HAS_TR1_TUPLE 1536 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsEmptyTuple) {
1541 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsOneTuple) {
1547 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsTwoTuple) {
1554 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsTersely) {
1557 tuple<const int&, const char*>(n,
"a"));
1563 #endif // GTEST_HAS_TR1_TUPLE
TypeWithSize< 8 >::Int Int64
std::ostream & operator<<(std::ostream &os, EnumWithStreaming e)
AssertionResult AssertionFailure()
#define EXPECT_PRINT_TO_STRING_(value, expected_string)
::std::string PrintToString(const T &value)
TypeWithSize< 4 >::Int Int32
UnprintableTemplateInGlobal()
void UniversalTersePrint(const T &value,::std::ostream *os)
static string PrintPointer(const void *p)
#define EXPECT_LT(val1, val2)
#define EXPECT_TRUE(condition)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
#define EXPECT_STREQ(expected, actual)
string PrintArrayHelper(T(&a)[N])
#define ASSERT_NE(val1, val2)
void PrintTo(EnumWithPrintTo e, std::ostream *os)
AssertionResult AssertionSuccess()
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)
std::vector< OpcUa::Variant > MyMethod(NodeId context, std::vector< OpcUa::Variant > arguments)
PrintableViaPrintToTemplate(const T &a_value)
#define TEST(test_case_name, test_name)
virtual ~StreamableInGlobal()
#define ASSERT_EQ(val1, val2)
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
#define EXPECT_PRED2(pred, v1, v2)
AssertionResult HasPrefix(const StringType &str, const StringType &prefix)
virtual char MyVirtualMethod(int)
::std::vector< string > Strings
StreamableTemplateInFoo()
#define EXPECT_EQ(expected, actual)
const T & Const(const T &x)