OLD | NEW |
1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 using ::std::make_pair; | 146 using ::std::make_pair; |
147 using ::std::map; | 147 using ::std::map; |
148 using ::std::multimap; | 148 using ::std::multimap; |
149 using ::std::multiset; | 149 using ::std::multiset; |
150 using ::std::pair; | 150 using ::std::pair; |
151 using ::std::set; | 151 using ::std::set; |
152 using ::std::tr1::make_tuple; | 152 using ::std::tr1::make_tuple; |
153 using ::std::tr1::tuple; | 153 using ::std::tr1::tuple; |
154 using ::std::vector; | 154 using ::std::vector; |
155 using ::testing::ElementsAre; | 155 using ::testing::ElementsAre; |
| 156 using ::testing::PrintToString; |
156 using ::testing::StartsWith; | 157 using ::testing::StartsWith; |
157 using ::testing::internal::NativeArray; | 158 using ::testing::internal::NativeArray; |
158 using ::testing::internal::Strings; | 159 using ::testing::internal::Strings; |
159 using ::testing::internal::UniversalTersePrint; | 160 using ::testing::internal::UniversalTersePrint; |
160 using ::testing::internal::UniversalPrint; | 161 using ::testing::internal::UniversalPrint; |
161 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; | 162 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; |
162 using ::testing::internal::UniversalPrinter; | 163 using ::testing::internal::UniversalPrinter; |
163 using ::testing::internal::kReference; | 164 using ::testing::internal::kReference; |
164 using ::testing::internal::string; | 165 using ::testing::internal::string; |
165 | 166 |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 | 1004 |
1004 // Tests that the universal printer prints a member variable pointer | 1005 // Tests that the universal printer prints a member variable pointer |
1005 // passed by reference. | 1006 // passed by reference. |
1006 TEST(PrintReferenceTest, HandlesMemberVariablePointer) { | 1007 TEST(PrintReferenceTest, HandlesMemberVariablePointer) { |
1007 int (Foo::*p) = &Foo::value; // NOLINT | 1008 int (Foo::*p) = &Foo::value; // NOLINT |
1008 EXPECT_THAT(PrintByRef(p), | 1009 EXPECT_THAT(PrintByRef(p), |
1009 StartsWith("@" + PrintPointer(&p) | 1010 StartsWith("@" + PrintPointer(&p) |
1010 + " " + Print(sizeof(p)) + "-byte object ")); | 1011 + " " + Print(sizeof(p)) + "-byte object ")); |
1011 } | 1012 } |
1012 | 1013 |
1013 TEST(PrintToStringTest, WorksForNonReference) { | 1014 TEST(PrintToStringTest, WorksForScalar) { |
1014 EXPECT_EQ("123", UniversalPrinter<int>::PrintToString(123)); | 1015 EXPECT_EQ("123", PrintToString(123)); |
1015 } | 1016 } |
1016 | 1017 |
1017 TEST(PrintToStringTest, WorksForReference) { | 1018 TEST(PrintToStringTest, WorksForPointerToConstChar) { |
1018 int n = 123; | 1019 const char* p = "hello"; |
1019 EXPECT_EQ("@" + PrintPointer(&n) + " 123", | 1020 EXPECT_EQ("\"hello\"", PrintToString(p)); |
1020 UniversalPrinter<const int&>::PrintToString(n)); | 1021 } |
| 1022 |
| 1023 TEST(PrintToStringTest, WorksForPointerToNonConstChar) { |
| 1024 char s[] = "hello"; |
| 1025 char* p = s; |
| 1026 EXPECT_EQ("\"hello\"", PrintToString(p)); |
1021 } | 1027 } |
1022 | 1028 |
1023 TEST(PrintToStringTest, WorksForArray) { | 1029 TEST(PrintToStringTest, WorksForArray) { |
1024 int n[3] = { 1, 2, 3 }; | 1030 int n[3] = { 1, 2, 3 }; |
1025 EXPECT_EQ("{ 1, 2, 3 }", UniversalPrinter<int[3]>::PrintToString(n)); | 1031 EXPECT_EQ("{ 1, 2, 3 }", PrintToString(n)); |
1026 } | 1032 } |
1027 | 1033 |
1028 TEST(UniversalTersePrintTest, WorksForNonReference) { | 1034 TEST(UniversalTersePrintTest, WorksForNonReference) { |
1029 ::std::stringstream ss; | 1035 ::std::stringstream ss; |
1030 UniversalTersePrint(123, &ss); | 1036 UniversalTersePrint(123, &ss); |
1031 EXPECT_EQ("123", ss.str()); | 1037 EXPECT_EQ("123", ss.str()); |
1032 } | 1038 } |
1033 | 1039 |
1034 TEST(UniversalTersePrintTest, WorksForReference) { | 1040 TEST(UniversalTersePrintTest, WorksForReference) { |
1035 const int& n = 123; | 1041 const int& n = 123; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1109 |
1104 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsTersely) { | 1110 TEST(UniversalTersePrintTupleFieldsToStringsTest, PrintsTersely) { |
1105 const int n = 1; | 1111 const int n = 1; |
1106 EXPECT_THAT(UniversalTersePrintTupleFieldsToStrings( | 1112 EXPECT_THAT(UniversalTersePrintTupleFieldsToStrings( |
1107 tuple<const int&, const char*>(n, "a")), | 1113 tuple<const int&, const char*>(n, "a")), |
1108 ElementsAre("1", "\"a\"")); | 1114 ElementsAre("1", "\"a\"")); |
1109 } | 1115 } |
1110 | 1116 |
1111 } // namespace gmock_printers_test | 1117 } // namespace gmock_printers_test |
1112 } // namespace testing | 1118 } // namespace testing |
OLD | NEW |