35 #include <google/protobuf/test_messages_proto3.pb.h>
36 #include <google/protobuf/test_messages_proto2.pb.h>
45 using conformance::ConformanceRequest;
46 using conformance::ConformanceResponse;
47 using conformance::WireFormat;
54 using protobuf_test_messages::proto3::TestAllTypesProto3;
55 using protobuf_test_messages::proto2::TestAllTypesProto2;
73 string cat(
const string&
a,
const string&
b,
74 const string& c = empty,
75 const string& d = empty,
76 const string& e = empty,
77 const string&
f = empty,
78 const string&
g = empty,
79 const string&
h = empty,
80 const string&
i = empty,
81 const string& j = empty,
82 const string& k = empty,
83 const string& l = 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; }
109 uint8_t
byte =
val & 0x7fU;
111 if (
val || over_encoded_bytes)
byte |= 0x80U;
114 while (over_encoded_bytes--) {
116 uint8_t
byte = over_encoded_bytes ? 0x80 : 0;
122 string varint(uint64_t
x) {
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); }
148 string tag(uint32_t fieldnum,
char wire_type) {
149 return varint((fieldnum << 3) | wire_type);
152 string submsg(uint32_t fn,
const string&
buf) {
156 #define UNKNOWN_FIELD 666
159 bool repeated,
bool is_proto3) {
162 TestAllTypesProto3().GetDescriptor() : TestAllTypesProto2().GetDescriptor();
163 for (
int i = 0;
i <
d->field_count();
i++) {
165 if (
f->type() ==
type &&
f->is_repeated() == repeated) {
173 string UpperCase(
string str) {
174 for (
int i = 0;
i <
str.size();
i++) {
180 std::unique_ptr<Message> NewTestMessage(
bool is_proto3) {
181 std::unique_ptr<Message> prototype;
183 prototype.reset(
new TestAllTypesProto3());
185 prototype.reset(
new TestAllTypesProto2());
196 const ConformanceResponse& response,
198 string binary_protobuf;
201 response.json_payload(), &binary_protobuf);
209 <<
"INTERNAL ERROR: internal JSON->protobuf transcode "
210 <<
"yielded unparseable proto.";
218 const ConformanceResponse& response,
221 const ConformanceRequest& request = setting.
GetRequest();
222 WireFormat requested_output = request.requested_output_format();
227 case ConformanceResponse::kProtobufPayload: {
228 if (requested_output != conformance::PROTOBUF) {
232 " output but provided PROTOBUF instead.").c_str());
238 "Protobuf output we received from test was unparseable.");
245 case ConformanceResponse::kJsonPayload: {
246 if (requested_output != conformance::JSON) {
250 " output but provided JSON instead.").c_str());
256 "JSON output we received from test was unparseable.");
274 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
278 level, conformance::PROTOBUF, conformance::PROTOBUF,
279 conformance::BINARY_TEST,
280 *prototype, test_name, proto);
282 const ConformanceRequest& request = setting.
GetRequest();
284 string effective_test_name =
286 (is_proto3 ?
".Proto3" :
".Proto2"),
287 ".ProtobufInput.", test_name);
290 if (
response.result_case() == ConformanceResponse::kParseError) {
292 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
296 "Should have failed to parse, but didn't.");
319 const string& equivalent_text_format) {
320 TestAllTypesProto3 prototype;
322 level, conformance::JSON, conformance::PROTOBUF,
323 conformance::JSON_TEST,
324 prototype, test_name, input_json);
327 level, conformance::JSON, conformance::JSON,
328 conformance::JSON_TEST,
329 prototype, test_name, input_json);
335 const string& equivalent_text_format) {
337 level, conformance::PROTOBUF, conformance::JSON,
338 conformance::JSON_TEST,
345 const string& equivalent_text_format) {
346 TestAllTypesProto3 prototype;
348 level, conformance::JSON, conformance::PROTOBUF,
349 conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST,
350 prototype, test_name, input_json);
356 const string& input_protobuf,
const string& equivalent_text_format,
358 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
361 level, conformance::PROTOBUF, conformance::PROTOBUF,
362 conformance::BINARY_TEST,
363 *prototype, test_name, input_protobuf);
368 level, conformance::PROTOBUF, conformance::JSON,
369 conformance::BINARY_TEST,
370 *prototype, test_name, input_protobuf);
377 const string& input_protobuf,
bool is_proto3) {
378 std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
380 level, conformance::PROTOBUF, conformance::PROTOBUF,
381 conformance::BINARY_TEST,
382 *prototype, test_name, input_protobuf);
388 const string& equivalent_text_format,
bool is_proto3) {
390 equivalent_text_format, is_proto3);
401 TestAllTypesProto3 prototype;
403 level, conformance::JSON, conformance::JSON,
404 conformance::JSON_TEST,
405 prototype, test_name, input_json);
406 const ConformanceRequest& request = setting.
GetRequest();
408 string effective_test_name =
410 ".Proto3.JsonInput.",
411 test_name,
".Validator");
415 if (
response.result_case() == ConformanceResponse::kSkipped) {
420 if (
response.result_case() != ConformanceResponse::kJsonPayload) {
422 "Expected JSON payload but got type %d.",
430 "JSON payload cannot be parsed as valid JSON: %s",
434 if (!validator(
value)) {
436 "JSON payload validation failed.");
444 TestAllTypesProto3 prototype;
448 level, conformance::JSON, conformance::JSON,
449 conformance::JSON_TEST,
450 prototype, test_name, input_json);
451 const ConformanceRequest& request = setting.
GetRequest();
453 string effective_test_name =
455 ".Proto3.JsonInput.", test_name);
458 if (
response.result_case() == ConformanceResponse::kParseError) {
460 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
464 "Should have failed to parse, but didn't.");
470 TestAllTypesProto3 payload_message;
473 <<
"Failed to parse: " << text_format;
475 TestAllTypesProto3 prototype;
477 level, conformance::PROTOBUF, conformance::JSON,
478 conformance::JSON_TEST,
479 prototype, test_name, payload_message.SerializeAsString());
480 const ConformanceRequest& request = setting.
GetRequest();
482 string effective_test_name =
484 ".", test_name,
".JsonOutput");
487 if (
response.result_case() == ConformanceResponse::kSerializeError) {
489 }
else if (
response.result_case() == ConformanceResponse::kSkipped) {
493 "Should have failed to serialize, but didn't.");
501 static const string incompletes[6] = {
514 const string& incomplete = incompletes[wire_type];
515 const string type_name =
519 tag(
field->number(), wire_type),
520 "PrematureEofBeforeKnownNonRepeatedValue" + type_name,
REQUIRED);
523 tag(rep_field->
number(), wire_type),
524 "PrematureEofBeforeKnownRepeatedValue" + type_name,
REQUIRED);
528 "PrematureEofBeforeUnknownValue" + type_name,
REQUIRED);
531 cat( tag(
field->number(), wire_type), incomplete ),
532 "PrematureEofInsideKnownNonRepeatedValue" + type_name,
REQUIRED);
535 cat( tag(rep_field->
number(), wire_type), incomplete ),
536 "PrematureEofInsideKnownRepeatedValue" + type_name,
REQUIRED);
540 "PrematureEofInsideUnknownValue" + type_name,
REQUIRED);
544 cat( tag(
field->number(), wire_type), varint(1) ),
545 "PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name,
549 cat( tag(rep_field->
number(), wire_type), varint(1) ),
550 "PrematureEofInDelimitedDataForKnownRepeatedValue" + type_name,
556 "PrematureEofInDelimitedDataForUnknownValue" + type_name,
REQUIRED);
560 string incomplete_submsg =
565 varint(incomplete_submsg.size()),
567 "PrematureEofInSubmessageValue" + type_name,
REQUIRED);
575 varint(incomplete.size()), incomplete),
576 "PrematureEofInPackedFieldValue" + type_name,
REQUIRED);
582 "PrematureEofInPackedField" + type_name,
REQUIRED);
588 std::vector<std::pair<std::string, std::string>>
values) {
589 for (
int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
590 const string type_name =
598 cat(tag(
field->number(), wire_type),
values[0].first),
599 field->name() +
": " +
values[0].second, is_proto3);
602 string text =
field->name() +
": " +
values.back().second;
603 for (
size_t i = 0;
i <
values.size();
i++) {
604 proto += cat(tag(
field->number(), wire_type),
values[
i].first);
607 proto, text, is_proto3);
612 for (
size_t i = 0;
i <
values.size();
i++) {
613 proto += cat(tag(rep_field->
number(), wire_type),
values[
i].first);
614 text += rep_field->
name() +
": " +
values[
i].second +
" ";
617 proto, text, is_proto3);
624 string nullfield[] = {
630 for (
int i = 0;
i < 4;
i++) {
631 string name =
"IllegalZeroFieldNum_Case_0";
636 template <
class MessageType>
638 MessageType &
message,
bool is_proto3) {
642 message.mutable_oneof_nested_message()->set_a(0);
645 is_proto3 ?
"oneof_nested_message: {}" :
"oneof_nested_message: {a: 0}",
647 message.mutable_oneof_nested_message()->set_a(1);
650 "oneof_nested_message: {a: 1}",
670 message.set_oneof_enum(MessageType::FOO);
675 template <
class MessageType>
677 MessageType&
message,
bool is_proto3) {
678 message.ParseFromString(
"\xA8\x1F\x01");
680 message.SerializeAsString(), is_proto3);
686 conformance::FailureSet failure_set;
687 ConformanceRequest
req;
688 ConformanceResponse res;
689 req.set_message_type(failure_set.GetTypeName());
690 req.set_protobuf_payload(
"");
691 req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
693 GOOGLE_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
694 for (
const string& failure : failure_set.failure()) {
709 int64 kInt64Min = -9223372036854775808
ULL;
710 int64 kInt64Max = 9223372036854775807
ULL;
711 uint64 kUint64Max = 18446744073709551615
ULL;
712 int32 kInt32Max = 2147483647;
713 int32 kInt32Min = -2147483648;
714 uint32 kUint32Max = 4294967295UL;
718 {dbl(1.7976931348623157e+308),
"1.7976931348623157e+308"},
719 {dbl(2.22507385850720138309e-308),
"2.22507385850720138309e-308"}
723 {flt(1.00000075e-36),
"1.00000075e-36"},
724 {flt(3.402823e+38),
"3.402823e+38"},
725 {flt(1.17549435e-38
f),
"1.17549435e-38"}
728 {varint(12345),
"12345"},
729 {varint(kInt64Max), std::to_string(kInt64Max)},
730 {varint(kInt64Min), std::to_string(kInt64Min)}
733 {varint(12345),
"12345"},
734 {varint(kUint64Max), std::to_string(kUint64Max)},
738 {varint(12345),
"12345"},
739 {longvarint(12345, 2),
"12345"},
740 {longvarint(12345, 7),
"12345"},
741 {varint(kInt32Max), std::to_string(kInt32Max)},
742 {varint(kInt32Min), std::to_string(kInt32Min)},
743 {varint(1
LL << 33), std::to_string(
static_cast<int32>(1
LL << 33))},
744 {varint((1
LL << 33) - 1),
745 std::to_string(
static_cast<int32>((1
LL << 33) - 1))},
748 {varint(12345),
"12345"},
749 {longvarint(12345, 2),
"12345"},
750 {longvarint(12345, 7),
"12345"},
751 {varint(kUint32Max), std::to_string(kUint32Max)},
753 {varint(1
LL << 33), std::to_string(
static_cast<uint32>(1
LL << 33))},
754 {varint((1
LL << 33) - 1),
755 std::to_string(
static_cast<uint32>((1
LL << 33) - 1))},
758 {u64(12345),
"12345"},
759 {u64(kUint64Max), std::to_string(kUint64Max)},
763 {u32(12345),
"12345"},
764 {u32(kUint32Max), std::to_string(kUint32Max)},
768 {u64(12345),
"12345"},
769 {u64(kInt64Max), std::to_string(kInt64Max)},
770 {u64(kInt64Min), std::to_string(kInt64Min)}
773 {u32(12345),
"12345"},
774 {u32(kInt32Max), std::to_string(kInt32Max)},
775 {u32(kInt32Min), std::to_string(kInt32Min)}
779 {varint(0),
"false"},
780 {varint(12345678),
"true"}
783 {zz32(12345),
"12345"},
784 {zz32(kInt32Max), std::to_string(kInt32Max)},
785 {zz32(kInt32Min), std::to_string(kInt32Min)}
788 {zz64(12345),
"12345"},
789 {zz64(kInt64Max), std::to_string(kInt64Max)},
790 {zz64(kInt64Min), std::to_string(kInt64Min)}
801 "{\"optionalString\":\"Hello, World!\"}",
802 "optional_string: 'Hello, World!'");
832 "FieldNameWithMixedCases",
REQUIRED,
883 "__field_name13": 13,
884 "__Field_name14": 14,
887 "field_name17__": 17,
913 R
"({"fieldn\u0061me1": 1})",
918 "{\"optionalString\": \"abc\\");
926 R
"({"fieldname1":1,})");
929 R
"({"fieldname1":1 ,})");
931 "TrailingCommaInAnObjectWithSpaceCommaSpace",
RECOMMENDED,
932 R
"({"fieldname1":1 , })");
934 "TrailingCommaInAnObjectWithNewlines",
RECOMMENDED,
942 // This is a comment.
948 "{\"optionalInt32\":1,\"optionalInt64\":2}",
955 "{ \"optionalInt32\" : 1 , \"optionalInt64\" : 2 }",
962 "{\n\"optionalInt32\"\n:\n1\n,\n\"optionalInt64\"\n:\n2\n}",
969 "{\n \"optionalInt32\" : 1\n ,\n \"optionalInt64\" : 2\n}\n",
977 "{ \"optionalInt32\": 1 \"optionalInt64\": 2 }");
980 "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
985 "optionalNestedMessage": {a: 1},
986 "optionalNestedMessage": {}
991 "optional_nested_message": {a: 1},
992 "optionalNestedMessage": {}
997 "optionalNestedMessage": {a: 1},
998 "optional_nested_message": {}
1002 "FieldNameInLowerCamelCase",
REQUIRED,
1010 return value.isMember(
"fieldname1") &&
1011 value.isMember(
"fieldName2") &&
1012 value.isMember(
"FieldName3") &&
1013 value.isMember(
"fieldName4");
1022 return value.isMember(
"field0name5") &&
1023 value.isMember(
"field0Name6");
1026 "FieldNameWithMixedCases",
REQUIRED,
1036 return value.isMember(
"fieldName7") &&
1037 value.isMember(
"FieldName8") &&
1038 value.isMember(
"fieldName9") &&
1039 value.isMember(
"FieldName10") &&
1040 value.isMember(
"FIELDNAME11") &&
1041 value.isMember(
"FIELDName12");
1054 return value.isMember(
"FieldName13") &&
1055 value.isMember(
"FieldName14") &&
1056 value.isMember(
"fieldName15") &&
1057 value.isMember(
"fieldName16") &&
1058 value.isMember(
"fieldName17") &&
1059 value.isMember(
"FieldName18");
1065 R
"({"optionalInt32": 2147483647})",
1066 "optional_int32: 2147483647");
1069 R
"({"optionalInt32": -2147483648})",
1070 "optional_int32: -2147483648");
1073 R
"({"optionalUint32": 4294967295})",
1074 "optional_uint32: 4294967295");
1077 R
"({"optionalInt64": "9223372036854775807"})",
1078 "optional_int64: 9223372036854775807");
1081 R
"({"optionalInt64": "-9223372036854775808"})",
1082 "optional_int64: -9223372036854775808");
1085 R
"({"optionalUint64": "18446744073709551615"})",
1086 "optional_uint64: 18446744073709551615");
1094 "Int64FieldMaxValueNotQuoted",
REQUIRED,
1095 R
"({"optionalInt64": 9223372036854774784})",
1096 "optional_int64: 9223372036854774784");
1098 "Int64FieldMinValueNotQuoted",
REQUIRED,
1099 R
"({"optionalInt64": -9223372036854775808})",
1100 "optional_int64: -9223372036854775808");
1104 "Uint64FieldMaxValueNotQuoted",
REQUIRED,
1105 R
"({"optionalUint64": 18446744073709549568})",
1106 "optional_uint64: 18446744073709549568");
1110 R
"({"optionalInt32": "2147483647"})",
1111 "optional_int32: 2147483647");
1113 "Int32FieldStringValueEscaped",
REQUIRED,
1114 R
"({"optionalInt32": "2\u003147483647"})",
1115 "optional_int32: 2147483647");
1120 R
"({"optionalInt32": 2147483648})");
1123 R
"({"optionalInt32": -2147483649})");
1126 R
"({"optionalUint32": 4294967296})");
1129 R
"({"optionalInt64": "9223372036854775808"})");
1132 R
"({"optionalInt64": "-9223372036854775809"})");
1135 R
"({"optionalUint64": "18446744073709551616"})");
1139 R
"({"optionalInt32": 0.5})");
1142 R
"({"optionalUint32": 0.5})");
1145 R
"({"optionalInt64": "0.5"})");
1148 R
"({"optionalUint64": "0.5"})");
1152 "Int32FieldFloatTrailingZero",
REQUIRED,
1153 R
"({"optionalInt32": 100000.000})",
1154 "optional_int32: 100000");
1156 "Int32FieldExponentialFormat",
REQUIRED,
1157 R
"({"optionalInt32": 1e5})",
1158 "optional_int32: 100000");
1160 "Int32FieldMaxFloatValue",
REQUIRED,
1161 R
"({"optionalInt32": 2.147483647e9})",
1162 "optional_int32: 2147483647");
1164 "Int32FieldMinFloatValue",
REQUIRED,
1165 R
"({"optionalInt32": -2.147483648e9})",
1166 "optional_int32: -2147483648");
1168 "Uint32FieldMaxFloatValue",
REQUIRED,
1169 R
"({"optionalUint32": 4.294967295e9})",
1170 "optional_uint32: 4294967295");
1175 R
"({"optionalInt32": "3x3"})");
1178 R
"({"optionalUint32": "3x3"})");
1181 R
"({"optionalInt64": "3x3"})");
1184 R
"({"optionalUint64": "3x3"})");
1188 R
"({"optionalInt32": +1})");
1192 R
"({"optionalInt32": 01})");
1194 "Int32FieldNegativeWithLeadingZero",
REQUIRED,
1195 R
"({"optionalInt32": -01})");
1199 "Int32FieldLeadingSpace",
REQUIRED,
1200 R
"({"optionalInt32": " 1"})");
1202 "Int32FieldTrailingSpace",
REQUIRED,
1203 R
"({"optionalInt32": "1 "})");
1208 R
"({"optionalInt64": 1})",
1211 value[
"optionalInt64"].asString() ==
"1";
1215 R
"({"optionalUint64": 1})",
1218 value[
"optionalUint64"].asString() ==
"1";
1224 R
"({"optionalBool":true})",
1225 "optional_bool: true");
1228 R
"({"optionalBool":false})",
1229 "optional_bool: false");
1234 R
"({"optionalBool":0})");
1237 R
"({"optionalBool":1})");
1240 R
"({"optionalBool":True})");
1243 R
"({"optionalBool":False})");
1246 R
"({"optionalBool":TRUE})");
1249 R
"({"optionalBool":FALSE})");
1252 R
"({"optionalBool":"true"})");
1255 R
"({"optionalBool":"false"})");
1259 "FloatFieldMinPositiveValue",
REQUIRED,
1260 R
"({"optionalFloat": 1.175494e-38})",
1261 "optional_float: 1.175494e-38");
1263 "FloatFieldMaxNegativeValue",
REQUIRED,
1264 R
"({"optionalFloat": -1.175494e-38})",
1265 "optional_float: -1.175494e-38");
1267 "FloatFieldMaxPositiveValue",
REQUIRED,
1268 R
"({"optionalFloat": 3.402823e+38})",
1269 "optional_float: 3.402823e+38");
1271 "FloatFieldMinNegativeValue",
REQUIRED,
1272 R
"({"optionalFloat": 3.402823e+38})",
1273 "optional_float: 3.402823e+38");
1277 R
"({"optionalFloat": "1"})",
1278 "optional_float: 1");
1282 R
"({"optionalFloat": "NaN"})",
1283 "optional_float: nan");
1286 R
"({"optionalFloat": "Infinity"})",
1287 "optional_float: inf");
1289 "FloatFieldNegativeInfinity",
REQUIRED,
1290 R
"({"optionalFloat": "-Infinity"})",
1291 "optional_float: -inf");
1301 "optional_float: nan");
1308 "optional_float: nan");
1314 R
"({"optionalFloat": NaN})");
1317 R
"({"optionalFloat": Infinity})");
1319 "FloatFieldNegativeInfinityNotQuoted",
RECOMMENDED,
1320 R
"({"optionalFloat": -Infinity})");
1324 R
"({"optionalFloat": -3.502823e+38})");
1327 R
"({"optionalFloat": 3.502823e+38})");
1331 "DoubleFieldMinPositiveValue",
REQUIRED,
1332 R
"({"optionalDouble": 2.22507e-308})",
1333 "optional_double: 2.22507e-308");
1335 "DoubleFieldMaxNegativeValue",
REQUIRED,
1336 R
"({"optionalDouble": -2.22507e-308})",
1337 "optional_double: -2.22507e-308");
1339 "DoubleFieldMaxPositiveValue",
REQUIRED,
1340 R
"({"optionalDouble": 1.79769e+308})",
1341 "optional_double: 1.79769e+308");
1343 "DoubleFieldMinNegativeValue",
REQUIRED,
1344 R
"({"optionalDouble": -1.79769e+308})",
1345 "optional_double: -1.79769e+308");
1348 "DoubleFieldQuotedValue",
REQUIRED,
1349 R
"({"optionalDouble": "1"})",
1350 "optional_double: 1");
1354 R
"({"optionalDouble": "NaN"})",
1355 "optional_double: nan");
1358 R
"({"optionalDouble": "Infinity"})",
1359 "optional_double: inf");
1361 "DoubleFieldNegativeInfinity",
REQUIRED,
1362 R
"({"optionalDouble": "-Infinity"})",
1363 "optional_double: -inf");
1371 "optional_double: nan");
1376 "optional_double: nan");
1382 R
"({"optionalDouble": NaN})");
1385 R
"({"optionalDouble": Infinity})");
1387 "DoubleFieldNegativeInfinityNotQuoted",
RECOMMENDED,
1388 R
"({"optionalDouble": -Infinity})");
1393 R
"({"optionalDouble": -1.89769e+308})");
1396 R
"({"optionalDouble": +1.89769e+308})");
1401 R
"({"optionalNestedEnum": "FOO"})",
1402 "optional_nested_enum: FOO");
1406 R
"({"optionalAliasedEnum": "ALIAS_BAZ"})",
1407 "optional_aliased_enum: ALIAS_BAZ");
1409 "EnumFieldWithAliasUseAlias",
REQUIRED,
1410 R
"({"optionalAliasedEnum": "QUX"})",
1411 "optional_aliased_enum: ALIAS_BAZ");
1413 "EnumFieldWithAliasLowerCase",
REQUIRED,
1414 R
"({"optionalAliasedEnum": "qux"})",
1415 "optional_aliased_enum: ALIAS_BAZ");
1417 "EnumFieldWithAliasDifferentCase",
REQUIRED,
1418 R
"({"optionalAliasedEnum": "bAz"})",
1419 "optional_aliased_enum: ALIAS_BAZ");
1423 R
"({"optionalNestedEnum": FOO})");
1426 "EnumFieldNumericValueZero",
REQUIRED,
1427 R
"({"optionalNestedEnum": 0})",
1428 "optional_nested_enum: FOO");
1430 "EnumFieldNumericValueNonZero",
REQUIRED,
1431 R
"({"optionalNestedEnum": 1})",
1432 "optional_nested_enum: BAR");
1436 R
"({"optionalNestedEnum": 123})",
1439 value[
"optionalNestedEnum"].asInt() == 123;
1445 R
"({"optionalString": "Hello world!"})",
1446 "optional_string: \"Hello world!\"");
1450 R
"({"optionalString": "谷歌"})",
1451 R"(optional_string: "谷歌")");
1454 R
"({"optionalString": "\"\\\/\b\f\n\r\t"})",
1455 R"(optional_string: "\"\\/\b\f\n\r\t")");
1457 "StringFieldUnicodeEscape",
REQUIRED,
1458 R
"({"optionalString": "\u8C37\u6B4C"})",
1459 R"(optional_string: "谷歌")");
1461 "StringFieldUnicodeEscapeWithLowercaseHexLetters",
REQUIRED,
1462 R
"({"optionalString": "\u8c37\u6b4c"})",
1463 R"(optional_string: "谷歌")");
1465 "StringFieldSurrogatePair",
REQUIRED,
1467 R
"({"optionalString": "\uD83D\uDE01"})",
1468 R"(optional_string: "\xF0\x9F\x98\x81")");
1473 R
"({"optionalString": "\U8C37\U6b4C"})");
1476 R
"({"optionalString": "\uXXXX\u6B4C"})");
1479 R
"({"optionalString": "\u8C3"})");
1482 R
"({"optionalString": "\uD800"})");
1485 R
"({"optionalString": "\uDC00"})");
1488 R
"({"optionalString": "\uDE01\uD83D"})");
1491 R
"({"optionalString": 12345})");
1496 R
"({"optionalBytes": "AQI="})",
1497 R"(optional_bytes: "\x01\x02")");
1500 R
"({"optionalBytes": "-_"})",
1501 R"(optional_bytes: "\xfb")");
1506 R
"({"optionalNestedMessage": {"a": 1234}})",
1507 "optional_nested_message: {a: 1234}");
1512 R
"({"oneofUint32": 1, "oneofString": "test"})");
1514 TestAllTypesProto3 messageProto3;
1515 TestAllTypesProto2 messageProto2;
1520 R
"({"oneofUint32": 0})", "oneof_uint32: 0");
1523 R
"({"oneofNestedMessage": {}})", "oneof_nested_message: {}");
1526 R
"({"oneofString": ""})", "oneof_string: \"\"");
1529 R
"({"oneofBytes": ""})", "oneof_bytes: \"\"");
1532 R
"({"oneofBool": false})", "oneof_bool: false");
1535 R
"({"oneofUint64": 0})", "oneof_uint64: 0");
1538 R
"({"oneofFloat": 0.0})", "oneof_float: 0");
1541 R
"({"oneofDouble": 0.0})", "oneof_double: 0");
1544 R
"({"oneofEnum":"FOO"})", "oneof_enum: FOO");
1548 "PrimitiveRepeatedField",
REQUIRED,
1549 R
"({"repeatedInt32": [1, 2, 3, 4]})",
1550 "repeated_int32: [1, 2, 3, 4]");
1553 R
"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})",
1554 "repeated_nested_enum: [FOO, BAR, BAZ]");
1557 R
"({"repeatedString": ["Hello", "world"]})",
1558 R"(repeated_string: ["Hello", "world"])");
1561 R
"({"repeatedBytes": ["AAEC", "AQI="]})",
1562 R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])");
1565 R
"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})",
1566 "repeated_nested_message: {a: 1234}"
1567 "repeated_nested_message: {a: 5678}");
1571 "RepeatedFieldWrongElementTypeExpectingIntegersGotBool",
REQUIRED,
1572 R
"({"repeatedInt32": [1, false, 3, 4]})");
1574 "RepeatedFieldWrongElementTypeExpectingIntegersGotString",
REQUIRED,
1575 R
"({"repeatedInt32": [1, 2, "name", 4]})");
1577 "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage",
REQUIRED,
1578 R
"({"repeatedInt32": [1, 2, 3, {"a": 4}]})");
1580 "RepeatedFieldWrongElementTypeExpectingStringsGotInt",
REQUIRED,
1581 R
"({"repeatedString": ["1", 2, "3", "4"]})");
1583 "RepeatedFieldWrongElementTypeExpectingStringsGotBool",
REQUIRED,
1584 R
"({"repeatedString": ["1", "2", false, "4"]})");
1586 "RepeatedFieldWrongElementTypeExpectingStringsGotMessage",
REQUIRED,
1587 R
"({"repeatedString": ["1", 2, "3", {"a": 4}]})");
1589 "RepeatedFieldWrongElementTypeExpectingMessagesGotInt",
REQUIRED,
1590 R
"({"repeatedNestedMessage": [{"a": 1}, 2]})");
1592 "RepeatedFieldWrongElementTypeExpectingMessagesGotBool",
REQUIRED,
1593 R
"({"repeatedNestedMessage": [{"a": 1}, false]})");
1595 "RepeatedFieldWrongElementTypeExpectingMessagesGotString",
REQUIRED,
1596 R
"({"repeatedNestedMessage": [{"a": 1}, "2"]})");
1600 R
"({"repeatedInt32": [1, 2, 3, 4,]})");
1602 "RepeatedFieldTrailingCommaWithSpace",
RECOMMENDED,
1603 "{\"repeatedInt32\": [1, 2, 3, 4 ,]}");
1605 "RepeatedFieldTrailingCommaWithSpaceCommaSpace",
RECOMMENDED,
1606 "{\"repeatedInt32\": [1, 2, 3, 4 , ]}");
1608 "RepeatedFieldTrailingCommaWithNewlines",
RECOMMENDED,
1609 "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}");
1614 R
"({"mapInt32Int32": {"1": 2, "3": 4}})",
1615 "map_int32_int32: {key: 1 value: 2}"
1616 "map_int32_int32: {key: 3 value: 4}");
1619 R
"({"mapInt32Int32": {1: 2, 3: 4}})");
1622 R
"({"mapUint32Uint32": {"1": 2, "3": 4}})",
1623 "map_uint32_uint32: {key: 1 value: 2}"
1624 "map_uint32_uint32: {key: 3 value: 4}");
1627 R
"({"mapUint32Uint32": {1: 2, 3: 4}})");
1630 R
"({"mapInt64Int64": {"1": 2, "3": 4}})",
1631 "map_int64_int64: {key: 1 value: 2}"
1632 "map_int64_int64: {key: 3 value: 4}");
1635 R
"({"mapInt64Int64": {1: 2, 3: 4}})");
1638 R
"({"mapUint64Uint64": {"1": 2, "3": 4}})",
1639 "map_uint64_uint64: {key: 1 value: 2}"
1640 "map_uint64_uint64: {key: 3 value: 4}");
1643 R
"({"mapUint64Uint64": {1: 2, 3: 4}})");
1646 R
"({"mapBoolBool": {"true": true, "false": false}})",
1647 "map_bool_bool: {key: true value: true}"
1648 "map_bool_bool: {key: false value: false}");
1651 R
"({"mapBoolBool": {true: true, false: false}})");
1655 "mapStringNestedMessage": {
1656 "hello": {"a": 1234},
1657 "world": {"a": 5678}
1661 map_string_nested_message: {
1665 map_string_nested_message: {
1673 R
"({"mapInt32Int32": {"\u0031": 2}})",
1674 "map_int32_int32: {key: 1 value: 2}");
1677 R
"({"mapInt64Int64": {"\u0031": 2}})",
1678 "map_int64_int64: {key: 1 value: 2}");
1681 R
"({"mapBoolBool": {"tr\u0075e": true}})",
1682 "map_bool_bool: {key: true value: true}");
1688 "optionalInt32": null,
1689 "optionalInt64": null,
1690 "optionalUint32": null,
1691 "optionalUint64": null,
1692 "optionalSint32": null,
1693 "optionalSint64": null,
1694 "optionalFixed32": null,
1695 "optionalFixed64": null,
1696 "optionalSfixed32": null,
1697 "optionalSfixed64": null,
1698 "optionalFloat": null,
1699 "optionalDouble": null,
1700 "optionalBool": null,
1701 "optionalString": null,
1702 "optionalBytes": null,
1703 "optionalNestedEnum": null,
1704 "optionalNestedMessage": null,
1705 "repeatedInt32": null,
1706 "repeatedInt64": null,
1707 "repeatedUint32": null,
1708 "repeatedUint64": null,
1709 "repeatedSint32": null,
1710 "repeatedSint64": null,
1711 "repeatedFixed32": null,
1712 "repeatedFixed64": null,
1713 "repeatedSfixed32": null,
1714 "repeatedSfixed64": null,
1715 "repeatedFloat": null,
1716 "repeatedDouble": null,
1717 "repeatedBool": null,
1718 "repeatedString": null,
1719 "repeatedBytes": null,
1720 "repeatedNestedEnum": null,
1721 "repeatedNestedMessage": null,
1722 "mapInt32Int32": null,
1723 "mapBoolBool": null,
1724 "mapStringNestedMessage": null
1730 "RepeatedFieldPrimitiveElementIsNull",
RECOMMENDED,
1731 R
"({"repeatedInt32": [1, null, 2]})");
1734 R
"({"repeatedNestedMessage": [{"a":1}, null, {"a":2}]})");
1738 R
"({"mapInt32Int32": {null: 1}})");
1742 R
"({"mapInt32Int32": {"0": null}})");
1748 R
"({'optionalString': "Hello world!"})");
1751 R
"({"optionalString": 'Hello world!'})");
1754 R
"({'optionalString': 'Hello world!'})");
1758 TestAllTypesProto3 messageProto3;
1759 TestAllTypesProto2 messageProto2;
1771 R
"({"optionalBoolWrapper": false})",
1772 "optional_bool_wrapper: {value: false}");
1775 R
"({"optionalInt32Wrapper": 0})",
1776 "optional_int32_wrapper: {value: 0}");
1779 R
"({"optionalUint32Wrapper": 0})",
1780 "optional_uint32_wrapper: {value: 0}");
1783 R
"({"optionalInt64Wrapper": 0})",
1784 "optional_int64_wrapper: {value: 0}");
1787 R
"({"optionalUint64Wrapper": 0})",
1788 "optional_uint64_wrapper: {value: 0}");
1791 R
"({"optionalFloatWrapper": 0})",
1792 "optional_float_wrapper: {value: 0}");
1795 R
"({"optionalDoubleWrapper": 0})",
1796 "optional_double_wrapper: {value: 0}");
1799 R
"({"optionalStringWrapper": ""})",
1800 R"(optional_string_wrapper: {value: ""})");
1803 R
"({"optionalBytesWrapper": ""})",
1804 R"(optional_bytes_wrapper: {value: ""})");
1806 "OptionalWrapperTypesWithNonDefaultValue",
REQUIRED,
1808 "optionalBoolWrapper": true,
1809 "optionalInt32Wrapper": 1,
1810 "optionalUint32Wrapper": 1,
1811 "optionalInt64Wrapper": "1",
1812 "optionalUint64Wrapper": "1",
1813 "optionalFloatWrapper": 1,
1814 "optionalDoubleWrapper": 1,
1815 "optionalStringWrapper": "1",
1816 "optionalBytesWrapper": "AQI="
1819 optional_bool_wrapper: {value: true}
1820 optional_int32_wrapper: {value: 1}
1821 optional_uint32_wrapper: {value: 1}
1822 optional_int64_wrapper: {value: 1}
1823 optional_uint64_wrapper: {value: 1}
1824 optional_float_wrapper: {value: 1}
1825 optional_double_wrapper: {value: 1}
1826 optional_string_wrapper: {value: "1"}
1827 optional_bytes_wrapper: {value: "\x01\x02"}
1831 R
"({"repeatedBoolWrapper": [true, false]})",
1832 "repeated_bool_wrapper: {value: true}"
1833 "repeated_bool_wrapper: {value: false}");
1836 R
"({"repeatedInt32Wrapper": [0, 1]})",
1837 "repeated_int32_wrapper: {value: 0}"
1838 "repeated_int32_wrapper: {value: 1}");
1841 R
"({"repeatedUint32Wrapper": [0, 1]})",
1842 "repeated_uint32_wrapper: {value: 0}"
1843 "repeated_uint32_wrapper: {value: 1}");
1846 R
"({"repeatedInt64Wrapper": [0, 1]})",
1847 "repeated_int64_wrapper: {value: 0}"
1848 "repeated_int64_wrapper: {value: 1}");
1851 R
"({"repeatedUint64Wrapper": [0, 1]})",
1852 "repeated_uint64_wrapper: {value: 0}"
1853 "repeated_uint64_wrapper: {value: 1}");
1856 R
"({"repeatedFloatWrapper": [0, 1]})",
1857 "repeated_float_wrapper: {value: 0}"
1858 "repeated_float_wrapper: {value: 1}");
1861 R
"({"repeatedDoubleWrapper": [0, 1]})",
1862 "repeated_double_wrapper: {value: 0}"
1863 "repeated_double_wrapper: {value: 1}");
1866 R
"({"repeatedStringWrapper": ["", "AQI="]})",
1868 repeated_string_wrapper: {value: ""}
1869 repeated_string_wrapper: {value: "AQI="}
1873 R
"({"repeatedBytesWrapper": ["", "AQI="]})",
1875 repeated_bytes_wrapper: {value: ""}
1876 repeated_bytes_wrapper: {value: "\x01\x02"}
1879 "WrapperTypesWithNullValue",
REQUIRED,
1881 "optionalBoolWrapper": null,
1882 "optionalInt32Wrapper": null,
1883 "optionalUint32Wrapper": null,
1884 "optionalInt64Wrapper": null,
1885 "optionalUint64Wrapper": null,
1886 "optionalFloatWrapper": null,
1887 "optionalDoubleWrapper": null,
1888 "optionalStringWrapper": null,
1889 "optionalBytesWrapper": null,
1890 "repeatedBoolWrapper": null,
1891 "repeatedInt32Wrapper": null,
1892 "repeatedUint32Wrapper": null,
1893 "repeatedInt64Wrapper": null,
1894 "repeatedUint64Wrapper": null,
1895 "repeatedFloatWrapper": null,
1896 "repeatedDoubleWrapper": null,
1897 "repeatedStringWrapper": null,
1898 "repeatedBytesWrapper": null
1905 R
"({"optionalDuration": "-315576000000.999999999s"})",
1906 "optional_duration: {seconds: -315576000000 nanos: -999999999}");
1909 R
"({"optionalDuration": "315576000000.999999999s"})",
1910 "optional_duration: {seconds: 315576000000 nanos: 999999999}");
1913 R
"({"repeatedDuration": ["1.5s", "-1.5s"]})",
1914 "repeated_duration: {seconds: 1 nanos: 500000000}"
1915 "repeated_duration: {seconds: -1 nanos: -500000000}");
1918 R
"({"optionalDuration": null})",
1923 R
"({"optionalDuration": "1"})");
1925 "DurationJsonInputTooSmall",
REQUIRED,
1926 R
"({"optionalDuration": "-315576000001.000000000s"})");
1928 "DurationJsonInputTooLarge",
REQUIRED,
1929 R
"({"optionalDuration": "315576000001.000000000s"})");
1931 "DurationProtoInputTooSmall",
REQUIRED,
1932 "optional_duration: {seconds: -315576000001 nanos: 0}");
1934 "DurationProtoInputTooLarge",
REQUIRED,
1935 "optional_duration: {seconds: 315576000001 nanos: 0}");
1939 R
"({"optionalDuration": "1.000000000s"})",
1941 return value[
"optionalDuration"].asString() ==
"1s";
1945 R
"({"optionalDuration": "1.010000000s"})",
1947 return value[
"optionalDuration"].asString() ==
"1.010s";
1951 R
"({"optionalDuration": "1.000010000s"})",
1953 return value[
"optionalDuration"].asString() ==
"1.000010s";
1957 R
"({"optionalDuration": "1.000000010s"})",
1959 return value[
"optionalDuration"].asString() ==
"1.000000010s";
1965 R
"({"optionalTimestamp": "0001-01-01T00:00:00Z"})",
1966 "optional_timestamp: {seconds: -62135596800}");
1969 R
"({"optionalTimestamp": "9999-12-31T23:59:59.999999999Z"})",
1970 "optional_timestamp: {seconds: 253402300799 nanos: 999999999}");
1972 "TimestampRepeatedValue",
REQUIRED,
1974 "repeatedTimestamp": [
1975 "0001-01-01T00:00:00Z",
1976 "9999-12-31T23:59:59.999999999Z"
1979 "repeated_timestamp: {seconds: -62135596800}"
1980 "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}");
1982 "TimestampWithPositiveOffset",
REQUIRED,
1983 R
"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})",
1984 "optional_timestamp: {seconds: 1}");
1986 "TimestampWithNegativeOffset",
REQUIRED,
1987 R
"({"optionalTimestamp": "1969-12-31T16:00:01-08:00"})",
1988 "optional_timestamp: {seconds: 1}");
1991 R
"({"optionalTimestamp": null})",
1995 "TimestampJsonInputTooSmall",
REQUIRED,
1996 R
"({"optionalTimestamp": "0000-01-01T00:00:00Z"})");
1998 "TimestampJsonInputTooLarge",
REQUIRED,
1999 R
"({"optionalTimestamp": "10000-01-01T00:00:00Z"})");
2001 "TimestampJsonInputMissingZ",
REQUIRED,
2002 R
"({"optionalTimestamp": "0001-01-01T00:00:00"})");
2004 "TimestampJsonInputMissingT",
REQUIRED,
2005 R
"({"optionalTimestamp": "0001-01-01 00:00:00Z"})");
2007 "TimestampJsonInputLowercaseZ",
REQUIRED,
2008 R
"({"optionalTimestamp": "0001-01-01T00:00:00z"})");
2010 "TimestampJsonInputLowercaseT",
REQUIRED,
2011 R
"({"optionalTimestamp": "0001-01-01t00:00:00Z"})");
2013 "TimestampProtoInputTooSmall",
REQUIRED,
2014 "optional_timestamp: {seconds: -62135596801}");
2016 "TimestampProtoInputTooLarge",
REQUIRED,
2017 "optional_timestamp: {seconds: 253402300800}");
2020 R
"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})",
2022 return value[
"optionalTimestamp"].asString() ==
2023 "1970-01-01T00:00:00Z";
2027 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})",
2029 return value[
"optionalTimestamp"].asString() ==
2030 "1970-01-01T00:00:00Z";
2034 R
"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})",
2036 return value[
"optionalTimestamp"].asString() ==
2037 "1970-01-01T00:00:00.010Z";
2041 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})",
2043 return value[
"optionalTimestamp"].asString() ==
2044 "1970-01-01T00:00:00.000010Z";
2048 R
"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})",
2050 return value[
"optionalTimestamp"].asString() ==
2051 "1970-01-01T00:00:00.000000010Z";
2057 R
"({"optionalFieldMask": "foo,barBaz"})",
2058 R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
2061 R
"({"optionalFieldMask": ""})",
2062 R"(optional_field_mask: {})");
2065 R
"({"optionalFieldMask": "foo,bar_bar"})");
2068 R
"(optional_field_mask: {paths: "fooBar"})");
2071 R
"(optional_field_mask: {paths: "foo_3_bar"})");
2074 R
"(optional_field_mask: {paths: "foo__bar"})");
2084 "doubleValue": 1234.5678,
2085 "stringValue": "Hello world!",
2086 "listValue": [1234, "5678"],
2096 value: {null_value: NULL_VALUE}
2100 value: {number_value: 1234}
2104 value: {bool_value: true}
2108 value: {number_value: 1234.5678}
2112 value: {string_value: "Hello world!"}
2122 string_value: "5678"
2143 "StructWithEmptyListValue",
REQUIRED,
2163 R
"({"optionalValue": 1})",
2164 "optional_value: { number_value: 1}");
2167 R
"({"optionalValue": 1.5})",
2168 "optional_value: { number_value: 1.5}");
2171 R
"({"optionalValue": false})",
2172 "optional_value: { bool_value: false}");
2175 R
"({"optionalValue": null})",
2176 "optional_value: { null_value: NULL_VALUE}");
2179 R
"({"optionalValue": "hello"})",
2180 R"(optional_value: { string_value: "hello"})");
2183 R
"({"optionalValue": [0, "hello"]})",
2191 string_value: "hello"
2198 R
"({"optionalValue": {"value": 1}})",
2214 "repeatedValue": [["a"]]
2221 { string_value: "a"}
2230 "repeatedListValue": [["a"]]
2233 repeated_list_value: [
2236 { string_value: "a"}
2247 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
2248 "optionalInt32": 12345
2253 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2254 optional_int32: 12345
2262 "@type": "type.googleapis.com/google.protobuf.Any",
2264 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
2265 "optionalInt32": 12345
2271 [type.googleapis.com/google.protobuf.Any] {
2272 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2273 optional_int32: 12345
2283 "optionalInt32": 12345,
2284 "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3"
2289 [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2290 optional_int32: 12345
2296 "AnyWithInt32ValueWrapper",
REQUIRED,
2299 "@type": "type.googleapis.com/google.protobuf.Int32Value",
2305 [type.googleapis.com/google.protobuf.Int32Value] {
2314 "@type": "type.googleapis.com/google.protobuf.Duration",
2320 [type.googleapis.com/google.protobuf.Duration] {
2330 "@type": "type.googleapis.com/google.protobuf.Timestamp",
2331 "value": "1970-01-01T00:00:00Z"
2336 [type.googleapis.com/google.protobuf.Timestamp] {
2346 "@type": "type.googleapis.com/google.protobuf.FieldMask",
2347 "value": "foo,barBaz"
2352 [type.googleapis.com/google.protobuf.FieldMask] {
2353 paths: ["foo", "bar_baz"]
2361 "@type": "type.googleapis.com/google.protobuf.Struct",
2369 [type.googleapis.com/google.protobuf.Struct] {
2380 "AnyWithValueForJsonObject",
REQUIRED,
2383 "@type": "type.googleapis.com/google.protobuf.Value",
2391 [type.googleapis.com/google.protobuf.Value] {
2404 "AnyWithValueForInteger",
REQUIRED,
2407 "@type": "type.googleapis.com/google.protobuf.Value",
2413 [type.googleapis.com/google.protobuf.Value] {
2420 "IgnoreUnknownJsonNumber",
REQUIRED,
2426 "IgnoreUnknownJsonString",
REQUIRED,
2438 "IgnoreUnknownJsonFalse",
REQUIRED,
2450 "IgnoreUnknownJsonObject",
REQUIRED,