Improves protobuf print format.

This commit is contained in:
zhanyong.wan
2009-08-14 04:50:02 +00:00
parent 9571b28675
commit 0ea67f88ae
3 changed files with 40 additions and 7 deletions

View File

@@ -48,6 +48,12 @@
#include <sys/types.h> // For ssize_t. NOLINT
#endif
class ProtocolMessage;
namespace proto2 {
class Message;
} // namespace proto2
namespace testing {
namespace internal {
@@ -384,6 +390,7 @@ TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
// Tests that IsAProtocolMessage<T>::value is true when T is
// ProtocolMessage or a sub-class of it.
TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
EXPECT_TRUE(IsAProtocolMessage< ::proto2::Message>::value);
EXPECT_TRUE(IsAProtocolMessage<ProtocolMessage>::value);
#if GMOCK_HAS_PROTOBUF_
EXPECT_TRUE(IsAProtocolMessage<const TestMessage>::value);

View File

@@ -919,12 +919,31 @@ TEST(PrintProtocolMessageTest, PrintsShortDebugString) {
EXPECT_EQ("<member:\"yes\">", Print(msg));
}
// Tests printing a proto2 message.
TEST(PrintProto2MessageTest, PrintsShortDebugString) {
// Tests printing a short proto2 message.
TEST(PrintProto2MessageTest, PrintsShortDebugStringWhenItIsShort) {
testing::internal::FooMessage msg;
msg.set_int_field(2);
msg.set_string_field("hello");
EXPECT_PRED2(RE::FullMatch, Print(msg),
"<int_field:\\s*2\\s*>");
"<int_field:\\s*2\\s+string_field:\\s*\"hello\">");
}
// Tests printing a long proto2 message.
TEST(PrintProto2MessageTest, PrintsDebugStringWhenItIsLong) {
testing::internal::FooMessage msg;
msg.set_int_field(2);
msg.set_string_field("hello");
msg.add_names("peter");
msg.add_names("paul");
msg.add_names("mary");
EXPECT_PRED2(RE::FullMatch, Print(msg),
"<\n"
"int_field:\\s*2\n"
"string_field:\\s*\"hello\"\n"
"names:\\s*\"peter\"\n"
"names:\\s*\"paul\"\n"
"names:\\s*\"mary\"\n"
">");
}
#endif // GMOCK_HAS_PROTOBUF_