33 #include <google/protobuf/text_format.h>
34 #include <google/protobuf/wire_format_lite.h>
35 #include <google/protobuf/util/json_util.h>
36 #include <google/protobuf/util/type_resolver_util.h>
37 #include "third_party/jsoncpp/json.h"
39 #include <google/protobuf/test_messages_proto2.pb.h>
40 #include <google/protobuf/test_messages_proto3.pb.h>
41 #include <google/protobuf/stubs/status.h>
43 namespace proto2_messages = protobuf_test_messages::proto2;
45 using conformance::ConformanceRequest;
46 using conformance::ConformanceResponse;
47 using conformance::WireFormat;
54 using proto2_messages::TestAllTypesProto2;
55 using protobuf_test_messages::proto3::TestAllTypesProto3;
73 string cat(
const string&
a,
const string&
b,
76 const string& e =
empty,
79 const string& h =
empty,
81 const string& j =
empty,
85 ret.reserve(
a.size() +
b.size() +
c.size() +
d.size() +
e.size() +
f.size() +
86 g.size() +
h.size() +
i.size() +
j.size() +
k.size() +
l.size());
103 #define VARINT_MAX_LEN 10
105 size_t vencode64(
uint64_t val,
int over_encoded_bytes,
char *
buf) {
106 if (val == 0) {
buf[0] = 0;
return 1; }
111 if (val || over_encoded_bytes)
byte |= 0x80U;
114 while (over_encoded_bytes--) {
116 uint8_t byte = over_encoded_bytes ? 0x80 : 0;
124 size_t len = vencode64(
x, 0,
buf);
130 string longvarint(
uint64_t x,
int extra) {
132 size_t len = vencode64(
x, extra,
buf);
137 string fixed32(
void *
data) {
return string(
static_cast<char*
>(
data), 4); }
138 string fixed64(
void *
data) {
return string(
static_cast<char*
>(
data), 8); }
140 string delim(
const string&
buf) {
return cat(varint(
buf.size()),
buf); }
141 string u32(
uint32_t u32) {
return fixed32(&u32); }
142 string u64(
uint64_t u64) {
return fixed64(&u64); }
143 string flt(
float f) {
return fixed32(&
f); }
144 string dbl(
double d) {
return fixed64(&
d); }
149 return varint((fieldnum << 3) | wire_type);
154 case FieldDescriptor::TYPE_INT32:
155 case FieldDescriptor::TYPE_INT64:
156 case FieldDescriptor::TYPE_UINT32:
157 case FieldDescriptor::TYPE_UINT64:
158 case FieldDescriptor::TYPE_ENUM:
159 case FieldDescriptor::TYPE_BOOL:
161 case FieldDescriptor::TYPE_SINT32:
163 case FieldDescriptor::TYPE_SINT64:
165 case FieldDescriptor::TYPE_FIXED32:
166 case FieldDescriptor::TYPE_SFIXED32:
168 case FieldDescriptor::TYPE_FIXED64:
169 case FieldDescriptor::TYPE_SFIXED64:
171 case FieldDescriptor::TYPE_FLOAT:
173 case FieldDescriptor::TYPE_DOUBLE:
175 case FieldDescriptor::TYPE_STRING:
176 case FieldDescriptor::TYPE_BYTES:
177 case FieldDescriptor::TYPE_MESSAGE:
187 case FieldDescriptor::TYPE_INT32:
188 case FieldDescriptor::TYPE_INT64:
189 case FieldDescriptor::TYPE_UINT32:
190 case FieldDescriptor::TYPE_UINT64:
191 case FieldDescriptor::TYPE_ENUM:
192 case FieldDescriptor::TYPE_BOOL:
194 case FieldDescriptor::TYPE_SINT32:
196 case FieldDescriptor::TYPE_SINT64:
198 case FieldDescriptor::TYPE_FIXED32:
199 case FieldDescriptor::TYPE_SFIXED32:
201 case FieldDescriptor::TYPE_FIXED64:
202 case FieldDescriptor::TYPE_SFIXED64:
204 case FieldDescriptor::TYPE_FLOAT:
206 case FieldDescriptor::TYPE_DOUBLE:
208 case FieldDescriptor::TYPE_STRING:
209 case FieldDescriptor::TYPE_BYTES:
211 case FieldDescriptor::TYPE_MESSAGE:
219 #define UNKNOWN_FIELD 666
229 Packed packed = Packed::kUnspecified) {
231 TestAllTypesProto3().GetDescriptor() : TestAllTypesProto2().GetDescriptor();
232 for (
int i = 0;
i <
d->field_count();
i++) {
235 if ((packed == Packed::kTrue && !
f->is_packed()) ||
236 (packed == Packed::kFalse &&
f->is_packed())) {
243 string packed_string =
"";
244 const string repeated_string =
repeated ?
"Repeated " :
"Singular ";
245 const string proto_string = is_proto3 ?
"Proto3" :
"Proto2";
246 if (packed == Packed::kTrue) {
247 packed_string =
"Packed ";
249 if (packed == Packed::kFalse) {
250 packed_string =
"Unpacked ";
252 GOOGLE_LOG(
FATAL) <<
"Couldn't find field with type: " << repeated_string.c_str()
254 <<
" for " << proto_string.c_str();
261 const Descriptor*
d = is_proto3 ? TestAllTypesProto3().GetDescriptor()
262 : TestAllTypesProto2().GetDescriptor();
263 for (
int i = 0;
i <
d->field_count();
i++) {
275 const string proto_string = is_proto3 ?
"Proto3" :
"Proto2";
279 << proto_string.c_str();
285 bool exclusive =
false) {
286 const Descriptor*
d = is_proto3 ? TestAllTypesProto3().GetDescriptor()
287 : TestAllTypesProto2().GetDescriptor();
288 for (
int i = 0;
i <
d->field_count();
i++) {
290 if (
f->containing_oneof() && ((
f->type() ==
type) ^ exclusive)) {
295 const string proto_string = is_proto3 ?
"Proto3" :
"Proto2";
298 << proto_string.c_str();
302 string UpperCase(
string str) {
303 for (
size_t i = 0;
i <
str.size();
i++) {
309 std::unique_ptr<Message> NewTestMessage(
bool is_proto3) {
310 std::unique_ptr<Message> prototype;
312 prototype.reset(
new TestAllTypesProto3());
314 prototype.reset(
new TestAllTypesProto2());
321 case FieldDescriptor::TYPE_DOUBLE:
322 return binary_data == dbl(0);
323 case FieldDescriptor::TYPE_FLOAT:
324 return binary_data == flt(0);
325 case FieldDescriptor::TYPE_BOOL:
326 case FieldDescriptor::TYPE_INT64:
327 case FieldDescriptor::TYPE_UINT64:
328 case FieldDescriptor::TYPE_INT32:
329 case FieldDescriptor::TYPE_UINT32:
330 case FieldDescriptor::TYPE_SINT32:
331 case FieldDescriptor::TYPE_SINT64:
332 case FieldDescriptor::TYPE_ENUM:
333 return binary_data == varint(0);
334 case FieldDescriptor::TYPE_FIXED64:
335 case FieldDescriptor::TYPE_SFIXED64:
336 return binary_data == u64(0);
337 case FieldDescriptor::TYPE_FIXED32:
338 case FieldDescriptor::TYPE_SFIXED32:
339 return binary_data == u32(0);
340 case FieldDescriptor::TYPE_STRING:
341 case FieldDescriptor::TYPE_BYTES:
342 return binary_data == delim(
"");
354 const ConformanceResponse&
response,
356 string binary_protobuf;
359 response.json_payload(), &binary_protobuf);
366 GOOGLE_LOG(
FATAL) <<
"INTERNAL ERROR: internal JSON->protobuf transcode "
367 <<
"yielded unparseable proto.";
375 const ConformanceResponse&
response,
376 const ConformanceRequestSetting& setting,
378 const ConformanceRequest&
request = setting.GetRequest();
379 WireFormat requested_output =
request.requested_output_format();
380 const string& test_name = setting.GetTestName();
384 case ConformanceResponse::kProtobufPayload: {
385 if (requested_output != conformance::PROTOBUF) {
387 StrCat(
"Test was asked for ",
389 " output but provided PROTOBUF instead.")
396 "Protobuf output we received from test was unparseable.");
403 case ConformanceResponse::kJsonPayload: {
404 if (requested_output != conformance::JSON) {
406 StrCat(
"Test was asked for ",
408 " output but provided JSON instead.")
415 "JSON output we received from test was unparseable.");
424 <<
": unknown payload type: " <<
response.result_case();
431 const string& proto,
const string& test_name, ConformanceLevel
level,
433 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
436 ConformanceRequestSetting setting(
437 level, conformance::PROTOBUF, conformance::PROTOBUF,
438 conformance::BINARY_TEST,
439 *prototype, test_name, proto);
441 const ConformanceRequest&
request = setting.GetRequest();
443 string effective_test_name =
StrCat(
444 setting.ConformanceLevelToString(
level),
445 (is_proto3 ?
".Proto3" :
".Proto2"),
".ProtobufInput.", test_name);
450 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
454 "Should have failed to parse, but didn't.");
460 const string& proto,
const string& test_name, ConformanceLevel
level) {
471 const string& proto,
const string& test_name, ConformanceLevel
level) {
476 const string& test_name, ConformanceLevel
level,
const string& input_json,
477 const string& equivalent_text_format) {
478 TestAllTypesProto3 prototype;
479 ConformanceRequestSetting setting1(
480 level, conformance::JSON, conformance::PROTOBUF,
481 conformance::JSON_TEST,
482 prototype, test_name, input_json);
484 ConformanceRequestSetting setting2(
485 level, conformance::JSON, conformance::JSON,
486 conformance::JSON_TEST,
487 prototype, test_name, input_json);
492 const string& test_name, ConformanceLevel
level,
const TestAllTypesProto3&
input,
493 const string& equivalent_text_format) {
494 ConformanceRequestSetting setting(
495 level, conformance::PROTOBUF, conformance::JSON,
496 conformance::JSON_TEST,
502 const string& test_name, ConformanceLevel
level,
const string& input_json,
503 const string& equivalent_text_format) {
504 TestAllTypesProto3 prototype;
505 ConformanceRequestSetting setting(
506 level, conformance::JSON, conformance::PROTOBUF,
507 conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST,
508 prototype, test_name, input_json);
513 const string& test_name, ConformanceLevel
level,
514 const string& input_protobuf,
const string& equivalent_text_format,
516 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
518 ConformanceRequestSetting setting1(
519 level, conformance::PROTOBUF, conformance::PROTOBUF,
520 conformance::BINARY_TEST,
521 *prototype, test_name, input_protobuf);
525 ConformanceRequestSetting setting2(
526 level, conformance::PROTOBUF, conformance::JSON,
527 conformance::BINARY_TEST,
528 *prototype, test_name, input_protobuf);
534 const string& test_name, ConformanceLevel
level,
535 const string& input_protobuf,
bool is_proto3) {
541 const string& test_name, ConformanceLevel
level,
542 const string& input_protobuf,
const string& expected_protobuf,
544 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
545 ConformanceRequestSetting setting(
546 level, conformance::PROTOBUF, conformance::PROTOBUF,
547 conformance::BINARY_TEST,
548 *prototype, test_name, input_protobuf);
554 const string& equivalent_text_format,
bool is_proto3) {
556 equivalent_text_format, is_proto3);
565 const string& test_name, ConformanceLevel
level,
const string& input_json,
567 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
568 ConformanceRequestSetting setting(
level, conformance::JSON, conformance::JSON,
569 conformance::JSON_TEST, *prototype,
570 test_name, input_json);
571 const ConformanceRequest&
request = setting.GetRequest();
573 string effective_test_name =
575 is_proto3 ?
".Proto3.JsonInput." :
".Proto2.JsonInput.",
576 test_name,
".Validator");
580 if (
response.result_case() == ConformanceResponse::kSkipped) {
585 if (
response.result_case() != ConformanceResponse::kJsonPayload) {
587 "Expected JSON payload but got type %d.",
595 "JSON payload cannot be parsed as valid JSON: %s",
596 reader.getFormattedErrorMessages().c_str());
601 "JSON payload validation failed.");
608 const string& test_name, ConformanceLevel
level,
const string& input_json) {
609 TestAllTypesProto3 prototype;
612 ConformanceRequestSetting setting(
613 level, conformance::JSON, conformance::JSON,
614 conformance::JSON_TEST,
615 prototype, test_name, input_json);
616 const ConformanceRequest&
request = setting.GetRequest();
618 string effective_test_name =
StrCat(
619 setting.ConformanceLevelToString(
level),
".Proto3.JsonInput.", test_name);
624 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
628 "Should have failed to parse, but didn't.");
633 const string& test_name, ConformanceLevel
level,
const string& text_format) {
634 TestAllTypesProto3 payload_message;
636 <<
"Failed to parse: " << text_format;
638 TestAllTypesProto3 prototype;
639 ConformanceRequestSetting setting(
640 level, conformance::PROTOBUF, conformance::JSON,
641 conformance::JSON_TEST,
642 prototype, test_name, payload_message.SerializeAsString());
643 const ConformanceRequest&
request = setting.GetRequest();
645 string effective_test_name =
StrCat(
646 setting.ConformanceLevelToString(
level),
".", test_name,
".JsonOutput");
649 if (
response.result_case() == ConformanceResponse::kSerializeError) {
651 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
655 "Should have failed to serialize, but didn't.");
662 static const string incompletes[6] = {
675 const string& incomplete = incompletes[wire_type];
684 tag(rep_field->number(), wire_type),
692 cat(
tag(
field->number(), wire_type), incomplete ),
696 cat(
tag(rep_field->number(), wire_type), incomplete ),
705 cat(
tag(
field->number(), wire_type), varint(1) ),
706 "PrematureEofInDelimitedDataForKnownNonRepeatedValue" +
type_name,
710 cat(
tag(rep_field->number(), wire_type), varint(1) ),
711 "PrematureEofInDelimitedDataForKnownRepeatedValue" +
type_name,
721 string incomplete_submsg =
726 varint(incomplete_submsg.size()),
736 varint(incomplete.size()), incomplete),
749 std::vector<std::pair<std::string, std::string>>
values) {
750 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
759 for (
size_t i = 0;
i <
values.size();
i++) {
760 string proto = cat(
tag(
field->number(), wire_type),
values[i].first);
762 string expected_proto =
763 is_proto3 && IsProto3Default(
field->type(),
values[i].second)
766 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
767 test_message->MergeFromString(expected_proto);
768 string text = test_message->DebugString();
772 proto,
text, is_proto3);
783 for (
size_t i = 0;
i <
values.size();
i++) {
786 string expected_proto =
788 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
789 test_message->MergeFromString(expected_proto);
790 string text = test_message->DebugString();
793 proto,
text, is_proto3);
799 GetFieldForType(
type,
true, is_proto3, Packed::kTrue);
801 GetFieldForType(
type,
true, is_proto3, Packed::kFalse);
803 string default_proto_packed;
804 string default_proto_unpacked;
805 string default_proto_packed_expected;
806 string default_proto_unpacked_expected;
807 string packed_proto_packed;
808 string packed_proto_unpacked;
809 string packed_proto_expected;
810 string unpacked_proto_packed;
811 string unpacked_proto_unpacked;
812 string unpacked_proto_expected;
814 for (
size_t i = 0;
i <
values.size();
i++) {
815 default_proto_unpacked +=
816 cat(
tag(rep_field->number(), wire_type),
values[i].first);
817 default_proto_unpacked_expected +=
818 cat(
tag(rep_field->number(), wire_type),
values[i].second);
819 default_proto_packed +=
values[
i].first;
820 default_proto_packed_expected +=
values[
i].second;
821 packed_proto_unpacked +=
822 cat(
tag(packed_field->number(), wire_type),
values[i].first);
823 packed_proto_packed +=
values[
i].first;
824 packed_proto_expected +=
values[
i].second;
825 unpacked_proto_unpacked +=
826 cat(
tag(unpacked_field->number(), wire_type),
values[i].first);
827 unpacked_proto_packed +=
values[
i].first;
828 unpacked_proto_expected +=
829 cat(
tag(unpacked_field->number(), wire_type),
values[i].second);
831 default_proto_packed = cat(
833 delim(default_proto_packed));
834 default_proto_packed_expected = cat(
836 delim(default_proto_packed_expected));
837 packed_proto_packed = cat(
tag(packed_field->number(),
839 delim(packed_proto_packed));
840 packed_proto_expected =
841 cat(
tag(packed_field->number(),
843 delim(packed_proto_expected));
844 unpacked_proto_packed =
845 cat(
tag(unpacked_field->number(),
847 delim(unpacked_proto_packed));
849 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
850 test_message->MergeFromString(default_proto_packed_expected);
851 string text = test_message->DebugString();
863 string expected_proto = rep_field->is_packed()
864 ? default_proto_packed_expected
865 : default_proto_unpacked_expected;
867 ".UnpackedInput.DefaultOutput"),
869 expected_proto, is_proto3);
871 ".PackedInput.DefaultOutput"),
873 expected_proto, is_proto3);
875 ".UnpackedInput.PackedOutput"),
877 packed_proto_expected, is_proto3);
879 ".PackedInput.PackedOutput"),
881 packed_proto_expected, is_proto3);
883 ".UnpackedInput.UnpackedOutput"),
885 unpacked_proto_expected, is_proto3);
887 ".PackedInput.UnpackedOutput"),
889 unpacked_proto_expected, is_proto3);
892 string expected_proto;
893 for (
size_t i = 0;
i <
values.size();
i++) {
894 proto += cat(
tag(rep_field->number(), wire_type),
values[i].first);
896 cat(
tag(rep_field->number(), wire_type),
values[i].second);
898 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
899 test_message->MergeFromString(expected_proto);
900 string text = test_message->DebugString();
909 std::vector<std::string>
values = {
925 optional_int32: 4321,
926 optional_int64: 1234,
927 optional_uint32: 4321,
928 repeated_int32: [1234, 4321],
932 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
936 for (
size_t i = 0;
i <
values.size();
i++) {
943 field->name() +
": " + expected, is_proto3);
949 const string key_type_name =
951 const string value_type_name =
962 string key2_data = cat(
tag(1, key_wire_type), GetNonDefaultValue(
key_type));
964 cat(
tag(2, value_wire_type), GetNonDefaultValue(
value_type));
966 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
974 delim(cat(key1_data, value1_data)));
975 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
976 test_message->MergeFromString(proto);
977 string text = test_message->DebugString();
979 value_type_name,
".Default"),
988 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
989 test_message->MergeFromString(proto);
990 string text = test_message->DebugString();
992 value_type_name,
".MissingDefault"),
1000 delim(cat(key2_data, value2_data)));
1001 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1002 test_message->MergeFromString(proto);
1003 string text = test_message->DebugString();
1005 value_type_name,
".NonDefault"),
1013 delim(cat(value2_data, key2_data)));
1014 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1015 test_message->MergeFromString(proto);
1016 string text = test_message->DebugString();
1018 value_type_name,
".Unordered"),
1026 delim(cat(key2_data, value1_data)));
1029 delim(cat(key2_data, value2_data)));
1030 string proto = cat(proto1,
proto2);
1031 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1032 test_message->MergeFromString(
proto2);
1033 string text = test_message->DebugString();
1035 value_type_name,
".DuplicateKey"),
1043 delim(cat(key1_data, key2_data, value2_data)));
1044 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1045 test_message->MergeFromString(proto);
1046 string text = test_message->DebugString();
1048 StrCat(
"ValidDataMap", key_type_name, value_type_name,
1049 ".DuplicateKeyInMapEntry"),
1057 delim(cat(key2_data, value1_data, value2_data)));
1058 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1059 test_message->MergeFromString(proto);
1060 string text = test_message->DebugString();
1062 StrCat(
"ValidDataMap", key_type_name, value_type_name,
1063 ".DuplicateValueInMapEntry"),
1074 string field31_data =
1076 string submsg1_data = delim(cat(field1_data, field31_data));
1077 string submsg2_data = delim(cat(field2_data, field31_data));
1078 string value1_data =
1082 string value2_data =
1087 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
1093 delim(cat(key_data, value1_data)));
1096 delim(cat(key_data, value2_data)));
1097 string proto = cat(proto1,
proto2);
1098 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1100 string text = test_message->DebugString();
1102 proto,
text, is_proto3);
1113 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
1115 const string default_value =
1117 const string non_default_value =
1118 cat(
tag(
field->number(), wire_type), GetNonDefaultValue(
type));
1122 const string proto = default_value;
1123 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1124 test_message->MergeFromString(proto);
1125 string text = test_message->DebugString();
1129 proto,
text, is_proto3);
1137 const string proto = non_default_value;
1138 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1139 test_message->MergeFromString(proto);
1140 string text = test_message->DebugString();
1152 const string proto =
StrCat(default_value, non_default_value);
1153 const string expected_proto = non_default_value;
1154 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1155 test_message->MergeFromString(expected_proto);
1156 string text = test_message->DebugString();
1159 ".MultipleValuesForSameField"),
1162 ".MultipleValuesForSameField"),
1169 GetFieldForOneofType(
type, is_proto3,
true);
1174 const string other_value =
1175 cat(
tag(other_field->number(), other_wire_type),
1178 const string proto =
StrCat(other_value, non_default_value);
1179 const string expected_proto = non_default_value;
1180 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1181 test_message->MergeFromString(expected_proto);
1182 string text = test_message->DebugString();
1185 ".MultipleValuesForDifferentField"),
1189 ".MultipleValuesForDifferentField"),
1199 string field89_data =
1201 string submsg1_data =
1203 delim(cat(field1_data, field2a_data, field89_data)));
1205 delim(cat(field2b_data, field89_data)));
1206 string merged_data =
1208 delim(cat(field1_data, field2b_data, field89_data, field89_data)));
1210 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
1216 delim(submsg1_data));
1219 delim(submsg2_data));
1220 string proto = cat(proto1,
proto2);
1221 string expected_proto =
1223 delim(merged_data));
1225 std::unique_ptr<Message> test_message = NewTestMessage(is_proto3);
1226 test_message->MergeFromString(expected_proto);
1227 string text = test_message->DebugString();
1237 string nullfield[] = {
1243 for (
int i = 0;
i < 4;
i++) {
1244 string name =
"IllegalZeroFieldNum_Case_0";
1249 template <
class MessageType>
1251 MessageType &
message,
bool is_proto3) {
1255 message.mutable_oneof_nested_message()->set_a(0);
1258 is_proto3 ?
"oneof_nested_message: {}" :
"oneof_nested_message: {a: 0}",
1260 message.mutable_oneof_nested_message()->set_a(1);
1263 "oneof_nested_message: {a: 1}",
1271 message.set_oneof_bool(
false);
1277 message.set_oneof_float(0.0f);
1280 message.set_oneof_double(0.0);
1283 message.set_oneof_enum(MessageType::FOO);
1288 template <
class MessageType>
1290 MessageType&
message,
bool is_proto3) {
1291 message.ParseFromString(
"\xA8\x1F\x01");
1293 message.SerializeAsString(), is_proto3);
1299 conformance::FailureSet failure_set;
1300 ConformanceRequest
req;
1301 ConformanceResponse res;
1302 req.set_message_type(failure_set.GetTypeName());
1303 req.set_protobuf_payload(
"");
1304 req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
1306 GOOGLE_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
1307 for (
const string& failure : failure_set.failure()) {
1322 int64 kInt64Min = -9223372036854775808
ULL;
1323 int64 kInt64Max = 9223372036854775807
ULL;
1324 uint64 kUint64Max = 18446744073709551615
ULL;
1325 int32 kInt32Max = 2147483647;
1326 int32 kInt32Min = -2147483648;
1327 uint32 kUint32Max = 4294967295UL;
1333 {dbl(0.1), dbl(0.1)},
1334 {dbl(1.7976931348623157e+308), dbl(1.7976931348623157e+308)},
1335 {dbl(2.22507385850720138309e-308), dbl(2.22507385850720138309e-308)},
1341 {flt(0.1), flt(0.1)},
1342 {flt(1.00000075e-36), flt(1.00000075e-36)},
1343 {flt(3.402823e+38), flt(3.402823e+38)},
1344 {flt(1.17549435e-38f), flt(1.17549435e-38)},
1348 {varint(0), varint(0)},
1349 {varint(12345), varint(12345)},
1350 {varint(kInt64Max), varint(kInt64Max)},
1351 {varint(kInt64Min), varint(kInt64Min)},
1355 {varint(0), varint(0)},
1356 {varint(12345), varint(12345)},
1357 {varint(kUint64Max), varint(kUint64Max)},
1361 {varint(0), varint(0)},
1362 {varint(12345), varint(12345)},
1363 {longvarint(12345, 2), varint(12345)},
1364 {longvarint(12345, 7), varint(12345)},
1365 {varint(kInt32Max), varint(kInt32Max)},
1366 {varint(kInt32Min), varint(kInt32Min)},
1367 {varint(1
LL << 33), varint(0)},
1368 {varint((1
LL << 33) - 1), varint(-1)},
1369 {varint(kInt64Max), varint(-1)},
1370 {varint(kInt64Min + 1), varint(1)},
1375 {varint(0), varint(0)},
1376 {varint(12345), varint(12345)},
1377 {longvarint(12345, 2), varint(12345)},
1378 {longvarint(12345, 7), varint(12345)},
1379 {varint(kUint32Max), varint(kUint32Max)},
1380 {varint(1
LL << 33), varint(0)},
1381 {varint((1
LL << 33) + 1), varint(1)},
1382 {varint((1
LL << 33) - 1), varint((1
LL << 32) - 1)},
1383 {varint(kInt64Max), varint((1
LL << 32) - 1)},
1384 {varint(kInt64Min + 1), varint(1)},
1389 {u64(12345), u64(12345)},
1390 {u64(kUint64Max), u64(kUint64Max)},
1395 {u32(12345), u32(12345)},
1396 {u32(kUint32Max), u32(kUint32Max)},
1401 {u64(12345), u64(12345)},
1402 {u64(kInt64Max), u64(kInt64Max)},
1403 {u64(kInt64Min), u64(kInt64Min)},
1408 {u32(12345), u32(12345)},
1409 {u32(kInt32Max), u32(kInt32Max)},
1410 {u32(kInt32Min), u32(kInt32Min)},
1416 {varint(0), varint(0)},
1417 {varint(1), varint(1)},
1418 {varint(-1), varint(1)},
1419 {varint(12345678), varint(1)},
1420 {varint(1
LL << 33), varint(1)},
1421 {varint(kInt64Max), varint(1)},
1422 {varint(kInt64Min), varint(1)},
1427 {zz32(12345), zz32(12345)},
1428 {zz32(kInt32Max), zz32(kInt32Max)},
1429 {zz32(kInt32Min), zz32(kInt32Min)},
1430 {zz64(kInt32Max + 2
LL), zz32(1)},
1435 {zz64(12345), zz64(12345)},
1436 {zz64(kInt64Max), zz64(kInt64Max)},
1437 {zz64(kInt64Min), zz64(kInt64Min)},
1442 {delim(
""), delim(
"")},
1443 {delim(
"Hello world!"), delim(
"Hello world!")},
1444 {delim(
"\'\"\?\\\a\b\f\n\r\t\v"),
1445 delim(
"\'\"\?\\\a\b\f\n\r\t\v")},
1446 {delim(
"谷歌"), delim(
"谷歌")},
1447 {delim(
"\u8C37\u6B4C"), delim(
"谷歌")},
1448 {delim(
"\u8c37\u6b4c"), delim(
"谷歌")},
1449 {delim(
"\xF0\x9F\x98\x81"), delim(
"\xF0\x9F\x98\x81")},
1453 {delim(
""), delim(
"")},
1454 {delim(
"Hello world!"), delim(
"Hello world!")},
1455 {delim(
"\x01\x02"), delim(
"\x01\x02")},
1456 {delim(
"\xfb"), delim(
"\xfb")},
1460 {varint(0), varint(0)},
1461 {varint(1), varint(1)},
1462 {varint(2), varint(2)},
1463 {varint(-1), varint(-1)},
1464 {varint(kInt64Max), varint(-1)},
1465 {varint(kInt64Min + 1), varint(1)},
1471 {delim(
""), delim(
"")},
1530 TestAllTypesProto3 messageProto3;
1531 TestAllTypesProto2 messageProto2;
1545 "{\"optionalString\":\"Hello, World!\"}",
1546 "optional_string: 'Hello, World!'");
1621 "FieldNameWithMixedCases",
REQUIRED,
1658 "OriginalProtoFieldName",
REQUIRED,
1672 "__field_name13": 13,
1673 "__Field_name14": 14,
1674 "field__name15": 15,
1675 "field__Name16": 16,
1676 "field_name17__": 17,
1677 "Field_name18__": 18
1702 R
"({"fieldn\u0061me1": 1})",
1707 "{\"optionalString\": \"abc\\");
1715 R
"({"fieldname1":1,})");
1718 R
"({"fieldname1":1 ,})");
1720 "TrailingCommaInAnObjectWithSpaceCommaSpace",
RECOMMENDED,
1721 R
"({"fieldname1":1 , })");
1723 "TrailingCommaInAnObjectWithNewlines",
RECOMMENDED,
1731 // This is a comment.
1737 "{\"optionalInt32\":1,\"optionalInt64\":2}",
1744 "{ \"optionalInt32\" : 1 , \"optionalInt64\" : 2 }",
1751 "{\n\"optionalInt32\"\n:\n1\n,\n\"optionalInt64\"\n:\n2\n}",
1758 "{\n \"optionalInt32\" : 1\n ,\n \"optionalInt64\" : 2\n}\n",
1766 "{ \"optionalInt32\": 1 \"optionalInt64\": 2 }");
1769 "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
1774 "optionalNestedMessage": {a: 1},
1775 "optionalNestedMessage": {}
1778 "FieldNameDuplicateDifferentCasing1",
RECOMMENDED,
1780 "optional_nested_message": {a: 1},
1781 "optionalNestedMessage": {}
1784 "FieldNameDuplicateDifferentCasing2",
RECOMMENDED,
1786 "optionalNestedMessage": {a: 1},
1787 "optional_nested_message": {}
1791 "FieldNameInLowerCamelCase",
REQUIRED,
1799 return value.isMember(
"fieldname1") &&
1800 value.isMember(
"fieldName2") &&
1801 value.isMember(
"FieldName3") &&
1802 value.isMember(
"fieldName4");
1812 return value.isMember(
"field0name5") &&
1813 value.isMember(
"field0Name6");
1817 "FieldNameWithMixedCases",
REQUIRED,
1827 return value.isMember(
"fieldName7") &&
1828 value.isMember(
"FieldName8") &&
1829 value.isMember(
"fieldName9") &&
1830 value.isMember(
"FieldName10") &&
1831 value.isMember(
"FIELDNAME11") &&
1832 value.isMember(
"FIELDName12");
1846 return value.isMember(
"FieldName13") &&
1847 value.isMember(
"FieldName14") &&
1848 value.isMember(
"fieldName15") &&
1849 value.isMember(
"fieldName16") &&
1850 value.isMember(
"fieldName17") &&
1851 value.isMember(
"FieldName18");
1855 "StoresDefaultPrimitive",
REQUIRED,
1871 "[protobuf_test_messages.proto2.extension_int32]": 1
1874 return value.isMember(
1875 "[protobuf_test_messages.proto2.extension_int32]");
1884 R
"({"optionalInt32": 2147483647})",
1885 "optional_int32: 2147483647");
1888 R
"({"optionalInt32": -2147483648})",
1889 "optional_int32: -2147483648");
1892 R
"({"optionalUint32": 4294967295})",
1893 "optional_uint32: 4294967295");
1896 R
"({"optionalInt64": "9223372036854775807"})",
1897 "optional_int64: 9223372036854775807");
1900 R
"({"optionalInt64": "-9223372036854775808"})",
1901 "optional_int64: -9223372036854775808");
1904 R
"({"optionalUint64": "18446744073709551615"})",
1905 "optional_uint64: 18446744073709551615");
1913 "Int64FieldMaxValueNotQuoted",
REQUIRED,
1914 R
"({"optionalInt64": 9223372036854774784})",
1915 "optional_int64: 9223372036854774784");
1917 "Int64FieldMinValueNotQuoted",
REQUIRED,
1918 R
"({"optionalInt64": -9223372036854775808})",
1919 "optional_int64: -9223372036854775808");
1923 "Uint64FieldMaxValueNotQuoted",
REQUIRED,
1924 R
"({"optionalUint64": 18446744073709549568})",
1925 "optional_uint64: 18446744073709549568");
1929 R
"({"optionalInt32": "2147483647"})",
1930 "optional_int32: 2147483647");
1932 "Int32FieldStringValueEscaped",
REQUIRED,
1933 R
"({"optionalInt32": "2\u003147483647"})",
1934 "optional_int32: 2147483647");
1939 R
"({"optionalInt32": 2147483648})");
1942 R
"({"optionalInt32": -2147483649})");
1945 R
"({"optionalUint32": 4294967296})");
1948 R
"({"optionalInt64": "9223372036854775808"})");
1951 R
"({"optionalInt64": "-9223372036854775809"})");
1954 R
"({"optionalUint64": "18446744073709551616"})");
1958 R
"({"optionalInt32": 0.5})");
1961 R
"({"optionalUint32": 0.5})");
1964 R
"({"optionalInt64": "0.5"})");
1967 R
"({"optionalUint64": "0.5"})");
1971 "Int32FieldFloatTrailingZero",
REQUIRED,
1972 R
"({"optionalInt32": 100000.000})",
1973 "optional_int32: 100000");
1975 "Int32FieldExponentialFormat",
REQUIRED,
1976 R
"({"optionalInt32": 1e5})",
1977 "optional_int32: 100000");
1979 "Int32FieldMaxFloatValue",
REQUIRED,
1980 R
"({"optionalInt32": 2.147483647e9})",
1981 "optional_int32: 2147483647");
1983 "Int32FieldMinFloatValue",
REQUIRED,
1984 R
"({"optionalInt32": -2.147483648e9})",
1985 "optional_int32: -2147483648");
1987 "Uint32FieldMaxFloatValue",
REQUIRED,
1988 R
"({"optionalUint32": 4.294967295e9})",
1989 "optional_uint32: 4294967295");
1994 R
"({"optionalInt32": "3x3"})");
1997 R
"({"optionalUint32": "3x3"})");
2000 R
"({"optionalInt64": "3x3"})");
2003 R
"({"optionalUint64": "3x3"})");
2007 R
"({"optionalInt32": +1})");
2011 R
"({"optionalInt32": 01})");
2013 "Int32FieldNegativeWithLeadingZero",
REQUIRED,
2014 R
"({"optionalInt32": -01})");
2018 "Int32FieldLeadingSpace",
REQUIRED,
2019 R
"({"optionalInt32": " 1"})");
2021 "Int32FieldTrailingSpace",
REQUIRED,
2022 R
"({"optionalInt32": "1 "})");
2026 "Int64FieldBeString",
RECOMMENDED, R
"({"optionalInt64": 1})",
2029 value[
"optionalInt64"].asString() ==
"1";
2033 "Uint64FieldBeString",
RECOMMENDED, R
"({"optionalUint64": 1})",
2036 value[
"optionalUint64"].asString() ==
"1";
2043 R
"({"optionalBool":true})",
2044 "optional_bool: true");
2047 R
"({"optionalBool":false})",
2048 "optional_bool: false");
2053 R
"({"optionalBool":0})");
2056 R
"({"optionalBool":1})");
2059 R
"({"optionalBool":True})");
2062 R
"({"optionalBool":False})");
2065 R
"({"optionalBool":TRUE})");
2068 R
"({"optionalBool":FALSE})");
2071 R
"({"optionalBool":"true"})");
2074 R
"({"optionalBool":"false"})");
2078 "FloatFieldMinPositiveValue",
REQUIRED,
2079 R
"({"optionalFloat": 1.175494e-38})",
2080 "optional_float: 1.175494e-38");
2082 "FloatFieldMaxNegativeValue",
REQUIRED,
2083 R
"({"optionalFloat": -1.175494e-38})",
2084 "optional_float: -1.175494e-38");
2086 "FloatFieldMaxPositiveValue",
REQUIRED,
2087 R
"({"optionalFloat": 3.402823e+38})",
2088 "optional_float: 3.402823e+38");
2090 "FloatFieldMinNegativeValue",
REQUIRED,
2091 R
"({"optionalFloat": 3.402823e+38})",
2092 "optional_float: 3.402823e+38");
2096 R
"({"optionalFloat": "1"})",
2097 "optional_float: 1");
2101 R
"({"optionalFloat": "NaN"})",
2102 "optional_float: nan");
2105 R
"({"optionalFloat": "Infinity"})",
2106 "optional_float: inf");
2108 "FloatFieldNegativeInfinity",
REQUIRED,
2109 R
"({"optionalFloat": "-Infinity"})",
2110 "optional_float: -inf");
2120 "optional_float: nan");
2127 "optional_float: nan");
2133 R
"({"optionalFloat": NaN})");
2136 R
"({"optionalFloat": Infinity})");
2138 "FloatFieldNegativeInfinityNotQuoted",
RECOMMENDED,
2139 R
"({"optionalFloat": -Infinity})");
2143 R
"({"optionalFloat": -3.502823e+38})");
2146 R
"({"optionalFloat": 3.502823e+38})");
2150 "DoubleFieldMinPositiveValue",
REQUIRED,
2151 R
"({"optionalDouble": 2.22507e-308})",
2152 "optional_double: 2.22507e-308");
2154 "DoubleFieldMaxNegativeValue",
REQUIRED,
2155 R
"({"optionalDouble": -2.22507e-308})",
2156 "optional_double: -2.22507e-308");
2158 "DoubleFieldMaxPositiveValue",
REQUIRED,
2159 R
"({"optionalDouble": 1.79769e+308})",
2160 "optional_double: 1.79769e+308");
2162 "DoubleFieldMinNegativeValue",
REQUIRED,
2163 R
"({"optionalDouble": -1.79769e+308})",
2164 "optional_double: -1.79769e+308");
2167 "DoubleFieldQuotedValue",
REQUIRED,
2168 R
"({"optionalDouble": "1"})",
2169 "optional_double: 1");
2173 R
"({"optionalDouble": "NaN"})",
2174 "optional_double: nan");
2177 R
"({"optionalDouble": "Infinity"})",
2178 "optional_double: inf");
2180 "DoubleFieldNegativeInfinity",
REQUIRED,
2181 R
"({"optionalDouble": "-Infinity"})",
2182 "optional_double: -inf");
2190 "optional_double: nan");
2195 "optional_double: nan");
2201 R
"({"optionalDouble": NaN})");
2204 R
"({"optionalDouble": Infinity})");
2206 "DoubleFieldNegativeInfinityNotQuoted",
RECOMMENDED,
2207 R
"({"optionalDouble": -Infinity})");
2212 R
"({"optionalDouble": -1.89769e+308})");
2215 R
"({"optionalDouble": +1.89769e+308})");
2220 R
"({"optionalNestedEnum": "FOO"})",
2221 "optional_nested_enum: FOO");
2225 R
"({"optionalAliasedEnum": "ALIAS_BAZ"})",
2226 "optional_aliased_enum: ALIAS_BAZ");
2228 "EnumFieldWithAliasUseAlias",
REQUIRED,
2229 R
"({"optionalAliasedEnum": "QUX"})",
2230 "optional_aliased_enum: ALIAS_BAZ");
2232 "EnumFieldWithAliasLowerCase",
REQUIRED,
2233 R
"({"optionalAliasedEnum": "qux"})",
2234 "optional_aliased_enum: ALIAS_BAZ");
2236 "EnumFieldWithAliasDifferentCase",
REQUIRED,
2237 R
"({"optionalAliasedEnum": "bAz"})",
2238 "optional_aliased_enum: ALIAS_BAZ");
2242 R
"({"optionalNestedEnum": FOO})");
2245 "EnumFieldNumericValueZero",
REQUIRED,
2246 R
"({"optionalNestedEnum": 0})",
2247 "optional_nested_enum: FOO");
2249 "EnumFieldNumericValueNonZero",
REQUIRED,
2250 R
"({"optionalNestedEnum": 1})",
2251 "optional_nested_enum: BAR");
2254 "EnumFieldUnknownValue",
REQUIRED, R
"({"optionalNestedEnum": 123})",
2257 value[
"optionalNestedEnum"].asInt() == 123;
2264 R
"({"optionalString": "Hello world!"})",
2265 "optional_string: \"Hello world!\"");
2269 R
"({"optionalString": "谷歌"})",
2270 R"(optional_string: "谷歌")");
2273 R
"({"optionalString": "\"\\\/\b\f\n\r\t"})",
2274 R"(optional_string: "\"\\/\b\f\n\r\t")");
2276 "StringFieldUnicodeEscape",
REQUIRED,
2277 R
"({"optionalString": "\u8C37\u6B4C"})",
2278 R"(optional_string: "谷歌")");
2280 "StringFieldUnicodeEscapeWithLowercaseHexLetters",
REQUIRED,
2281 R
"({"optionalString": "\u8c37\u6b4c"})",
2282 R"(optional_string: "谷歌")");
2284 "StringFieldSurrogatePair",
REQUIRED,
2286 R
"({"optionalString": "\uD83D\uDE01"})",
2287 R"(optional_string: "\xF0\x9F\x98\x81")");
2292 R
"({"optionalString": "\U8C37\U6b4C"})");
2295 R
"({"optionalString": "\uXXXX\u6B4C"})");
2298 R
"({"optionalString": "\u8C3"})");
2301 R
"({"optionalString": "\uD800"})");
2304 R
"({"optionalString": "\uDC00"})");
2307 R
"({"optionalString": "\uDE01\uD83D"})");
2310 R
"({"optionalString": 12345})");
2315 R
"({"optionalBytes": "AQI="})",
2316 R"(optional_bytes: "\x01\x02")");
2319 R
"({"optionalBytes": "-_"})",
2320 R"(optional_bytes: "\xfb")");
2325 R
"({"optionalNestedMessage": {"a": 1234}})",
2326 "optional_nested_message: {a: 1234}");
2331 R
"({"oneofUint32": 1, "oneofString": "test"})");
2333 R
"({"oneofUint32": null, "oneofString": "test"})",
2334 "oneof_string: \"test\"");
2336 R
"({"oneofString": "test", "oneofUint32": null})",
2337 "oneof_string: \"test\"");
2339 TestAllTypesProto3 messageProto3;
2340 TestAllTypesProto2 messageProto2;
2345 R
"({"oneofUint32": 0})", "oneof_uint32: 0");
2348 R
"({"oneofNestedMessage": {}})", "oneof_nested_message: {}");
2351 R
"({"oneofString": ""})", "oneof_string: \"\"");
2354 R
"({"oneofBytes": ""})", "oneof_bytes: \"\"");
2357 R
"({"oneofBool": false})", "oneof_bool: false");
2360 R
"({"oneofUint64": 0})", "oneof_uint64: 0");
2363 R
"({"oneofFloat": 0.0})", "oneof_float: 0");
2366 R
"({"oneofDouble": 0.0})", "oneof_double: 0");
2369 R
"({"oneofEnum":"FOO"})", "oneof_enum: FOO");
2374 R
"({"mapInt32Int32": {"1": 2, "3": 4}})",
2375 "map_int32_int32: {key: 1 value: 2}"
2376 "map_int32_int32: {key: 3 value: 4}");
2379 R
"({"mapInt32Int32": {1: 2, 3: 4}})");
2382 R
"({"mapUint32Uint32": {"1": 2, "3": 4}})",
2383 "map_uint32_uint32: {key: 1 value: 2}"
2384 "map_uint32_uint32: {key: 3 value: 4}");
2387 R
"({"mapUint32Uint32": {1: 2, 3: 4}})");
2390 R
"({"mapInt64Int64": {"1": 2, "3": 4}})",
2391 "map_int64_int64: {key: 1 value: 2}"
2392 "map_int64_int64: {key: 3 value: 4}");
2395 R
"({"mapInt64Int64": {1: 2, 3: 4}})");
2398 R
"({"mapUint64Uint64": {"1": 2, "3": 4}})",
2399 "map_uint64_uint64: {key: 1 value: 2}"
2400 "map_uint64_uint64: {key: 3 value: 4}");
2403 R
"({"mapUint64Uint64": {1: 2, 3: 4}})");
2406 R
"({"mapBoolBool": {"true": true, "false": false}})",
2407 "map_bool_bool: {key: true value: true}"
2408 "map_bool_bool: {key: false value: false}");
2411 R
"({"mapBoolBool": {true: true, false: false}})");
2415 "mapStringNestedMessage": {
2416 "hello": {"a": 1234},
2417 "world": {"a": 5678}
2421 map_string_nested_message: {
2425 map_string_nested_message: {
2433 R
"({"mapInt32Int32": {"\u0031": 2}})",
2434 "map_int32_int32: {key: 1 value: 2}");
2437 R
"({"mapInt64Int64": {"\u0031": 2}})",
2438 "map_int64_int64: {key: 1 value: 2}");
2441 R
"({"mapBoolBool": {"tr\u0075e": true}})",
2442 "map_bool_bool: {key: true value: true}");
2447 R
"({'optionalString': "Hello world!"})");
2449 R
"({"optionalString": 'Hello world!'})");
2451 R
"({'optionalString': 'Hello world!'})");
2457 R
"({"repeatedInt32": [1, 2, 3, 4]})",
2458 "repeated_int32: [1, 2, 3, 4]");
2460 R
"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})",
2461 "repeated_nested_enum: [FOO, BAR, BAZ]");
2463 R
"({"repeatedString": ["Hello", "world"]})",
2464 R"(repeated_string: ["Hello", "world"])");
2466 R
"({"repeatedBytes": ["AAEC", "AQI="]})",
2467 R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])");
2469 R
"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})",
2470 "repeated_nested_message: {a: 1234}"
2471 "repeated_nested_message: {a: 5678}");
2475 "RepeatedFieldWrongElementTypeExpectingIntegersGotBool",
REQUIRED,
2476 R
"({"repeatedInt32": [1, false, 3, 4]})");
2478 "RepeatedFieldWrongElementTypeExpectingIntegersGotString",
REQUIRED,
2479 R
"({"repeatedInt32": [1, 2, "name", 4]})");
2481 "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage",
REQUIRED,
2482 R
"({"repeatedInt32": [1, 2, 3, {"a": 4}]})");
2484 "RepeatedFieldWrongElementTypeExpectingStringsGotInt",
REQUIRED,
2485 R
"({"repeatedString": ["1", 2, "3", "4"]})");
2487 "RepeatedFieldWrongElementTypeExpectingStringsGotBool",
REQUIRED,
2488 R
"({"repeatedString": ["1", "2", false, "4"]})");
2490 "RepeatedFieldWrongElementTypeExpectingStringsGotMessage",
REQUIRED,
2491 R
"({"repeatedString": ["1", 2, "3", {"a": 4}]})");
2493 "RepeatedFieldWrongElementTypeExpectingMessagesGotInt",
REQUIRED,
2494 R
"({"repeatedNestedMessage": [{"a": 1}, 2]})");
2496 "RepeatedFieldWrongElementTypeExpectingMessagesGotBool",
REQUIRED,
2497 R
"({"repeatedNestedMessage": [{"a": 1}, false]})");
2499 "RepeatedFieldWrongElementTypeExpectingMessagesGotString",
REQUIRED,
2500 R
"({"repeatedNestedMessage": [{"a": 1}, "2"]})");
2503 R
"({"repeatedInt32": [1, 2, 3, 4,]})");
2505 "{\"repeatedInt32\": [1, 2, 3, 4 ,]}");
2508 "{\"repeatedInt32\": [1, 2, 3, 4 , ]}");
2510 "RepeatedFieldTrailingCommaWithNewlines",
RECOMMENDED,
2511 "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}");
2519 "optionalInt32": null,
2520 "optionalInt64": null,
2521 "optionalUint32": null,
2522 "optionalUint64": null,
2523 "optionalSint32": null,
2524 "optionalSint64": null,
2525 "optionalFixed32": null,
2526 "optionalFixed64": null,
2527 "optionalSfixed32": null,
2528 "optionalSfixed64": null,
2529 "optionalFloat": null,
2530 "optionalDouble": null,
2531 "optionalBool": null,
2532 "optionalString": null,
2533 "optionalBytes": null,
2534 "optionalNestedEnum": null,
2535 "optionalNestedMessage": null,
2536 "repeatedInt32": null,
2537 "repeatedInt64": null,
2538 "repeatedUint32": null,
2539 "repeatedUint64": null,
2540 "repeatedSint32": null,
2541 "repeatedSint64": null,
2542 "repeatedFixed32": null,
2543 "repeatedFixed64": null,
2544 "repeatedSfixed32": null,
2545 "repeatedSfixed64": null,
2546 "repeatedFloat": null,
2547 "repeatedDouble": null,
2548 "repeatedBool": null,
2549 "repeatedString": null,
2550 "repeatedBytes": null,
2551 "repeatedNestedEnum": null,
2552 "repeatedNestedMessage": null,
2553 "mapInt32Int32": null,
2554 "mapBoolBool": null,
2555 "mapStringNestedMessage": null
2561 "RepeatedFieldPrimitiveElementIsNull",
RECOMMENDED,
2562 R
"({"repeatedInt32": [1, null, 2]})");
2565 R
"({"repeatedNestedMessage": [{"a":1}, null, {"a":2}]})");
2569 R
"({"mapInt32Int32": {null: 1}})");
2573 R
"({"mapInt32Int32": {"0": null}})");
2578 R
"({"optionalBoolWrapper": false})",
2579 "optional_bool_wrapper: {value: false}");
2582 R
"({"optionalInt32Wrapper": 0})",
2583 "optional_int32_wrapper: {value: 0}");
2586 R
"({"optionalUint32Wrapper": 0})",
2587 "optional_uint32_wrapper: {value: 0}");
2590 R
"({"optionalInt64Wrapper": 0})",
2591 "optional_int64_wrapper: {value: 0}");
2594 R
"({"optionalUint64Wrapper": 0})",
2595 "optional_uint64_wrapper: {value: 0}");
2598 R
"({"optionalFloatWrapper": 0})",
2599 "optional_float_wrapper: {value: 0}");
2602 R
"({"optionalDoubleWrapper": 0})",
2603 "optional_double_wrapper: {value: 0}");
2606 R
"({"optionalStringWrapper": ""})",
2607 R"(optional_string_wrapper: {value: ""})");
2610 R
"({"optionalBytesWrapper": ""})",
2611 R"(optional_bytes_wrapper: {value: ""})");
2613 "OptionalWrapperTypesWithNonDefaultValue",
REQUIRED,
2615 "optionalBoolWrapper": true,
2616 "optionalInt32Wrapper": 1,
2617 "optionalUint32Wrapper": 1,
2618 "optionalInt64Wrapper": "1",
2619 "optionalUint64Wrapper": "1",
2620 "optionalFloatWrapper": 1,
2621 "optionalDoubleWrapper": 1,
2622 "optionalStringWrapper": "1",
2623 "optionalBytesWrapper": "AQI="
2626 optional_bool_wrapper: {value: true}
2627 optional_int32_wrapper: {value: 1}
2628 optional_uint32_wrapper: {value: 1}
2629 optional_int64_wrapper: {value: 1}
2630 optional_uint64_wrapper: {value: 1}
2631 optional_float_wrapper: {value: 1}
2632 optional_double_wrapper: {value: 1}
2633 optional_string_wrapper: {value: "1"}
2634 optional_bytes_wrapper: {value: "\x01\x02"}
2638 R
"({"repeatedBoolWrapper": [true, false]})",
2639 "repeated_bool_wrapper: {value: true}"
2640 "repeated_bool_wrapper: {value: false}");
2643 R
"({"repeatedInt32Wrapper": [0, 1]})",
2644 "repeated_int32_wrapper: {value: 0}"
2645 "repeated_int32_wrapper: {value: 1}");
2648 R
"({"repeatedUint32Wrapper": [0, 1]})",
2649 "repeated_uint32_wrapper: {value: 0}"
2650 "repeated_uint32_wrapper: {value: 1}");
2653 R
"({"repeatedInt64Wrapper": [0, 1]})",
2654 "repeated_int64_wrapper: {value: 0}"
2655 "repeated_int64_wrapper: {value: 1}");
2658 R
"({"repeatedUint64Wrapper": [0, 1]})",
2659 "repeated_uint64_wrapper: {value: 0}"
2660 "repeated_uint64_wrapper: {value: 1}");
2663 R
"({"repeatedFloatWrapper": [0, 1]})",
2664 "repeated_float_wrapper: {value: 0}"
2665 "repeated_float_wrapper: {value: 1}");
2668 R
"({"repeatedDoubleWrapper": [0, 1]})",
2669 "repeated_double_wrapper: {value: 0}"
2670 "repeated_double_wrapper: {value: 1}");
2673 R
"({"repeatedStringWrapper": ["", "AQI="]})",
2675 repeated_string_wrapper: {value: ""}
2676 repeated_string_wrapper: {value: "AQI="}
2680 R
"({"repeatedBytesWrapper": ["", "AQI="]})",
2682 repeated_bytes_wrapper: {value: ""}
2683 repeated_bytes_wrapper: {value: "\x01\x02"}
2686 "WrapperTypesWithNullValue",
REQUIRED,
2688 "optionalBoolWrapper": null,
2689 "optionalInt32Wrapper": null,
2690 "optionalUint32Wrapper": null,
2691 "optionalInt64Wrapper": null,
2692 "optionalUint64Wrapper": null,
2693 "optionalFloatWrapper": null,
2694 "optionalDoubleWrapper": null,
2695 "optionalStringWrapper": null,
2696 "optionalBytesWrapper": null,
2697 "repeatedBoolWrapper": null,
2698 "repeatedInt32Wrapper": null,
2699 "repeatedUint32Wrapper": null,
2700 "repeatedInt64Wrapper": null,
2701 "repeatedUint64Wrapper": null,
2702 "repeatedFloatWrapper": null,
2703 "repeatedDoubleWrapper": null,
2704 "repeatedStringWrapper": null,
2705 "repeatedBytesWrapper": null
2712 R
"({"optionalDuration": "-315576000000.999999999s"})",
2713 "optional_duration: {seconds: -315576000000 nanos: -999999999}");
2716 R
"({"optionalDuration": "315576000000.999999999s"})",
2717 "optional_duration: {seconds: 315576000000 nanos: 999999999}");
2720 R
"({"repeatedDuration": ["1.5s", "-1.5s"]})",
2721 "repeated_duration: {seconds: 1 nanos: 500000000}"
2722 "repeated_duration: {seconds: -1 nanos: -500000000}");
2725 R
"({"optionalDuration": null})",
2730 R
"({"optionalDuration": "1"})");
2732 "DurationJsonInputTooSmall",
REQUIRED,
2733 R
"({"optionalDuration": "-315576000001.000000000s"})");
2735 "DurationJsonInputTooLarge",
REQUIRED,
2736 R
"({"optionalDuration": "315576000001.000000000s"})");
2738 "DurationProtoInputTooSmall",
REQUIRED,
2739 "optional_duration: {seconds: -315576000001 nanos: 0}");
2741 "DurationProtoInputTooLarge",
REQUIRED,
2742 "optional_duration: {seconds: 315576000001 nanos: 0}");
2746 R
"({"optionalDuration": "1.000000000s"})",
2748 return value[
"optionalDuration"].asString() ==
"1s";
2753 R
"({"optionalDuration": "1.010000000s"})",
2755 return value[
"optionalDuration"].asString() ==
"1.010s";
2760 R
"({"optionalDuration": "1.000010000s"})",
2762 return value[
"optionalDuration"].asString() ==
"1.000010s";
2767 R
"({"optionalDuration": "1.000000010s"})",
2769 return value[
"optionalDuration"].asString() ==
"1.000000010s";
2776 R
"({"optionalTimestamp": "0001-01-01T00:00:00Z"})",
2777 "optional_timestamp: {seconds: -62135596800}");
2780 R
"({"optionalTimestamp": "9999-12-31T23:59:59.999999999Z"})",
2781 "optional_timestamp: {seconds: 253402300799 nanos: 999999999}");
2783 "TimestampRepeatedValue",
REQUIRED,
2785 "repeatedTimestamp": [
2786 "0001-01-01T00:00:00Z",
2787 "9999-12-31T23:59:59.999999999Z"
2790 "repeated_timestamp: {seconds: -62135596800}"
2791 "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}");
2793 R
"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})",
2794 "optional_timestamp: {seconds: 729302400}");
2796 R
"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})",
2797 "optional_timestamp: {seconds: 1}");
2799 R
"({"optionalTimestamp": "1969-12-31T16:00:01-08:00"})",
2800 "optional_timestamp: {seconds: 1}");
2803 R
"({"optionalTimestamp": null})",
2807 "TimestampJsonInputTooSmall",
REQUIRED,
2808 R
"({"optionalTimestamp": "0000-01-01T00:00:00Z"})");
2810 "TimestampJsonInputTooLarge",
REQUIRED,
2811 R
"({"optionalTimestamp": "10000-01-01T00:00:00Z"})");
2813 "TimestampJsonInputMissingZ",
REQUIRED,
2814 R
"({"optionalTimestamp": "0001-01-01T00:00:00"})");
2817 R
"({"optionalTimestamp": "0001-01-01 00:00:00Z"})");
2819 "TimestampJsonInputLowercaseZ",
REQUIRED,
2820 R
"({"optionalTimestamp": "0001-01-01T00:00:00z"})");
2822 "TimestampJsonInputLowercaseT",
REQUIRED,
2823 R
"({"optionalTimestamp": "0001-01-01t00:00:00Z"})");
2825 "TimestampProtoInputTooSmall",
REQUIRED,
2826 "optional_timestamp: {seconds: -62135596801}");
2828 "TimestampProtoInputTooLarge",
REQUIRED,
2829 "optional_timestamp: {seconds: 253402300800}");
2832 R
"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})",
2834 return value[
"optionalTimestamp"].asString() ==
"1970-01-01T00:00:00Z";
2839 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})",
2841 return value[
"optionalTimestamp"].asString() ==
"1970-01-01T00:00:00Z";
2846 R
"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})",
2848 return value[
"optionalTimestamp"].asString() ==
2849 "1970-01-01T00:00:00.010Z";
2854 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})",
2856 return value[
"optionalTimestamp"].asString() ==
2857 "1970-01-01T00:00:00.000010Z";
2862 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})",
2864 return value[
"optionalTimestamp"].asString() ==
2865 "1970-01-01T00:00:00.000000010Z";
2873 R
"({"optionalFieldMask": "foo,barBaz"})",
2874 R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
2877 R
"({"optionalFieldMask": ""})",
2878 R"(optional_field_mask: {})");
2881 R
"({"optionalFieldMask": "foo,bar_bar"})");
2884 R
"(optional_field_mask: {paths: "fooBar"})");
2887 R
"(optional_field_mask: {paths: "foo_3_bar"})");
2890 R
"(optional_field_mask: {paths: "foo__bar"})");
2901 "doubleValue": 1234.5678,
2902 "stringValue": "Hello world!",
2903 "listValue": [1234, "5678"],
2913 value: {null_value: NULL_VALUE}
2917 value: {number_value: 1234}
2921 value: {bool_value: true}
2925 value: {number_value: 1234.5678}
2929 value: {string_value: "Hello world!"}
2939 string_value: "5678"
2960 "StructWithEmptyListValue",
REQUIRED,
2982 R
"({"optionalValue": 1})",
2983 "optional_value: { number_value: 1}");
2986 R
"({"optionalValue": 1.5})",
2987 "optional_value: { number_value: 1.5}");
2990 R
"({"optionalValue": false})",
2991 "optional_value: { bool_value: false}");
2994 R
"({"optionalValue": null})",
2995 "optional_value: { null_value: NULL_VALUE}");
2998 R
"({"optionalValue": "hello"})",
2999 R"(optional_value: { string_value: "hello"})");
3002 R
"({"optionalValue": [0, "hello"]})",
3010 string_value: "hello"
3017 R
"({"optionalValue": {"value": 1}})",
3033 "repeatedValue": [["a"]]
3040 { string_value: "a"}
3049 "repeatedListValue": [["a"]]
3052 repeated_list_value: [
3055 { string_value: "a"}
3062 R
"({"oneofNullValue": "NULL_VALUE"})",
3064 return (
value.isMember(
"oneofNullValue") &&
3065 value[
"oneofNullValue"].isNull());
3070 R
"({"oneofNullValue": null})",
3072 return (
value.isMember(
"oneofNullValue") &&
3073 value[
"oneofNullValue"].isNull());
3078 R
"({"optionalNullValue": null})",
3080 return value.empty();
3090 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
3091 "optionalInt32": 12345
3096 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
3097 optional_int32: 12345
3105 "@type": "type.googleapis.com/google.protobuf.Any",
3107 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
3108 "optionalInt32": 12345
3114 [type.googleapis.com/google.protobuf.Any] {
3115 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
3116 optional_int32: 12345
3126 "optionalInt32": 12345,
3127 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3"
3132 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
3133 optional_int32: 12345
3139 "AnyWithInt32ValueWrapper",
REQUIRED,
3142 "@type": "type.googleapis.com/google.protobuf.Int32Value",
3148 [type.googleapis.com/google.protobuf.Int32Value] {
3157 "@type": "type.googleapis.com/google.protobuf.Duration",
3163 [type.googleapis.com/google.protobuf.Duration] {
3173 "@type": "type.googleapis.com/google.protobuf.Timestamp",
3174 "value": "1970-01-01T00:00:00Z"
3179 [type.googleapis.com/google.protobuf.Timestamp] {
3189 "@type": "type.googleapis.com/google.protobuf.FieldMask",
3190 "value": "foo,barBaz"
3195 [type.googleapis.com/google.protobuf.FieldMask] {
3196 paths: ["foo", "bar_baz"]
3204 "@type": "type.googleapis.com/google.protobuf.Struct",
3212 [type.googleapis.com/google.protobuf.Struct] {
3223 "AnyWithValueForJsonObject",
REQUIRED,
3226 "@type": "type.googleapis.com/google.protobuf.Value",
3234 [type.googleapis.com/google.protobuf.Value] {
3247 "AnyWithValueForInteger",
REQUIRED,
3250 "@type": "type.googleapis.com/google.protobuf.Value",
3256 [type.googleapis.com/google.protobuf.Value] {