|
|
|
@ -42,9 +42,7 @@ |
|
|
|
|
#include "src/core/json/json_reader.h" |
|
|
|
|
#include "src/core/json/json_writer.h" |
|
|
|
|
|
|
|
|
|
typedef struct json_writer_userdata { |
|
|
|
|
FILE* cmp; |
|
|
|
|
} json_writer_userdata; |
|
|
|
|
typedef struct json_writer_userdata { FILE* cmp; } json_writer_userdata; |
|
|
|
|
|
|
|
|
|
typedef struct stacked_container { |
|
|
|
|
grpc_json_type type; |
|
|
|
@ -83,11 +81,9 @@ static void json_writer_output_string_with_len(void* userdata, const char* str, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_json_writer_vtable writer_vtable = { |
|
|
|
|
json_writer_output_char, |
|
|
|
|
grpc_json_writer_vtable writer_vtable = {json_writer_output_char, |
|
|
|
|
json_writer_output_string, |
|
|
|
|
json_writer_output_string_with_len |
|
|
|
|
}; |
|
|
|
|
json_writer_output_string_with_len}; |
|
|
|
|
|
|
|
|
|
static void check_string(json_reader_userdata* state, size_t needed) { |
|
|
|
|
if (state->free_space >= needed) return; |
|
|
|
@ -216,19 +212,12 @@ static void json_reader_set_null(void* userdata) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_json_reader_vtable reader_vtable = { |
|
|
|
|
json_reader_string_clear, |
|
|
|
|
json_reader_string_add_char, |
|
|
|
|
json_reader_string_add_utf32, |
|
|
|
|
json_reader_read_char, |
|
|
|
|
json_reader_container_begins, |
|
|
|
|
json_reader_container_ends, |
|
|
|
|
json_reader_set_key, |
|
|
|
|
json_reader_set_string, |
|
|
|
|
json_reader_set_number, |
|
|
|
|
json_reader_set_true, |
|
|
|
|
json_reader_set_false, |
|
|
|
|
json_reader_set_null |
|
|
|
|
}; |
|
|
|
|
json_reader_string_clear, json_reader_string_add_char, |
|
|
|
|
json_reader_string_add_utf32, json_reader_read_char, |
|
|
|
|
json_reader_container_begins, json_reader_container_ends, |
|
|
|
|
json_reader_set_key, json_reader_set_string, |
|
|
|
|
json_reader_set_number, json_reader_set_true, |
|
|
|
|
json_reader_set_false, json_reader_set_null}; |
|
|
|
|
|
|
|
|
|
int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { |
|
|
|
|
grpc_json_writer writer; |
|
|
|
@ -275,26 +264,14 @@ typedef struct test_file { |
|
|
|
|
} test_file; |
|
|
|
|
|
|
|
|
|
static test_file test_files[] = { |
|
|
|
|
{ |
|
|
|
|
"test/core/json/rewrite_test_input.json", |
|
|
|
|
"test/core/json/rewrite_test_output_condensed.json", |
|
|
|
|
0 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"test/core/json/rewrite_test_input.json", |
|
|
|
|
"test/core/json/rewrite_test_output_indented.json", |
|
|
|
|
2 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"test/core/json/rewrite_test_output_indented.json", |
|
|
|
|
"test/core/json/rewrite_test_output_condensed.json", |
|
|
|
|
0 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"test/core/json/rewrite_test_output_condensed.json", |
|
|
|
|
"test/core/json/rewrite_test_output_indented.json", |
|
|
|
|
2 |
|
|
|
|
}, |
|
|
|
|
{"test/core/json/rewrite_test_input.json", |
|
|
|
|
"test/core/json/rewrite_test_output_condensed.json", 0}, |
|
|
|
|
{"test/core/json/rewrite_test_input.json", |
|
|
|
|
"test/core/json/rewrite_test_output_indented.json", 2}, |
|
|
|
|
{"test/core/json/rewrite_test_output_indented.json", |
|
|
|
|
"test/core/json/rewrite_test_output_condensed.json", 0}, |
|
|
|
|
{"test/core/json/rewrite_test_output_condensed.json", |
|
|
|
|
"test/core/json/rewrite_test_output_indented.json", 2}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void test_rewrites() { |
|
|
|
@ -305,8 +282,8 @@ void test_rewrites() { |
|
|
|
|
FILE* input = fopen(test->input, "rb"); |
|
|
|
|
FILE* cmp = fopen(test->cmp, "rb"); |
|
|
|
|
int status; |
|
|
|
|
gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", |
|
|
|
|
test->input, test->cmp, test->indent); |
|
|
|
|
gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", test->input, |
|
|
|
|
test->cmp, test->indent); |
|
|
|
|
status = rewrite_and_compare(input, cmp, test->indent); |
|
|
|
|
GPR_ASSERT(status); |
|
|
|
|
fclose(input); |
|
|
|
|