gtestify test/core/http (#30200)

* Fix

* gtestify test/core/http

* Fix

* fix
pull/30295/head
Esun Kim 2 years ago committed by GitHub
parent 7b8e3d89c4
commit 34b380697d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 144
      CMakeLists.txt
  2. 56
      build_autogenerated.yaml
  3. 2
      test/core/http/BUILD
  4. 100
      test/core/http/format_request_test.cc
  5. 76
      test/core/http/parser_test.cc
  6. 96
      tools/run_tests/generated/tests.json

144
CMakeLists.txt generated

@ -806,7 +806,6 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c fling_test) add_dependencies(buildtests_c fling_test)
endif() endif()
add_dependencies(buildtests_c format_request_test)
add_dependencies(buildtests_c goaway_server_test) add_dependencies(buildtests_c goaway_server_test)
add_dependencies(buildtests_c grpc_ipv6_loopback_available_test) add_dependencies(buildtests_c grpc_ipv6_loopback_available_test)
add_dependencies(buildtests_c inproc_callback_test) add_dependencies(buildtests_c inproc_callback_test)
@ -815,7 +814,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c minimal_stack_is_minimal_test) add_dependencies(buildtests_c minimal_stack_is_minimal_test)
add_dependencies(buildtests_c multiple_server_queues_test) add_dependencies(buildtests_c multiple_server_queues_test)
add_dependencies(buildtests_c no_server_test) add_dependencies(buildtests_c no_server_test)
add_dependencies(buildtests_c parser_test)
add_dependencies(buildtests_c percent_encoding_test) add_dependencies(buildtests_c percent_encoding_test)
add_dependencies(buildtests_c public_headers_must_be_c89) add_dependencies(buildtests_c public_headers_must_be_c89)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -974,6 +972,7 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx fork_test) add_dependencies(buildtests_cxx fork_test)
endif() endif()
add_dependencies(buildtests_cxx format_request_test)
add_dependencies(buildtests_cxx frame_handler_test) add_dependencies(buildtests_cxx frame_handler_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx fuzzing_event_engine_test) add_dependencies(buildtests_cxx fuzzing_event_engine_test)
@ -1077,6 +1076,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx parse_address_with_named_scope_id_test) add_dependencies(buildtests_cxx parse_address_with_named_scope_id_test)
endif() endif()
add_dependencies(buildtests_cxx parsed_metadata_test) add_dependencies(buildtests_cxx parsed_metadata_test)
add_dependencies(buildtests_cxx parser_test)
add_dependencies(buildtests_cxx periodic_update_test) add_dependencies(buildtests_cxx periodic_update_test)
add_dependencies(buildtests_cxx pid_controller_test) add_dependencies(buildtests_cxx pid_controller_test)
add_dependencies(buildtests_cxx pipe_test) add_dependencies(buildtests_cxx pipe_test)
@ -4691,37 +4691,6 @@ endif()
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)
add_executable(format_request_test
test/core/end2end/data/client_certs.cc
test/core/end2end/data/server1_cert.cc
test/core/end2end/data/server1_key.cc
test/core/end2end/data/test_root_cert.cc
test/core/http/format_request_test.cc
)
target_include_directories(format_request_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(format_request_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(goaway_server_test add_executable(goaway_server_test
test/core/end2end/cq_verifier.cc test/core/end2end/cq_verifier.cc
test/core/end2end/goaway_server_test.cc test/core/end2end/goaway_server_test.cc
@ -4939,37 +4908,6 @@ target_link_libraries(no_server_test
) )
endif()
if(gRPC_BUILD_TESTS)
add_executable(parser_test
test/core/end2end/data/client_certs.cc
test/core/end2end/data/server1_cert.cc
test/core/end2end/data/server1_key.cc
test/core/end2end/data/test_root_cert.cc
test/core/http/parser_test.cc
)
target_include_directories(parser_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(parser_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)
@ -9975,6 +9913,45 @@ endif()
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)
add_executable(format_request_test
test/core/end2end/data/client_certs.cc
test/core/end2end/data/server1_cert.cc
test/core/end2end/data/server1_key.cc
test/core/end2end/data/test_root_cert.cc
test/core/http/format_request_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(format_request_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(format_request_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(frame_handler_test add_executable(frame_handler_test
test/core/tsi/alts/crypt/gsec_test_util.cc test/core/tsi/alts/crypt/gsec_test_util.cc
test/core/tsi/alts/frame_protector/frame_handler_test.cc test/core/tsi/alts/frame_protector/frame_handler_test.cc
@ -13608,6 +13585,45 @@ target_link_libraries(parsed_metadata_test
) )
endif()
if(gRPC_BUILD_TESTS)
add_executable(parser_test
test/core/end2end/data/client_certs.cc
test/core/end2end/data/server1_cert.cc
test/core/end2end/data/server1_key.cc
test/core/end2end/data/test_root_cert.cc
test/core/http/parser_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(parser_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(parser_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)

@ -3360,19 +3360,6 @@ targets:
- linux - linux
- posix - posix
- mac - mac
- name: format_request_test
build: test
language: c
headers:
- test/core/end2end/data/ssl_test_data.h
src:
- test/core/end2end/data/client_certs.cc
- test/core/end2end/data/server1_cert.cc
- test/core/end2end/data/server1_key.cc
- test/core/end2end/data/test_root_cert.cc
- test/core/http/format_request_test.cc
deps:
- grpc_test_util
- name: goaway_server_test - name: goaway_server_test
build: test build: test
language: c language: c
@ -3448,20 +3435,6 @@ targets:
- test/core/end2end/no_server_test.cc - test/core/end2end/no_server_test.cc
deps: deps:
- grpc_test_util - grpc_test_util
- name: parser_test
build: test
language: c
headers:
- test/core/end2end/data/ssl_test_data.h
src:
- test/core/end2end/data/client_certs.cc
- test/core/end2end/data/server1_cert.cc
- test/core/end2end/data/server1_key.cc
- test/core/end2end/data/test_root_cert.cc
- test/core/http/parser_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: percent_encoding_test - name: percent_encoding_test
build: test build: test
language: c language: c
@ -5651,6 +5624,20 @@ targets:
- posix - posix
- mac - mac
uses_polling: false uses_polling: false
- name: format_request_test
gtest: true
build: test
language: c++
headers:
- test/core/end2end/data/ssl_test_data.h
src:
- test/core/end2end/data/client_certs.cc
- test/core/end2end/data/server1_cert.cc
- test/core/end2end/data/server1_key.cc
- test/core/end2end/data/test_root_cert.cc
- test/core/http/format_request_test.cc
deps:
- grpc_test_util
- name: frame_handler_test - name: frame_handler_test
gtest: true gtest: true
build: test build: test
@ -7073,6 +7060,21 @@ targets:
- test/core/transport/parsed_metadata_test.cc - test/core/transport/parsed_metadata_test.cc
deps: deps:
- grpc_test_util - grpc_test_util
- name: parser_test
gtest: true
build: test
language: c++
headers:
- test/core/end2end/data/ssl_test_data.h
src:
- test/core/end2end/data/client_certs.cc
- test/core/end2end/data/server1_cert.cc
- test/core/end2end/data/server1_key.cc
- test/core/end2end/data/test_root_cert.cc
- test/core/http/parser_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: periodic_update_test - name: periodic_update_test
gtest: true gtest: true
build: test build: test

@ -123,6 +123,7 @@ grpc_cc_test(
grpc_cc_test( grpc_cc_test(
name = "parser_test", name = "parser_test",
srcs = ["parser_test.cc"], srcs = ["parser_test.cc"],
external_deps = ["gtest"],
language = "C++", language = "C++",
uses_event_engine = False, uses_event_engine = False,
uses_polling = False, uses_polling = False,
@ -137,6 +138,7 @@ grpc_cc_test(
grpc_cc_test( grpc_cc_test(
name = "format_request_test", name = "format_request_test",
srcs = ["format_request_test.cc"], srcs = ["format_request_test.cc"],
external_deps = ["gtest"],
language = "C++", language = "C++",
deps = [ deps = [
"//:gpr", "//:gpr",

@ -20,13 +20,15 @@
#include <string.h> #include <string.h>
#include <gtest/gtest.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/http/httpcli.h" #include "src/core/lib/http/httpcli.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
static void test_format_get_request(void) { TEST(FormatRequestTest, FormatGetRequest) {
grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")}; grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_http_request req; grpc_http_request req;
grpc_slice slice; grpc_slice slice;
@ -38,19 +40,19 @@ static void test_format_get_request(void) {
slice = grpc_httpcli_format_get_request(&req, host, "/index.html"); slice = grpc_httpcli_format_get_request(&req, host, "/index.html");
GPR_ASSERT(0 == grpc_slice_str_cmp(slice, ASSERT_EQ(grpc_core::StringViewFromSlice(slice),
"GET /index.html HTTP/1.1\r\n" "GET /index.html HTTP/1.1\r\n"
"Host: example.com\r\n" "Host: example.com\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"User-Agent: " GRPC_HTTPCLI_USER_AGENT "User-Agent: " GRPC_HTTPCLI_USER_AGENT
"\r\n" "\r\n"
"x-yz: abc\r\n" "x-yz: abc\r\n"
"\r\n")); "\r\n");
grpc_slice_unref(slice); grpc_slice_unref(slice);
} }
static void test_format_post_request(void) { TEST(FormatRequestTest, FormatPostRequest) {
grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")}; grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_http_request req; grpc_http_request req;
grpc_slice slice; grpc_slice slice;
@ -64,22 +66,22 @@ static void test_format_post_request(void) {
slice = grpc_httpcli_format_post_request(&req, host, "/index.html"); slice = grpc_httpcli_format_post_request(&req, host, "/index.html");
GPR_ASSERT(0 == grpc_slice_str_cmp(slice, ASSERT_EQ(grpc_core::StringViewFromSlice(slice),
"POST /index.html HTTP/1.1\r\n" "POST /index.html HTTP/1.1\r\n"
"Host: example.com\r\n" "Host: example.com\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"User-Agent: " GRPC_HTTPCLI_USER_AGENT "User-Agent: " GRPC_HTTPCLI_USER_AGENT
"\r\n" "\r\n"
"x-yz: abc\r\n" "x-yz: abc\r\n"
"Content-Type: text/plain\r\n" "Content-Type: text/plain\r\n"
"Content-Length: 9\r\n" "Content-Length: 9\r\n"
"\r\n" "\r\n"
"fake body")); "fake body");
grpc_slice_unref(slice); grpc_slice_unref(slice);
} }
static void test_format_post_request_no_body(void) { TEST(FormatRequestTest, FormatPostRequestNoBody) {
grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")}; grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_http_request req; grpc_http_request req;
grpc_slice slice; grpc_slice slice;
@ -91,19 +93,19 @@ static void test_format_post_request_no_body(void) {
slice = grpc_httpcli_format_post_request(&req, host, "/index.html"); slice = grpc_httpcli_format_post_request(&req, host, "/index.html");
GPR_ASSERT(0 == grpc_slice_str_cmp(slice, ASSERT_EQ(grpc_core::StringViewFromSlice(slice),
"POST /index.html HTTP/1.1\r\n" "POST /index.html HTTP/1.1\r\n"
"Host: example.com\r\n" "Host: example.com\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"User-Agent: " GRPC_HTTPCLI_USER_AGENT "User-Agent: " GRPC_HTTPCLI_USER_AGENT
"\r\n" "\r\n"
"x-yz: abc\r\n" "x-yz: abc\r\n"
"\r\n")); "\r\n");
grpc_slice_unref(slice); grpc_slice_unref(slice);
} }
static void test_format_post_request_content_type_override(void) { TEST(FormatRequestTest, FormatPostRequestContentTypeOverride) {
grpc_http_header hdrs[2]; grpc_http_header hdrs[2];
grpc_http_request req; grpc_http_request req;
grpc_slice slice; grpc_slice slice;
@ -121,30 +123,26 @@ static void test_format_post_request_content_type_override(void) {
slice = grpc_httpcli_format_post_request(&req, host, "/index.html"); slice = grpc_httpcli_format_post_request(&req, host, "/index.html");
GPR_ASSERT(0 == grpc_slice_str_cmp( ASSERT_EQ(grpc_core::StringViewFromSlice(slice),
slice, "POST /index.html HTTP/1.1\r\n"
"POST /index.html HTTP/1.1\r\n" "Host: example.com\r\n"
"Host: example.com\r\n" "Connection: close\r\n"
"Connection: close\r\n" "User-Agent: " GRPC_HTTPCLI_USER_AGENT
"User-Agent: " GRPC_HTTPCLI_USER_AGENT "\r\n" "\r\n"
"x-yz: abc\r\n" "x-yz: abc\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n" "Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: 11\r\n" "Content-Length: 11\r\n"
"\r\n" "\r\n"
"fake%20body")); "fake%20body");
grpc_slice_unref(slice); grpc_slice_unref(slice);
} }
// scope
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::TestEnvironment env(&argc, argv);
grpc_init(); ::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestGrpcScope grpc_scope;
test_format_get_request(); return RUN_ALL_TESTS();
test_format_post_request();
test_format_post_request_no_body();
test_format_post_request_content_type_override();
grpc_shutdown();
return 0;
} }

@ -23,6 +23,8 @@
#include <string> #include <string>
#include <gtest/gtest.h>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include <grpc/grpc.h> #include <grpc/grpc.h>
@ -54,22 +56,22 @@ static void test_request_succeeds(grpc_slice_split_mode split_mode,
grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request); grpc_http_parser_init(&parser, GRPC_HTTP_REQUEST, &request);
for (i = 0; i < num_slices; i++) { for (i = 0; i < num_slices; i++) {
GPR_ASSERT(grpc_http_parser_parse(&parser, slices[i], nullptr) == ASSERT_EQ(grpc_http_parser_parse(&parser, slices[i], nullptr),
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
grpc_slice_unref(slices[i]); grpc_slice_unref(slices[i]);
} }
GPR_ASSERT(grpc_http_parser_eof(&parser) == GRPC_ERROR_NONE); ASSERT_EQ(grpc_http_parser_eof(&parser), GRPC_ERROR_NONE);
GPR_ASSERT(GRPC_HTTP_REQUEST == parser.type); ASSERT_EQ(GRPC_HTTP_REQUEST, parser.type);
GPR_ASSERT(0 == strcmp(expect_method, request.method)); ASSERT_STREQ(expect_method, request.method);
GPR_ASSERT(0 == strcmp(expect_path, request.path)); ASSERT_STREQ(expect_path, request.path);
GPR_ASSERT(expect_version == request.version); ASSERT_EQ(expect_version, request.version);
if (expect_body != nullptr) { if (expect_body != nullptr) {
GPR_ASSERT(strlen(expect_body) == request.body_length); ASSERT_EQ(strlen(expect_body), request.body_length);
GPR_ASSERT(0 == memcmp(expect_body, request.body, request.body_length)); ASSERT_EQ(0, memcmp(expect_body, request.body, request.body_length));
} else { } else {
GPR_ASSERT(request.body_length == 0); ASSERT_EQ(request.body_length, 0);
} }
va_start(args, expect_body); va_start(args, expect_body);
@ -79,15 +81,15 @@ static void test_request_succeeds(grpc_slice_split_mode split_mode,
char* expect_value; char* expect_value;
expect_key = va_arg(args, char*); expect_key = va_arg(args, char*);
if (!expect_key) break; if (!expect_key) break;
GPR_ASSERT(i < request.hdr_count); ASSERT_LT(i, request.hdr_count);
expect_value = va_arg(args, char*); expect_value = va_arg(args, char*);
GPR_ASSERT(expect_value); ASSERT_TRUE(expect_value);
GPR_ASSERT(0 == strcmp(expect_key, request.hdrs[i].key)); ASSERT_STREQ(expect_key, request.hdrs[i].key);
GPR_ASSERT(0 == strcmp(expect_value, request.hdrs[i].value)); ASSERT_STREQ(expect_value, request.hdrs[i].value);
i++; i++;
} }
va_end(args); va_end(args);
GPR_ASSERT(i == request.hdr_count); ASSERT_EQ(i, request.hdr_count);
grpc_http_request_destroy(&request); grpc_http_request_destroy(&request);
grpc_http_parser_destroy(&parser); grpc_http_parser_destroy(&parser);
@ -112,19 +114,19 @@ static void test_succeeds(grpc_slice_split_mode split_mode,
grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response); grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response);
for (i = 0; i < num_slices; i++) { for (i = 0; i < num_slices; i++) {
GPR_ASSERT(grpc_http_parser_parse(&parser, slices[i], nullptr) == ASSERT_EQ(grpc_http_parser_parse(&parser, slices[i], nullptr),
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
grpc_slice_unref(slices[i]); grpc_slice_unref(slices[i]);
} }
GPR_ASSERT(grpc_http_parser_eof(&parser) == GRPC_ERROR_NONE); ASSERT_EQ(grpc_http_parser_eof(&parser), GRPC_ERROR_NONE);
GPR_ASSERT(GRPC_HTTP_RESPONSE == parser.type); ASSERT_EQ(GRPC_HTTP_RESPONSE, parser.type);
GPR_ASSERT(expect_status == response.status); ASSERT_EQ(expect_status, response.status);
if (expect_body != nullptr) { if (expect_body != nullptr) {
GPR_ASSERT(strlen(expect_body) == response.body_length); ASSERT_EQ(strlen(expect_body), response.body_length);
GPR_ASSERT(0 == memcmp(expect_body, response.body, response.body_length)); ASSERT_EQ(0, memcmp(expect_body, response.body, response.body_length));
} else { } else {
GPR_ASSERT(response.body_length == 0); ASSERT_EQ(response.body_length, 0);
} }
va_start(args, expect_body); va_start(args, expect_body);
@ -134,15 +136,15 @@ static void test_succeeds(grpc_slice_split_mode split_mode,
char* expect_value; char* expect_value;
expect_key = va_arg(args, char*); expect_key = va_arg(args, char*);
if (!expect_key) break; if (!expect_key) break;
GPR_ASSERT(i < response.hdr_count); ASSERT_LT(i, response.hdr_count);
expect_value = va_arg(args, char*); expect_value = va_arg(args, char*);
GPR_ASSERT(expect_value); ASSERT_TRUE(expect_value);
GPR_ASSERT(0 == strcmp(expect_key, response.hdrs[i].key)); ASSERT_STREQ(expect_key, response.hdrs[i].key);
GPR_ASSERT(0 == strcmp(expect_value, response.hdrs[i].value)); ASSERT_STREQ(expect_value, response.hdrs[i].value);
i++; i++;
} }
va_end(args); va_end(args);
GPR_ASSERT(i == response.hdr_count); ASSERT_EQ(i, response.hdr_count);
grpc_http_response_destroy(&response); grpc_http_response_destroy(&response);
grpc_http_parser_destroy(&parser); grpc_http_parser_destroy(&parser);
@ -174,7 +176,7 @@ static void test_fails(grpc_slice_split_mode split_mode,
if (GRPC_ERROR_NONE == error) { if (GRPC_ERROR_NONE == error) {
error = grpc_http_parser_eof(&parser); error = grpc_http_parser_eof(&parser);
} }
GPR_ASSERT(!GRPC_ERROR_IS_NONE(error)); ASSERT_FALSE(GRPC_ERROR_IS_NONE(error));
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
grpc_http_response_destroy(&response); grpc_http_response_destroy(&response);
@ -207,7 +209,7 @@ static void test_request_fails(grpc_slice_split_mode split_mode,
if (GRPC_ERROR_IS_NONE(error)) { if (GRPC_ERROR_IS_NONE(error)) {
error = grpc_http_parser_eof(&parser); error = grpc_http_parser_eof(&parser);
} }
GPR_ASSERT(!GRPC_ERROR_IS_NONE(error)); ASSERT_FALSE(GRPC_ERROR_IS_NONE(error));
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
grpc_http_request_destroy(&request); grpc_http_request_destroy(&request);
@ -215,14 +217,10 @@ static void test_request_fails(grpc_slice_split_mode split_mode,
gpr_free(slices); gpr_free(slices);
} }
int main(int argc, char** argv) { TEST(ParserTest, MainTest) {
size_t i; size_t i;
const grpc_slice_split_mode split_modes[] = {GRPC_SLICE_SPLIT_IDENTITY, const grpc_slice_split_mode split_modes[] = {GRPC_SLICE_SPLIT_IDENTITY,
GRPC_SLICE_SPLIT_ONE_BYTE}; GRPC_SLICE_SPLIT_ONE_BYTE};
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) {
test_succeeds(split_modes[i], test_succeeds(split_modes[i],
"HTTP/1.0 200 OK\r\n" "HTTP/1.0 200 OK\r\n"
@ -332,7 +330,11 @@ int main(int argc, char** argv) {
gpr_free(tmp1); gpr_free(tmp1);
test_fails(split_modes[i], tmp2.c_str()); test_fails(split_modes[i], tmp2.c_str());
} }
}
grpc_shutdown(); int main(int argc, char** argv) {
return 0; grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestGrpcScope grpc_scope;
return RUN_ALL_TESTS();
} }

@ -321,30 +321,6 @@
], ],
"uses_polling": true "uses_polling": true
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "format_request_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,
@ -537,30 +513,6 @@
], ],
"uses_polling": true "uses_polling": true
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "parser_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,
@ -3315,6 +3267,30 @@
], ],
"uses_polling": false "uses_polling": false
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "format_request_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,
@ -5113,6 +5089,30 @@
], ],
"uses_polling": true "uses_polling": true
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "parser_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,

Loading…
Cancel
Save