Commit ac3df39c authored by Thomas Van Lenten's avatar Thomas Van Lenten Committed by GitHub

Add conformance test for zero fields in oneofs. (#1939)

* Add conformance test for zero fields in oneofs.
* Add failures to the "expected" files.
parent 30bbbe99
...@@ -272,11 +272,16 @@ void ConformanceTestSuite::RunValidInputTest( ...@@ -272,11 +272,16 @@ void ConformanceTestSuite::RunValidInputTest(
TestAllTypes test_message; TestAllTypes test_message;
switch (response.result_case()) { switch (response.result_case()) {
case ConformanceResponse::RESULT_NOT_SET:
ReportFailure(test_name, request, response,
"Response didn't have any field in the Response.");
return;
case ConformanceResponse::kParseError: case ConformanceResponse::kParseError:
case ConformanceResponse::kRuntimeError: case ConformanceResponse::kRuntimeError:
case ConformanceResponse::kSerializeError: case ConformanceResponse::kSerializeError:
ReportFailure(test_name, request, response, ReportFailure(test_name, request, response,
"Failed to parse JSON input or produce JSON output."); "Failed to parse input or produce output.");
return; return;
case ConformanceResponse::kSkipped: case ConformanceResponse::kSkipped:
...@@ -400,6 +405,17 @@ void ConformanceTestSuite::RunValidJsonTestWithProtobufInput( ...@@ -400,6 +405,17 @@ void ConformanceTestSuite::RunValidJsonTestWithProtobufInput(
equivalent_text_format, conformance::JSON); equivalent_text_format, conformance::JSON);
} }
void ConformanceTestSuite::RunValidProtobufTest(
const string& test_name, const TestAllTypes& input,
const string& equivalent_text_format) {
RunValidInputTest("ProtobufInput." + test_name + ".ProtobufOutput",
input.SerializeAsString(), conformance::PROTOBUF,
equivalent_text_format, conformance::PROTOBUF);
RunValidInputTest("ProtobufInput." + test_name + ".JsonOutput",
input.SerializeAsString(), conformance::PROTOBUF,
equivalent_text_format, conformance::JSON);
}
// According to proto3 JSON specification, JSON serializers follow more strict // According to proto3 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
...@@ -1225,6 +1241,34 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, ...@@ -1225,6 +1241,34 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
ExpectParseFailureForJson( ExpectParseFailureForJson(
"OneofFieldDuplicate", "OneofFieldDuplicate",
R"({"oneofUint32": 1, "oneofString": "test"})"); R"({"oneofUint32": 1, "oneofString": "test"})");
// Ensure zero values for oneof make it out/backs.
{
TestAllTypes message;
message.set_oneof_uint32(0);
RunValidProtobufTest(
"OneofZeroUint32", message, "oneof_uint32: 0");
message.mutable_oneof_nested_message()->set_a(0);
RunValidProtobufTest(
"OneofZeroMessage", message, "oneof_nested_message: {}");
message.set_oneof_string("");
RunValidProtobufTest(
"OneofZeroString", message, "oneof_string: \"\"");
message.set_oneof_bytes("");
RunValidProtobufTest(
"OneofZeroBytes", message, "oneof_bytes: \"\"");
}
RunValidJsonTest(
"OneofZeroUint32",
R"({"oneofUint32": 0})", "oneof_uint32: 0");
RunValidJsonTest(
"OneofZeroMessage",
R"({"oneofNestedMessage": {}})", "oneof_nested_message: {}");
RunValidJsonTest(
"OneofZeroString",
R"({"oneofString": ""})", "oneof_string: \"\"");
RunValidJsonTest(
"OneofZeroBytes",
R"({"oneofBytes": ""})", "oneof_bytes: \"\"");
// Repeated fields. // Repeated fields.
RunValidJsonTest( RunValidJsonTest(
......
...@@ -133,6 +133,9 @@ class ConformanceTestSuite { ...@@ -133,6 +133,9 @@ class ConformanceTestSuite {
void RunValidJsonTestWithProtobufInput(const string& test_name, void RunValidJsonTestWithProtobufInput(const string& test_name,
const conformance::TestAllTypes& input, const conformance::TestAllTypes& input,
const string& equivalent_text_format); const string& equivalent_text_format);
void RunValidProtobufTest(const string& test_name,
const conformance::TestAllTypes& input,
const string& equivalent_text_format);
typedef std::function<bool(const Json::Value&)> Validator; typedef std::function<bool(const Json::Value&)> Validator;
void RunValidJsonTestWithValidator(const string& test_name, void RunValidJsonTestWithValidator(const string& test_name,
......
# No tests currently failing. ProtobufInput.OneofZeroBytes.ProtobufOutput
ProtobufInput.OneofZeroString.ProtobufOutput
ProtobufInput.OneofZeroUint32.ProtobufOutput
# #
# json input or output tests are skipped (in conformance_objc.m) as mobile # json input or output tests are skipped (in conformance_objc.m) as mobile
# platforms don't support json wire format to avoid code bloat. # platforms don't support json wire format to avoid code bloat.
...@@ -35,6 +35,8 @@ JsonInput.Int32FieldMaxFloatValue.JsonOutput ...@@ -35,6 +35,8 @@ JsonInput.Int32FieldMaxFloatValue.JsonOutput
JsonInput.Int32FieldMaxFloatValue.ProtobufOutput JsonInput.Int32FieldMaxFloatValue.ProtobufOutput
JsonInput.Int32FieldMinFloatValue.JsonOutput JsonInput.Int32FieldMinFloatValue.JsonOutput
JsonInput.Int32FieldMinFloatValue.ProtobufOutput JsonInput.Int32FieldMinFloatValue.ProtobufOutput
JsonInput.OneofZeroMessage.JsonOutput
JsonInput.OneofZeroMessage.ProtobufOutput
JsonInput.OriginalProtoFieldName.JsonOutput JsonInput.OriginalProtoFieldName.JsonOutput
JsonInput.OriginalProtoFieldName.ProtobufOutput JsonInput.OriginalProtoFieldName.ProtobufOutput
JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
......
...@@ -44,6 +44,8 @@ JsonInput.Int32FieldMaxFloatValue.JsonOutput ...@@ -44,6 +44,8 @@ JsonInput.Int32FieldMaxFloatValue.JsonOutput
JsonInput.Int32FieldMaxFloatValue.ProtobufOutput JsonInput.Int32FieldMaxFloatValue.ProtobufOutput
JsonInput.Int32FieldMinFloatValue.JsonOutput JsonInput.Int32FieldMinFloatValue.JsonOutput
JsonInput.Int32FieldMinFloatValue.ProtobufOutput JsonInput.Int32FieldMinFloatValue.ProtobufOutput
JsonInput.OneofZeroMessage.JsonOutput
JsonInput.OneofZeroMessage.ProtobufOutput
JsonInput.OriginalProtoFieldName.JsonOutput JsonInput.OriginalProtoFieldName.JsonOutput
JsonInput.OriginalProtoFieldName.ProtobufOutput JsonInput.OriginalProtoFieldName.ProtobufOutput
JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
......
...@@ -103,6 +103,8 @@ JsonInput.MessageMapField.JsonOutput ...@@ -103,6 +103,8 @@ JsonInput.MessageMapField.JsonOutput
JsonInput.MessageMapField.ProtobufOutput JsonInput.MessageMapField.ProtobufOutput
JsonInput.MessageRepeatedField.JsonOutput JsonInput.MessageRepeatedField.JsonOutput
JsonInput.MessageRepeatedField.ProtobufOutput JsonInput.MessageRepeatedField.ProtobufOutput
JsonInput.OneofZeroUint32.JsonOutput
JsonInput.OneofZeroUint32.ProtobufOutput
JsonInput.OptionalBoolWrapper.JsonOutput JsonInput.OptionalBoolWrapper.JsonOutput
JsonInput.OptionalBoolWrapper.ProtobufOutput JsonInput.OptionalBoolWrapper.ProtobufOutput
JsonInput.OptionalBytesWrapper.JsonOutput JsonInput.OptionalBytesWrapper.JsonOutput
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment