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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 *os << (x ? "true" : "false"); | 395 *os << (x ? "true" : "false"); |
396 } | 396 } |
397 | 397 |
398 // Overload for wchar_t type. | 398 // Overload for wchar_t type. |
399 // Prints a wchar_t as a symbol if it is printable or as its internal | 399 // Prints a wchar_t as a symbol if it is printable or as its internal |
400 // code otherwise and also as its decimal code (except for L'\0'). | 400 // code otherwise and also as its decimal code (except for L'\0'). |
401 // The L'\0' char is printed as "L'\\0'". The decimal code is printed | 401 // The L'\0' char is printed as "L'\\0'". The decimal code is printed |
402 // as signed integer when wchar_t is implemented by the compiler | 402 // as signed integer when wchar_t is implemented by the compiler |
403 // as a signed type and is printed as an unsigned integer when wchar_t | 403 // as a signed type and is printed as an unsigned integer when wchar_t |
404 // is implemented as an unsigned type. | 404 // is implemented as an unsigned type. |
| 405 #if GTEST_HAS_WCHAR |
405 GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os); | 406 GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os); |
| 407 #endif // GTEST_HAS_WCHAR |
406 | 408 |
407 // Overloads for C strings. | 409 // Overloads for C strings. |
408 GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); | 410 GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); |
409 inline void PrintTo(char* s, ::std::ostream* os) { | 411 inline void PrintTo(char* s, ::std::ostream* os) { |
410 PrintTo(ImplicitCast_<const char*>(s), os); | 412 PrintTo(ImplicitCast_<const char*>(s), os); |
411 } | 413 } |
412 | 414 |
413 // signed/unsigned char is often used for representing binary data, so | 415 // signed/unsigned char is often used for representing binary data, so |
414 // we print pointers to it as void* to be safe. | 416 // we print pointers to it as void* to be safe. |
415 inline void PrintTo(const signed char* s, ::std::ostream* os) { | 417 inline void PrintTo(const signed char* s, ::std::ostream* os) { |
416 PrintTo(ImplicitCast_<const void*>(s), os); | 418 PrintTo(ImplicitCast_<const void*>(s), os); |
417 } | 419 } |
418 inline void PrintTo(signed char* s, ::std::ostream* os) { | 420 inline void PrintTo(signed char* s, ::std::ostream* os) { |
419 PrintTo(ImplicitCast_<const void*>(s), os); | 421 PrintTo(ImplicitCast_<const void*>(s), os); |
420 } | 422 } |
421 inline void PrintTo(const unsigned char* s, ::std::ostream* os) { | 423 inline void PrintTo(const unsigned char* s, ::std::ostream* os) { |
422 PrintTo(ImplicitCast_<const void*>(s), os); | 424 PrintTo(ImplicitCast_<const void*>(s), os); |
423 } | 425 } |
424 inline void PrintTo(unsigned char* s, ::std::ostream* os) { | 426 inline void PrintTo(unsigned char* s, ::std::ostream* os) { |
425 PrintTo(ImplicitCast_<const void*>(s), os); | 427 PrintTo(ImplicitCast_<const void*>(s), os); |
426 } | 428 } |
427 | 429 |
428 // MSVC can be configured to define wchar_t as a typedef of unsigned | 430 // MSVC can be configured to define wchar_t as a typedef of unsigned |
429 // short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native | 431 // short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native |
430 // type. When wchar_t is a typedef, defining an overload for const | 432 // type. When wchar_t is a typedef, defining an overload for const |
431 // wchar_t* would cause unsigned short* be printed as a wide string, | 433 // wchar_t* would cause unsigned short* be printed as a wide string, |
432 // possibly causing invalid memory accesses. | 434 // possibly causing invalid memory accesses. |
433 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) | 435 #if GTEST_HAS_WCHAR && (!defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)) |
434 // Overloads for wide C strings | 436 // Overloads for wide C strings |
435 GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os); | 437 GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os); |
436 inline void PrintTo(wchar_t* s, ::std::ostream* os) { | 438 inline void PrintTo(wchar_t* s, ::std::ostream* os) { |
437 PrintTo(ImplicitCast_<const wchar_t*>(s), os); | 439 PrintTo(ImplicitCast_<const wchar_t*>(s), os); |
438 } | 440 } |
439 #endif | 441 #endif |
440 | 442 |
441 // Overload for C arrays. Multi-dimensional arrays are printed | 443 // Overload for C arrays. Multi-dimensional arrays are printed |
442 // properly. | 444 // properly. |
443 | 445 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 template <typename T> | 792 template <typename T> |
791 ::std::string PrintToString(const T& value) { | 793 ::std::string PrintToString(const T& value) { |
792 ::std::stringstream ss; | 794 ::std::stringstream ss; |
793 internal::UniversalTersePrint(value, &ss); | 795 internal::UniversalTersePrint(value, &ss); |
794 return ss.str(); | 796 return ss.str(); |
795 } | 797 } |
796 | 798 |
797 } // namespace testing | 799 } // namespace testing |
798 | 800 |
799 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ | 801 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ |
OLD | NEW |