31 #include <google/protobuf/any_test.pb.h>
32 #include <google/protobuf/unittest.pb.h>
33 #include <gtest/gtest.h>
37 #include <google/protobuf/port_def.inc>
43 TEST(AnyMetadataTest, ConstInit) {
44 PROTOBUF_CONSTINIT
static internal::AnyMetadata
metadata(
nullptr,
nullptr);
48 TEST(AnyTest, TestPackAndUnpack) {
49 protobuf_unittest::TestAny submessage;
50 submessage.set_int32_value(12345);
51 protobuf_unittest::TestAny
message;
60 EXPECT_EQ(12345, submessage.int32_value());
63 TEST(AnyTest, TestPackFromSerializationExceedsSizeLimit) {
64 protobuf_unittest::TestAny submessage;
65 submessage.mutable_text()->resize(INT_MAX,
'a');
66 protobuf_unittest::TestAny
message;
70 TEST(AnyTest, TestUnpackWithTypeMismatch) {
71 protobuf_unittest::TestAny
payload;
77 protobuf_unittest::TestAllTypes
dest;
81 TEST(AnyTest, TestPackAndUnpackAny) {
83 protobuf_unittest::TestAny submessage;
84 submessage.set_int32_value(12345);
87 protobuf_unittest::TestAny
message;
88 message.mutable_any_value()->PackFrom(any);
98 EXPECT_EQ(12345, submessage.int32_value());
101 TEST(AnyTest, TestPackWithCustomTypeUrl) {
102 protobuf_unittest::TestAny submessage;
103 submessage.set_int32_value(12345);
106 any.
PackFrom(submessage,
"type.myservice.com");
107 EXPECT_EQ(
"type.myservice.com/protobuf_unittest.TestAny", any.type_url());
109 any.PackFrom(submessage,
"type.myservice.com/");
110 EXPECT_EQ(
"type.myservice.com/protobuf_unittest.TestAny", any.type_url());
112 any.PackFrom(submessage,
"");
113 EXPECT_EQ(
"/protobuf_unittest.TestAny", any.type_url());
118 EXPECT_EQ(12345, submessage.int32_value());
121 TEST(AnyTest, TestIs) {
122 protobuf_unittest::TestAny submessage;
123 submessage.set_int32_value(12345);
126 ASSERT_TRUE(any.ParseFromString(any.SerializeAsString()));
130 protobuf_unittest::TestAny
message;
131 message.mutable_any_value()->PackFrom(any);
136 any.set_type_url(
"/protobuf_unittest.TestAny");
139 any.set_type_url(
"protobuf_unittest.TestAny");
142 any.set_type_url(
"/TestAny");
146 TEST(AnyTest, MoveConstructor) {
147 protobuf_unittest::TestAny
payload;
148 payload.set_int32_value(12345);
153 const char*
type_url = src.type_url().data();
162 TEST(AnyTest, MoveAssignment) {
163 protobuf_unittest::TestAny
payload;
164 payload.set_int32_value(12345);
169 const char*
type_url = src.type_url().data();
184 #include <google/protobuf/port_undef.inc>