diff options
Diffstat (limited to 'tests/json/test_json.cc')
-rw-r--r-- | tests/json/test_json.cc | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc index 5ca04fc..6874131 100644 --- a/tests/json/test_json.cc +++ b/tests/json/test_json.cc @@ -36,6 +36,17 @@ static TestCase kTestRoundtripMessages[] = { "{\"foo\":2}]}"), EXPECT_SAME }, + // We must also recognize raw proto names. + { + TEST("{\"optional_int32\":-42,\"optional_string\":\"Test\\u0001Message\"," + "\"optional_msg\":{\"foo\":42}," + "\"optional_bool\":true,\"repeated_msg\":[{\"foo\":1}," + "{\"foo\":2}]}"), + EXPECT("{\"optionalInt32\":-42,\"optionalString\":\"Test\\u0001Message\"," + "\"optionalMsg\":{\"foo\":42}," + "\"optionalBool\":true,\"repeatedMsg\":[{\"foo\":1}," + "{\"foo\":2}]}") + }, // Test special escapes in strings. { TEST("{\"repeatedString\":[\"\\b\",\"\\r\",\"\\n\",\"\\f\",\"\\t\"," @@ -112,6 +123,18 @@ static TestCase kTestRoundtripMessages[] = { TEST_SENTINEL }; +static TestCase kTestRoundtripMessagesPreserve[] = { + // Test most fields here. + { + TEST("{\"optional_int32\":-42,\"optional_string\":\"Test\\u0001Message\"," + "\"optional_msg\":{\"foo\":42}," + "\"optional_bool\":true,\"repeated_msg\":[{\"foo\":1}," + "{\"foo\":2}]}"), + EXPECT_SAME + }, + TEST_SENTINEL +}; + static void AddField(upb::MessageDef* message, int number, const char* name, @@ -323,7 +346,7 @@ void test_json_roundtrip() { upb::reffed_ptr<upb::SymbolTable> symtab(upb::SymbolTable::New()); const upb::MessageDef* md = BuildTestMessage(symtab.get()); upb::reffed_ptr<const upb::Handlers> serialize_handlers( - upb::json::Printer::NewHandlers(md)); + upb::json::Printer::NewHandlers(md, false)); upb::reffed_ptr<const upb::json::ParserMethod> parser_method( upb::json::ParserMethod::New(md)); @@ -340,6 +363,22 @@ void test_json_roundtrip() { i); } } + + serialize_handlers = upb::json::Printer::NewHandlers(md, true); + + for (const TestCase* test_case = kTestRoundtripMessagesPreserve; + test_case->input != NULL; test_case++) { + const char *expected = + (test_case->expected == EXPECT_SAME) ? + test_case->input : + test_case->expected; + + for (size_t i = 0; i < strlen(test_case->input); i++) { + test_json_roundtrip_message(test_case->input, expected, + serialize_handlers.get(), parser_method.get(), + i); + } + } } extern "C" { |