diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-11-07 17:02:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-07 17:02:23 -0800 |
commit | d9da7387b8057f3bd99a417a5ee905377bce9296 (patch) | |
tree | df5e16acf65e083ce2b56a9543eba918ef35b451 /test/core/json | |
parent | c03867ff224a98dab5a93b3ba70b95c46f05a440 (diff) | |
parent | 67c0effd324b3fa86c13dabe5a63f66d48672e30 (diff) |
Merge pull request #13147 from yashykt/testc++ize
Convert test/core to C++
Diffstat (limited to 'test/core/json')
-rw-r--r-- | test/core/json/BUILD | 20 | ||||
-rw-r--r-- | test/core/json/fuzzer.cc (renamed from test/core/json/fuzzer.c) | 4 | ||||
-rw-r--r-- | test/core/json/json_rewrite.cc (renamed from test/core/json/json_rewrite.c) | 34 | ||||
-rw-r--r-- | test/core/json/json_rewrite_test.cc (renamed from test/core/json/json_rewrite_test.c) | 30 | ||||
-rw-r--r-- | test/core/json/json_stream_error_test.cc (renamed from test/core/json/json_stream_error_test.c) | 0 | ||||
-rw-r--r-- | test/core/json/json_test.cc (renamed from test/core/json/json_test.c) | 0 |
6 files changed, 46 insertions, 42 deletions
diff --git a/test/core/json/BUILD b/test/core/json/BUILD index 3ff7918677..b8b36c0652 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -22,8 +22,8 @@ load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( name = "json_fuzzer", - srcs = ["fuzzer.c"], - language = "C", + srcs = ["fuzzer.cc"], + language = "C++", corpus = "corpus", deps = [ "//:gpr", @@ -35,8 +35,8 @@ grpc_fuzzer( grpc_cc_binary( name = "json_rewrite", testonly = 1, - srcs = ["json_rewrite.c"], - language = "C", + srcs = ["json_rewrite.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -47,8 +47,8 @@ grpc_cc_binary( grpc_cc_test( name = "json_rewrite_test", - srcs = ["json_rewrite_test.c"], - language = "C", + srcs = ["json_rewrite_test.cc"], + language = "C++", data = [ "rewrite_test_input.json", "rewrite_test_output_condensed.json", @@ -65,8 +65,8 @@ grpc_cc_test( grpc_cc_test( name = "json_stream_error_test", - srcs = ["json_stream_error_test.c"], - language = "C", + srcs = ["json_stream_error_test.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -77,8 +77,8 @@ grpc_cc_test( grpc_cc_test( name = "json_test", - srcs = ["json_test.c"], - language = "C", + srcs = ["json_test.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", diff --git a/test/core/json/fuzzer.c b/test/core/json/fuzzer.cc index 273886873c..6dafabb95b 100644 --- a/test/core/json/fuzzer.c +++ b/test/core/json/fuzzer.cc @@ -29,11 +29,11 @@ bool squelch = true; bool leak_check = true; -int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { char* s; struct grpc_memory_counters counters; grpc_memory_counters_init(); - s = gpr_malloc(size); + s = static_cast<char*>(gpr_malloc(size)); memcpy(s, data, size); grpc_json* x; if ((x = grpc_json_parse_string_with_len(s, size))) { diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.cc index 3bd50e67b3..98e76e9772 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.cc @@ -47,18 +47,18 @@ typedef struct json_reader_userdata { } json_reader_userdata; static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = userdata; + json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata); fputc(c, state->out); } static void json_writer_output_string(void* userdata, const char* str) { - json_writer_userdata* state = userdata; + json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata); fputs(str, state->out); } static void json_writer_output_string_with_len(void* userdata, const char* str, size_t len) { - json_writer_userdata* state = userdata; + json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata); fwrite(str, len, 1, state->out); } @@ -70,19 +70,20 @@ static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; needed = (needed + 0xffu) & ~0xffu; - state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed); + state->scratchpad = static_cast<char*>( + gpr_realloc(state->scratchpad, state->allocated + needed)); state->free_space += needed; state->allocated += needed; } static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); state->free_space = state->allocated; state->string_len = 0; } static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); check_string(state, 1); GPR_ASSERT(c < 256); state->scratchpad[state->string_len++] = (char)c; @@ -117,7 +118,7 @@ static void json_reader_string_add_utf32(void* userdata, uint32_t c) { static uint32_t json_reader_read_char(void* userdata) { int r; - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; @@ -125,8 +126,9 @@ static uint32_t json_reader_read_char(void* userdata) { } static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = userdata; - stacked_container* container = gpr_malloc(sizeof(stacked_container)); + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); + stacked_container* container = + static_cast<stacked_container*>(gpr_malloc(sizeof(stacked_container))); container->type = type; container->next = state->top; @@ -136,7 +138,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { } static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); stacked_container* container = state->top; grpc_json_writer_container_ends(state->writer, container->type); @@ -146,21 +148,21 @@ static grpc_json_type json_reader_container_ends(void* userdata) { } static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); json_reader_string_add_char(userdata, 0); grpc_json_writer_object_key(state->writer, state->scratchpad); } static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); json_reader_string_add_char(userdata, 0); grpc_json_writer_value_string(state->writer, state->scratchpad); } static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, state->string_len); @@ -169,19 +171,19 @@ static int json_reader_set_number(void* userdata) { } static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "true", 4); } static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "false", 5); } static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "null", 4); } diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.cc index a83989f402..47b4f01e8b 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.cc @@ -49,7 +49,7 @@ typedef struct json_reader_userdata { } json_reader_userdata; static void json_writer_output_char(void* userdata, char c) { - json_writer_userdata* state = userdata; + json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata); int cmp = fgetc(state->cmp); /* treat CRLF as LF */ @@ -81,19 +81,20 @@ static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; needed = (needed + 0xffu) & ~0xffu; - state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed); + state->scratchpad = static_cast<char*>( + gpr_realloc(state->scratchpad, state->allocated + needed)); state->free_space += needed; state->allocated += needed; } static void json_reader_string_clear(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); state->free_space = state->allocated; state->string_len = 0; } static void json_reader_string_add_char(void* userdata, uint32_t c) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); check_string(state, 1); GPR_ASSERT(c <= 256); state->scratchpad[state->string_len++] = (char)c; @@ -128,7 +129,7 @@ static void json_reader_string_add_utf32(void* userdata, uint32_t c) { static uint32_t json_reader_read_char(void* userdata) { int r; - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); if (!state->did_eagain) { state->did_eagain = 1; @@ -143,8 +144,9 @@ static uint32_t json_reader_read_char(void* userdata) { } static void json_reader_container_begins(void* userdata, grpc_json_type type) { - json_reader_userdata* state = userdata; - stacked_container* container = gpr_malloc(sizeof(stacked_container)); + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); + stacked_container* container = + static_cast<stacked_container*>(gpr_malloc(sizeof(stacked_container))); container->type = type; container->next = state->top; @@ -154,7 +156,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { } static grpc_json_type json_reader_container_ends(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); stacked_container* container = state->top; grpc_json_writer_container_ends(state->writer, container->type); @@ -164,21 +166,21 @@ static grpc_json_type json_reader_container_ends(void* userdata) { } static void json_reader_set_key(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); json_reader_string_add_char(userdata, 0); grpc_json_writer_object_key(state->writer, state->scratchpad); } static void json_reader_set_string(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); json_reader_string_add_char(userdata, 0); grpc_json_writer_value_string(state->writer, state->scratchpad); } static int json_reader_set_number(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, state->string_len); @@ -187,19 +189,19 @@ static int json_reader_set_number(void* userdata) { } static void json_reader_set_true(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "true", 4); } static void json_reader_set_false(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "false", 5); } static void json_reader_set_null(void* userdata) { - json_reader_userdata* state = userdata; + json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata); grpc_json_writer_value_raw_with_len(state->writer, "null", 4); } diff --git a/test/core/json/json_stream_error_test.c b/test/core/json/json_stream_error_test.cc index 975ccd2b42..975ccd2b42 100644 --- a/test/core/json/json_stream_error_test.c +++ b/test/core/json/json_stream_error_test.cc diff --git a/test/core/json/json_test.c b/test/core/json/json_test.cc index 9e4d351dd7..9e4d351dd7 100644 --- a/test/core/json/json_test.c +++ b/test/core/json/json_test.cc |