diff --git a/src/google/protobuf/json/json_test.cc b/src/google/protobuf/json/json_test.cc index e628d2afa5c2d..1d8f2a283ea0f 100644 --- a/src/google/protobuf/json/json_test.cc +++ b/src/google/protobuf/json/json_test.cc @@ -507,6 +507,76 @@ TEST_P(JsonTest, ParseMap) { EXPECT_EQ(other->DebugString(), message.DebugString()); } +TEST_P(JsonTest, ParseMapWithEnumValuesProto2) { + ParseOptions options; + options.ignore_unknown_fields = false; + protobuf_unittest::TestMapOfEnums message; + EXPECT_THAT(ToProto(message, R"json({ + "enum_map": { + "key1": "PROTOCOL", + "key2": "UNKNOWN_ENUM_STRING_VALUE", + "key3": "BUFFER", + "key4": "UNKNOWN_ENUM_STRING_VALUE", + "key5": "PROTOCOL", + } + })json", options), + StatusIs(absl::StatusCode::kInvalidArgument) + ); +} + +TEST_P(JsonTest, ParseMapWithEnumValuesProto3) { + ParseOptions options; + options.ignore_unknown_fields = false; + proto3::MapOfEnums message; + EXPECT_THAT(ToProto(message, R"json({ + "map": { + "key1": "FOO", + "key2": "UNKNOWN_ENUM_STRING_VALUE", + "key3": "BAR", + "key4": "UNKNOWN_ENUM_STRING_VALUE", + "key5": "FOO", + } + })json", options), + StatusIs(absl::StatusCode::kInvalidArgument) + ); +} + +TEST_P(JsonTest, ParseMapWithEnumValuesProto2WithUnknownFields) { + ParseOptions options; + options.ignore_unknown_fields = true; + protobuf_unittest::TestMapOfEnums message; + ASSERT_OK(ToProto(message, R"json({ + "enum_map": { + "key1": "PROTOCOL", + "key2": "UNKNOWN_ENUM_STRING_VALUE", + "key3": "BUFFER", + "key4": "UNKNOWN_ENUM_STRING_VALUE", + "key5": "PROTOCOL", + } + })json", options)); + EXPECT_EQ(message.enum_map().size(), 5); + EXPECT_EQ(message.enum_map().contains("key2"), true); + EXPECT_EQ(message.enum_map().contains("key4"), true); +} + +TEST_P(JsonTest, ParseMapWithEnumValuesProto3WithUnknownFields) { + ParseOptions options; + options.ignore_unknown_fields = true; + proto3::MapOfEnums message; + ASSERT_OK(ToProto(message, R"json({ + "map": { + "key1": "FOO", + "key2": "UNKNOWN_ENUM_STRING_VALUE", + "key3": "BAR", + "key4": "UNKNOWN_ENUM_STRING_VALUE", + "key5": "FOO", + } + })json", options)); + EXPECT_EQ(message.map().size(), 5); + EXPECT_EQ(message.map().contains("key2"), true); + EXPECT_EQ(message.map().contains("key4"), true); +} + TEST_P(JsonTest, RepeatedMapKey) { EXPECT_THAT(ToProto(R"json({ "string_map": {