diff options
Diffstat (limited to 'test/core/channel')
-rw-r--r-- | test/core/channel/BUILD | 12 | ||||
-rw-r--r-- | test/core/channel/channel_args_test.cc (renamed from test/core/channel/channel_args_test.c) | 14 | ||||
-rw-r--r-- | test/core/channel/channel_stack_builder_test.cc (renamed from test/core/channel/channel_stack_builder_test.c) | 61 | ||||
-rw-r--r-- | test/core/channel/channel_stack_test.cc (renamed from test/core/channel/channel_stack_test.c) | 99 | ||||
-rw-r--r-- | test/core/channel/minimal_stack_is_minimal_test.cc (renamed from test/core/channel/minimal_stack_is_minimal_test.c) | 56 |
5 files changed, 126 insertions, 116 deletions
diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index 5ac77c449b..92f5907aac 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -20,8 +20,8 @@ licenses(["notice"]) # Apache v2 grpc_cc_test( name = "channel_args_test", - srcs = ["channel_args_test.c"], - language = "C", + srcs = ["channel_args_test.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -32,8 +32,8 @@ grpc_cc_test( grpc_cc_test( name = "channel_stack_test", - srcs = ["channel_stack_test.c"], - language = "C", + srcs = ["channel_stack_test.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", @@ -44,8 +44,8 @@ grpc_cc_test( grpc_cc_test( name = "channel_stack_builder_test", - srcs = ["channel_stack_builder_test.c"], - language = "C", + srcs = ["channel_stack_builder_test.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.cc index deaf2933ec..4b4bd3e718 100644 --- a/test/core/channel/channel_args_test.c +++ b/test/core/channel/channel_args_test.cc @@ -31,15 +31,15 @@ static void test_create(void) { grpc_arg arg_int; grpc_arg arg_string; grpc_arg to_add[2]; - grpc_channel_args *ch_args; + grpc_channel_args* ch_args; - arg_int.key = "int_arg"; + arg_int.key = const_cast<char*>("int_arg"); arg_int.type = GRPC_ARG_INTEGER; arg_int.value.integer = 123; - arg_string.key = "str key"; + arg_string.key = const_cast<char*>("str key"); arg_string.type = GRPC_ARG_STRING; - arg_string.value.string = "str value"; + arg_string.value.string = const_cast<char*>("str value"); to_add[0] = arg_int; to_add[1] = arg_string; @@ -61,7 +61,7 @@ static void test_create(void) { static void test_set_compression_algorithm(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_channel_args *ch_args; + grpc_channel_args* ch_args; ch_args = grpc_channel_args_set_compression_algorithm(NULL, GRPC_COMPRESS_GZIP); @@ -127,7 +127,7 @@ static void test_compression_algorithm_states(void) { } static void test_set_socket_mutator(void) { - grpc_channel_args *ch_args; + grpc_channel_args* ch_args; grpc_socket_mutator mutator; grpc_socket_mutator_init(&mutator, NULL); @@ -143,7 +143,7 @@ static void test_set_socket_mutator(void) { } } -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); test_create(); diff --git a/test/core/channel/channel_stack_builder_test.c b/test/core/channel/channel_stack_builder_test.cc index 682efd1438..1571f6ec09 100644 --- a/test/core/channel/channel_stack_builder_test.c +++ b/test/core/channel/channel_stack_builder_test.cc @@ -29,30 +29,30 @@ #include "src/core/lib/surface/channel_init.h" #include "test/core/util/test_config.h" -static grpc_error *channel_init_func(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { +static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static grpc_error *call_init_func(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { +static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) {} +static void channel_destroy_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) {} +static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) {} -static void call_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *op) {} +static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) {} -static void channel_func(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - grpc_transport_op *op) { +static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op) { if (op->disconnect_with_error != GRPC_ERROR_NONE) { GRPC_ERROR_UNREF(op->disconnect_with_error); } @@ -61,16 +61,16 @@ static void channel_func(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, bool g_replacement_fn_called = false; bool g_original_fn_called = false; -void set_arg_once_fn(grpc_channel_stack *channel_stack, - grpc_channel_element *elem, void *arg) { - bool *called = arg; +void set_arg_once_fn(grpc_channel_stack* channel_stack, + grpc_channel_element* elem, void* arg) { + bool* called = static_cast<bool*>(arg); // Make sure this function is only called once per arg. GPR_ASSERT(*called == false); *called = true; } static void test_channel_stack_builder_filter_replace(void) { - grpc_channel *channel = + grpc_channel* channel = grpc_insecure_channel_create("target name isn't used", NULL, NULL); GPR_ASSERT(channel != NULL); // Make sure the high priority filter has been created. @@ -106,10 +106,11 @@ const grpc_channel_filter original_filter = { grpc_channel_next_get_info, "filter_name"}; -static bool add_replacement_filter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, - void *arg) { - const grpc_channel_filter *filter = arg; +static bool add_replacement_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, + void* arg) { + const grpc_channel_filter* filter = + static_cast<const grpc_channel_filter*>(arg); // Get rid of any other version of the filter, as determined by having the // same name. GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder, filter->name)); @@ -117,26 +118,26 @@ static bool add_replacement_filter(grpc_exec_ctx *exec_ctx, builder, filter, set_arg_once_fn, &g_replacement_fn_called); } -static bool add_original_filter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, - void *arg) { +static bool add_original_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, + void* arg) { return grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter *)arg, set_arg_once_fn, + builder, (const grpc_channel_filter*)arg, set_arg_once_fn, &g_original_fn_called); } static void init_plugin(void) { grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, add_original_filter, - (void *)&original_filter); + (void*)&original_filter); grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, add_replacement_filter, - (void *)&replacement_filter); + (void*)&replacement_filter); } static void destroy_plugin(void) {} -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_register_plugin(init_plugin, destroy_plugin); grpc_init(); diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.cc index a07ef89ba8..1b661ac2f4 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.cc @@ -27,54 +27,55 @@ #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" -static grpc_error *channel_init_func(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { +static grpc_error* channel_init_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { GPR_ASSERT(args->channel_args->num_args == 1); GPR_ASSERT(args->channel_args->args[0].type == GRPC_ARG_INTEGER); GPR_ASSERT(0 == strcmp(args->channel_args->args[0].key, "test_key")); GPR_ASSERT(args->channel_args->args[0].value.integer == 42); GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); - *(int *)(elem->channel_data) = 0; + *(int*)(elem->channel_data) = 0; return GRPC_ERROR_NONE; } -static grpc_error *call_init_func(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - ++*(int *)(elem->channel_data); - *(int *)(elem->call_data) = 0; +static grpc_error* call_init_func(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + ++*(int*)(elem->channel_data); + *(int*)(elem->call_data) = 0; return GRPC_ERROR_NONE; } -static void channel_destroy_func(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) {} +static void channel_destroy_func(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} -static void call_destroy_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) { - ++*(int *)(elem->channel_data); +static void call_destroy_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + ++*(int*)(elem->channel_data); } -static void call_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *op) { - ++*(int *)(elem->call_data); +static void call_func(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { + ++*(int*)(elem->call_data); } -static void channel_func(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - grpc_transport_op *op) { - ++*(int *)(elem->channel_data); +static void channel_func(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_transport_op* op) { + ++*(int*)(elem->channel_data); } -static void free_channel(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_channel_stack_destroy(exec_ctx, arg); +static void free_channel(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_channel_stack_destroy(exec_ctx, static_cast<grpc_channel_stack*>(arg)); gpr_free(arg); } -static void free_call(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - grpc_call_stack_destroy(exec_ctx, arg, NULL, NULL); +static void free_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + grpc_call_stack_destroy(exec_ctx, static_cast<grpc_call_stack*>(arg), NULL, + NULL); gpr_free(arg); } @@ -91,50 +92,54 @@ static void test_create_channel_stack(void) { channel_destroy_func, grpc_channel_next_get_info, "some_test_filter"}; - const grpc_channel_filter *filters = &filter; - grpc_channel_stack *channel_stack; - grpc_call_stack *call_stack; - grpc_channel_element *channel_elem; - grpc_call_element *call_elem; + const grpc_channel_filter* filters = &filter; + grpc_channel_stack* channel_stack; + grpc_call_stack* call_stack; + grpc_channel_element* channel_elem; + grpc_call_element* call_elem; grpc_arg arg; grpc_channel_args chan_args; - int *channel_data; - int *call_data; + int* channel_data; + int* call_data; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; - arg.key = "test_key"; + arg.key = const_cast<char*>("test_key"); arg.value.integer = 42; chan_args.num_args = 1; chan_args.args = &arg; - channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1)); + channel_stack = static_cast<grpc_channel_stack*>( + gpr_malloc(grpc_channel_stack_size(&filters, 1))); grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, 1, &chan_args, NULL, "test", channel_stack); GPR_ASSERT(channel_stack->count == 1); channel_elem = grpc_channel_stack_element(channel_stack, 0); - channel_data = (int *)channel_elem->channel_data; + channel_data = (int*)channel_elem->channel_data; GPR_ASSERT(*channel_data == 0); - call_stack = gpr_malloc(channel_stack->call_stack_size); + call_stack = + static_cast<grpc_call_stack*>(gpr_malloc(channel_stack->call_stack_size)); const grpc_call_element_args args = { - .call_stack = call_stack, - .server_transport_data = NULL, - .context = NULL, - .path = path, - .start_time = gpr_now(GPR_CLOCK_MONOTONIC), - .deadline = GRPC_MILLIS_INF_FUTURE, - .arena = NULL}; - grpc_error *error = grpc_call_stack_init(&exec_ctx, channel_stack, 1, + call_stack, /* call_stack */ + nullptr, /* server_transport_data */ + nullptr, /* context */ + path, /* path */ + gpr_now(GPR_CLOCK_MONOTONIC), /* start_time */ + GRPC_MILLIS_INF_FUTURE, /* deadline */ + nullptr, /* arena */ + nullptr /* call_combiner */ + }; + grpc_error* error = grpc_call_stack_init(&exec_ctx, channel_stack, 1, free_call, call_stack, &args); GPR_ASSERT(error == GRPC_ERROR_NONE); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); GPR_ASSERT(call_elem->filter == channel_elem->filter); GPR_ASSERT(call_elem->channel_data == channel_elem->channel_data); - call_data = (int *)call_elem->call_data; + call_data = (int*)call_elem->call_data; GPR_ASSERT(*call_data == 0); GPR_ASSERT(*channel_data == 1); @@ -148,7 +153,7 @@ static void test_create_channel_stack(void) { grpc_exec_ctx_finish(&exec_ctx); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); test_create_channel_stack(); diff --git a/test/core/channel/minimal_stack_is_minimal_test.c b/test/core/channel/minimal_stack_is_minimal_test.cc index b4528346f7..c54ff2e01b 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.c +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -42,8 +42,8 @@ #include "test/core/util/test_config.h" // use CHECK_STACK instead -static int check_stack(const char *file, int line, const char *transport_name, - grpc_channel_args *init_args, +static int check_stack(const char* file, int line, const char* transport_name, + grpc_channel_args* init_args, unsigned channel_stack_type, ...); // arguments: const char *transport_name - the name of the transport type to @@ -55,17 +55,17 @@ static int check_stack(const char *file, int line, const char *transport_name, // filters to instantiate, terminated with NULL #define CHECK_STACK(...) check_stack(__FILE__, __LINE__, __VA_ARGS__) -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); int errors = 0; // tests with a minimal stack - grpc_arg minimal_stack_arg = {.type = GRPC_ARG_INTEGER, - .key = GRPC_ARG_MINIMAL_STACK, - .value.integer = 1}; - grpc_channel_args minimal_stack_args = {.num_args = 1, - .args = &minimal_stack_arg}; + grpc_arg minimal_stack_arg; + minimal_stack_arg.type = GRPC_ARG_INTEGER; + minimal_stack_arg.key = const_cast<char*>(GRPC_ARG_MINIMAL_STACK); + minimal_stack_arg.value.integer = 1; + grpc_channel_args minimal_stack_args = {1, &minimal_stack_arg}; errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, "connected", NULL); errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, @@ -109,15 +109,17 @@ int main(int argc, char **argv) { * End of tests definitions, start of test infrastructure */ -static int check_stack(const char *file, int line, const char *transport_name, - grpc_channel_args *init_args, +static int check_stack(const char* file, int line, const char* transport_name, + grpc_channel_args* init_args, unsigned channel_stack_type, ...) { // create dummy channel stack - grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); - grpc_transport_vtable fake_transport_vtable = {.name = transport_name}; - grpc_transport fake_transport = {.vtable = &fake_transport_vtable}; + grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_transport_vtable fake_transport_vtable; + memset(&fake_transport_vtable, 0, sizeof(grpc_transport_vtable)); + fake_transport_vtable.name = transport_name; + grpc_transport fake_transport = {&fake_transport_vtable}; grpc_channel_stack_builder_set_target(builder, "foo.test.google.fr"); - grpc_channel_args *channel_args = grpc_channel_args_copy(init_args); + grpc_channel_args* channel_args = grpc_channel_args_copy(init_args); if (transport_name != NULL) { grpc_channel_stack_builder_set_transport(builder, &fake_transport); } @@ -136,26 +138,26 @@ static int check_stack(const char *file, int line, const char *transport_name, va_list args; va_start(args, channel_stack_type); for (;;) { - char *a = va_arg(args, char *); + char* a = va_arg(args, char*); if (a == NULL) break; if (v.count != 0) gpr_strvec_add(&v, gpr_strdup(", ")); gpr_strvec_add(&v, gpr_strdup(a)); } va_end(args); - char *expect = gpr_strvec_flatten(&v, NULL); + char* expect = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); // build up our "got" list gpr_strvec_init(&v); - grpc_channel_stack_builder_iterator *it = + grpc_channel_stack_builder_iterator* it = grpc_channel_stack_builder_create_iterator_at_first(builder); while (grpc_channel_stack_builder_move_next(it)) { - const char *name = grpc_channel_stack_builder_iterator_filter_name(it); + const char* name = grpc_channel_stack_builder_iterator_filter_name(it); if (name == NULL) continue; if (v.count != 0) gpr_strvec_add(&v, gpr_strdup(", ")); gpr_strvec_add(&v, gpr_strdup(name)); } - char *got = gpr_strvec_flatten(&v, NULL); + char* got = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); grpc_channel_stack_builder_iterator_destroy(it); @@ -170,7 +172,7 @@ static int check_stack(const char *file, int line, const char *transport_name, gpr_strvec_add(&v, gpr_strdup("=")); switch (channel_args->args[i].type) { case GRPC_ARG_INTEGER: { - char *tmp; + char* tmp; gpr_asprintf(&tmp, "%d", channel_args->args[i].value.integer); gpr_strvec_add(&v, tmp); break; @@ -179,7 +181,7 @@ static int check_stack(const char *file, int line, const char *transport_name, gpr_strvec_add(&v, gpr_strdup(channel_args->args[i].value.string)); break; case GRPC_ARG_POINTER: { - char *tmp; + char* tmp; gpr_asprintf(&tmp, "%p", channel_args->args[i].value.pointer.p); gpr_strvec_add(&v, tmp); break; @@ -187,15 +189,17 @@ static int check_stack(const char *file, int line, const char *transport_name, } } gpr_strvec_add(&v, gpr_strdup("}")); - char *args_str = gpr_strvec_flatten(&v, NULL); + char* args_str = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "**************************************************"); - gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, - "FAILED transport=%s; stack_type=%s; channel_args=%s:", - transport_name, grpc_channel_stack_type_string(channel_stack_type), - args_str); + gpr_log( + file, line, GPR_LOG_SEVERITY_ERROR, + "FAILED transport=%s; stack_type=%s; channel_args=%s:", transport_name, + grpc_channel_stack_type_string( + static_cast<grpc_channel_stack_type>(channel_stack_type)), + args_str); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "EXPECTED: %s", expect); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "GOT: %s", got); result = 1; |