diff options
| author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-08-14 04:50:02 +0000 |
|---|---|---|
| committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-08-14 04:50:02 +0000 |
| commit | 0ea67f88aea208e7ef13c91b374b352679beab38 (patch) | |
| tree | 86cd0753aeb1d884472594283499fa5bc8fabf3f /include | |
| parent | 9571b28675a5a602ed3c8a7acf270d03aca69c96 (diff) | |
| download | googletest-0ea67f88aea208e7ef13c91b374b352679beab38.tar.gz googletest-0ea67f88aea208e7ef13c91b374b352679beab38.tar.bz2 googletest-0ea67f88aea208e7ef13c91b374b352679beab38.zip | |
Improves protobuf print format.
Diffstat (limited to 'include')
| -rw-r--r-- | include/gmock/gmock-printers.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/include/gmock/gmock-printers.h b/include/gmock/gmock-printers.h index 561de3d9..69eee120 100644 --- a/include/gmock/gmock-printers.h +++ b/include/gmock/gmock-printers.h @@ -129,14 +129,21 @@ class TypeWithoutFormatter { sizeof(value), os); } }; + +// We print a protobuf using its ShortDebugString() when the string +// doesn't exceed this many characters; otherwise we print it using +// DebugString() for better readability. +const size_t kProtobufOneLinerMaxLength = 50; + template <typename T> class TypeWithoutFormatter<T, true> { public: static void PrintValue(const T& value, ::std::ostream* os) { - // Both ProtocolMessage and proto2::Message have the - // ShortDebugString() method, so the same implementation works for - // both. - ::std::operator<<(*os, "<" + value.ShortDebugString() + ">"); + const ::testing::internal::string short_str = value.ShortDebugString(); + const ::testing::internal::string pretty_str = + short_str.length() <= kProtobufOneLinerMaxLength ? + short_str : ("\n" + value.DebugString()); + ::std::operator<<(*os, "<" + pretty_str + ">"); } }; |
