gtest-printers_test.cc
Go to the documentation of this file.
00001 // Copyright 2007, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 
00032 // Google Test - The Google C++ Testing Framework
00033 //
00034 // This file tests the universal value printer.
00035 
00036 #include "gtest/gtest-printers.h"
00037 
00038 #include <ctype.h>
00039 #include <limits.h>
00040 #include <string.h>
00041 #include <algorithm>
00042 #include <deque>
00043 #include <list>
00044 #include <map>
00045 #include <set>
00046 #include <sstream>
00047 #include <string>
00048 #include <utility>
00049 #include <vector>
00050 
00051 #include "gtest/gtest.h"
00052 
00053 // hash_map and hash_set are available under Visual C++.
00054 #if _MSC_VER
00055 # define GTEST_HAS_HASH_MAP_ 1  // Indicates that hash_map is available.
00056 # include <hash_map>            // NOLINT
00057 # define GTEST_HAS_HASH_SET_ 1  // Indicates that hash_set is available.
00058 # include <hash_set>            // NOLINT
00059 #endif  // GTEST_OS_WINDOWS
00060 
00061 // Some user-defined types for testing the universal value printer.
00062 
00063 // An anonymous enum type.
00064 enum AnonymousEnum {
00065   kAE1 = -1,
00066   kAE2 = 1
00067 };
00068 
00069 // An enum without a user-defined printer.
00070 enum EnumWithoutPrinter {
00071   kEWP1 = -2,
00072   kEWP2 = 42
00073 };
00074 
00075 // An enum with a << operator.
00076 enum EnumWithStreaming {
00077   kEWS1 = 10
00078 };
00079 
00080 std::ostream& operator<<(std::ostream& os, EnumWithStreaming e) {
00081   return os << (e == kEWS1 ? "kEWS1" : "invalid");
00082 }
00083 
00084 // An enum with a PrintTo() function.
00085 enum EnumWithPrintTo {
00086   kEWPT1 = 1
00087 };
00088 
00089 void PrintTo(EnumWithPrintTo e, std::ostream* os) {
00090   *os << (e == kEWPT1 ? "kEWPT1" : "invalid");
00091 }
00092 
00093 // A class implicitly convertible to BiggestInt.
00094 class BiggestIntConvertible {
00095  public:
00096   operator ::testing::internal::BiggestInt() const { return 42; }
00097 };
00098 
00099 // A user-defined unprintable class template in the global namespace.
00100 template <typename T>
00101 class UnprintableTemplateInGlobal {
00102  public:
00103   UnprintableTemplateInGlobal() : value_() {}
00104  private:
00105   T value_;
00106 };
00107 
00108 // A user-defined streamable type in the global namespace.
00109 class StreamableInGlobal {
00110  public:
00111   virtual ~StreamableInGlobal() {}
00112 };
00113 
00114 inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
00115   os << "StreamableInGlobal";
00116 }
00117 
00118 void operator<<(::std::ostream& os, const StreamableInGlobal* /* x */) {
00119   os << "StreamableInGlobal*";
00120 }
00121 
00122 namespace foo {
00123 
00124 // A user-defined unprintable type in a user namespace.
00125 class UnprintableInFoo {
00126  public:
00127   UnprintableInFoo() : z_(0) { memcpy(xy_, "\xEF\x12\x0\x0\x34\xAB\x0\x0", 8); }
00128   double z() const { return z_; }
00129  private:
00130   char xy_[8];
00131   double z_;
00132 };
00133 
00134 // A user-defined printable type in a user-chosen namespace.
00135 struct PrintableViaPrintTo {
00136   PrintableViaPrintTo() : value() {}
00137   int value;
00138 };
00139 
00140 void PrintTo(const PrintableViaPrintTo& x, ::std::ostream* os) {
00141   *os << "PrintableViaPrintTo: " << x.value;
00142 }
00143 
00144 // A type with a user-defined << for printing its pointer.
00145 struct PointerPrintable {
00146 };
00147 
00148 ::std::ostream& operator<<(::std::ostream& os,
00149                            const PointerPrintable* /* x */) {
00150   return os << "PointerPrintable*";
00151 }
00152 
00153 // A user-defined printable class template in a user-chosen namespace.
00154 template <typename T>
00155 class PrintableViaPrintToTemplate {
00156  public:
00157   explicit PrintableViaPrintToTemplate(const T& a_value) : value_(a_value) {}
00158 
00159   const T& value() const { return value_; }
00160  private:
00161   T value_;
00162 };
00163 
00164 template <typename T>
00165 void PrintTo(const PrintableViaPrintToTemplate<T>& x, ::std::ostream* os) {
00166   *os << "PrintableViaPrintToTemplate: " << x.value();
00167 }
00168 
00169 // A user-defined streamable class template in a user namespace.
00170 template <typename T>
00171 class StreamableTemplateInFoo {
00172  public:
00173   StreamableTemplateInFoo() : value_() {}
00174 
00175   const T& value() const { return value_; }
00176  private:
00177   T value_;
00178 };
00179 
00180 template <typename T>
00181 inline ::std::ostream& operator<<(::std::ostream& os,
00182                                   const StreamableTemplateInFoo<T>& x) {
00183   return os << "StreamableTemplateInFoo: " << x.value();
00184 }
00185 
00186 }  // namespace foo
00187 
00188 namespace testing {
00189 namespace gtest_printers_test {
00190 
00191 using ::std::deque;
00192 using ::std::list;
00193 using ::std::make_pair;
00194 using ::std::map;
00195 using ::std::multimap;
00196 using ::std::multiset;
00197 using ::std::pair;
00198 using ::std::set;
00199 using ::std::vector;
00200 using ::testing::PrintToString;
00201 using ::testing::internal::FormatForComparisonFailureMessage;
00202 using ::testing::internal::ImplicitCast_;
00203 using ::testing::internal::NativeArray;
00204 using ::testing::internal::RE;
00205 using ::testing::internal::RelationToSourceReference;
00206 using ::testing::internal::Strings;
00207 using ::testing::internal::UniversalPrint;
00208 using ::testing::internal::UniversalPrinter;
00209 using ::testing::internal::UniversalTersePrint;
00210 using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
00211 using ::testing::internal::string;
00212 
00213 // The hash_* classes are not part of the C++ standard.  STLport
00214 // defines them in namespace std.  MSVC defines them in ::stdext.  GCC
00215 // defines them in ::.
00216 #ifdef _STLP_HASH_MAP  // We got <hash_map> from STLport.
00217 using ::std::hash_map;
00218 using ::std::hash_set;
00219 using ::std::hash_multimap;
00220 using ::std::hash_multiset;
00221 #elif _MSC_VER
00222 using ::stdext::hash_map;
00223 using ::stdext::hash_set;
00224 using ::stdext::hash_multimap;
00225 using ::stdext::hash_multiset;
00226 #endif
00227 
00228 // Prints a value to a string using the universal value printer.  This
00229 // is a helper for testing UniversalPrinter<T>::Print() for various types.
00230 template <typename T>
00231 string Print(const T& value) {
00232   ::std::stringstream ss;
00233   UniversalPrinter<T>::Print(value, &ss);
00234   return ss.str();
00235 }
00236 
00237 // Prints a value passed by reference to a string, using the universal
00238 // value printer.  This is a helper for testing
00239 // UniversalPrinter<T&>::Print() for various types.
00240 template <typename T>
00241 string PrintByRef(const T& value) {
00242   ::std::stringstream ss;
00243   UniversalPrinter<T&>::Print(value, &ss);
00244   return ss.str();
00245 }
00246 
00247 // Tests printing various enum types.
00248 
00249 TEST(PrintEnumTest, AnonymousEnum) {
00250   EXPECT_EQ("-1", Print(kAE1));
00251   EXPECT_EQ("1", Print(kAE2));
00252 }
00253 
00254 TEST(PrintEnumTest, EnumWithoutPrinter) {
00255   EXPECT_EQ("-2", Print(kEWP1));
00256   EXPECT_EQ("42", Print(kEWP2));
00257 }
00258 
00259 TEST(PrintEnumTest, EnumWithStreaming) {
00260   EXPECT_EQ("kEWS1", Print(kEWS1));
00261   EXPECT_EQ("invalid", Print(static_cast<EnumWithStreaming>(0)));
00262 }
00263 
00264 TEST(PrintEnumTest, EnumWithPrintTo) {
00265   EXPECT_EQ("kEWPT1", Print(kEWPT1));
00266   EXPECT_EQ("invalid", Print(static_cast<EnumWithPrintTo>(0)));
00267 }
00268 
00269 // Tests printing a class implicitly convertible to BiggestInt.
00270 
00271 TEST(PrintClassTest, BiggestIntConvertible) {
00272   EXPECT_EQ("42", Print(BiggestIntConvertible()));
00273 }
00274 
00275 // Tests printing various char types.
00276 
00277 // char.
00278 TEST(PrintCharTest, PlainChar) {
00279   EXPECT_EQ("'\\0'", Print('\0'));
00280   EXPECT_EQ("'\\'' (39, 0x27)", Print('\''));
00281   EXPECT_EQ("'\"' (34, 0x22)", Print('"'));
00282   EXPECT_EQ("'?' (63, 0x3F)", Print('?'));
00283   EXPECT_EQ("'\\\\' (92, 0x5C)", Print('\\'));
00284   EXPECT_EQ("'\\a' (7)", Print('\a'));
00285   EXPECT_EQ("'\\b' (8)", Print('\b'));
00286   EXPECT_EQ("'\\f' (12, 0xC)", Print('\f'));
00287   EXPECT_EQ("'\\n' (10, 0xA)", Print('\n'));
00288   EXPECT_EQ("'\\r' (13, 0xD)", Print('\r'));
00289   EXPECT_EQ("'\\t' (9)", Print('\t'));
00290   EXPECT_EQ("'\\v' (11, 0xB)", Print('\v'));
00291   EXPECT_EQ("'\\x7F' (127)", Print('\x7F'));
00292   EXPECT_EQ("'\\xFF' (255)", Print('\xFF'));
00293   EXPECT_EQ("' ' (32, 0x20)", Print(' '));
00294   EXPECT_EQ("'a' (97, 0x61)", Print('a'));
00295 }
00296 
00297 // signed char.
00298 TEST(PrintCharTest, SignedChar) {
00299   EXPECT_EQ("'\\0'", Print(static_cast<signed char>('\0')));
00300   EXPECT_EQ("'\\xCE' (-50)",
00301             Print(static_cast<signed char>(-50)));
00302 }
00303 
00304 // unsigned char.
00305 TEST(PrintCharTest, UnsignedChar) {
00306   EXPECT_EQ("'\\0'", Print(static_cast<unsigned char>('\0')));
00307   EXPECT_EQ("'b' (98, 0x62)",
00308             Print(static_cast<unsigned char>('b')));
00309 }
00310 
00311 // Tests printing other simple, built-in types.
00312 
00313 // bool.
00314 TEST(PrintBuiltInTypeTest, Bool) {
00315   EXPECT_EQ("false", Print(false));
00316   EXPECT_EQ("true", Print(true));
00317 }
00318 
00319 // wchar_t.
00320 TEST(PrintBuiltInTypeTest, Wchar_t) {
00321   EXPECT_EQ("L'\\0'", Print(L'\0'));
00322   EXPECT_EQ("L'\\'' (39, 0x27)", Print(L'\''));
00323   EXPECT_EQ("L'\"' (34, 0x22)", Print(L'"'));
00324   EXPECT_EQ("L'?' (63, 0x3F)", Print(L'?'));
00325   EXPECT_EQ("L'\\\\' (92, 0x5C)", Print(L'\\'));
00326   EXPECT_EQ("L'\\a' (7)", Print(L'\a'));
00327   EXPECT_EQ("L'\\b' (8)", Print(L'\b'));
00328   EXPECT_EQ("L'\\f' (12, 0xC)", Print(L'\f'));
00329   EXPECT_EQ("L'\\n' (10, 0xA)", Print(L'\n'));
00330   EXPECT_EQ("L'\\r' (13, 0xD)", Print(L'\r'));
00331   EXPECT_EQ("L'\\t' (9)", Print(L'\t'));
00332   EXPECT_EQ("L'\\v' (11, 0xB)", Print(L'\v'));
00333   EXPECT_EQ("L'\\x7F' (127)", Print(L'\x7F'));
00334   EXPECT_EQ("L'\\xFF' (255)", Print(L'\xFF'));
00335   EXPECT_EQ("L' ' (32, 0x20)", Print(L' '));
00336   EXPECT_EQ("L'a' (97, 0x61)", Print(L'a'));
00337   EXPECT_EQ("L'\\x576' (1398)", Print(static_cast<wchar_t>(0x576)));
00338   EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D)));
00339 }
00340 
00341 // Test that Int64 provides more storage than wchar_t.
00342 TEST(PrintTypeSizeTest, Wchar_t) {
00343   EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64));
00344 }
00345 
00346 // Various integer types.
00347 TEST(PrintBuiltInTypeTest, Integer) {
00348   EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255)));  // uint8
00349   EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128)));  // int8
00350   EXPECT_EQ("65535", Print(USHRT_MAX));  // uint16
00351   EXPECT_EQ("-32768", Print(SHRT_MIN));  // int16
00352   EXPECT_EQ("4294967295", Print(UINT_MAX));  // uint32
00353   EXPECT_EQ("-2147483648", Print(INT_MIN));  // int32
00354   EXPECT_EQ("18446744073709551615",
00355             Print(static_cast<testing::internal::UInt64>(-1)));  // uint64
00356   EXPECT_EQ("-9223372036854775808",
00357             Print(static_cast<testing::internal::Int64>(1) << 63));  // int64
00358 }
00359 
00360 // Size types.
00361 TEST(PrintBuiltInTypeTest, Size_t) {
00362   EXPECT_EQ("1", Print(sizeof('a')));  // size_t.
00363 #if !GTEST_OS_WINDOWS
00364   // Windows has no ssize_t type.
00365   EXPECT_EQ("-2", Print(static_cast<ssize_t>(-2)));  // ssize_t.
00366 #endif  // !GTEST_OS_WINDOWS
00367 }
00368 
00369 // Floating-points.
00370 TEST(PrintBuiltInTypeTest, FloatingPoints) {
00371   EXPECT_EQ("1.5", Print(1.5f));   // float
00372   EXPECT_EQ("-2.5", Print(-2.5));  // double
00373 }
00374 
00375 // Since ::std::stringstream::operator<<(const void *) formats the pointer
00376 // output differently with different compilers, we have to create the expected
00377 // output first and use it as our expectation.
00378 static string PrintPointer(const void *p) {
00379   ::std::stringstream expected_result_stream;
00380   expected_result_stream << p;
00381   return expected_result_stream.str();
00382 }
00383 
00384 // Tests printing C strings.
00385 
00386 // const char*.
00387 TEST(PrintCStringTest, Const) {
00388   const char* p = "World";
00389   EXPECT_EQ(PrintPointer(p) + " pointing to \"World\"", Print(p));
00390 }
00391 
00392 // char*.
00393 TEST(PrintCStringTest, NonConst) {
00394   char p[] = "Hi";
00395   EXPECT_EQ(PrintPointer(p) + " pointing to \"Hi\"",
00396             Print(static_cast<char*>(p)));
00397 }
00398 
00399 // NULL C string.
00400 TEST(PrintCStringTest, Null) {
00401   const char* p = NULL;
00402   EXPECT_EQ("NULL", Print(p));
00403 }
00404 
00405 // Tests that C strings are escaped properly.
00406 TEST(PrintCStringTest, EscapesProperly) {
00407   const char* p = "'\"?\\\a\b\f\n\r\t\v\x7F\xFF a";
00408   EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"?\\\\\\a\\b\\f"
00409             "\\n\\r\\t\\v\\x7F\\xFF a\"",
00410             Print(p));
00411 }
00412 
00413 // MSVC compiler can be configured to define whar_t as a typedef
00414 // of unsigned short. Defining an overload for const wchar_t* in that case
00415 // would cause pointers to unsigned shorts be printed as wide strings,
00416 // possibly accessing more memory than intended and causing invalid
00417 // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
00418 // wchar_t is implemented as a native type.
00419 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
00420 
00421 // const wchar_t*.
00422 TEST(PrintWideCStringTest, Const) {
00423   const wchar_t* p = L"World";
00424   EXPECT_EQ(PrintPointer(p) + " pointing to L\"World\"", Print(p));
00425 }
00426 
00427 // wchar_t*.
00428 TEST(PrintWideCStringTest, NonConst) {
00429   wchar_t p[] = L"Hi";
00430   EXPECT_EQ(PrintPointer(p) + " pointing to L\"Hi\"",
00431             Print(static_cast<wchar_t*>(p)));
00432 }
00433 
00434 // NULL wide C string.
00435 TEST(PrintWideCStringTest, Null) {
00436   const wchar_t* p = NULL;
00437   EXPECT_EQ("NULL", Print(p));
00438 }
00439 
00440 // Tests that wide C strings are escaped properly.
00441 TEST(PrintWideCStringTest, EscapesProperly) {
00442   const wchar_t s[] = {'\'', '"', '?', '\\', '\a', '\b', '\f', '\n', '\r',
00443                        '\t', '\v', 0xD3, 0x576, 0x8D3, 0xC74D, ' ', 'a', '\0'};
00444   EXPECT_EQ(PrintPointer(s) + " pointing to L\"'\\\"?\\\\\\a\\b\\f"
00445             "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
00446             Print(static_cast<const wchar_t*>(s)));
00447 }
00448 #endif  // native wchar_t
00449 
00450 // Tests printing pointers to other char types.
00451 
00452 // signed char*.
00453 TEST(PrintCharPointerTest, SignedChar) {
00454   signed char* p = reinterpret_cast<signed char*>(0x1234);
00455   EXPECT_EQ(PrintPointer(p), Print(p));
00456   p = NULL;
00457   EXPECT_EQ("NULL", Print(p));
00458 }
00459 
00460 // const signed char*.
00461 TEST(PrintCharPointerTest, ConstSignedChar) {
00462   signed char* p = reinterpret_cast<signed char*>(0x1234);
00463   EXPECT_EQ(PrintPointer(p), Print(p));
00464   p = NULL;
00465   EXPECT_EQ("NULL", Print(p));
00466 }
00467 
00468 // unsigned char*.
00469 TEST(PrintCharPointerTest, UnsignedChar) {
00470   unsigned char* p = reinterpret_cast<unsigned char*>(0x1234);
00471   EXPECT_EQ(PrintPointer(p), Print(p));
00472   p = NULL;
00473   EXPECT_EQ("NULL", Print(p));
00474 }
00475 
00476 // const unsigned char*.
00477 TEST(PrintCharPointerTest, ConstUnsignedChar) {
00478   const unsigned char* p = reinterpret_cast<const unsigned char*>(0x1234);
00479   EXPECT_EQ(PrintPointer(p), Print(p));
00480   p = NULL;
00481   EXPECT_EQ("NULL", Print(p));
00482 }
00483 
00484 // Tests printing pointers to simple, built-in types.
00485 
00486 // bool*.
00487 TEST(PrintPointerToBuiltInTypeTest, Bool) {
00488   bool* p = reinterpret_cast<bool*>(0xABCD);
00489   EXPECT_EQ(PrintPointer(p), Print(p));
00490   p = NULL;
00491   EXPECT_EQ("NULL", Print(p));
00492 }
00493 
00494 // void*.
00495 TEST(PrintPointerToBuiltInTypeTest, Void) {
00496   void* p = reinterpret_cast<void*>(0xABCD);
00497   EXPECT_EQ(PrintPointer(p), Print(p));
00498   p = NULL;
00499   EXPECT_EQ("NULL", Print(p));
00500 }
00501 
00502 // const void*.
00503 TEST(PrintPointerToBuiltInTypeTest, ConstVoid) {
00504   const void* p = reinterpret_cast<const void*>(0xABCD);
00505   EXPECT_EQ(PrintPointer(p), Print(p));
00506   p = NULL;
00507   EXPECT_EQ("NULL", Print(p));
00508 }
00509 
00510 // Tests printing pointers to pointers.
00511 TEST(PrintPointerToPointerTest, IntPointerPointer) {
00512   int** p = reinterpret_cast<int**>(0xABCD);
00513   EXPECT_EQ(PrintPointer(p), Print(p));
00514   p = NULL;
00515   EXPECT_EQ("NULL", Print(p));
00516 }
00517 
00518 // Tests printing (non-member) function pointers.
00519 
00520 void MyFunction(int /* n */) {}
00521 
00522 TEST(PrintPointerTest, NonMemberFunctionPointer) {
00523   // We cannot directly cast &MyFunction to const void* because the
00524   // standard disallows casting between pointers to functions and
00525   // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
00526   // this limitation.
00527   EXPECT_EQ(
00528       PrintPointer(reinterpret_cast<const void*>(
00529           reinterpret_cast<internal::BiggestInt>(&MyFunction))),
00530       Print(&MyFunction));
00531   int (*p)(bool) = NULL;  // NOLINT
00532   EXPECT_EQ("NULL", Print(p));
00533 }
00534 
00535 // An assertion predicate determining whether a one string is a prefix for
00536 // another.
00537 template <typename StringType>
00538 AssertionResult HasPrefix(const StringType& str, const StringType& prefix) {
00539   if (str.find(prefix, 0) == 0)
00540     return AssertionSuccess();
00541 
00542   const bool is_wide_string = sizeof(prefix[0]) > 1;
00543   const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
00544   return AssertionFailure()
00545       << begin_string_quote << prefix << "\" is not a prefix of "
00546       << begin_string_quote << str << "\"\n";
00547 }
00548 
00549 // Tests printing member variable pointers.  Although they are called
00550 // pointers, they don't point to a location in the address space.
00551 // Their representation is implementation-defined.  Thus they will be
00552 // printed as raw bytes.
00553 
00554 struct Foo {
00555  public:
00556   virtual ~Foo() {}
00557   int MyMethod(char x) { return x + 1; }
00558   virtual char MyVirtualMethod(int /* n */) { return 'a'; }
00559 
00560   int value;
00561 };
00562 
00563 TEST(PrintPointerTest, MemberVariablePointer) {
00564   EXPECT_TRUE(HasPrefix(Print(&Foo::value),
00565                         Print(sizeof(&Foo::value)) + "-byte object "));
00566   int (Foo::*p) = NULL;  // NOLINT
00567   EXPECT_TRUE(HasPrefix(Print(p),
00568                         Print(sizeof(p)) + "-byte object "));
00569 }
00570 
00571 // Tests printing member function pointers.  Although they are called
00572 // pointers, they don't point to a location in the address space.
00573 // Their representation is implementation-defined.  Thus they will be
00574 // printed as raw bytes.
00575 TEST(PrintPointerTest, MemberFunctionPointer) {
00576   EXPECT_TRUE(HasPrefix(Print(&Foo::MyMethod),
00577                         Print(sizeof(&Foo::MyMethod)) + "-byte object "));
00578   EXPECT_TRUE(
00579       HasPrefix(Print(&Foo::MyVirtualMethod),
00580                 Print(sizeof((&Foo::MyVirtualMethod))) + "-byte object "));
00581   int (Foo::*p)(char) = NULL;  // NOLINT
00582   EXPECT_TRUE(HasPrefix(Print(p),
00583                         Print(sizeof(p)) + "-byte object "));
00584 }
00585 
00586 // Tests printing C arrays.
00587 
00588 // The difference between this and Print() is that it ensures that the
00589 // argument is a reference to an array.
00590 template <typename T, size_t N>
00591 string PrintArrayHelper(T (&a)[N]) {
00592   return Print(a);
00593 }
00594 
00595 // One-dimensional array.
00596 TEST(PrintArrayTest, OneDimensionalArray) {
00597   int a[5] = { 1, 2, 3, 4, 5 };
00598   EXPECT_EQ("{ 1, 2, 3, 4, 5 }", PrintArrayHelper(a));
00599 }
00600 
00601 // Two-dimensional array.
00602 TEST(PrintArrayTest, TwoDimensionalArray) {
00603   int a[2][5] = {
00604     { 1, 2, 3, 4, 5 },
00605     { 6, 7, 8, 9, 0 }
00606   };
00607   EXPECT_EQ("{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }", PrintArrayHelper(a));
00608 }
00609 
00610 // Array of const elements.
00611 TEST(PrintArrayTest, ConstArray) {
00612   const bool a[1] = { false };
00613   EXPECT_EQ("{ false }", PrintArrayHelper(a));
00614 }
00615 
00616 // char array without terminating NUL.
00617 TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
00618   // Array a contains '\0' in the middle and doesn't end with '\0'.
00619   char a[] = { 'H', '\0', 'i' };
00620   EXPECT_EQ("\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
00621 }
00622 
00623 // const char array with terminating NUL.
00624 TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
00625   const char a[] = "\0Hi";
00626   EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a));
00627 }
00628 
00629 // const wchar_t array without terminating NUL.
00630 TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
00631   // Array a contains '\0' in the middle and doesn't end with '\0'.
00632   const wchar_t a[] = { L'H', L'\0', L'i' };
00633   EXPECT_EQ("L\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
00634 }
00635 
00636 // wchar_t array with terminating NUL.
00637 TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
00638   const wchar_t a[] = L"\0Hi";
00639   EXPECT_EQ("L\"\\0Hi\"", PrintArrayHelper(a));
00640 }
00641 
00642 // Array of objects.
00643 TEST(PrintArrayTest, ObjectArray) {
00644   string a[3] = { "Hi", "Hello", "Ni hao" };
00645   EXPECT_EQ("{ \"Hi\", \"Hello\", \"Ni hao\" }", PrintArrayHelper(a));
00646 }
00647 
00648 // Array with many elements.
00649 TEST(PrintArrayTest, BigArray) {
00650   int a[100] = { 1, 2, 3 };
00651   EXPECT_EQ("{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
00652             PrintArrayHelper(a));
00653 }
00654 
00655 // Tests printing ::string and ::std::string.
00656 
00657 #if GTEST_HAS_GLOBAL_STRING
00658 // ::string.
00659 TEST(PrintStringTest, StringInGlobalNamespace) {
00660   const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
00661   const ::string str(s, sizeof(s));
00662   EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
00663             Print(str));
00664 }
00665 #endif  // GTEST_HAS_GLOBAL_STRING
00666 
00667 // ::std::string.
00668 TEST(PrintStringTest, StringInStdNamespace) {
00669   const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
00670   const ::std::string str(s, sizeof(s));
00671   EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
00672             Print(str));
00673 }
00674 
00675 TEST(PrintStringTest, StringAmbiguousHex) {
00676   // "\x6BANANA" is ambiguous, it can be interpreted as starting with either of:
00677   // '\x6', '\x6B', or '\x6BA'.
00678 
00679   // a hex escaping sequence following by a decimal digit
00680   EXPECT_EQ("\"0\\x12\" \"3\"", Print(::std::string("0\x12" "3")));
00681   // a hex escaping sequence following by a hex digit (lower-case)
00682   EXPECT_EQ("\"mm\\x6\" \"bananas\"", Print(::std::string("mm\x6" "bananas")));
00683   // a hex escaping sequence following by a hex digit (upper-case)
00684   EXPECT_EQ("\"NOM\\x6\" \"BANANA\"", Print(::std::string("NOM\x6" "BANANA")));
00685   // a hex escaping sequence following by a non-xdigit
00686   EXPECT_EQ("\"!\\x5-!\"", Print(::std::string("!\x5-!")));
00687 }
00688 
00689 // Tests printing ::wstring and ::std::wstring.
00690 
00691 #if GTEST_HAS_GLOBAL_WSTRING
00692 // ::wstring.
00693 TEST(PrintWideStringTest, StringInGlobalNamespace) {
00694   const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
00695   const ::wstring str(s, sizeof(s)/sizeof(wchar_t));
00696   EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
00697             "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
00698             Print(str));
00699 }
00700 #endif  // GTEST_HAS_GLOBAL_WSTRING
00701 
00702 #if GTEST_HAS_STD_WSTRING
00703 // ::std::wstring.
00704 TEST(PrintWideStringTest, StringInStdNamespace) {
00705   const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a";
00706   const ::std::wstring str(s, sizeof(s)/sizeof(wchar_t));
00707   EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v"
00708             "\\xD3\\x576\\x8D3\\xC74D a\\0\"",
00709             Print(str));
00710 }
00711 
00712 TEST(PrintWideStringTest, StringAmbiguousHex) {
00713   // same for wide strings.
00714   EXPECT_EQ("L\"0\\x12\" L\"3\"", Print(::std::wstring(L"0\x12" L"3")));
00715   EXPECT_EQ("L\"mm\\x6\" L\"bananas\"",
00716             Print(::std::wstring(L"mm\x6" L"bananas")));
00717   EXPECT_EQ("L\"NOM\\x6\" L\"BANANA\"",
00718             Print(::std::wstring(L"NOM\x6" L"BANANA")));
00719   EXPECT_EQ("L\"!\\x5-!\"", Print(::std::wstring(L"!\x5-!")));
00720 }
00721 #endif  // GTEST_HAS_STD_WSTRING
00722 
00723 // Tests printing types that support generic streaming (i.e. streaming
00724 // to std::basic_ostream<Char, CharTraits> for any valid Char and
00725 // CharTraits types).
00726 
00727 // Tests printing a non-template type that supports generic streaming.
00728 
00729 class AllowsGenericStreaming {};
00730 
00731 template <typename Char, typename CharTraits>
00732 std::basic_ostream<Char, CharTraits>& operator<<(
00733     std::basic_ostream<Char, CharTraits>& os,
00734     const AllowsGenericStreaming& /* a */) {
00735   return os << "AllowsGenericStreaming";
00736 }
00737 
00738 TEST(PrintTypeWithGenericStreamingTest, NonTemplateType) {
00739   AllowsGenericStreaming a;
00740   EXPECT_EQ("AllowsGenericStreaming", Print(a));
00741 }
00742 
00743 // Tests printing a template type that supports generic streaming.
00744 
00745 template <typename T>
00746 class AllowsGenericStreamingTemplate {};
00747 
00748 template <typename Char, typename CharTraits, typename T>
00749 std::basic_ostream<Char, CharTraits>& operator<<(
00750     std::basic_ostream<Char, CharTraits>& os,
00751     const AllowsGenericStreamingTemplate<T>& /* a */) {
00752   return os << "AllowsGenericStreamingTemplate";
00753 }
00754 
00755 TEST(PrintTypeWithGenericStreamingTest, TemplateType) {
00756   AllowsGenericStreamingTemplate<int> a;
00757   EXPECT_EQ("AllowsGenericStreamingTemplate", Print(a));
00758 }
00759 
00760 // Tests printing a type that supports generic streaming and can be
00761 // implicitly converted to another printable type.
00762 
00763 template <typename T>
00764 class AllowsGenericStreamingAndImplicitConversionTemplate {
00765  public:
00766   operator bool() const { return false; }
00767 };
00768 
00769 template <typename Char, typename CharTraits, typename T>
00770 std::basic_ostream<Char, CharTraits>& operator<<(
00771     std::basic_ostream<Char, CharTraits>& os,
00772     const AllowsGenericStreamingAndImplicitConversionTemplate<T>& /* a */) {
00773   return os << "AllowsGenericStreamingAndImplicitConversionTemplate";
00774 }
00775 
00776 TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
00777   AllowsGenericStreamingAndImplicitConversionTemplate<int> a;
00778   EXPECT_EQ("AllowsGenericStreamingAndImplicitConversionTemplate", Print(a));
00779 }
00780 
00781 #if GTEST_HAS_STRING_PIECE_
00782 
00783 // Tests printing StringPiece.
00784 
00785 TEST(PrintStringPieceTest, SimpleStringPiece) {
00786   const StringPiece sp = "Hello";
00787   EXPECT_EQ("\"Hello\"", Print(sp));
00788 }
00789 
00790 TEST(PrintStringPieceTest, UnprintableCharacters) {
00791   const char str[] = "NUL (\0) and \r\t";
00792   const StringPiece sp(str, sizeof(str) - 1);
00793   EXPECT_EQ("\"NUL (\\0) and \\r\\t\"", Print(sp));
00794 }
00795 
00796 #endif  // GTEST_HAS_STRING_PIECE_
00797 
00798 // Tests printing STL containers.
00799 
00800 TEST(PrintStlContainerTest, EmptyDeque) {
00801   deque<char> empty;
00802   EXPECT_EQ("{}", Print(empty));
00803 }
00804 
00805 TEST(PrintStlContainerTest, NonEmptyDeque) {
00806   deque<int> non_empty;
00807   non_empty.push_back(1);
00808   non_empty.push_back(3);
00809   EXPECT_EQ("{ 1, 3 }", Print(non_empty));
00810 }
00811 
00812 #if GTEST_HAS_HASH_MAP_
00813 
00814 TEST(PrintStlContainerTest, OneElementHashMap) {
00815   hash_map<int, char> map1;
00816   map1[1] = 'a';
00817   EXPECT_EQ("{ (1, 'a' (97, 0x61)) }", Print(map1));
00818 }
00819 
00820 TEST(PrintStlContainerTest, HashMultiMap) {
00821   hash_multimap<int, bool> map1;
00822   map1.insert(make_pair(5, true));
00823   map1.insert(make_pair(5, false));
00824 
00825   // Elements of hash_multimap can be printed in any order.
00826   const string result = Print(map1);
00827   EXPECT_TRUE(result == "{ (5, true), (5, false) }" ||
00828               result == "{ (5, false), (5, true) }")
00829                   << " where Print(map1) returns \"" << result << "\".";
00830 }
00831 
00832 #endif  // GTEST_HAS_HASH_MAP_
00833 
00834 #if GTEST_HAS_HASH_SET_
00835 
00836 TEST(PrintStlContainerTest, HashSet) {
00837   hash_set<string> set1;
00838   set1.insert("hello");
00839   EXPECT_EQ("{ \"hello\" }", Print(set1));
00840 }
00841 
00842 TEST(PrintStlContainerTest, HashMultiSet) {
00843   const int kSize = 5;
00844   int a[kSize] = { 1, 1, 2, 5, 1 };
00845   hash_multiset<int> set1(a, a + kSize);
00846 
00847   // Elements of hash_multiset can be printed in any order.
00848   const string result = Print(set1);
00849   const string expected_pattern = "{ d, d, d, d, d }";  // d means a digit.
00850 
00851   // Verifies the result matches the expected pattern; also extracts
00852   // the numbers in the result.
00853   ASSERT_EQ(expected_pattern.length(), result.length());
00854   std::vector<int> numbers;
00855   for (size_t i = 0; i != result.length(); i++) {
00856     if (expected_pattern[i] == 'd') {
00857       ASSERT_NE(isdigit(static_cast<unsigned char>(result[i])), 0);
00858       numbers.push_back(result[i] - '0');
00859     } else {
00860       EXPECT_EQ(expected_pattern[i], result[i]) << " where result is "
00861                                                 << result;
00862     }
00863   }
00864 
00865   // Makes sure the result contains the right numbers.
00866   std::sort(numbers.begin(), numbers.end());
00867   std::sort(a, a + kSize);
00868   EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin()));
00869 }
00870 
00871 #endif  // GTEST_HAS_HASH_SET_
00872 
00873 TEST(PrintStlContainerTest, List) {
00874   const string a[] = {
00875     "hello",
00876     "world"
00877   };
00878   const list<string> strings(a, a + 2);
00879   EXPECT_EQ("{ \"hello\", \"world\" }", Print(strings));
00880 }
00881 
00882 TEST(PrintStlContainerTest, Map) {
00883   map<int, bool> map1;
00884   map1[1] = true;
00885   map1[5] = false;
00886   map1[3] = true;
00887   EXPECT_EQ("{ (1, true), (3, true), (5, false) }", Print(map1));
00888 }
00889 
00890 TEST(PrintStlContainerTest, MultiMap) {
00891   multimap<bool, int> map1;
00892   // The make_pair template function would deduce the type as
00893   // pair<bool, int> here, and since the key part in a multimap has to
00894   // be constant, without a templated ctor in the pair class (as in
00895   // libCstd on Solaris), make_pair call would fail to compile as no
00896   // implicit conversion is found.  Thus explicit typename is used
00897   // here instead.
00898   map1.insert(pair<const bool, int>(true, 0));
00899   map1.insert(pair<const bool, int>(true, 1));
00900   map1.insert(pair<const bool, int>(false, 2));
00901   EXPECT_EQ("{ (false, 2), (true, 0), (true, 1) }", Print(map1));
00902 }
00903 
00904 TEST(PrintStlContainerTest, Set) {
00905   const unsigned int a[] = { 3, 0, 5 };
00906   set<unsigned int> set1(a, a + 3);
00907   EXPECT_EQ("{ 0, 3, 5 }", Print(set1));
00908 }
00909 
00910 TEST(PrintStlContainerTest, MultiSet) {
00911   const int a[] = { 1, 1, 2, 5, 1 };
00912   multiset<int> set1(a, a + 5);
00913   EXPECT_EQ("{ 1, 1, 1, 2, 5 }", Print(set1));
00914 }
00915 
00916 TEST(PrintStlContainerTest, Pair) {
00917   pair<const bool, int> p(true, 5);
00918   EXPECT_EQ("(true, 5)", Print(p));
00919 }
00920 
00921 TEST(PrintStlContainerTest, Vector) {
00922   vector<int> v;
00923   v.push_back(1);
00924   v.push_back(2);
00925   EXPECT_EQ("{ 1, 2 }", Print(v));
00926 }
00927 
00928 TEST(PrintStlContainerTest, LongSequence) {
00929   const int a[100] = { 1, 2, 3 };
00930   const vector<int> v(a, a + 100);
00931   EXPECT_EQ("{ 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
00932             "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... }", Print(v));
00933 }
00934 
00935 TEST(PrintStlContainerTest, NestedContainer) {
00936   const int a1[] = { 1, 2 };
00937   const int a2[] = { 3, 4, 5 };
00938   const list<int> l1(a1, a1 + 2);
00939   const list<int> l2(a2, a2 + 3);
00940 
00941   vector<list<int> > v;
00942   v.push_back(l1);
00943   v.push_back(l2);
00944   EXPECT_EQ("{ { 1, 2 }, { 3, 4, 5 } }", Print(v));
00945 }
00946 
00947 TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
00948   const int a[3] = { 1, 2, 3 };
00949   NativeArray<int> b(a, 3, RelationToSourceReference());
00950   EXPECT_EQ("{ 1, 2, 3 }", Print(b));
00951 }
00952 
00953 TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
00954   const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
00955   NativeArray<int[3]> b(a, 2, RelationToSourceReference());
00956   EXPECT_EQ("{ { 1, 2, 3 }, { 4, 5, 6 } }", Print(b));
00957 }
00958 
00959 // Tests that a class named iterator isn't treated as a container.
00960 
00961 struct iterator {
00962   char x;
00963 };
00964 
00965 TEST(PrintStlContainerTest, Iterator) {
00966   iterator it = {};
00967   EXPECT_EQ("1-byte object <00>", Print(it));
00968 }
00969 
00970 // Tests that a class named const_iterator isn't treated as a container.
00971 
00972 struct const_iterator {
00973   char x;
00974 };
00975 
00976 TEST(PrintStlContainerTest, ConstIterator) {
00977   const_iterator it = {};
00978   EXPECT_EQ("1-byte object <00>", Print(it));
00979 }
00980 
00981 #if GTEST_HAS_TR1_TUPLE
00982 // Tests printing ::std::tr1::tuples.
00983 
00984 // Tuples of various arities.
00985 TEST(PrintTr1TupleTest, VariousSizes) {
00986   ::std::tr1::tuple<> t0;
00987   EXPECT_EQ("()", Print(t0));
00988 
00989   ::std::tr1::tuple<int> t1(5);
00990   EXPECT_EQ("(5)", Print(t1));
00991 
00992   ::std::tr1::tuple<char, bool> t2('a', true);
00993   EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
00994 
00995   ::std::tr1::tuple<bool, int, int> t3(false, 2, 3);
00996   EXPECT_EQ("(false, 2, 3)", Print(t3));
00997 
00998   ::std::tr1::tuple<bool, int, int, int> t4(false, 2, 3, 4);
00999   EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
01000 
01001   ::std::tr1::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
01002   EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
01003 
01004   ::std::tr1::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
01005   EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
01006 
01007   ::std::tr1::tuple<bool, int, int, int, bool, int, int> t7(
01008       false, 2, 3, 4, true, 6, 7);
01009   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
01010 
01011   ::std::tr1::tuple<bool, int, int, int, bool, int, int, bool> t8(
01012       false, 2, 3, 4, true, 6, 7, true);
01013   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
01014 
01015   ::std::tr1::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
01016       false, 2, 3, 4, true, 6, 7, true, 9);
01017   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
01018 
01019   const char* const str = "8";
01020   // VC++ 2010's implementation of tuple of C++0x is deficient, requiring
01021   // an explicit type cast of NULL to be used.
01022   ::std::tr1::tuple<bool, char, short, testing::internal::Int32,  // NOLINT
01023       testing::internal::Int64, float, double, const char*, void*, string>
01024       t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str,
01025           ImplicitCast_<void*>(NULL), "10");
01026   EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
01027             " pointing to \"8\", NULL, \"10\")",
01028             Print(t10));
01029 }
01030 
01031 // Nested tuples.
01032 TEST(PrintTr1TupleTest, NestedTuple) {
01033   ::std::tr1::tuple< ::std::tr1::tuple<int, bool>, char> nested(
01034       ::std::tr1::make_tuple(5, true), 'a');
01035   EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
01036 }
01037 
01038 #endif  // GTEST_HAS_TR1_TUPLE
01039 
01040 #if GTEST_HAS_STD_TUPLE_
01041 // Tests printing ::std::tuples.
01042 
01043 // Tuples of various arities.
01044 TEST(PrintStdTupleTest, VariousSizes) {
01045   ::std::tuple<> t0;
01046   EXPECT_EQ("()", Print(t0));
01047 
01048   ::std::tuple<int> t1(5);
01049   EXPECT_EQ("(5)", Print(t1));
01050 
01051   ::std::tuple<char, bool> t2('a', true);
01052   EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
01053 
01054   ::std::tuple<bool, int, int> t3(false, 2, 3);
01055   EXPECT_EQ("(false, 2, 3)", Print(t3));
01056 
01057   ::std::tuple<bool, int, int, int> t4(false, 2, 3, 4);
01058   EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
01059 
01060   ::std::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
01061   EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
01062 
01063   ::std::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
01064   EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
01065 
01066   ::std::tuple<bool, int, int, int, bool, int, int> t7(
01067       false, 2, 3, 4, true, 6, 7);
01068   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
01069 
01070   ::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
01071       false, 2, 3, 4, true, 6, 7, true);
01072   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
01073 
01074   ::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
01075       false, 2, 3, 4, true, 6, 7, true, 9);
01076   EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
01077 
01078   const char* const str = "8";
01079   // VC++ 2010's implementation of tuple of C++0x is deficient, requiring
01080   // an explicit type cast of NULL to be used.
01081   ::std::tuple<bool, char, short, testing::internal::Int32,  // NOLINT
01082       testing::internal::Int64, float, double, const char*, void*, string>
01083       t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str,
01084           ImplicitCast_<void*>(NULL), "10");
01085   EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
01086             " pointing to \"8\", NULL, \"10\")",
01087             Print(t10));
01088 }
01089 
01090 // Nested tuples.
01091 TEST(PrintStdTupleTest, NestedTuple) {
01092   ::std::tuple< ::std::tuple<int, bool>, char> nested(
01093       ::std::make_tuple(5, true), 'a');
01094   EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
01095 }
01096 
01097 #endif  // GTEST_LANG_CXX11
01098 
01099 // Tests printing user-defined unprintable types.
01100 
01101 // Unprintable types in the global namespace.
01102 TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
01103   EXPECT_EQ("1-byte object <00>",
01104             Print(UnprintableTemplateInGlobal<char>()));
01105 }
01106 
01107 // Unprintable types in a user namespace.
01108 TEST(PrintUnprintableTypeTest, InUserNamespace) {
01109   EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
01110             Print(::foo::UnprintableInFoo()));
01111 }
01112 
01113 // Unprintable types are that too big to be printed completely.
01114 
01115 struct Big {
01116   Big() { memset(array, 0, sizeof(array)); }
01117   char array[257];
01118 };
01119 
01120 TEST(PrintUnpritableTypeTest, BigObject) {
01121   EXPECT_EQ("257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
01122             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
01123             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
01124             "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
01125             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
01126             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
01127             "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
01128             Print(Big()));
01129 }
01130 
01131 // Tests printing user-defined streamable types.
01132 
01133 // Streamable types in the global namespace.
01134 TEST(PrintStreamableTypeTest, InGlobalNamespace) {
01135   StreamableInGlobal x;
01136   EXPECT_EQ("StreamableInGlobal", Print(x));
01137   EXPECT_EQ("StreamableInGlobal*", Print(&x));
01138 }
01139 
01140 // Printable template types in a user namespace.
01141 TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
01142   EXPECT_EQ("StreamableTemplateInFoo: 0",
01143             Print(::foo::StreamableTemplateInFoo<int>()));
01144 }
01145 
01146 // Tests printing user-defined types that have a PrintTo() function.
01147 TEST(PrintPrintableTypeTest, InUserNamespace) {
01148   EXPECT_EQ("PrintableViaPrintTo: 0",
01149             Print(::foo::PrintableViaPrintTo()));
01150 }
01151 
01152 // Tests printing a pointer to a user-defined type that has a <<
01153 // operator for its pointer.
01154 TEST(PrintPrintableTypeTest, PointerInUserNamespace) {
01155   ::foo::PointerPrintable x;
01156   EXPECT_EQ("PointerPrintable*", Print(&x));
01157 }
01158 
01159 // Tests printing user-defined class template that have a PrintTo() function.
01160 TEST(PrintPrintableTypeTest, TemplateInUserNamespace) {
01161   EXPECT_EQ("PrintableViaPrintToTemplate: 5",
01162             Print(::foo::PrintableViaPrintToTemplate<int>(5)));
01163 }
01164 
01165 #if GTEST_HAS_PROTOBUF_
01166 
01167 // Tests printing a short proto2 message.
01168 TEST(PrintProto2MessageTest, PrintsShortDebugStringWhenItIsShort) {
01169   testing::internal::FooMessage msg;
01170   msg.set_int_field(2);
01171   msg.set_string_field("hello");
01172   EXPECT_PRED2(RE::FullMatch, Print(msg),
01173                "<int_field:\\s*2\\s+string_field:\\s*\"hello\">");
01174 }
01175 
01176 // Tests printing a long proto2 message.
01177 TEST(PrintProto2MessageTest, PrintsDebugStringWhenItIsLong) {
01178   testing::internal::FooMessage msg;
01179   msg.set_int_field(2);
01180   msg.set_string_field("hello");
01181   msg.add_names("peter");
01182   msg.add_names("paul");
01183   msg.add_names("mary");
01184   EXPECT_PRED2(RE::FullMatch, Print(msg),
01185                "<\n"
01186                "int_field:\\s*2\n"
01187                "string_field:\\s*\"hello\"\n"
01188                "names:\\s*\"peter\"\n"
01189                "names:\\s*\"paul\"\n"
01190                "names:\\s*\"mary\"\n"
01191                ">");
01192 }
01193 
01194 #endif  // GTEST_HAS_PROTOBUF_
01195 
01196 // Tests that the universal printer prints both the address and the
01197 // value of a reference.
01198 TEST(PrintReferenceTest, PrintsAddressAndValue) {
01199   int n = 5;
01200   EXPECT_EQ("@" + PrintPointer(&n) + " 5", PrintByRef(n));
01201 
01202   int a[2][3] = {
01203     { 0, 1, 2 },
01204     { 3, 4, 5 }
01205   };
01206   EXPECT_EQ("@" + PrintPointer(a) + " { { 0, 1, 2 }, { 3, 4, 5 } }",
01207             PrintByRef(a));
01208 
01209   const ::foo::UnprintableInFoo x;
01210   EXPECT_EQ("@" + PrintPointer(&x) + " 16-byte object "
01211             "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
01212             PrintByRef(x));
01213 }
01214 
01215 // Tests that the universal printer prints a function pointer passed by
01216 // reference.
01217 TEST(PrintReferenceTest, HandlesFunctionPointer) {
01218   void (*fp)(int n) = &MyFunction;
01219   const string fp_pointer_string =
01220       PrintPointer(reinterpret_cast<const void*>(&fp));
01221   // We cannot directly cast &MyFunction to const void* because the
01222   // standard disallows casting between pointers to functions and
01223   // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
01224   // this limitation.
01225   const string fp_string = PrintPointer(reinterpret_cast<const void*>(
01226       reinterpret_cast<internal::BiggestInt>(fp)));
01227   EXPECT_EQ("@" + fp_pointer_string + " " + fp_string,
01228             PrintByRef(fp));
01229 }
01230 
01231 // Tests that the universal printer prints a member function pointer
01232 // passed by reference.
01233 TEST(PrintReferenceTest, HandlesMemberFunctionPointer) {
01234   int (Foo::*p)(char ch) = &Foo::MyMethod;
01235   EXPECT_TRUE(HasPrefix(
01236       PrintByRef(p),
01237       "@" + PrintPointer(reinterpret_cast<const void*>(&p)) + " " +
01238           Print(sizeof(p)) + "-byte object "));
01239 
01240   char (Foo::*p2)(int n) = &Foo::MyVirtualMethod;
01241   EXPECT_TRUE(HasPrefix(
01242       PrintByRef(p2),
01243       "@" + PrintPointer(reinterpret_cast<const void*>(&p2)) + " " +
01244           Print(sizeof(p2)) + "-byte object "));
01245 }
01246 
01247 // Tests that the universal printer prints a member variable pointer
01248 // passed by reference.
01249 TEST(PrintReferenceTest, HandlesMemberVariablePointer) {
01250   int (Foo::*p) = &Foo::value;  // NOLINT
01251   EXPECT_TRUE(HasPrefix(
01252       PrintByRef(p),
01253       "@" + PrintPointer(&p) + " " + Print(sizeof(p)) + "-byte object "));
01254 }
01255 
01256 // Tests that FormatForComparisonFailureMessage(), which is used to print
01257 // an operand in a comparison assertion (e.g. ASSERT_EQ) when the assertion
01258 // fails, formats the operand in the desired way.
01259 
01260 // scalar
01261 TEST(FormatForComparisonFailureMessageTest, WorksForScalar) {
01262   EXPECT_STREQ("123",
01263                FormatForComparisonFailureMessage(123, 124).c_str());
01264 }
01265 
01266 // non-char pointer
01267 TEST(FormatForComparisonFailureMessageTest, WorksForNonCharPointer) {
01268   int n = 0;
01269   EXPECT_EQ(PrintPointer(&n),
01270             FormatForComparisonFailureMessage(&n, &n).c_str());
01271 }
01272 
01273 // non-char array
01274 TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
01275   // In expression 'array == x', 'array' is compared by pointer.
01276   // Therefore we want to print an array operand as a pointer.
01277   int n[] = { 1, 2, 3 };
01278   EXPECT_EQ(PrintPointer(n),
01279             FormatForComparisonFailureMessage(n, n).c_str());
01280 }
01281 
01282 // Tests formatting a char pointer when it's compared with another pointer.
01283 // In this case we want to print it as a raw pointer, as the comparision is by
01284 // pointer.
01285 
01286 // char pointer vs pointer
01287 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsPointer) {
01288   // In expression 'p == x', where 'p' and 'x' are (const or not) char
01289   // pointers, the operands are compared by pointer.  Therefore we
01290   // want to print 'p' as a pointer instead of a C string (we don't
01291   // even know if it's supposed to point to a valid C string).
01292 
01293   // const char*
01294   const char* s = "hello";
01295   EXPECT_EQ(PrintPointer(s),
01296             FormatForComparisonFailureMessage(s, s).c_str());
01297 
01298   // char*
01299   char ch = 'a';
01300   EXPECT_EQ(PrintPointer(&ch),
01301             FormatForComparisonFailureMessage(&ch, &ch).c_str());
01302 }
01303 
01304 // wchar_t pointer vs pointer
01305 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsPointer) {
01306   // In expression 'p == x', where 'p' and 'x' are (const or not) char
01307   // pointers, the operands are compared by pointer.  Therefore we
01308   // want to print 'p' as a pointer instead of a wide C string (we don't
01309   // even know if it's supposed to point to a valid wide C string).
01310 
01311   // const wchar_t*
01312   const wchar_t* s = L"hello";
01313   EXPECT_EQ(PrintPointer(s),
01314             FormatForComparisonFailureMessage(s, s).c_str());
01315 
01316   // wchar_t*
01317   wchar_t ch = L'a';
01318   EXPECT_EQ(PrintPointer(&ch),
01319             FormatForComparisonFailureMessage(&ch, &ch).c_str());
01320 }
01321 
01322 // Tests formatting a char pointer when it's compared to a string object.
01323 // In this case we want to print the char pointer as a C string.
01324 
01325 #if GTEST_HAS_GLOBAL_STRING
01326 // char pointer vs ::string
01327 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsString) {
01328   const char* s = "hello \"world";
01329   EXPECT_STREQ("\"hello \\\"world\"",  // The string content should be escaped.
01330                FormatForComparisonFailureMessage(s, ::string()).c_str());
01331 
01332   // char*
01333   char str[] = "hi\1";
01334   char* p = str;
01335   EXPECT_STREQ("\"hi\\x1\"",  // The string content should be escaped.
01336                FormatForComparisonFailureMessage(p, ::string()).c_str());
01337 }
01338 #endif
01339 
01340 // char pointer vs std::string
01341 TEST(FormatForComparisonFailureMessageTest, WorksForCharPointerVsStdString) {
01342   const char* s = "hello \"world";
01343   EXPECT_STREQ("\"hello \\\"world\"",  // The string content should be escaped.
01344                FormatForComparisonFailureMessage(s, ::std::string()).c_str());
01345 
01346   // char*
01347   char str[] = "hi\1";
01348   char* p = str;
01349   EXPECT_STREQ("\"hi\\x1\"",  // The string content should be escaped.
01350                FormatForComparisonFailureMessage(p, ::std::string()).c_str());
01351 }
01352 
01353 #if GTEST_HAS_GLOBAL_WSTRING
01354 // wchar_t pointer vs ::wstring
01355 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsWString) {
01356   const wchar_t* s = L"hi \"world";
01357   EXPECT_STREQ("L\"hi \\\"world\"",  // The string content should be escaped.
01358                FormatForComparisonFailureMessage(s, ::wstring()).c_str());
01359 
01360   // wchar_t*
01361   wchar_t str[] = L"hi\1";
01362   wchar_t* p = str;
01363   EXPECT_STREQ("L\"hi\\x1\"",  // The string content should be escaped.
01364                FormatForComparisonFailureMessage(p, ::wstring()).c_str());
01365 }
01366 #endif
01367 
01368 #if GTEST_HAS_STD_WSTRING
01369 // wchar_t pointer vs std::wstring
01370 TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) {
01371   const wchar_t* s = L"hi \"world";
01372   EXPECT_STREQ("L\"hi \\\"world\"",  // The string content should be escaped.
01373                FormatForComparisonFailureMessage(s, ::std::wstring()).c_str());
01374 
01375   // wchar_t*
01376   wchar_t str[] = L"hi\1";
01377   wchar_t* p = str;
01378   EXPECT_STREQ("L\"hi\\x1\"",  // The string content should be escaped.
01379                FormatForComparisonFailureMessage(p, ::std::wstring()).c_str());
01380 }
01381 #endif
01382 
01383 // Tests formatting a char array when it's compared with a pointer or array.
01384 // In this case we want to print the array as a row pointer, as the comparison
01385 // is by pointer.
01386 
01387 // char array vs pointer
01388 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) {
01389   char str[] = "hi \"world\"";
01390   char* p = NULL;
01391   EXPECT_EQ(PrintPointer(str),
01392             FormatForComparisonFailureMessage(str, p).c_str());
01393 }
01394 
01395 // char array vs char array
01396 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) {
01397   const char str[] = "hi \"world\"";
01398   EXPECT_EQ(PrintPointer(str),
01399             FormatForComparisonFailureMessage(str, str).c_str());
01400 }
01401 
01402 // wchar_t array vs pointer
01403 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) {
01404   wchar_t str[] = L"hi \"world\"";
01405   wchar_t* p = NULL;
01406   EXPECT_EQ(PrintPointer(str),
01407             FormatForComparisonFailureMessage(str, p).c_str());
01408 }
01409 
01410 // wchar_t array vs wchar_t array
01411 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWCharArray) {
01412   const wchar_t str[] = L"hi \"world\"";
01413   EXPECT_EQ(PrintPointer(str),
01414             FormatForComparisonFailureMessage(str, str).c_str());
01415 }
01416 
01417 // Tests formatting a char array when it's compared with a string object.
01418 // In this case we want to print the array as a C string.
01419 
01420 #if GTEST_HAS_GLOBAL_STRING
01421 // char array vs string
01422 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsString) {
01423   const char str[] = "hi \"w\0rld\"";
01424   EXPECT_STREQ("\"hi \\\"w\"",  // The content should be escaped.
01425                                 // Embedded NUL terminates the string.
01426                FormatForComparisonFailureMessage(str, ::string()).c_str());
01427 }
01428 #endif
01429 
01430 // char array vs std::string
01431 TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsStdString) {
01432   const char str[] = "hi \"world\"";
01433   EXPECT_STREQ("\"hi \\\"world\\\"\"",  // The content should be escaped.
01434                FormatForComparisonFailureMessage(str, ::std::string()).c_str());
01435 }
01436 
01437 #if GTEST_HAS_GLOBAL_WSTRING
01438 // wchar_t array vs wstring
01439 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsWString) {
01440   const wchar_t str[] = L"hi \"world\"";
01441   EXPECT_STREQ("L\"hi \\\"world\\\"\"",  // The content should be escaped.
01442                FormatForComparisonFailureMessage(str, ::wstring()).c_str());
01443 }
01444 #endif
01445 
01446 #if GTEST_HAS_STD_WSTRING
01447 // wchar_t array vs std::wstring
01448 TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsStdWString) {
01449   const wchar_t str[] = L"hi \"w\0rld\"";
01450   EXPECT_STREQ(
01451       "L\"hi \\\"w\"",  // The content should be escaped.
01452                         // Embedded NUL terminates the string.
01453       FormatForComparisonFailureMessage(str, ::std::wstring()).c_str());
01454 }
01455 #endif
01456 
01457 // Useful for testing PrintToString().  We cannot use EXPECT_EQ()
01458 // there as its implementation uses PrintToString().  The caller must
01459 // ensure that 'value' has no side effect.
01460 #define EXPECT_PRINT_TO_STRING_(value, expected_string)         \
01461   EXPECT_TRUE(PrintToString(value) == (expected_string))        \
01462       << " where " #value " prints as " << (PrintToString(value))
01463 
01464 TEST(PrintToStringTest, WorksForScalar) {
01465   EXPECT_PRINT_TO_STRING_(123, "123");
01466 }
01467 
01468 TEST(PrintToStringTest, WorksForPointerToConstChar) {
01469   const char* p = "hello";
01470   EXPECT_PRINT_TO_STRING_(p, "\"hello\"");
01471 }
01472 
01473 TEST(PrintToStringTest, WorksForPointerToNonConstChar) {
01474   char s[] = "hello";
01475   char* p = s;
01476   EXPECT_PRINT_TO_STRING_(p, "\"hello\"");
01477 }
01478 
01479 TEST(PrintToStringTest, EscapesForPointerToConstChar) {
01480   const char* p = "hello\n";
01481   EXPECT_PRINT_TO_STRING_(p, "\"hello\\n\"");
01482 }
01483 
01484 TEST(PrintToStringTest, EscapesForPointerToNonConstChar) {
01485   char s[] = "hello\1";
01486   char* p = s;
01487   EXPECT_PRINT_TO_STRING_(p, "\"hello\\x1\"");
01488 }
01489 
01490 TEST(PrintToStringTest, WorksForArray) {
01491   int n[3] = { 1, 2, 3 };
01492   EXPECT_PRINT_TO_STRING_(n, "{ 1, 2, 3 }");
01493 }
01494 
01495 TEST(PrintToStringTest, WorksForCharArray) {
01496   char s[] = "hello";
01497   EXPECT_PRINT_TO_STRING_(s, "\"hello\"");
01498 }
01499 
01500 TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
01501   const char str_with_nul[] = "hello\0 world";
01502   EXPECT_PRINT_TO_STRING_(str_with_nul, "\"hello\\0 world\"");
01503 
01504   char mutable_str_with_nul[] = "hello\0 world";
01505   EXPECT_PRINT_TO_STRING_(mutable_str_with_nul, "\"hello\\0 world\"");
01506 }
01507 
01508 #undef EXPECT_PRINT_TO_STRING_
01509 
01510 TEST(UniversalTersePrintTest, WorksForNonReference) {
01511   ::std::stringstream ss;
01512   UniversalTersePrint(123, &ss);
01513   EXPECT_EQ("123", ss.str());
01514 }
01515 
01516 TEST(UniversalTersePrintTest, WorksForReference) {
01517   const int& n = 123;
01518   ::std::stringstream ss;
01519   UniversalTersePrint(n, &ss);
01520   EXPECT_EQ("123", ss.str());
01521 }
01522 
01523 TEST(UniversalTersePrintTest, WorksForCString) {
01524   const char* s1 = "abc";
01525   ::std::stringstream ss1;
01526   UniversalTersePrint(s1, &ss1);
01527   EXPECT_EQ("\"abc\"", ss1.str());
01528 
01529   char* s2 = const_cast<char*>(s1);
01530   ::std::stringstream ss2;
01531   UniversalTersePrint(s2, &ss2);
01532   EXPECT_EQ("\"abc\"", ss2.str());
01533 
01534   const char* s3 = NULL;
01535   ::std::stringstream ss3;
01536   UniversalTersePrint(s3, &ss3);
01537   EXPECT_EQ("NULL", ss3.str());
01538 }
01539 
01540 TEST(UniversalPrintTest, WorksForNonReference) {
01541   ::std::stringstream ss;
01542   UniversalPrint(123, &ss);
01543   EXPECT_EQ("123", ss.str());
01544 }
01545 
01546 TEST(UniversalPrintTest, WorksForReference) {
01547   const int& n = 123;
01548   ::std::stringstream ss;
01549   UniversalPrint(n, &ss);
01550   EXPECT_EQ("123", ss.str());
01551 }
01552 
01553 TEST(UniversalPrintTest, WorksForCString) {
01554   const char* s1 = "abc";
01555   ::std::stringstream ss1;
01556   UniversalPrint(s1, &ss1);
01557   EXPECT_EQ(PrintPointer(s1) + " pointing to \"abc\"", string(ss1.str()));
01558 
01559   char* s2 = const_cast<char*>(s1);
01560   ::std::stringstream ss2;
01561   UniversalPrint(s2, &ss2);
01562   EXPECT_EQ(PrintPointer(s2) + " pointing to \"abc\"", string(ss2.str()));
01563 
01564   const char* s3 = NULL;
01565   ::std::stringstream ss3;
01566   UniversalPrint(s3, &ss3);
01567   EXPECT_EQ("NULL", ss3.str());
01568 }
01569 
01570 TEST(UniversalPrintTest, WorksForCharArray) {
01571   const char str[] = "\"Line\0 1\"\nLine 2";
01572   ::std::stringstream ss1;
01573   UniversalPrint(str, &ss1);
01574   EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss1.str());
01575 
01576   const char mutable_str[] = "\"Line\0 1\"\nLine 2";
01577   ::std::stringstream ss2;
01578   UniversalPrint(mutable_str, &ss2);
01579   EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
01580 }
01581 
01582 #if GTEST_HAS_TR1_TUPLE
01583 
01584 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
01585   Strings result = UniversalTersePrintTupleFieldsToStrings(
01586       ::std::tr1::make_tuple());
01587   EXPECT_EQ(0u, result.size());
01588 }
01589 
01590 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
01591   Strings result = UniversalTersePrintTupleFieldsToStrings(
01592       ::std::tr1::make_tuple(1));
01593   ASSERT_EQ(1u, result.size());
01594   EXPECT_EQ("1", result[0]);
01595 }
01596 
01597 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
01598   Strings result = UniversalTersePrintTupleFieldsToStrings(
01599       ::std::tr1::make_tuple(1, 'a'));
01600   ASSERT_EQ(2u, result.size());
01601   EXPECT_EQ("1", result[0]);
01602   EXPECT_EQ("'a' (97, 0x61)", result[1]);
01603 }
01604 
01605 TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
01606   const int n = 1;
01607   Strings result = UniversalTersePrintTupleFieldsToStrings(
01608       ::std::tr1::tuple<const int&, const char*>(n, "a"));
01609   ASSERT_EQ(2u, result.size());
01610   EXPECT_EQ("1", result[0]);
01611   EXPECT_EQ("\"a\"", result[1]);
01612 }
01613 
01614 #endif  // GTEST_HAS_TR1_TUPLE
01615 
01616 #if GTEST_HAS_STD_TUPLE_
01617 
01618 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
01619   Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
01620   EXPECT_EQ(0u, result.size());
01621 }
01622 
01623 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsOneTuple) {
01624   Strings result = UniversalTersePrintTupleFieldsToStrings(
01625       ::std::make_tuple(1));
01626   ASSERT_EQ(1u, result.size());
01627   EXPECT_EQ("1", result[0]);
01628 }
01629 
01630 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTwoTuple) {
01631   Strings result = UniversalTersePrintTupleFieldsToStrings(
01632       ::std::make_tuple(1, 'a'));
01633   ASSERT_EQ(2u, result.size());
01634   EXPECT_EQ("1", result[0]);
01635   EXPECT_EQ("'a' (97, 0x61)", result[1]);
01636 }
01637 
01638 TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
01639   const int n = 1;
01640   Strings result = UniversalTersePrintTupleFieldsToStrings(
01641       ::std::tuple<const int&, const char*>(n, "a"));
01642   ASSERT_EQ(2u, result.size());
01643   EXPECT_EQ("1", result[0]);
01644   EXPECT_EQ("\"a\"", result[1]);
01645 }
01646 
01647 #endif  // GTEST_HAS_STD_TUPLE_
01648 
01649 }  // namespace gtest_printers_test
01650 }  // namespace testing
01651 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:03