|
|
@ -556,24 +556,24 @@ void BinaryAndJsonConformanceSuite::RunValidProtobufTestWithMessage( |
|
|
|
equivalent_text_format, is_proto3); |
|
|
|
equivalent_text_format, is_proto3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// According to proto3 JSON specification, JSON serializers follow more strict
|
|
|
|
// According to proto JSON specification, JSON serializers follow more strict
|
|
|
|
// rules than parsers (e.g., a serializer must serialize int32 values as JSON
|
|
|
|
// rules than parsers (e.g., a serializer must serialize int32 values as JSON
|
|
|
|
// numbers while the parser is allowed to accept them as JSON strings). This
|
|
|
|
// numbers while the parser is allowed to accept them as JSON strings). This
|
|
|
|
// method allows strict checking on a proto3 JSON serializer by inspecting
|
|
|
|
// method allows strict checking on a proto JSON serializer by inspecting
|
|
|
|
// the JSON output directly.
|
|
|
|
// the JSON output directly.
|
|
|
|
void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( |
|
|
|
void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( |
|
|
|
const string& test_name, ConformanceLevel level, const string& input_json, |
|
|
|
const string& test_name, ConformanceLevel level, const string& input_json, |
|
|
|
const Validator& validator) { |
|
|
|
const Validator& validator, bool is_proto3) { |
|
|
|
TestAllTypesProto3 prototype; |
|
|
|
std::unique_ptr<Message> prototype = NewTestMessage(is_proto3); |
|
|
|
ConformanceRequestSetting setting( |
|
|
|
ConformanceRequestSetting setting(level, conformance::JSON, conformance::JSON, |
|
|
|
level, conformance::JSON, conformance::JSON, |
|
|
|
conformance::JSON_TEST, *prototype, |
|
|
|
conformance::JSON_TEST, |
|
|
|
test_name, input_json); |
|
|
|
prototype, test_name, input_json); |
|
|
|
|
|
|
|
const ConformanceRequest& request = setting.GetRequest(); |
|
|
|
const ConformanceRequest& request = setting.GetRequest(); |
|
|
|
ConformanceResponse response; |
|
|
|
ConformanceResponse response; |
|
|
|
string effective_test_name = |
|
|
|
string effective_test_name = |
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
".Proto3.JsonInput.", test_name, ".Validator"); |
|
|
|
is_proto3 ? ".Proto3.JsonInput." : ".Proto2.JsonInput.", |
|
|
|
|
|
|
|
test_name, ".Validator"); |
|
|
|
|
|
|
|
|
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
|
|
|
|
|
|
|
@ -1800,7 +1800,8 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { |
|
|
|
value.isMember("fieldName2") && |
|
|
|
value.isMember("fieldName2") && |
|
|
|
value.isMember("FieldName3") && |
|
|
|
value.isMember("FieldName3") && |
|
|
|
value.isMember("fieldName4"); |
|
|
|
value.isMember("fieldName4"); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"FieldNameWithNumbers", REQUIRED, |
|
|
|
"FieldNameWithNumbers", REQUIRED, |
|
|
|
R"({ |
|
|
|
R"({ |
|
|
@ -1810,7 +1811,8 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value.isMember("field0name5") && |
|
|
|
return value.isMember("field0name5") && |
|
|
|
value.isMember("field0Name6"); |
|
|
|
value.isMember("field0Name6"); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"FieldNameWithMixedCases", REQUIRED, |
|
|
|
"FieldNameWithMixedCases", REQUIRED, |
|
|
|
R"({ |
|
|
|
R"({ |
|
|
@ -1828,7 +1830,8 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { |
|
|
|
value.isMember("FieldName10") && |
|
|
|
value.isMember("FieldName10") && |
|
|
|
value.isMember("FIELDNAME11") && |
|
|
|
value.isMember("FIELDNAME11") && |
|
|
|
value.isMember("FIELDName12"); |
|
|
|
value.isMember("FIELDName12"); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"FieldNameWithDoubleUnderscores", RECOMMENDED, |
|
|
|
"FieldNameWithDoubleUnderscores", RECOMMENDED, |
|
|
|
R"({ |
|
|
|
R"({ |
|
|
@ -1846,7 +1849,22 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { |
|
|
|
value.isMember("fieldName16") && |
|
|
|
value.isMember("fieldName16") && |
|
|
|
value.isMember("fieldName17") && |
|
|
|
value.isMember("fieldName17") && |
|
|
|
value.isMember("FieldName18"); |
|
|
|
value.isMember("FieldName18"); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
|
|
|
"StoresDefaultPrimitive", REQUIRED, |
|
|
|
|
|
|
|
R"({ |
|
|
|
|
|
|
|
"FieldName13": 0 |
|
|
|
|
|
|
|
})", |
|
|
|
|
|
|
|
[](const Json::Value& value) { return value.isMember("FieldName13"); }, |
|
|
|
|
|
|
|
false); |
|
|
|
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
|
|
|
"SkipsDefaultPrimitive", REQUIRED, |
|
|
|
|
|
|
|
R"({ |
|
|
|
|
|
|
|
"FieldName13": 0 |
|
|
|
|
|
|
|
})", |
|
|
|
|
|
|
|
[](const Json::Value& value) { return !value.isMember("FieldName13"); }, |
|
|
|
|
|
|
|
true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { |
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { |
|
|
@ -1995,19 +2013,19 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { |
|
|
|
|
|
|
|
|
|
|
|
// 64-bit values are serialized as strings.
|
|
|
|
// 64-bit values are serialized as strings.
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"Int64FieldBeString", RECOMMENDED, |
|
|
|
"Int64FieldBeString", RECOMMENDED, R"({"optionalInt64": 1})", |
|
|
|
R"({"optionalInt64": 1})", |
|
|
|
|
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalInt64"].type() == Json::stringValue && |
|
|
|
return value["optionalInt64"].type() == Json::stringValue && |
|
|
|
value["optionalInt64"].asString() == "1"; |
|
|
|
value["optionalInt64"].asString() == "1"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"Uint64FieldBeString", RECOMMENDED, |
|
|
|
"Uint64FieldBeString", RECOMMENDED, R"({"optionalUint64": 1})", |
|
|
|
R"({"optionalUint64": 1})", |
|
|
|
|
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalUint64"].type() == Json::stringValue && |
|
|
|
return value["optionalUint64"].type() == Json::stringValue && |
|
|
|
value["optionalUint64"].asString() == "1"; |
|
|
|
value["optionalUint64"].asString() == "1"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
|
|
|
|
|
|
|
|
// Bool fields.
|
|
|
|
// Bool fields.
|
|
|
|
RunValidJsonTest( |
|
|
|
RunValidJsonTest( |
|
|
@ -2223,12 +2241,12 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { |
|
|
|
"optional_nested_enum: BAR"); |
|
|
|
"optional_nested_enum: BAR"); |
|
|
|
// Unknown enum values are represented as numeric values.
|
|
|
|
// Unknown enum values are represented as numeric values.
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"EnumFieldUnknownValue", REQUIRED, |
|
|
|
"EnumFieldUnknownValue", REQUIRED, R"({"optionalNestedEnum": 123})", |
|
|
|
R"({"optionalNestedEnum": 123})", |
|
|
|
|
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalNestedEnum"].type() == Json::intValue && |
|
|
|
return value["optionalNestedEnum"].type() == Json::intValue && |
|
|
|
value["optionalNestedEnum"].asInt() == 123; |
|
|
|
value["optionalNestedEnum"].asInt() == 123; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
|
|
|
|
|
|
|
|
// String fields.
|
|
|
|
// String fields.
|
|
|
|
RunValidJsonTest( |
|
|
|
RunValidJsonTest( |
|
|
@ -2712,25 +2730,29 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForWrapperTypes() { |
|
|
|
R"({"optionalDuration": "1.000000000s"})", |
|
|
|
R"({"optionalDuration": "1.000000000s"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalDuration"].asString() == "1s"; |
|
|
|
return value["optionalDuration"].asString() == "1s"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"DurationHas3FractionalDigits", RECOMMENDED, |
|
|
|
"DurationHas3FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalDuration": "1.010000000s"})", |
|
|
|
R"({"optionalDuration": "1.010000000s"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalDuration"].asString() == "1.010s"; |
|
|
|
return value["optionalDuration"].asString() == "1.010s"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"DurationHas6FractionalDigits", RECOMMENDED, |
|
|
|
"DurationHas6FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalDuration": "1.000010000s"})", |
|
|
|
R"({"optionalDuration": "1.000010000s"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalDuration"].asString() == "1.000010s"; |
|
|
|
return value["optionalDuration"].asString() == "1.000010s"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"DurationHas9FractionalDigits", RECOMMENDED, |
|
|
|
"DurationHas9FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalDuration": "1.000000010s"})", |
|
|
|
R"({"optionalDuration": "1.000000010s"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalDuration"].asString() == "1.000000010s"; |
|
|
|
return value["optionalDuration"].asString() == "1.000000010s"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
|
|
|
|
|
|
|
|
// Timestamp
|
|
|
|
// Timestamp
|
|
|
|
RunValidJsonTest( |
|
|
|
RunValidJsonTest( |
|
|
@ -2794,34 +2816,39 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForWrapperTypes() { |
|
|
|
R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", |
|
|
|
R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"TimestampHasZeroFractionalDigit", RECOMMENDED, |
|
|
|
"TimestampHasZeroFractionalDigit", RECOMMENDED, |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})", |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"TimestampHas3FractionalDigits", RECOMMENDED, |
|
|
|
"TimestampHas3FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})", |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
"1970-01-01T00:00:00.010Z"; |
|
|
|
"1970-01-01T00:00:00.010Z"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"TimestampHas6FractionalDigits", RECOMMENDED, |
|
|
|
"TimestampHas6FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})", |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
"1970-01-01T00:00:00.000010Z"; |
|
|
|
"1970-01-01T00:00:00.000010Z"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
"TimestampHas9FractionalDigits", RECOMMENDED, |
|
|
|
"TimestampHas9FractionalDigits", RECOMMENDED, |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})", |
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})", |
|
|
|
[](const Json::Value& value) { |
|
|
|
[](const Json::Value& value) { |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
"1970-01-01T00:00:00.000000010Z"; |
|
|
|
"1970-01-01T00:00:00.000000010Z"; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldMask() { |
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldMask() { |
|
|
|