Unverified Commit 2849a799 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Add binary conformance test for message type. (#6435)

* Add binary conformance test for message type.

* Add test case for merge repeated scalar message field

* Add failed tests to failure list

* Add failed test to php's failure list

* Remove successful tests from php c's failure list
parent ff21d0f8
...@@ -149,10 +149,6 @@ string tag(uint32_t fieldnum, char wire_type) { ...@@ -149,10 +149,6 @@ string tag(uint32_t fieldnum, char wire_type) {
return varint((fieldnum << 3) | wire_type); return varint((fieldnum << 3) | wire_type);
} }
string submsg(uint32_t fn, const string& buf) {
return cat( tag(fn, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), delim(buf) );
}
#define UNKNOWN_FIELD 666 #define UNKNOWN_FIELD 666
const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type, const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
...@@ -594,17 +590,24 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( ...@@ -594,17 +590,24 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
const FieldDescriptor* field = GetFieldForType(type, false, is_proto3); const FieldDescriptor* field = GetFieldForType(type, false, is_proto3);
const FieldDescriptor* rep_field = GetFieldForType(type, true, is_proto3); const FieldDescriptor* rep_field = GetFieldForType(type, true, is_proto3);
RunValidProtobufTest("ValidDataScalar" + type_name, REQUIRED, for (size_t i = 0; i < values.size(); i++) {
cat(tag(field->number(), wire_type), values[0].first), RunValidProtobufTest(StrCat("ValidDataScalar", type_name, "[", i, "]"),
field->name() + ": " + values[0].second, is_proto3); REQUIRED,
cat(tag(field->number(), wire_type), values[0].first),
field->name() + ": " + values[0].second, is_proto3);
}
string proto; string proto;
string text = field->name() + ": " + values.back().second; string text = field->name() + ": " + values.back().second;
for (size_t i = 0; i < values.size(); i++) { for (size_t i = 0; i < values.size(); i++) {
proto += cat(tag(field->number(), wire_type), values[i].first); proto += cat(tag(field->number(), wire_type), values[i].first);
} }
RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED, // For scalar message fields, repeated values are merged, which is tested
proto, text, is_proto3); // separately.
if (type != FieldDescriptor::TYPE_MESSAGE) {
RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED,
proto, text, is_proto3);
}
proto.clear(); proto.clear();
text.clear(); text.clear();
...@@ -618,6 +621,48 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( ...@@ -618,6 +621,48 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType(
} }
} }
void BinaryAndJsonConformanceSuite::TestValidDataForRepeatedScalarMessage() {
std::vector<std::string> values = {
delim(cat(tag(2, WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
delim(cat(
tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234),
tag(2, WireFormatLite::WIRETYPE_VARINT), varint(1234),
tag(31, WireFormatLite::WIRETYPE_VARINT), varint(1234)
)))),
delim(cat(tag(2, WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
delim(cat(
tag(1, WireFormatLite::WIRETYPE_VARINT), varint(4321),
tag(3, WireFormatLite::WIRETYPE_VARINT), varint(4321),
tag(31, WireFormatLite::WIRETYPE_VARINT), varint(4321)
)))),
};
const std::string expected =
R"({
corecursive: {
optional_int32: 4321,
optional_int64: 1234,
optional_uint32: 4321,
repeated_int32: [1234, 4321],
}
})";
for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
string proto;
const FieldDescriptor* field =
GetFieldForType(FieldDescriptor::TYPE_MESSAGE, false, is_proto3);
for (size_t i = 0; i < values.size(); i++) {
proto +=
cat(tag(field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
values[i]);
}
RunValidProtobufTest(
"RepeatedScalarMessageMerge", REQUIRED, proto,
field->name() + ": " + expected, is_proto3);
}
}
// TODO: proto2? // TODO: proto2?
void BinaryAndJsonConformanceSuite::TestIllegalTags() { void BinaryAndJsonConformanceSuite::TestIllegalTags() {
// field num 0 is illegal // field num 0 is illegal
...@@ -810,10 +855,15 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { ...@@ -810,10 +855,15 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
{varint(2), "BAZ"}, {varint(2), "BAZ"},
{varint(-1), "NEG"}, {varint(-1), "NEG"},
}); });
TestValidDataForRepeatedScalarMessage();
TestValidDataForType(FieldDescriptor::TYPE_MESSAGE, {
{delim(cat(tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234))),
"{a: 1234}"},
{delim(""), "{}"},
});
// TODO(haberman): // TODO(haberman):
// TestValidDataForType(FieldDescriptor::TYPE_GROUP // TestValidDataForType(FieldDescriptor::TYPE_GROUP
// TestValidDataForType(FieldDescriptor::TYPE_MESSAGE
RunValidJsonTest("HelloWorld", REQUIRED, RunValidJsonTest("HelloWorld", REQUIRED,
"{\"optionalString\":\"Hello, World!\"}", "{\"optionalString\":\"Hello, World!\"}",
......
...@@ -109,6 +109,7 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { ...@@ -109,6 +109,7 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
void TestValidDataForType( void TestValidDataForType(
google::protobuf::FieldDescriptor::Type, google::protobuf::FieldDescriptor::Type,
std::vector<std::pair<std::string, std::string>> values); std::vector<std::pair<std::string, std::string>> values);
void TestValidDataForRepeatedScalarMessage();
std::unique_ptr<google::protobuf::util::TypeResolver> std::unique_ptr<google::protobuf::util::TypeResolver>
type_resolver_; type_resolver_;
......
...@@ -12,3 +12,4 @@ Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput ...@@ -12,3 +12,4 @@ Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.ProtobufOutput
...@@ -18,3 +18,5 @@ Required.Proto3.JsonInput.Uint64FieldNotInteger ...@@ -18,3 +18,5 @@ Required.Proto3.JsonInput.Uint64FieldNotInteger
Required.Proto3.JsonInput.Int32FieldLeadingSpace Required.Proto3.JsonInput.Int32FieldLeadingSpace
Required.Proto3.JsonInput.OneofFieldDuplicate Required.Proto3.JsonInput.OneofFieldDuplicate
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput
Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput
Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.ProtobufOutput
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