Add unit test for loading unknown fields in Any messages

Use ./tests.sh cpp to run it
pull/5099/head
Brandon Cole 6 years ago
parent 45d03a9771
commit d83a9f66bc
  1. 18
      src/google/protobuf/util/json_util_test.cc

@ -56,6 +56,7 @@ using proto3::TestEnumValue;
using proto3::TestMap; using proto3::TestMap;
using proto3::TestMessage; using proto3::TestMessage;
using proto3::TestOneof; using proto3::TestOneof;
using proto3::TestAny;
static const char kTypeUrlPrefix[] = "type.googleapis.com"; static const char kTypeUrlPrefix[] = "type.googleapis.com";
@ -357,6 +358,23 @@ TEST_F(JsonUtilTest, TestDynamicMessage) {
EXPECT_EQ(ToJson(generated, options), ToJson(*message, options)); EXPECT_EQ(ToJson(generated, options), ToJson(*message, options));
} }
TEST_F(JsonUtilTest, TestParsingUnknownAnyFields) {
string input =
"{\n"
" \"value\": {\n"
" \"@type\": \"type.googleapis.com/proto3.TestMessage\",\n"
" \"unknown_field\": \"UNKOWN_VALUE\"\n"
" }\n"
"}";
TestAny m;
JsonParseOptions options;
EXPECT_FALSE(FromJson(input, &m, options));
options.ignore_unknown_fields = true;
EXPECT_TRUE(FromJson(input, &m, options));
}
TEST_F(JsonUtilTest, TestParsingUnknownEnumsProto2) { TEST_F(JsonUtilTest, TestParsingUnknownEnumsProto2) {
string input = string input =
"{\n" "{\n"

Loading…
Cancel
Save