summaryrefslogtreecommitdiffstats
path: root/include/gtest/gtest-printers.h
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-07-21 22:15:17 (GMT)
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-07-21 22:15:17 (GMT)
commite2a7f03b80fc0e9e6a6f36acb43776509486a6d4 (patch)
tree650c7033b14cd54fa03d46100e314ef141a3f492 /include/gtest/gtest-printers.h
parent447ed6474deca82844b211e57503579ab1c560f0 (diff)
downloadgoogletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.zip
googletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.tar.gz
googletest-e2a7f03b80fc0e9e6a6f36acb43776509486a6d4.tar.bz2
Allows EXPECT_EQ to accept arguments that don't have operator << (by Zhanyong Wan).
Allows a user to customize how the universal printer prints a pointer of a specific type by overloading << (by Zhanyong Wan). Works around a bug in Cymbian's C++ compiler (by Vlad Losev).
Diffstat (limited to 'include/gtest/gtest-printers.h')
-rw-r--r--include/gtest/gtest-printers.h47
1 files changed, 34 insertions, 13 deletions
diff --git a/include/gtest/gtest-printers.h b/include/gtest/gtest-printers.h
index 0466c9c..0676269 100644
--- a/include/gtest/gtest-printers.h
+++ b/include/gtest/gtest-printers.h
@@ -280,12 +280,23 @@ void DefaultPrintTo(IsNotContainer /* dummy */,
if (p == NULL) {
*os << "NULL";
} else {
- // We want to print p as a const void*. However, we cannot cast
- // it to const void* directly, even using reinterpret_cast, as
- // earlier versions of gcc (e.g. 3.4.5) cannot compile the cast
- // when p is a function pointer. Casting to UInt64 first solves
- // the problem.
- *os << reinterpret_cast<const void*>(reinterpret_cast<internal::UInt64>(p));
+ // C++ doesn't allow casting from a function pointer to any object
+ // pointer.
+ if (ImplicitlyConvertible<T*, const void*>::value) {
+ // T is not a function type. We just call << to print p,
+ // relying on ADL to pick up user-defined << for their pointer
+ // types, if any.
+ *os << p;
+ } else {
+ // T is a function type, so '*os << p' doesn't do what we want
+ // (it just prints p as bool). We want to print p as a const
+ // void*. However, we cannot cast it to const void* directly,
+ // even using reinterpret_cast, as earlier versions of gcc
+ // (e.g. 3.4.5) cannot compile the cast when p is a function
+ // pointer. Casting to UInt64 first solves the problem.
+ *os << reinterpret_cast<const void*>(
+ reinterpret_cast<internal::UInt64>(p));
+ }
}
}
@@ -341,13 +352,8 @@ void PrintTo(const T& value, ::std::ostream* os) {
// types, strings, plain arrays, and pointers).
// Overloads for various char types.
-GTEST_API_ void PrintCharTo(char c, int char_code, ::std::ostream* os);
-inline void PrintTo(unsigned char c, ::std::ostream* os) {
- PrintCharTo(c, c, os);
-}
-inline void PrintTo(signed char c, ::std::ostream* os) {
- PrintCharTo(c, c, os);
-}
+GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
+GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
inline void PrintTo(char c, ::std::ostream* os) {
// When printing a plain char, we always treat it as unsigned. This
// way, the output won't be affected by whether the compiler thinks
@@ -375,6 +381,21 @@ inline void PrintTo(char* s, ::std::ostream* os) {
PrintTo(implicit_cast<const char*>(s), os);
}
+// signed/unsigned char is often used for representing binary data, so
+// we print pointers to it as void* to be safe.
+inline void PrintTo(const signed char* s, ::std::ostream* os) {
+ PrintTo(implicit_cast<const void*>(s), os);
+}
+inline void PrintTo(signed char* s, ::std::ostream* os) {
+ PrintTo(implicit_cast<const void*>(s), os);
+}
+inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
+ PrintTo(implicit_cast<const void*>(s), os);
+}
+inline void PrintTo(unsigned char* s, ::std::ostream* os) {
+ PrintTo(implicit_cast<const void*>(s), os);
+}
+
// MSVC can be configured to define wchar_t as a typedef of unsigned
// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
// type. When wchar_t is a typedef, defining an overload for const