aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/http
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-07 17:02:23 -0800
committerGravatar GitHub <noreply@github.com>2017-11-07 17:02:23 -0800
commitd9da7387b8057f3bd99a417a5ee905377bce9296 (patch)
treedf5e16acf65e083ce2b56a9543eba918ef35b451 /test/core/http
parentc03867ff224a98dab5a93b3ba70b95c46f05a440 (diff)
parent67c0effd324b3fa86c13dabe5a63f66d48672e30 (diff)
Merge pull request #13147 from yashykt/testc++ize
Convert test/core to C++
Diffstat (limited to 'test/core/http')
-rw-r--r--test/core/http/BUILD20
-rw-r--r--test/core/http/format_request_test.cc (renamed from test/core/http/format_request_test.c)30
-rw-r--r--test/core/http/httpcli_test.cc (renamed from test/core/http/httpcli_test.c)16
-rw-r--r--test/core/http/httpscli_test.cc (renamed from test/core/http/httpscli_test.c)22
-rw-r--r--test/core/http/parser_test.cc (renamed from test/core/http/parser_test.c)19
-rw-r--r--test/core/http/request_fuzzer.cc (renamed from test/core/http/request_fuzzer.c)2
-rw-r--r--test/core/http/response_fuzzer.cc (renamed from test/core/http/response_fuzzer.c)2
7 files changed, 60 insertions, 51 deletions
diff --git a/test/core/http/BUILD b/test/core/http/BUILD
index fffdac5e08..a5ae6272db 100644
--- a/test/core/http/BUILD
+++ b/test/core/http/BUILD
@@ -22,8 +22,8 @@ load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
name = "response_fuzzer",
- srcs = ["response_fuzzer.c"],
- language = "C",
+ srcs = ["response_fuzzer.cc"],
+ language = "C++",
corpus = "response_corpus",
deps = [
"//:gpr",
@@ -34,8 +34,8 @@ grpc_fuzzer(
grpc_fuzzer(
name = "request_fuzzer",
- srcs = ["request_fuzzer.c"],
- language = "C",
+ srcs = ["request_fuzzer.cc"],
+ language = "C++",
corpus = "request_corpus",
deps = [
"//:gpr",
@@ -64,8 +64,8 @@ load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_cc_test(
name = "httpcli_test",
- srcs = ["httpcli_test.c"],
- language = "C",
+ srcs = ["httpcli_test.cc"],
+ language = "C++",
data = ["test_server.py"],
deps = [
"//:gpr",
@@ -78,8 +78,8 @@ grpc_cc_test(
grpc_cc_test(
name = "httpscli_test",
- srcs = ["httpscli_test.c"],
- language = "C",
+ srcs = ["httpscli_test.cc"],
+ language = "C++",
data = ["test_server.py"],
deps = [
"//:gpr",
@@ -92,8 +92,8 @@ grpc_cc_test(
grpc_cc_test(
name = "parser_test",
- srcs = ["parser_test.c"],
- language = "C",
+ srcs = ["parser_test.cc"],
+ language = "C++",
deps = [
"//:gpr",
"//:grpc",
diff --git a/test/core/http/format_request_test.c b/test/core/http/format_request_test.cc
index a1476e1b39..253e59135d 100644
--- a/test/core/http/format_request_test.c
+++ b/test/core/http/format_request_test.cc
@@ -24,13 +24,13 @@
#include "test/core/util/test_config.h"
static void test_format_get_request(void) {
- grpc_http_header hdr = {"x-yz", "abc"};
+ grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_httpcli_request req;
grpc_slice slice;
memset(&req, 0, sizeof(req));
- req.host = "example.com";
- req.http.path = "/index.html";
+ req.host = const_cast<char*>("example.com");
+ req.http.path = const_cast<char*>("/index.html");
req.http.hdr_count = 1;
req.http.hdrs = &hdr;
@@ -49,15 +49,15 @@ static void test_format_get_request(void) {
}
static void test_format_post_request(void) {
- grpc_http_header hdr = {"x-yz", "abc"};
+ grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_httpcli_request req;
grpc_slice slice;
char body_bytes[] = "fake body";
size_t body_len = 9;
memset(&req, 0, sizeof(req));
- req.host = "example.com";
- req.http.path = "/index.html";
+ req.host = const_cast<char*>("example.com");
+ req.http.path = const_cast<char*>("/index.html");
req.http.hdr_count = 1;
req.http.hdrs = &hdr;
@@ -79,13 +79,13 @@ static void test_format_post_request(void) {
}
static void test_format_post_request_no_body(void) {
- grpc_http_header hdr = {"x-yz", "abc"};
+ grpc_http_header hdr = {const_cast<char*>("x-yz"), const_cast<char*>("abc")};
grpc_httpcli_request req;
grpc_slice slice;
memset(&req, 0, sizeof(req));
- req.host = "example.com";
- req.http.path = "/index.html";
+ req.host = const_cast<char*>("example.com");
+ req.http.path = const_cast<char*>("/index.html");
req.http.hdr_count = 1;
req.http.hdrs = &hdr;
@@ -110,13 +110,13 @@ static void test_format_post_request_content_type_override(void) {
char body_bytes[] = "fake%20body";
size_t body_len = 11;
- hdrs[0].key = "x-yz";
- hdrs[0].value = "abc";
- hdrs[1].key = "Content-Type";
- hdrs[1].value = "application/x-www-form-urlencoded";
+ hdrs[0].key = const_cast<char*>("x-yz");
+ hdrs[0].value = const_cast<char*>("abc");
+ hdrs[1].key = const_cast<char*>("Content-Type");
+ hdrs[1].value = const_cast<char*>("application/x-www-form-urlencoded");
memset(&req, 0, sizeof(req));
- req.host = "example.com";
- req.http.path = "/index.html";
+ req.host = const_cast<char*>("example.com");
+ req.http.path = const_cast<char*>("/index.html");
req.http.hdr_count = 2;
req.http.hdrs = hdrs;
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.cc
index 8c22b644e7..ac3c6a2ce5 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.cc
@@ -44,7 +44,7 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
const char* expect =
"<html><head><title>Hello world!</title></head>"
"<body><p>This is a test</p></body></html>";
- grpc_http_response* response = arg;
+ grpc_http_response* response = static_cast<grpc_http_response*>(arg);
GPR_ASSERT(response);
GPR_ASSERT(response->status == 200);
GPR_ASSERT(response->body_length == strlen(expect));
@@ -70,7 +70,7 @@ static void test_get(int port) {
memset(&req, 0, sizeof(req));
req.host = host;
- req.http.path = "/get";
+ req.http.path = const_cast<char*>("/get");
req.handshaker = &grpc_httpcli_plaintext;
grpc_http_response response;
@@ -110,7 +110,7 @@ static void test_post(int port) {
memset(&req, 0, sizeof(req));
req.host = host;
- req.http.path = "/post";
+ req.http.path = const_cast<char*>("/post");
req.handshaker = &grpc_httpcli_plaintext;
grpc_http_response response;
@@ -139,7 +139,8 @@ static void test_post(int port) {
}
static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) {
- grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset(p));
+ grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset(
+ static_cast<grpc_polling_entity*>(p)));
}
int main(int argc, char** argv) {
@@ -154,7 +155,7 @@ int main(int argc, char** argv) {
/* figure out where we are */
char* root;
if (lslash) {
- root = gpr_malloc((size_t)(lslash - me + 1));
+ root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1)));
memcpy(root, me, (size_t)(lslash - me));
root[lslash - me] = 0;
} else {
@@ -171,7 +172,7 @@ int main(int argc, char** argv) {
}
/* start the server */
- args[1 + arg_shift] = "--port";
+ args[1 + arg_shift] = const_cast<char*>("--port");
gpr_asprintf(&args[2 + arg_shift], "%d", port);
server = gpr_subprocess_create(3 + arg_shift, (const char**)args);
GPR_ASSERT(server);
@@ -186,7 +187,8 @@ int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
grpc_httpcli_context_init(&g_context);
- grpc_pollset* pollset = gpr_zalloc(grpc_pollset_size());
+ grpc_pollset* pollset =
+ static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &g_mu);
g_pops = grpc_polling_entity_create_from_pollset(pollset);
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.cc
index b375d46b9f..bf851b1175 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.cc
@@ -44,7 +44,7 @@ static void on_finish(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
const char* expect =
"<html><head><title>Hello world!</title></head>"
"<body><p>This is a test</p></body></html>";
- grpc_http_response* response = arg;
+ grpc_http_response* response = static_cast<grpc_http_response*>(arg);
GPR_ASSERT(response);
GPR_ASSERT(response->status == 200);
GPR_ASSERT(response->body_length == strlen(expect));
@@ -70,8 +70,8 @@ static void test_get(int port) {
memset(&req, 0, sizeof(req));
req.host = host;
- req.ssl_host_override = "foo.test.google.fr";
- req.http.path = "/get";
+ req.ssl_host_override = const_cast<char*>("foo.test.google.fr");
+ req.http.path = const_cast<char*>("/get");
req.handshaker = &grpc_httpcli_ssl;
grpc_http_response response;
@@ -111,8 +111,8 @@ static void test_post(int port) {
memset(&req, 0, sizeof(req));
req.host = host;
- req.ssl_host_override = "foo.test.google.fr";
- req.http.path = "/post";
+ req.ssl_host_override = const_cast<char*>("foo.test.google.fr");
+ req.http.path = const_cast<char*>("/post");
req.handshaker = &grpc_httpcli_ssl;
grpc_http_response response;
@@ -141,7 +141,8 @@ static void test_post(int port) {
}
static void destroy_pops(grpc_exec_ctx* exec_ctx, void* p, grpc_error* error) {
- grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset(p));
+ grpc_pollset_destroy(exec_ctx, grpc_polling_entity_pollset(
+ static_cast<grpc_polling_entity*>(p)));
}
int main(int argc, char** argv) {
@@ -156,7 +157,7 @@ int main(int argc, char** argv) {
/* figure out where we are */
char* root;
if (lslash) {
- root = gpr_malloc((size_t)(lslash - me + 1));
+ root = static_cast<char*>(gpr_malloc((size_t)(lslash - me + 1)));
memcpy(root, me, (size_t)(lslash - me));
root[lslash - me] = 0;
} else {
@@ -173,9 +174,9 @@ int main(int argc, char** argv) {
}
/* start the server */
- args[1 + arg_shift] = "--port";
+ args[1 + arg_shift] = const_cast<char*>("--port");
gpr_asprintf(&args[2 + arg_shift], "%d", port);
- args[3 + arg_shift] = "--ssl";
+ args[3 + arg_shift] = const_cast<char*>("--ssl");
server = gpr_subprocess_create(4 + arg_shift, (const char**)args);
GPR_ASSERT(server);
gpr_free(args[0]);
@@ -189,7 +190,8 @@ int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
grpc_httpcli_context_init(&g_context);
- grpc_pollset* pollset = gpr_zalloc(grpc_pollset_size());
+ grpc_pollset* pollset =
+ static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &g_mu);
g_pops = grpc_polling_entity_create_from_pollset(pollset);
diff --git a/test/core/http/parser_test.c b/test/core/http/parser_test.cc
index 9a8528ddc8..d0d2559cdf 100644
--- a/test/core/http/parser_test.c
+++ b/test/core/http/parser_test.cc
@@ -29,9 +29,11 @@
#include "test/core/util/test_config.h"
static void test_request_succeeds(grpc_slice_split_mode split_mode,
- char* request_text, char* expect_method,
+ const char* request_text,
+ const char* expect_method,
grpc_http_version expect_version,
- char* expect_path, char* expect_body, ...) {
+ const char* expect_path,
+ const char* expect_body, ...) {
grpc_http_parser parser;
grpc_slice input_slice = grpc_slice_from_copied_string(request_text);
size_t num_slices;
@@ -87,8 +89,9 @@ static void test_request_succeeds(grpc_slice_split_mode split_mode,
gpr_free(slices);
}
-static void test_succeeds(grpc_slice_split_mode split_mode, char* response_text,
- int expect_status, char* expect_body, ...) {
+static void test_succeeds(grpc_slice_split_mode split_mode,
+ const char* response_text, int expect_status,
+ const char* expect_body, ...) {
grpc_http_parser parser;
grpc_slice input_slice = grpc_slice_from_copied_string(response_text);
size_t num_slices;
@@ -141,7 +144,8 @@ static void test_succeeds(grpc_slice_split_mode split_mode, char* response_text,
gpr_free(slices);
}
-static void test_fails(grpc_slice_split_mode split_mode, char* response_text) {
+static void test_fails(grpc_slice_split_mode split_mode,
+ const char* response_text) {
grpc_http_parser parser;
grpc_slice input_slice = grpc_slice_from_copied_string(response_text);
size_t num_slices;
@@ -174,7 +178,7 @@ static void test_fails(grpc_slice_split_mode split_mode, char* response_text) {
}
static void test_request_fails(grpc_slice_split_mode split_mode,
- char* request_text) {
+ const char* request_text) {
grpc_http_parser parser;
grpc_slice input_slice = grpc_slice_from_copied_string(request_text);
size_t num_slices;
@@ -286,7 +290,8 @@ int main(int argc, char** argv) {
test_request_fails(split_modes[i], "GET / HTTP/1.2\r\n");
test_request_fails(split_modes[i], "GET / HTTP/1.0\n");
- tmp1 = gpr_malloc(2 * GRPC_HTTP_PARSER_MAX_HEADER_LENGTH);
+ tmp1 =
+ static_cast<char*>(gpr_malloc(2 * GRPC_HTTP_PARSER_MAX_HEADER_LENGTH));
memset(tmp1, 'a', 2 * GRPC_HTTP_PARSER_MAX_HEADER_LENGTH - 1);
tmp1[2 * GRPC_HTTP_PARSER_MAX_HEADER_LENGTH - 1] = 0;
gpr_asprintf(&tmp2, "HTTP/1.0 200 OK\r\nxyz: %s\r\n\r\n", tmp1);
diff --git a/test/core/http/request_fuzzer.c b/test/core/http/request_fuzzer.cc
index 3f685711ff..dfdb5792ac 100644
--- a/test/core/http/request_fuzzer.c
+++ b/test/core/http/request_fuzzer.cc
@@ -27,7 +27,7 @@
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) {
grpc_http_parser parser;
grpc_http_request request;
memset(&request, 0, sizeof(request));
diff --git a/test/core/http/response_fuzzer.c b/test/core/http/response_fuzzer.cc
index b41a340f18..89ee676b49 100644
--- a/test/core/http/response_fuzzer.c
+++ b/test/core/http/response_fuzzer.cc
@@ -26,7 +26,7 @@
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) {
grpc_http_parser parser;
grpc_http_response response;
memset(&response, 0, sizeof(response));