diff options
Diffstat (limited to 'include/gmock/gmock-printers.h')
-rw-r--r-- | include/gmock/gmock-printers.h | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/include/gmock/gmock-printers.h b/include/gmock/gmock-printers.h index bbe44c38..6997a6c1 100644 --- a/include/gmock/gmock-printers.h +++ b/include/gmock/gmock-printers.h @@ -211,7 +211,9 @@ class UniversalPrinter; // Used to print an STL-style container when the user doesn't define // a PrintTo() for it. template <typename C> -void DefaultPrintTo(IsContainer, const C& container, ::std::ostream* os) { +void DefaultPrintTo(IsContainer /* dummy */, + false_type /* is not a pointer */, + const C& container, ::std::ostream* os) { const size_t kMaxCount = 32; // The maximum number of elements to print. *os << '{'; size_t count = 0; @@ -234,9 +236,31 @@ void DefaultPrintTo(IsContainer, const C& container, ::std::ostream* os) { *os << '}'; } -// Used to print a value when the user doesn't define PrintTo() for it. +// Used to print a pointer that is neither a char pointer nor a member +// pointer, when the user doesn't define PrintTo() for it. (A member +// variable pointer or member function pointer doesn't really point to +// a location in the address space. Their representation is +// implementation-defined. Therefore they will be printed as raw +// bytes.) template <typename T> -void DefaultPrintTo(IsNotContainer, const T& value, ::std::ostream* os) { +void DefaultPrintTo(IsNotContainer /* dummy */, + true_type /* is a pointer */, + T* p, ::std::ostream* os) { + if (p == NULL) { + *os << "NULL"; + } else { + // We cannot use implicit_cast or static_cast here, as they don't + // work when p is a function pointer. + *os << reinterpret_cast<const void*>(p); + } +} + +// Used to print a non-container, non-pointer value when the user +// doesn't define PrintTo() for it. +template <typename T> +void DefaultPrintTo(IsNotContainer /* dummy */, + false_type /* is not a pointer */, + const T& value, ::std::ostream* os) { ::testing_internal::DefaultPrintNonContainerTo(value, os); } @@ -253,10 +277,11 @@ void DefaultPrintTo(IsNotContainer, const T& value, ::std::ostream* os) { // wants). template <typename T> void PrintTo(const T& value, ::std::ostream* os) { - // DefaultPrintTo() is overloaded. The type of its first argument - // determines which version will be picked. If T is an STL-style - // container, the version for container will be called. Otherwise - // the generic version will be called. + // DefaultPrintTo() is overloaded. The type of its first two + // arguments determine which version will be picked. If T is an + // STL-style container, the version for container will be called; if + // T is a pointer, the pointer version will be called; otherwise the + // generic version will be called. // // Note that we check for container types here, prior to we check // for protocol message types in our operator<<. The rationale is: @@ -267,7 +292,14 @@ void PrintTo(const T& value, ::std::ostream* os) { // incompatible with Google Mock's format for the container // elements; therefore we check for container types here to ensure // that our format is used. - DefaultPrintTo(IsContainerTest<T>(0), value, os); + // + // The second argument of DefaultPrintTo() is needed to bypass a bug + // in Symbian's C++ compiler that prevents it from picking the right + // overload between: + // + // PrintTo(const T& x, ...); + // PrintTo(T* x, ...); + DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os); } // The following list of PrintTo() overloads tells @@ -323,22 +355,6 @@ inline void PrintTo(wchar_t* s, ::std::ostream* os) { } #endif -// Overload for pointers that are neither char pointers nor member -// pointers. (A member variable pointer or member function pointer -// doesn't really points to a location in the address space. Their -// representation is implementation-defined. Therefore they will be -// printed as raw bytes.) -template <typename T> -void PrintTo(T* p, ::std::ostream* os) { - if (p == NULL) { - *os << "NULL"; - } else { - // We cannot use implicit_cast or static_cast here, as they don't - // work when p is a function pointer. - *os << reinterpret_cast<const void*>(p); - } -} - // Overload for C arrays. Multi-dimensional arrays are printed // properly. |