aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/json
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/json')
-rw-r--r--test/core/json/BUILD20
-rw-r--r--test/core/json/fuzzer.cc (renamed from test/core/json/fuzzer.c)8
-rw-r--r--test/core/json/json_rewrite.cc (renamed from test/core/json/json_rewrite.c)92
-rw-r--r--test/core/json/json_rewrite_test.cc (renamed from test/core/json/json_rewrite_test.c)96
-rw-r--r--test/core/json/json_stream_error_test.cc (renamed from test/core/json/json_stream_error_test.c)6
-rw-r--r--test/core/json/json_test.cc (renamed from test/core/json/json_test.c)23
6 files changed, 127 insertions, 118 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 b825904d41..6dafabb95b 100644
--- a/test/core/json/fuzzer.c
+++ b/test/core/json/fuzzer.cc
@@ -29,13 +29,13 @@
bool squelch = true;
bool leak_check = true;
-int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
- char *s;
+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;
+ grpc_json* x;
if ((x = grpc_json_parse_string_with_len(s, size))) {
grpc_json_destroy(x);
}
diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.cc
index dfe32f5adf..98e76e9772 100644
--- a/test/core/json/json_rewrite.c
+++ b/test/core/json/json_rewrite.cc
@@ -26,37 +26,39 @@
#include "src/core/lib/json/json_reader.h"
#include "src/core/lib/json/json_writer.h"
-typedef struct json_writer_userdata { FILE *out; } json_writer_userdata;
+typedef struct json_writer_userdata {
+ FILE* out;
+} json_writer_userdata;
typedef struct stacked_container {
grpc_json_type type;
- struct stacked_container *next;
+ struct stacked_container* next;
} stacked_container;
typedef struct json_reader_userdata {
- FILE *in;
- grpc_json_writer *writer;
- char *scratchpad;
- char *ptr;
+ FILE* in;
+ grpc_json_writer* writer;
+ char* scratchpad;
+ char* ptr;
size_t free_space;
size_t allocated;
size_t string_len;
- stacked_container *top;
+ stacked_container* top;
} json_reader_userdata;
-static void json_writer_output_char(void *userdata, char c) {
- json_writer_userdata *state = userdata;
+static void json_writer_output_char(void* userdata, char c) {
+ 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;
+static void json_writer_output_string(void* userdata, const char* str) {
+ 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,
+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);
}
@@ -64,29 +66,30 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char,
json_writer_output_string,
json_writer_output_string_with_len};
-static void check_string(json_reader_userdata *state, size_t needed) {
+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;
+static void json_reader_string_clear(void* 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;
+static void json_reader_string_add_char(void* userdata, uint32_t c) {
+ 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;
}
-static void json_reader_string_add_utf32(void *userdata, uint32_t c) {
+static void json_reader_string_add_utf32(void* userdata, uint32_t c) {
if (c <= 0x7f) {
json_reader_string_add_char(userdata, c);
} else if (c <= 0x7ff) {
@@ -113,18 +116,19 @@ static void json_reader_string_add_utf32(void *userdata, uint32_t c) {
}
}
-static uint32_t json_reader_read_char(void *userdata) {
+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;
return (uint32_t)r;
}
-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));
+static void json_reader_container_begins(void* userdata, grpc_json_type type) {
+ 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;
@@ -133,9 +137,9 @@ static void json_reader_container_begins(void *userdata, grpc_json_type type) {
grpc_json_writer_container_begins(state->writer, type);
}
-static grpc_json_type json_reader_container_ends(void *userdata) {
- json_reader_userdata *state = userdata;
- stacked_container *container = state->top;
+static grpc_json_type json_reader_container_ends(void* 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);
state->top = container->next;
@@ -143,22 +147,22 @@ static grpc_json_type json_reader_container_ends(void *userdata) {
return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL;
}
-static void json_reader_set_key(void *userdata) {
- json_reader_userdata *state = userdata;
+static void json_reader_set_key(void* 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;
+static void json_reader_set_string(void* 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;
+static int json_reader_set_number(void* 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);
@@ -166,20 +170,20 @@ static int json_reader_set_number(void *userdata) {
return 1;
}
-static void json_reader_set_true(void *userdata) {
- json_reader_userdata *state = userdata;
+static void json_reader_set_true(void* 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;
+static void json_reader_set_false(void* 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;
+static void json_reader_set_null(void* userdata) {
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json_writer_value_raw_with_len(state->writer, "null", 4);
}
@@ -192,7 +196,7 @@ static grpc_json_reader_vtable reader_vtable = {
json_reader_set_number, json_reader_set_true,
json_reader_set_false, json_reader_set_null};
-int rewrite(FILE *in, FILE *out, int indent) {
+int rewrite(FILE* in, FILE* out, int indent) {
grpc_json_writer writer;
grpc_json_reader reader;
grpc_json_reader_status status;
@@ -216,7 +220,7 @@ int rewrite(FILE *in, FILE *out, int indent) {
free(reader_user.scratchpad);
while (reader_user.top) {
- stacked_container *container = reader_user.top;
+ stacked_container* container = reader_user.top;
reader_user.top = container->next;
free(container);
}
@@ -224,9 +228,9 @@ int rewrite(FILE *in, FILE *out, int indent) {
return status == GRPC_JSON_DONE;
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
int indent = 2;
- gpr_cmdline *cl;
+ gpr_cmdline* cl;
cl = gpr_cmdline_create(NULL);
gpr_cmdline_add_int(cl, "indent", NULL, &indent);
diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.cc
index a654971b34..47b4f01e8b 100644
--- a/test/core/json/json_rewrite_test.c
+++ b/test/core/json/json_rewrite_test.cc
@@ -27,27 +27,29 @@
#include "src/core/lib/json/json_reader.h"
#include "src/core/lib/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;
- struct stacked_container *next;
+ struct stacked_container* next;
} stacked_container;
typedef struct json_reader_userdata {
- FILE *in;
- grpc_json_writer *writer;
- char *scratchpad;
- char *ptr;
+ FILE* in;
+ grpc_json_writer* writer;
+ char* scratchpad;
+ char* ptr;
size_t free_space;
size_t allocated;
size_t string_len;
- stacked_container *top;
+ stacked_container* top;
int did_eagain;
} json_reader_userdata;
-static void json_writer_output_char(void *userdata, char c) {
- json_writer_userdata *state = userdata;
+static void json_writer_output_char(void* userdata, char c) {
+ json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
int cmp = fgetc(state->cmp);
/* treat CRLF as LF */
@@ -57,13 +59,13 @@ static void json_writer_output_char(void *userdata, char c) {
GPR_ASSERT(cmp == c);
}
-static void json_writer_output_string(void *userdata, const char *str) {
+static void json_writer_output_string(void* userdata, const char* str) {
while (*str) {
json_writer_output_char(userdata, *str++);
}
}
-static void json_writer_output_string_with_len(void *userdata, const char *str,
+static void json_writer_output_string_with_len(void* userdata, const char* str,
size_t len) {
size_t i;
for (i = 0; i < len; i++) {
@@ -75,29 +77,30 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char,
json_writer_output_string,
json_writer_output_string_with_len};
-static void check_string(json_reader_userdata *state, size_t needed) {
+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;
+static void json_reader_string_clear(void* 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;
+static void json_reader_string_add_char(void* userdata, uint32_t c) {
+ 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;
}
-static void json_reader_string_add_utf32(void *userdata, uint32_t c) {
+static void json_reader_string_add_utf32(void* userdata, uint32_t c) {
if (c <= 0x7f) {
json_reader_string_add_char(userdata, c);
} else if (c <= 0x7ffu) {
@@ -124,9 +127,9 @@ static void json_reader_string_add_utf32(void *userdata, uint32_t c) {
}
}
-static uint32_t json_reader_read_char(void *userdata) {
+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;
@@ -140,9 +143,10 @@ static uint32_t json_reader_read_char(void *userdata) {
return (uint32_t)r;
}
-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));
+static void json_reader_container_begins(void* userdata, grpc_json_type type) {
+ 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;
@@ -151,9 +155,9 @@ static void json_reader_container_begins(void *userdata, grpc_json_type type) {
grpc_json_writer_container_begins(state->writer, type);
}
-static grpc_json_type json_reader_container_ends(void *userdata) {
- json_reader_userdata *state = userdata;
- stacked_container *container = state->top;
+static grpc_json_type json_reader_container_ends(void* 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);
state->top = container->next;
@@ -161,22 +165,22 @@ static grpc_json_type json_reader_container_ends(void *userdata) {
return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL;
}
-static void json_reader_set_key(void *userdata) {
- json_reader_userdata *state = userdata;
+static void json_reader_set_key(void* 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;
+static void json_reader_set_string(void* 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;
+static int json_reader_set_number(void* 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);
@@ -184,20 +188,20 @@ static int json_reader_set_number(void *userdata) {
return 1;
}
-static void json_reader_set_true(void *userdata) {
- json_reader_userdata *state = userdata;
+static void json_reader_set_true(void* 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;
+static void json_reader_set_false(void* 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;
+static void json_reader_set_null(void* userdata) {
+ json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
grpc_json_writer_value_raw_with_len(state->writer, "null", 4);
}
@@ -210,7 +214,7 @@ static grpc_json_reader_vtable reader_vtable = {
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) {
+int rewrite_and_compare(FILE* in, FILE* cmp, int indent) {
grpc_json_writer writer;
grpc_json_reader reader;
grpc_json_reader_status status;
@@ -240,7 +244,7 @@ int rewrite_and_compare(FILE *in, FILE *cmp, int indent) {
free(reader_user.scratchpad);
while (reader_user.top) {
- stacked_container *container = reader_user.top;
+ stacked_container* container = reader_user.top;
reader_user.top = container->next;
free(container);
}
@@ -249,8 +253,8 @@ int rewrite_and_compare(FILE *in, FILE *cmp, int indent) {
}
typedef struct test_file {
- const char *input;
- const char *cmp;
+ const char* input;
+ const char* cmp;
int indent;
} test_file;
@@ -269,9 +273,9 @@ void test_rewrites() {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) {
- test_file *test = test_files + i;
- FILE *input = fopen(test->input, "rb");
- FILE *cmp = fopen(test->cmp, "rb");
+ test_file* test = test_files + i;
+ 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);
@@ -282,7 +286,7 @@ void test_rewrites() {
}
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_rewrites();
gpr_log(GPR_INFO, "json_rewrite_test success");
diff --git a/test/core/json/json_stream_error_test.c b/test/core/json/json_stream_error_test.cc
index 379cd5d078..975ccd2b42 100644
--- a/test/core/json/json_stream_error_test.c
+++ b/test/core/json/json_stream_error_test.cc
@@ -29,12 +29,12 @@
static int g_string_clear_once = 0;
-static void string_clear(void *userdata) {
+static void string_clear(void* userdata) {
GPR_ASSERT(!g_string_clear_once);
g_string_clear_once = 1;
}
-static uint32_t read_char(void *userdata) { return GRPC_JSON_READ_CHAR_ERROR; }
+static uint32_t read_char(void* userdata) { return GRPC_JSON_READ_CHAR_ERROR; }
static grpc_json_reader_vtable reader_vtable = {
string_clear, NULL, NULL, read_char, NULL, NULL,
@@ -49,7 +49,7 @@ static void read_error() {
GPR_ASSERT(status == GRPC_JSON_READ_ERROR);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
read_error();
gpr_log(GPR_INFO, "json_stream_error success");
diff --git a/test/core/json/json_test.c b/test/core/json/json_test.cc
index bbc6f7a4e6..9e4d351dd7 100644
--- a/test/core/json/json_test.c
+++ b/test/core/json/json_test.cc
@@ -28,8 +28,8 @@
#include "test/core/util/test_config.h"
typedef struct testing_pair {
- const char *input;
- const char *output;
+ const char* input;
+ const char* output;
} testing_pair;
static testing_pair testing_pairs[] = {
@@ -52,7 +52,8 @@ static testing_pair testing_pairs[] = {
{"{\"\\ud834\\udd1e\":0}", "{\"\\ud834\\udd1e\":0}"},
/* Testing nested empty containers. */
{
- " [ [ ] , { } , [ ] ] ", "[[],{},[]]",
+ " [ [ ] , { } , [ ] ] ",
+ "[[],{},[]]",
},
/* Testing escapes and control chars in key strings. */
{" { \"\\u007f\x7f\\n\\r\\\"\\f\\b\\\\a , b\": 1, \"\": 0 } ",
@@ -139,16 +140,16 @@ static void test_pairs() {
unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(testing_pairs); i++) {
- testing_pair *pair = testing_pairs + i;
- char *scratchpad = gpr_strdup(pair->input);
- grpc_json *json;
+ testing_pair* pair = testing_pairs + i;
+ char* scratchpad = gpr_strdup(pair->input);
+ grpc_json* json;
gpr_log(GPR_INFO, "parsing string %i - should %s", i,
pair->output ? "succeed" : "fail");
json = grpc_json_parse_string(scratchpad);
if (pair->output) {
- char *output;
+ char* output;
GPR_ASSERT(json);
output = grpc_json_dump_to_string(json, 0);
@@ -168,9 +169,9 @@ static void test_pairs() {
}
static void test_atypical() {
- char *scratchpad = gpr_strdup("[[],[],[]]");
- grpc_json *json = grpc_json_parse_string(scratchpad);
- grpc_json *brother;
+ char* scratchpad = gpr_strdup("[[],[],[]]");
+ grpc_json* json = grpc_json_parse_string(scratchpad);
+ grpc_json* brother;
GPR_ASSERT(json);
GPR_ASSERT(json->child);
@@ -182,7 +183,7 @@ static void test_atypical() {
gpr_free(scratchpad);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_pairs();
test_atypical();