31 #include <google/protobuf/any_test.pb.h>
32 #include <google/protobuf/unittest.pb.h>
41 TEST(AnyTest, TestPackAndUnpack) {
42 protobuf_unittest::TestAny submessage;
43 submessage.set_int32_value(12345);
44 protobuf_unittest::TestAny
message;
45 message.mutable_any_value()->PackFrom(submessage);
53 EXPECT_EQ(12345, submessage.int32_value());
56 TEST(AnyTest, TestUnpackWithTypeMismatch) {
57 protobuf_unittest::TestAny payload;
58 payload.set_int32_value(13);
63 protobuf_unittest::TestAllTypes
dest;
67 TEST(AnyTest, TestPackAndUnpackAny) {
69 protobuf_unittest::TestAny submessage;
70 submessage.set_int32_value(12345);
73 protobuf_unittest::TestAny
message;
74 message.mutable_any_value()->PackFrom(any);
84 EXPECT_EQ(12345, submessage.int32_value());
87 TEST(AnyTest, TestPackWithCustomTypeUrl) {
88 protobuf_unittest::TestAny submessage;
89 submessage.set_int32_value(12345);
92 any.
PackFrom(submessage,
"type.myservice.com");
93 EXPECT_EQ(
"type.myservice.com/protobuf_unittest.TestAny", any.type_url());
95 any.PackFrom(submessage,
"type.myservice.com/");
96 EXPECT_EQ(
"type.myservice.com/protobuf_unittest.TestAny", any.type_url());
98 any.PackFrom(submessage,
"");
99 EXPECT_EQ(
"/protobuf_unittest.TestAny", any.type_url());
104 EXPECT_EQ(12345, submessage.int32_value());
107 TEST(AnyTest, TestIs) {
108 protobuf_unittest::TestAny submessage;
109 submessage.set_int32_value(12345);
112 ASSERT_TRUE(any.ParseFromString(any.SerializeAsString()));
116 protobuf_unittest::TestAny
message;
117 message.mutable_any_value()->PackFrom(any);
122 any.set_type_url(
"/protobuf_unittest.TestAny");
125 any.set_type_url(
"protobuf_unittest.TestAny");
128 any.set_type_url(
"/TestAny");
132 TEST(AnyTest, MoveConstructor) {
133 protobuf_unittest::TestAny payload;
134 payload.set_int32_value(12345);
137 src.PackFrom(payload);
148 TEST(AnyTest, MoveAssignment) {
149 protobuf_unittest::TestAny payload;
150 payload.set_int32_value(12345);
153 src.PackFrom(payload);