Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
0ea67f88
Commit
0ea67f88
authored
Aug 14, 2009
by
zhanyong.wan
Browse files
Improves protobuf print format.
parent
9571b286
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
7 deletions
+40
-7
include/gmock/gmock-printers.h
include/gmock/gmock-printers.h
+11
-4
test/gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+7
-0
test/gmock-printers_test.cc
test/gmock-printers_test.cc
+22
-3
No files found.
include/gmock/gmock-printers.h
View file @
0ea67f88
...
@@ -129,14 +129,21 @@ class TypeWithoutFormatter {
...
@@ -129,14 +129,21 @@ class TypeWithoutFormatter {
sizeof
(
value
),
os
);
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
>
template
<
typename
T
>
class
TypeWithoutFormatter
<
T
,
true
>
{
class
TypeWithoutFormatter
<
T
,
true
>
{
public:
public:
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
// Both ProtocolMessage and proto2::Message have the
const
::
testing
::
internal
::
string
short_str
=
value
.
ShortDebugString
();
// ShortDebugString() method, so the same implementation works for
const
::
testing
::
internal
::
string
pretty_str
=
// both.
short_str
.
length
()
<=
kProtobufOneLinerMaxLength
?
::
std
::
operator
<<
(
*
os
,
"<"
+
value
.
ShortDebugString
()
+
">"
);
short_str
:
(
"
\n
"
+
value
.
DebugString
());
::
std
::
operator
<<
(
*
os
,
"<"
+
pretty_str
+
">"
);
}
}
};
};
...
...
test/gmock-internal-utils_test.cc
View file @
0ea67f88
...
@@ -48,6 +48,12 @@
...
@@ -48,6 +48,12 @@
#include <sys/types.h> // For ssize_t. NOLINT
#include <sys/types.h> // For ssize_t. NOLINT
#endif
#endif
class
ProtocolMessage
;
namespace
proto2
{
class
Message
;
}
// namespace proto2
namespace
testing
{
namespace
testing
{
namespace
internal
{
namespace
internal
{
...
@@ -384,6 +390,7 @@ TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
...
@@ -384,6 +390,7 @@ TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
// Tests that IsAProtocolMessage<T>::value is true when T is
// Tests that IsAProtocolMessage<T>::value is true when T is
// ProtocolMessage or a sub-class of it.
// ProtocolMessage or a sub-class of it.
TEST
(
IsAProtocolMessageTest
,
ValueIsTrueWhenTypeIsAProtocolMessage
)
{
TEST
(
IsAProtocolMessageTest
,
ValueIsTrueWhenTypeIsAProtocolMessage
)
{
EXPECT_TRUE
(
IsAProtocolMessage
<
::
proto2
::
Message
>::
value
);
EXPECT_TRUE
(
IsAProtocolMessage
<
ProtocolMessage
>::
value
);
EXPECT_TRUE
(
IsAProtocolMessage
<
ProtocolMessage
>::
value
);
#if GMOCK_HAS_PROTOBUF_
#if GMOCK_HAS_PROTOBUF_
EXPECT_TRUE
(
IsAProtocolMessage
<
const
TestMessage
>::
value
);
EXPECT_TRUE
(
IsAProtocolMessage
<
const
TestMessage
>::
value
);
...
...
test/gmock-printers_test.cc
View file @
0ea67f88
...
@@ -919,12 +919,31 @@ TEST(PrintProtocolMessageTest, PrintsShortDebugString) {
...
@@ -919,12 +919,31 @@ TEST(PrintProtocolMessageTest, PrintsShortDebugString) {
EXPECT_EQ
(
"<member:
\"
yes
\"
>"
,
Print
(
msg
));
EXPECT_EQ
(
"<member:
\"
yes
\"
>"
,
Print
(
msg
));
}
}
// Tests printing a proto2 message.
// Tests printing a
short
proto2 message.
TEST
(
PrintProto2MessageTest
,
PrintsShortDebugString
)
{
TEST
(
PrintProto2MessageTest
,
PrintsShortDebugString
WhenItIsShort
)
{
testing
::
internal
::
FooMessage
msg
;
testing
::
internal
::
FooMessage
msg
;
msg
.
set_int_field
(
2
);
msg
.
set_int_field
(
2
);
msg
.
set_string_field
(
"hello"
);
EXPECT_PRED2
(
RE
::
FullMatch
,
Print
(
msg
),
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_
#endif // GMOCK_HAS_PROTOBUF_
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment