static void test_vector(grpc_chttp2_hpack_parser *parser, grpc_slice_split_mode mode, const char *hexstring, ... /* char *key, char *value */) { gpr_slice input = parse_hexstring(hexstring); gpr_slice *slices; size_t nslices; size_t i; test_checker chk; va_start(chk.args, hexstring); parser->on_header = onhdr; parser->on_header_user_data = &chk; grpc_split_slices(mode, &input, 1, &slices, &nslices); gpr_slice_unref(input); for (i = 0; i < nslices; i++) { GPR_ASSERT(grpc_chttp2_hpack_parser_parse( parser, GPR_SLICE_START_PTR(slices[i]), GPR_SLICE_END_PTR(slices[i]))); } for (i = 0; i < nslices; i++) { gpr_slice_unref(slices[i]); } gpr_free(slices); GPR_ASSERT(NULL == va_arg(chk.args, char *)); va_end(chk.args); }
static void test_vector(grpc_chttp2_hpack_parser *parser, grpc_slice_split_mode mode, const char *hexstring, ... /* char *key, char *value */) { grpc_slice input = parse_hexstring(hexstring); grpc_slice *slices; size_t nslices; size_t i; test_checker chk; va_start(chk.args, hexstring); parser->on_header = onhdr; parser->on_header_user_data = &chk; grpc_split_slices(mode, &input, 1, &slices, &nslices); grpc_slice_unref(input); for (i = 0; i < nslices; i++) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == GRPC_ERROR_NONE); grpc_exec_ctx_finish(&exec_ctx); } for (i = 0; i < nslices; i++) { grpc_slice_unref(slices[i]); } gpr_free(slices); GPR_ASSERT(NULL == va_arg(chk.args, char *)); va_end(chk.args); }
static void test_decode_random_headers_inner(int max_len) { int i; test_decode_random_header_state st; gpr_slice_buffer output; gpr_slice merged; grpc_stream_op_buffer encops; grpc_chttp2_hpack_parser parser; grpc_chttp2_hpack_parser_init(&parser, g_mdctx); grpc_sopb_init(&encops); gpr_log(GPR_INFO, "max_len = %d", max_len); for (i = 0; i < 10000; i++) { randstr(st.key, max_len); randstr(st.value, max_len); add_sopb_headers(1, st.key, st.value); gpr_slice_buffer_init(&output); GPR_ASSERT(0 == grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, 0, &encops)); grpc_chttp2_encode(encops.ops, encops.nops, 0, 0xdeadbeef, &g_compressor, &output); encops.nops = 0; merged = grpc_slice_merge(output.slices, output.count); gpr_slice_buffer_destroy(&output); st.got_hdr = 0; parser.on_header = chk_hdr; parser.on_header_user_data = &st; grpc_chttp2_hpack_parser_parse(&parser, GPR_SLICE_START_PTR(merged) + 9, GPR_SLICE_END_PTR(merged)); GPR_ASSERT(st.got_hdr); gpr_slice_unref(merged); } grpc_chttp2_hpack_parser_destroy(&parser); grpc_sopb_destroy(&encops); }