|
|
|
@ -29,18 +29,18 @@ |
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
#include "binary_json_conformance_suite.h" |
|
|
|
|
#include "conformance_test.h" |
|
|
|
|
#include "third_party/jsoncpp/json.h" |
|
|
|
|
|
|
|
|
|
#include <google/protobuf/test_messages_proto3.pb.h> |
|
|
|
|
#include <google/protobuf/test_messages_proto2.pb.h> |
|
|
|
|
|
|
|
|
|
#include <google/protobuf/stubs/common.h> |
|
|
|
|
#include <google/protobuf/stubs/strutil.h> |
|
|
|
|
#include <google/protobuf/text_format.h> |
|
|
|
|
#include <google/protobuf/wire_format_lite.h> |
|
|
|
|
#include <google/protobuf/util/json_util.h> |
|
|
|
|
#include <google/protobuf/util/type_resolver_util.h> |
|
|
|
|
#include <google/protobuf/wire_format_lite.h> |
|
|
|
|
#include "third_party/jsoncpp/json.h" |
|
|
|
|
#include "conformance_test.h" |
|
|
|
|
#include <google/protobuf/test_messages_proto2.pb.h> |
|
|
|
|
#include <google/protobuf/test_messages_proto3.pb.h> |
|
|
|
|
#include <google/protobuf/stubs/status.h> |
|
|
|
|
|
|
|
|
|
namespace proto2_messages = protobuf_test_messages::proto2; |
|
|
|
|
|
|
|
|
|
using conformance::ConformanceRequest; |
|
|
|
|
using conformance::ConformanceResponse; |
|
|
|
@ -48,11 +48,11 @@ using conformance::WireFormat; |
|
|
|
|
using google::protobuf::Descriptor; |
|
|
|
|
using google::protobuf::FieldDescriptor; |
|
|
|
|
using google::protobuf::Message; |
|
|
|
|
using google::protobuf::internal::WireFormatLite; |
|
|
|
|
using google::protobuf::TextFormat; |
|
|
|
|
using google::protobuf::internal::WireFormatLite; |
|
|
|
|
using google::protobuf::util::NewTypeResolverForDescriptorPool; |
|
|
|
|
using proto2_messages::TestAllTypesProto2; |
|
|
|
|
using protobuf_test_messages::proto3::TestAllTypesProto3; |
|
|
|
|
using protobuf_test_messages::proto2::TestAllTypesProto2; |
|
|
|
|
using std::string; |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
@ -249,10 +249,9 @@ const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type, |
|
|
|
|
if (packed == Packed::FALSE) { |
|
|
|
|
packed_string = "Unpacked "; |
|
|
|
|
} |
|
|
|
|
GOOGLE_LOG(FATAL) << "Couldn't find field with type: " |
|
|
|
|
<< repeated_string.c_str() << packed_string.c_str() |
|
|
|
|
<< FieldDescriptor::TypeName(type) << " for " |
|
|
|
|
<< proto_string.c_str(); |
|
|
|
|
GOOGLE_LOG(FATAL) << "Couldn't find field with type: " << repeated_string.c_str() |
|
|
|
|
<< packed_string.c_str() << FieldDescriptor::TypeName(type) |
|
|
|
|
<< " for " << proto_string.c_str(); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -275,9 +274,9 @@ const FieldDescriptor* GetFieldForMapType(FieldDescriptor::Type key_type, |
|
|
|
|
|
|
|
|
|
const string proto_string = is_proto3 ? "Proto3" : "Proto2"; |
|
|
|
|
GOOGLE_LOG(FATAL) << "Couldn't find map field with type: " |
|
|
|
|
<< FieldDescriptor::TypeName(key_type) << " and " |
|
|
|
|
<< FieldDescriptor::TypeName(key_type) << " for " |
|
|
|
|
<< proto_string.c_str(); |
|
|
|
|
<< FieldDescriptor::TypeName(key_type) << " and " |
|
|
|
|
<< FieldDescriptor::TypeName(key_type) << " for " |
|
|
|
|
<< proto_string.c_str(); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -295,8 +294,8 @@ const FieldDescriptor* GetFieldForOneofType(FieldDescriptor::Type type, |
|
|
|
|
|
|
|
|
|
const string proto_string = is_proto3 ? "Proto3" : "Proto2"; |
|
|
|
|
GOOGLE_LOG(FATAL) << "Couldn't find oneof field with type: " |
|
|
|
|
<< FieldDescriptor::TypeName(type) << " for " |
|
|
|
|
<< proto_string.c_str(); |
|
|
|
|
<< FieldDescriptor::TypeName(type) << " for " |
|
|
|
|
<< proto_string.c_str(); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -364,9 +363,8 @@ bool BinaryAndJsonConformanceSuite::ParseJsonResponse( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!test_message->ParseFromString(binary_protobuf)) { |
|
|
|
|
GOOGLE_LOG(FATAL) |
|
|
|
|
<< "INTERNAL ERROR: internal JSON->protobuf transcode " |
|
|
|
|
<< "yielded unparseable proto."; |
|
|
|
|
GOOGLE_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode " |
|
|
|
|
<< "yielded unparseable proto."; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -385,10 +383,11 @@ bool BinaryAndJsonConformanceSuite::ParseResponse( |
|
|
|
|
switch (response.result_case()) { |
|
|
|
|
case ConformanceResponse::kProtobufPayload: { |
|
|
|
|
if (requested_output != conformance::PROTOBUF) { |
|
|
|
|
ReportFailure( |
|
|
|
|
test_name, level, request, response, |
|
|
|
|
StrCat("Test was asked for ", WireFormatToString(requested_output), |
|
|
|
|
" output but provided PROTOBUF instead.").c_str()); |
|
|
|
|
ReportFailure(test_name, level, request, response, |
|
|
|
|
StrCat("Test was asked for ", |
|
|
|
|
WireFormatToString(requested_output), |
|
|
|
|
" output but provided PROTOBUF instead.") |
|
|
|
|
.c_str()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -403,10 +402,11 @@ bool BinaryAndJsonConformanceSuite::ParseResponse( |
|
|
|
|
|
|
|
|
|
case ConformanceResponse::kJsonPayload: { |
|
|
|
|
if (requested_output != conformance::JSON) { |
|
|
|
|
ReportFailure( |
|
|
|
|
test_name, level, request, response, |
|
|
|
|
StrCat("Test was asked for ", WireFormatToString(requested_output), |
|
|
|
|
" output but provided JSON instead.").c_str()); |
|
|
|
|
ReportFailure(test_name, level, request, response, |
|
|
|
|
StrCat("Test was asked for ", |
|
|
|
|
WireFormatToString(requested_output), |
|
|
|
|
" output but provided JSON instead.") |
|
|
|
|
.c_str()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -420,8 +420,8 @@ bool BinaryAndJsonConformanceSuite::ParseResponse( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: " |
|
|
|
|
<< response.result_case(); |
|
|
|
|
GOOGLE_LOG(FATAL) << test_name |
|
|
|
|
<< ": unknown payload type: " << response.result_case(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
@ -440,10 +440,9 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForProtoWithProtoVersion ( |
|
|
|
|
|
|
|
|
|
const ConformanceRequest& request = setting.GetRequest(); |
|
|
|
|
ConformanceResponse response; |
|
|
|
|
string effective_test_name = |
|
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
|
(is_proto3 ? ".Proto3" : ".Proto2"), |
|
|
|
|
".ProtobufInput.", test_name); |
|
|
|
|
string effective_test_name = StrCat( |
|
|
|
|
setting.ConformanceLevelToString(level), |
|
|
|
|
(is_proto3 ? ".Proto3" : ".Proto2"), ".ProtobufInput.", test_name); |
|
|
|
|
|
|
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
|
if (response.result_case() == ConformanceResponse::kParseError) { |
|
|
|
@ -574,8 +573,7 @@ void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( |
|
|
|
|
ConformanceResponse response; |
|
|
|
|
string effective_test_name = |
|
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
|
".Proto3.JsonInput.", |
|
|
|
|
test_name, ".Validator"); |
|
|
|
|
".Proto3.JsonInput.", test_name, ".Validator"); |
|
|
|
|
|
|
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
|
|
|
|
|
@ -617,9 +615,8 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson( |
|
|
|
|
prototype, test_name, input_json); |
|
|
|
|
const ConformanceRequest& request = setting.GetRequest(); |
|
|
|
|
ConformanceResponse response; |
|
|
|
|
string effective_test_name = |
|
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
|
".Proto3.JsonInput.", test_name); |
|
|
|
|
string effective_test_name = StrCat( |
|
|
|
|
setting.ConformanceLevelToString(level), ".Proto3.JsonInput.", test_name); |
|
|
|
|
|
|
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
|
if (response.result_case() == ConformanceResponse::kParseError) { |
|
|
|
@ -635,9 +632,8 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson( |
|
|
|
|
void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson( |
|
|
|
|
const string& test_name, ConformanceLevel level, const string& text_format) { |
|
|
|
|
TestAllTypesProto3 payload_message; |
|
|
|
|
GOOGLE_CHECK( |
|
|
|
|
TextFormat::ParseFromString(text_format, &payload_message)) |
|
|
|
|
<< "Failed to parse: " << text_format; |
|
|
|
|
GOOGLE_CHECK(TextFormat::ParseFromString(text_format, &payload_message)) |
|
|
|
|
<< "Failed to parse: " << text_format; |
|
|
|
|
|
|
|
|
|
TestAllTypesProto3 prototype; |
|
|
|
|
ConformanceRequestSetting setting( |
|
|
|
@ -646,9 +642,8 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson( |
|
|
|
|
prototype, test_name, payload_message.SerializeAsString()); |
|
|
|
|
const ConformanceRequest& request = setting.GetRequest(); |
|
|
|
|
ConformanceResponse response; |
|
|
|
|
string effective_test_name = |
|
|
|
|
StrCat(setting.ConformanceLevelToString(level), |
|
|
|
|
".", test_name, ".JsonOutput"); |
|
|
|
|
string effective_test_name = StrCat( |
|
|
|
|
setting.ConformanceLevelToString(level), ".", test_name, ".JsonOutput"); |
|
|
|
|
|
|
|
|
|
RunTest(effective_test_name, request, &response); |
|
|
|
|
if (response.result_case() == ConformanceResponse::kSerializeError) { |
|
|
|
@ -772,11 +767,12 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( |
|
|
|
|
test_message->MergeFromString(expected_proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataScalar", type_name, "[", i, "]"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED, |
|
|
|
|
proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), RECOMMENDED, |
|
|
|
|
proto, expected_proto, is_proto3); |
|
|
|
|
StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), |
|
|
|
|
RECOMMENDED, proto, expected_proto, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test repeated data for singular fields.
|
|
|
|
@ -856,11 +852,11 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( |
|
|
|
|
|
|
|
|
|
// Ensures both packed and unpacked data can be parsed.
|
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), REQUIRED, |
|
|
|
|
default_proto_unpacked, text, is_proto3); |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), |
|
|
|
|
REQUIRED, default_proto_unpacked, text, is_proto3); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".PackedInput"), REQUIRED, |
|
|
|
|
default_proto_packed, text, is_proto3); |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".PackedInput"), |
|
|
|
|
REQUIRED, default_proto_packed, text, is_proto3); |
|
|
|
|
|
|
|
|
|
// proto2 should encode as unpacked by default and proto3 should encode as
|
|
|
|
|
// packed by default.
|
|
|
|
@ -868,26 +864,29 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( |
|
|
|
|
? default_proto_packed_expected |
|
|
|
|
: default_proto_unpacked_expected; |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".UnpackedInput.DefaultOutput"), |
|
|
|
|
".UnpackedInput.DefaultOutput"), |
|
|
|
|
RECOMMENDED, default_proto_unpacked, |
|
|
|
|
expected_proto, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".PackedInput.DefaultOutput"), |
|
|
|
|
RECOMMENDED, default_proto_packed, expected_proto, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".UnpackedInput.PackedOutput"), |
|
|
|
|
RECOMMENDED, packed_proto_unpacked, packed_proto_expected, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".PackedInput.PackedOutput"), |
|
|
|
|
RECOMMENDED, packed_proto_packed, packed_proto_expected, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".UnpackedInput.UnpackedOutput"), |
|
|
|
|
".PackedInput.DefaultOutput"), |
|
|
|
|
RECOMMENDED, default_proto_packed, |
|
|
|
|
expected_proto, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".UnpackedInput.PackedOutput"), |
|
|
|
|
RECOMMENDED, packed_proto_unpacked, |
|
|
|
|
packed_proto_expected, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".PackedInput.PackedOutput"), |
|
|
|
|
RECOMMENDED, packed_proto_packed, |
|
|
|
|
packed_proto_expected, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".UnpackedInput.UnpackedOutput"), |
|
|
|
|
RECOMMENDED, unpacked_proto_unpacked, |
|
|
|
|
unpacked_proto_expected, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataRepeated", type_name, ".PackedInput.UnpackedOutput"), |
|
|
|
|
RECOMMENDED, unpacked_proto_packed, unpacked_proto_expected, |
|
|
|
|
is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, |
|
|
|
|
".PackedInput.UnpackedOutput"), |
|
|
|
|
RECOMMENDED, unpacked_proto_packed, |
|
|
|
|
unpacked_proto_expected, is_proto3); |
|
|
|
|
} else { |
|
|
|
|
string proto; |
|
|
|
|
string expected_proto; |
|
|
|
@ -900,8 +899,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( |
|
|
|
|
test_message->MergeFromString(expected_proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataRepeated", type_name), REQUIRED, |
|
|
|
|
proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataRepeated", type_name), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -976,9 +975,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataMap", key_type_name, value_type_name, ".Default"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".Default"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
@ -990,7 +989,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".MissingDefault"), |
|
|
|
|
value_type_name, ".MissingDefault"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1002,9 +1001,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataMap", key_type_name, value_type_name, ".NonDefault"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".NonDefault"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
@ -1015,9 +1014,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataMap", key_type_name, value_type_name, ".Unordered"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".Unordered"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
@ -1033,7 +1032,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
test_message->MergeFromString(proto2); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".DuplicateKey"), |
|
|
|
|
value_type_name, ".DuplicateKey"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1045,9 +1044,10 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".DuplicateKeyInMapEntry"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataMap", key_type_name, value_type_name, |
|
|
|
|
".DuplicateKeyInMapEntry"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
@ -1058,9 +1058,10 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( |
|
|
|
|
std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, |
|
|
|
|
value_type_name, ".DuplicateValueInMapEntry"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataMap", key_type_name, value_type_name, |
|
|
|
|
".DuplicateValueInMapEntry"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1123,8 +1124,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( |
|
|
|
|
test_message->MergeFromString(proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataOneof", type_name, ".DefaultValue"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED, |
|
|
|
|
proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"), |
|
|
|
|
RECOMMENDED, proto, proto, is_proto3); |
|
|
|
@ -1138,8 +1140,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), REQUIRED, |
|
|
|
|
proto, text, is_proto3); |
|
|
|
|
StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"), |
|
|
|
|
RECOMMENDED, proto, proto, is_proto3); |
|
|
|
@ -1153,11 +1155,11 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( |
|
|
|
|
test_message->MergeFromString(expected_proto); |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest( |
|
|
|
|
StrCat("ValidDataOneof", type_name, ".MultipleValuesForSameField"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, |
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataOneof", type_name, |
|
|
|
|
".MultipleValuesForSameField"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, |
|
|
|
|
".MultipleValuesForSameField"), |
|
|
|
|
RECOMMENDED, proto, expected_proto, is_proto3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1180,11 +1182,12 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( |
|
|
|
|
string text = test_message->DebugString(); |
|
|
|
|
|
|
|
|
|
RunValidProtobufTest(StrCat("ValidDataOneof", type_name, |
|
|
|
|
".MultipleValuesForDifferentField"), |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, |
|
|
|
|
".MultipleValuesForDifferentField"), |
|
|
|
|
RECOMMENDED, proto, expected_proto, is_proto3); |
|
|
|
|
REQUIRED, proto, text, is_proto3); |
|
|
|
|
RunValidBinaryProtobufTest( |
|
|
|
|
StrCat("ValidDataOneofBinary", type_name, |
|
|
|
|
".MultipleValuesForDifferentField"), |
|
|
|
|
RECOMMENDED, proto, expected_proto, is_proto3); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1292,7 +1295,7 @@ void BinaryAndJsonConformanceSuite::TestUnknownMessage( |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
// Hack to get the list of test failures based on whether
|
|
|
|
|
// GOOGLE3_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not.
|
|
|
|
|
// GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not.
|
|
|
|
|
conformance::FailureSet failure_set; |
|
|
|
|
ConformanceRequest req; |
|
|
|
|
ConformanceResponse res; |
|
|
|
@ -1363,6 +1366,8 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
{varint(kInt32Min), varint(kInt32Min)}, |
|
|
|
|
{varint(1LL << 33), varint(0)}, |
|
|
|
|
{varint((1LL << 33) - 1), varint(-1)}, |
|
|
|
|
{varint(kInt64Max), varint(-1)}, |
|
|
|
|
{varint(kInt64Min + 1), varint(1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType( |
|
|
|
|
FieldDescriptor::TYPE_UINT32, |
|
|
|
@ -1373,7 +1378,10 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
{longvarint(12345, 7), varint(12345)}, |
|
|
|
|
{varint(kUint32Max), varint(kUint32Max)}, // UINT32_MAX
|
|
|
|
|
{varint(1LL << 33), varint(0)}, |
|
|
|
|
{varint((1LL << 33) + 1), varint(1)}, |
|
|
|
|
{varint((1LL << 33) - 1), varint((1LL << 32) - 1)}, |
|
|
|
|
{varint(kInt64Max), varint((1LL << 32) - 1)}, |
|
|
|
|
{varint(kInt64Min + 1), varint(1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_FIXED64, |
|
|
|
|
{ |
|
|
|
@ -1407,7 +1415,11 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
{ |
|
|
|
|
{varint(0), varint(0)}, |
|
|
|
|
{varint(1), varint(1)}, |
|
|
|
|
{varint(-1), varint(1)}, |
|
|
|
|
{varint(12345678), varint(1)}, |
|
|
|
|
{varint(1LL << 33), varint(1)}, |
|
|
|
|
{varint(kInt64Max), varint(1)}, |
|
|
|
|
{varint(kInt64Min), varint(1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_SINT32, |
|
|
|
|
{ |
|
|
|
@ -1415,6 +1427,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
{zz32(12345), zz32(12345)}, |
|
|
|
|
{zz32(kInt32Max), zz32(kInt32Max)}, |
|
|
|
|
{zz32(kInt32Min), zz32(kInt32Min)}, |
|
|
|
|
{zz64(kInt32Max + 2LL), zz32(1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_SINT64, |
|
|
|
|
{ |
|
|
|
@ -1438,15 +1451,19 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_BYTES, |
|
|
|
|
{ |
|
|
|
|
{delim(""), delim("")}, |
|
|
|
|
{delim("Hello world!"), delim("Hello world!")}, |
|
|
|
|
{delim("\x01\x02"), delim("\x01\x02")}, |
|
|
|
|
{delim("\xfb"), delim("\xfb")}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_ENUM, { |
|
|
|
|
{varint(0), varint(0)}, |
|
|
|
|
{varint(1), varint(1)}, |
|
|
|
|
{varint(2), varint(2)}, |
|
|
|
|
{varint(-1), varint(-1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForType(FieldDescriptor::TYPE_ENUM, |
|
|
|
|
{ |
|
|
|
|
{varint(0), varint(0)}, |
|
|
|
|
{varint(1), varint(1)}, |
|
|
|
|
{varint(2), varint(2)}, |
|
|
|
|
{varint(-1), varint(-1)}, |
|
|
|
|
{varint(kInt64Max), varint(-1)}, |
|
|
|
|
{varint(kInt64Min + 1), varint(1)}, |
|
|
|
|
}); |
|
|
|
|
TestValidDataForRepeatedScalarMessage(); |
|
|
|
|
TestValidDataForType( |
|
|
|
|
FieldDescriptor::TYPE_MESSAGE, |
|
|
|
@ -1508,13 +1525,74 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
// TODO(haberman):
|
|
|
|
|
// TestValidDataForType(FieldDescriptor::TYPE_GROUP
|
|
|
|
|
|
|
|
|
|
// Unknown fields.
|
|
|
|
|
{ |
|
|
|
|
TestAllTypesProto3 messageProto3; |
|
|
|
|
TestAllTypesProto2 messageProto2; |
|
|
|
|
// TODO(yilunchong): update this behavior when unknown field's behavior
|
|
|
|
|
// changed in open source. Also delete
|
|
|
|
|
// Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput
|
|
|
|
|
// from failure list of python_cpp python java
|
|
|
|
|
TestUnknownMessage(messageProto3, true); |
|
|
|
|
TestUnknownMessage(messageProto2, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RunJsonTests(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTests() { |
|
|
|
|
RunValidJsonTest("HelloWorld", REQUIRED, |
|
|
|
|
"{\"optionalString\":\"Hello, World!\"}", |
|
|
|
|
"optional_string: 'Hello, World!'"); |
|
|
|
|
|
|
|
|
|
// NOTE: The spec for JSON support is still being sorted out, these may not
|
|
|
|
|
// all be correct.
|
|
|
|
|
// Test field name conventions.
|
|
|
|
|
|
|
|
|
|
RunJsonTestsForFieldNameConvention(); |
|
|
|
|
RunJsonTestsForNonRepeatedTypes(); |
|
|
|
|
RunJsonTestsForRepeatedTypes(); |
|
|
|
|
RunJsonTestsForNullTypes(); |
|
|
|
|
RunJsonTestsForWrapperTypes(); |
|
|
|
|
RunJsonTestsForFieldMask(); |
|
|
|
|
RunJsonTestsForStruct(); |
|
|
|
|
RunJsonTestsForValue(); |
|
|
|
|
RunJsonTestsForAny(); |
|
|
|
|
|
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNumber", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": 1 |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonString", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": "a" |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonTrue", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": true |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonFalse", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": false |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNull", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": null |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonObject", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": {"a": 1} |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
|
|
|
|
|
ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"FieldNameInSnakeCase", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
@ -1769,7 +1847,9 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
value.isMember("fieldName17") && |
|
|
|
|
value.isMember("FieldName18"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { |
|
|
|
|
// Integer fields.
|
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"Int32FieldMaxValue", REQUIRED, |
|
|
|
@ -2254,71 +2334,6 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
"OneofZeroEnum", RECOMMENDED, |
|
|
|
|
R"({"oneofEnum":"FOO"})", "oneof_enum: FOO"); |
|
|
|
|
|
|
|
|
|
// Repeated fields.
|
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"PrimitiveRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, 4]})", |
|
|
|
|
"repeated_int32: [1, 2, 3, 4]"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"EnumRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})", |
|
|
|
|
"repeated_nested_enum: [FOO, BAR, BAZ]"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"StringRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["Hello", "world"]})", |
|
|
|
|
R"(repeated_string: ["Hello", "world"])"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"BytesRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedBytes": ["AAEC", "AQI="]})", |
|
|
|
|
R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"MessageRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})", |
|
|
|
|
"repeated_nested_message: {a: 1234}" |
|
|
|
|
"repeated_nested_message: {a: 5678}"); |
|
|
|
|
|
|
|
|
|
// Repeated field elements are of incorrect type.
|
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, false, 3, 4]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, "name", 4]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", 2, "3", "4"]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", "2", false, "4"]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", 2, "3", {"a": 4}]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, 2]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, false]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, "2"]})"); |
|
|
|
|
// Trailing comma in the repeated field is not allowed.
|
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldTrailingComma", RECOMMENDED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, 4,]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldTrailingCommaWithSpace", RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [1, 2, 3, 4 ,]}"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldTrailingCommaWithSpaceCommaSpace", RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [1, 2, 3, 4 , ]}"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}"); |
|
|
|
|
|
|
|
|
|
// Map fields.
|
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"Int32MapField", REQUIRED, |
|
|
|
@ -2392,6 +2407,77 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
R"({"mapBoolBool": {"tr\u0075e": true}})", |
|
|
|
|
"map_bool_bool: {key: true value: true}"); |
|
|
|
|
|
|
|
|
|
// http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double
|
|
|
|
|
// quotes.
|
|
|
|
|
ExpectParseFailureForJson("StringFieldSingleQuoteKey", RECOMMENDED, |
|
|
|
|
R"({'optionalString': "Hello world!"})"); |
|
|
|
|
ExpectParseFailureForJson("StringFieldSingleQuoteValue", RECOMMENDED, |
|
|
|
|
R"({"optionalString": 'Hello world!'})"); |
|
|
|
|
ExpectParseFailureForJson("StringFieldSingleQuoteBoth", RECOMMENDED, |
|
|
|
|
R"({'optionalString': 'Hello world!'})"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForRepeatedTypes() { |
|
|
|
|
// Repeated fields.
|
|
|
|
|
RunValidJsonTest("PrimitiveRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, 4]})", |
|
|
|
|
"repeated_int32: [1, 2, 3, 4]"); |
|
|
|
|
RunValidJsonTest("EnumRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})", |
|
|
|
|
"repeated_nested_enum: [FOO, BAR, BAZ]"); |
|
|
|
|
RunValidJsonTest("StringRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["Hello", "world"]})", |
|
|
|
|
R"(repeated_string: ["Hello", "world"])"); |
|
|
|
|
RunValidJsonTest("BytesRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedBytes": ["AAEC", "AQI="]})", |
|
|
|
|
R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])"); |
|
|
|
|
RunValidJsonTest("MessageRepeatedField", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})", |
|
|
|
|
"repeated_nested_message: {a: 1234}" |
|
|
|
|
"repeated_nested_message: {a: 5678}"); |
|
|
|
|
|
|
|
|
|
// Repeated field elements are of incorrect type.
|
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, false, 3, 4]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, "name", 4]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", 2, "3", "4"]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", "2", false, "4"]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED, |
|
|
|
|
R"({"repeatedString": ["1", 2, "3", {"a": 4}]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, 2]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, false]})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED, |
|
|
|
|
R"({"repeatedNestedMessage": [{"a": 1}, "2"]})"); |
|
|
|
|
// Trailing comma in the repeated field is not allowed.
|
|
|
|
|
ExpectParseFailureForJson("RepeatedFieldTrailingComma", RECOMMENDED, |
|
|
|
|
R"({"repeatedInt32": [1, 2, 3, 4,]})"); |
|
|
|
|
ExpectParseFailureForJson("RepeatedFieldTrailingCommaWithSpace", RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [1, 2, 3, 4 ,]}"); |
|
|
|
|
ExpectParseFailureForJson("RepeatedFieldTrailingCommaWithSpaceCommaSpace", |
|
|
|
|
RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [1, 2, 3, 4 , ]}"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED, |
|
|
|
|
"{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForNullTypes() { |
|
|
|
|
// "null" is accepted for all fields types.
|
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"AllFieldAcceptNull", REQUIRED, |
|
|
|
@ -2451,36 +2537,12 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"MapFieldValueIsNull", RECOMMENDED, |
|
|
|
|
R"({"mapInt32Int32": {"0": null}})"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double
|
|
|
|
|
// quotes.
|
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"StringFieldSingleQuoteKey", RECOMMENDED, |
|
|
|
|
R"({'optionalString': "Hello world!"})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"StringFieldSingleQuoteValue", RECOMMENDED, |
|
|
|
|
R"({"optionalString": 'Hello world!'})"); |
|
|
|
|
ExpectParseFailureForJson( |
|
|
|
|
"StringFieldSingleQuoteBoth", RECOMMENDED, |
|
|
|
|
R"({'optionalString': 'Hello world!'})"); |
|
|
|
|
|
|
|
|
|
// Unknown fields.
|
|
|
|
|
{ |
|
|
|
|
TestAllTypesProto3 messageProto3; |
|
|
|
|
TestAllTypesProto2 messageProto2; |
|
|
|
|
//TODO(yilunchong): update this behavior when unknown field's behavior
|
|
|
|
|
// changed in open source. Also delete
|
|
|
|
|
// Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput
|
|
|
|
|
// from failure list of python_cpp python java
|
|
|
|
|
TestUnknownMessage(messageProto3, true); |
|
|
|
|
TestUnknownMessage(messageProto2, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wrapper types.
|
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"OptionalBoolWrapper", REQUIRED, |
|
|
|
|
R"({"optionalBoolWrapper": false})", |
|
|
|
|
"optional_bool_wrapper: {value: false}"); |
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForWrapperTypes() { |
|
|
|
|
RunValidJsonTest("OptionalBoolWrapper", REQUIRED, |
|
|
|
|
R"({"optionalBoolWrapper": false})", |
|
|
|
|
"optional_bool_wrapper: {value: false}"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"OptionalInt32Wrapper", REQUIRED, |
|
|
|
|
R"({"optionalInt32Wrapper": 0})", |
|
|
|
@ -2689,10 +2751,9 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
})", |
|
|
|
|
"repeated_timestamp: {seconds: -62135596800}" |
|
|
|
|
"repeated_timestamp: {seconds: 253402300799 nanos: 999999999}"); |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"TimestampLeap", REQUIRED, |
|
|
|
|
R"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})", |
|
|
|
|
"optional_timestamp: {seconds: 729302400}"); |
|
|
|
|
RunValidJsonTest("TimestampLeap", REQUIRED, |
|
|
|
|
R"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})", |
|
|
|
|
"optional_timestamp: {seconds: 729302400}"); |
|
|
|
|
RunValidJsonTest("TimestampWithPositiveOffset", REQUIRED, |
|
|
|
|
R"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})", |
|
|
|
|
"optional_timestamp: {seconds: 1}"); |
|
|
|
@ -2732,39 +2793,38 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
"TimestampZeroNormalized", RECOMMENDED, |
|
|
|
|
R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", |
|
|
|
|
[](const Json::Value& value) { |
|
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
|
"1970-01-01T00:00:00Z"; |
|
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
|
}); |
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
"TimestampHasZeroFractionalDigit", RECOMMENDED, |
|
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})", |
|
|
|
|
[](const Json::Value& value) { |
|
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
|
"1970-01-01T00:00:00Z"; |
|
|
|
|
return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; |
|
|
|
|
}); |
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
"TimestampHas3FractionalDigits", RECOMMENDED, |
|
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})", |
|
|
|
|
[](const Json::Value& value) { |
|
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
|
"1970-01-01T00:00:00.010Z"; |
|
|
|
|
"1970-01-01T00:00:00.010Z"; |
|
|
|
|
}); |
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
"TimestampHas6FractionalDigits", RECOMMENDED, |
|
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})", |
|
|
|
|
[](const Json::Value& value) { |
|
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
|
"1970-01-01T00:00:00.000010Z"; |
|
|
|
|
"1970-01-01T00:00:00.000010Z"; |
|
|
|
|
}); |
|
|
|
|
RunValidJsonTestWithValidator( |
|
|
|
|
"TimestampHas9FractionalDigits", RECOMMENDED, |
|
|
|
|
R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})", |
|
|
|
|
[](const Json::Value& value) { |
|
|
|
|
return value["optionalTimestamp"].asString() == |
|
|
|
|
"1970-01-01T00:00:00.000000010Z"; |
|
|
|
|
"1970-01-01T00:00:00.000000010Z"; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FieldMask
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldMask() { |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"FieldMask", REQUIRED, |
|
|
|
|
R"({"optionalFieldMask": "foo,barBaz"})", |
|
|
|
@ -2785,8 +2845,9 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
ExpectSerializeFailureForJson( |
|
|
|
|
"FieldMaskTooManyUnderscore", RECOMMENDED, |
|
|
|
|
R"(optional_field_mask: {paths: "foo__bar"})"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Struct
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForStruct() { |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"Struct", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
@ -2870,7 +2931,9 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)"); |
|
|
|
|
// Value
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForValue() { |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"ValueAcceptInteger", REQUIRED, |
|
|
|
|
R"({"optionalValue": 1})", |
|
|
|
@ -2951,8 +3014,9 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
)"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Any
|
|
|
|
|
void BinaryAndJsonConformanceSuite::RunJsonTestsForAny() { |
|
|
|
|
RunValidJsonTest( |
|
|
|
|
"Any", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
@ -3128,45 +3192,6 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)"); |
|
|
|
|
|
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonNumber", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": 1 |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonString", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": "a" |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonTrue", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": true |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonFalse", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": false |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonNull", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": null |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
RunValidJsonIgnoreUnknownTest( |
|
|
|
|
"IgnoreUnknownJsonObject", REQUIRED, |
|
|
|
|
R"({ |
|
|
|
|
"unknown": {"a": 1} |
|
|
|
|
})", |
|
|
|
|
""); |
|
|
|
|
|
|
|
|
|
ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace protobuf
|
|
|
|
|