aboutsummaryrefslogtreecommitdiffstats
path: root/test/gmock-actions_test.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2009-05-13 23:38:40 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2009-05-13 23:38:40 +0000
commitc6a412397bc98f120d5e79d4a64e3972854b5af3 (patch)
treef36e9c70faf270aa9f4516110345e01778088e87 /test/gmock-actions_test.cc
parent18490653e80d484b4650d8799184fd1e021efc7b (diff)
downloadgoogletest-c6a412397bc98f120d5e79d4a64e3972854b5af3.tar.gz
googletest-c6a412397bc98f120d5e79d4a64e3972854b5af3.tar.bz2
googletest-c6a412397bc98f120d5e79d4a64e3972854b5af3.zip
Adds more tests for using SetArgumentPointee with protobufs; works around a compiler bug on Symbian that gmock-printers.h triggers; reduces template code bloat in gmock-matchers.h; avoids RTTI when it's disabled.
Diffstat (limited to 'test/gmock-actions_test.cc')
-rw-r--r--test/gmock-actions_test.cc64
1 files changed, 56 insertions, 8 deletions
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc
index e4939e1a..24462609 100644
--- a/test/gmock-actions_test.cc
+++ b/test/gmock-actions_test.cc
@@ -646,16 +646,15 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
#if GMOCK_HAS_PROTOBUF_
-// Tests that SetArgumentPointee<N>(proto_buffer) sets the variable
-// pointed to by the N-th (0-based) argument to proto_buffer.
+// Tests that SetArgumentPointee<N>(proto_buffer) sets the v1 protobuf
+// variable pointed to by the N-th (0-based) argument to proto_buffer.
TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferType) {
- typedef void MyFunction(bool, TestMessage*);
TestMessage* const msg = new TestMessage;
msg->set_member("yes");
TestMessage orig_msg;
orig_msg.CopyFrom(*msg);
- Action<MyFunction> a = SetArgumentPointee<1>(*msg);
+ Action<void(bool, TestMessage*)> a = SetArgumentPointee<1>(*msg);
// SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
@@ -668,18 +667,41 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferType) {
EXPECT_TRUE(orig_msg.Equals(dest));
}
-// Tests that SetArgumentPointee<N>(proto2_buffer) sets the variable
-// pointed to by the N-th (0-based) argument to proto2_buffer.
+// Tests that SetArgumentPointee<N>(proto_buffer) sets the
+// ::ProtocolMessage variable pointed to by the N-th (0-based)
+// argument to proto_buffer.
+TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferBaseType) {
+ TestMessage* const msg = new TestMessage;
+ msg->set_member("yes");
+ TestMessage orig_msg;
+ orig_msg.CopyFrom(*msg);
+
+ Action<void(bool, ::ProtocolMessage*)> a = SetArgumentPointee<1>(*msg);
+ // SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
+ // s.t. the action works even when the original proto_buffer has
+ // died. We ensure this behavior by deleting msg before using the
+ // action.
+ delete msg;
+
+ TestMessage dest;
+ ::ProtocolMessage* const dest_base = &dest;
+ EXPECT_FALSE(orig_msg.Equals(dest));
+ a.Perform(make_tuple(true, dest_base));
+ EXPECT_TRUE(orig_msg.Equals(dest));
+}
+
+// Tests that SetArgumentPointee<N>(proto2_buffer) sets the v2
+// protobuf variable pointed to by the N-th (0-based) argument to
+// proto2_buffer.
TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferType) {
using testing::internal::FooMessage;
- typedef void MyFunction(bool, FooMessage*);
FooMessage* const msg = new FooMessage;
msg->set_int_field(2);
msg->set_string_field("hi");
FooMessage orig_msg;
orig_msg.CopyFrom(*msg);
- Action<MyFunction> a = SetArgumentPointee<1>(*msg);
+ Action<void(bool, FooMessage*)> a = SetArgumentPointee<1>(*msg);
// SetArgumentPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
@@ -693,6 +715,32 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferType) {
EXPECT_EQ("hi", dest.string_field());
}
+// Tests that SetArgumentPointee<N>(proto2_buffer) sets the
+// proto2::Message variable pointed to by the N-th (0-based) argument
+// to proto2_buffer.
+TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) {
+ using testing::internal::FooMessage;
+ FooMessage* const msg = new FooMessage;
+ msg->set_int_field(2);
+ msg->set_string_field("hi");
+ FooMessage orig_msg;
+ orig_msg.CopyFrom(*msg);
+
+ Action<void(bool, ::proto2::Message*)> a = SetArgumentPointee<1>(*msg);
+ // SetArgumentPointee<N>(proto2_buffer) makes a copy of
+ // proto2_buffer s.t. the action works even when the original
+ // proto2_buffer has died. We ensure this behavior by deleting msg
+ // before using the action.
+ delete msg;
+
+ FooMessage dest;
+ dest.set_int_field(0);
+ ::proto2::Message* const dest_base = &dest;
+ a.Perform(make_tuple(true, dest_base));
+ EXPECT_EQ(2, dest.int_field());
+ EXPECT_EQ("hi", dest.string_field());
+}
+
#endif // GMOCK_HAS_PROTOBUF_
// Tests that SetArrayArgument<N>(first, last) sets the elements of the array