aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/slice
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
commit4e9265c828f0b559b5fdba04913fed46bf771399 (patch)
tree4a379fc2bdc037753cf8d81f8b86327e4bc50a42 /test/core/slice
parent0ee7574732a06e8cace4e099a678f4bd5dbff679 (diff)
parentd9da7387b8057f3bd99a417a5ee905377bce9296 (diff)
Merge with master
Diffstat (limited to 'test/core/slice')
-rw-r--r--test/core/slice/BUILD32
-rw-r--r--test/core/slice/b64_test.cc (renamed from test/core/slice/b64_test.c)26
-rw-r--r--test/core/slice/percent_decode_fuzzer.cc (renamed from test/core/slice/percent_decode_fuzzer.c)4
-rw-r--r--test/core/slice/percent_encode_fuzzer.cc (renamed from test/core/slice/percent_encode_fuzzer.c)6
-rw-r--r--test/core/slice/percent_encoding_test.cc (renamed from test/core/slice/percent_encoding_test.c)28
-rw-r--r--test/core/slice/slice_buffer_test.cc (renamed from test/core/slice/slice_buffer_test.c)2
-rw-r--r--test/core/slice/slice_hash_table_test.cc (renamed from test/core/slice/slice_hash_table_test.c)20
-rw-r--r--test/core/slice/slice_string_helpers_test.cc (renamed from test/core/slice/slice_string_helpers_test.c)15
-rw-r--r--test/core/slice/slice_test.cc (renamed from test/core/slice/slice_test.c)14
9 files changed, 75 insertions, 72 deletions
diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD
index ad2308a4d6..ba2b553e0b 100644
--- a/test/core/slice/BUILD
+++ b/test/core/slice/BUILD
@@ -22,8 +22,8 @@ load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
name = "percent_encode_fuzzer",
- srcs = ["percent_encode_fuzzer.c"],
- language = "C",
+ srcs = ["percent_encode_fuzzer.cc"],
+ language = "C++",
corpus = "percent_encode_corpus",
deps = [
"//:gpr",
@@ -34,8 +34,8 @@ grpc_fuzzer(
grpc_fuzzer(
name = "percent_decode_fuzzer",
- srcs = ["percent_decode_fuzzer.c"],
- language = "C",
+ srcs = ["percent_decode_fuzzer.cc"],
+ language = "C++",
corpus = "percent_decode_corpus",
deps = [
"//:gpr",
@@ -46,8 +46,8 @@ grpc_fuzzer(
grpc_cc_test(
name = "percent_encoding_test",
- srcs = ["percent_encoding_test.c"],
- language = "C",
+ srcs = ["percent_encoding_test.cc"],
+ language = "C++",
deps = [
"//:gpr",
"//:grpc",
@@ -58,15 +58,15 @@ grpc_cc_test(
grpc_cc_test(
name = "slice_test",
- srcs = ["slice_test.c"],
+ srcs = ["slice_test.cc"],
deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"],
- language = "C",
+ language = "C++",
)
grpc_cc_test(
name = "slice_string_helpers_test",
- srcs = ["slice_string_helpers_test.c"],
- language = "C",
+ srcs = ["slice_string_helpers_test.cc"],
+ language = "C++",
deps = [
"//:gpr",
"//:grpc",
@@ -77,22 +77,22 @@ grpc_cc_test(
grpc_cc_test(
name = "slice_buffer_test",
- srcs = ["slice_buffer_test.c"],
+ srcs = ["slice_buffer_test.cc"],
deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"],
- language = "C",
+ language = "C++",
)
grpc_cc_test(
name = "slice_hash_table_test",
- srcs = ["slice_hash_table_test.c"],
+ srcs = ["slice_hash_table_test.cc"],
deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"],
- language = "C",
+ language = "C++",
)
grpc_cc_test(
name = "b64_test",
- srcs = ["b64_test.c"],
- language = "C",
+ srcs = ["b64_test.cc"],
+ language = "C++",
deps = [
"//:gpr",
"//:grpc",
diff --git a/test/core/slice/b64_test.c b/test/core/slice/b64_test.cc
index 0740315195..3f1de9bc12 100644
--- a/test/core/slice/b64_test.c
+++ b/test/core/slice/b64_test.cc
@@ -27,8 +27,8 @@
#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
-static int buffers_are_equal(const unsigned char *buf1,
- const unsigned char *buf2, size_t size) {
+static int buffers_are_equal(const unsigned char* buf1,
+ const unsigned char* buf2, size_t size) {
size_t i;
for (i = 0; i < size; i++) {
if (buf1[i] != buf2[i]) {
@@ -41,13 +41,13 @@ static int buffers_are_equal(const unsigned char *buf1,
}
static void test_simple_encode_decode_b64(int url_safe, int multiline) {
- const char *hello = "hello";
- char *hello_b64 =
+ const char* hello = "hello";
+ char* hello_b64 =
grpc_base64_encode(hello, strlen(hello), url_safe, multiline);
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello));
- GPR_ASSERT(strncmp((const char *)GRPC_SLICE_START_PTR(hello_slice), hello,
+ GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello,
GRPC_SLICE_LENGTH(hello_slice)) == 0);
grpc_slice_unref_internal(hello_slice);
@@ -58,13 +58,13 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) {
static void test_full_range_encode_decode_b64(int url_safe, int multiline) {
unsigned char orig[256];
size_t i;
- char *b64;
+ char* b64;
grpc_slice orig_decoded;
for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i;
/* Try all the different paddings. */
for (i = 0; i < 3; i++) {
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline);
orig_decoded = grpc_base64_decode(b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i));
@@ -111,12 +111,12 @@ static void test_full_range_encode_decode_b64_urlsafe_multiline(void) {
static void test_url_safe_unsafe_mismatch_failure(void) {
unsigned char orig[256];
size_t i;
- char *b64;
+ char* b64;
grpc_slice orig_decoded;
int url_safe = 1;
for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i;
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0);
orig_decoded = grpc_base64_decode(b64, !url_safe);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded));
@@ -132,7 +132,7 @@ static void test_url_safe_unsafe_mismatch_failure(void) {
}
static void test_rfc4648_test_vectors(void) {
- char *b64;
+ char* b64;
b64 = grpc_base64_encode("", 0, 0, 0);
GPR_ASSERT(strcmp("", b64) == 0);
@@ -166,7 +166,7 @@ static void test_rfc4648_test_vectors(void) {
static void test_unpadded_decode(void) {
grpc_slice decoded;
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
decoded = grpc_base64_decode("Zm9vYmFy", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0);
@@ -202,7 +202,7 @@ static void test_unpadded_decode(void) {
grpc_exec_ctx_finish();
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_simple_encode_decode_b64_no_multiline();
test_simple_encode_decode_b64_multiline();
diff --git a/test/core/slice/percent_decode_fuzzer.c b/test/core/slice/percent_decode_fuzzer.cc
index ad4e3fed7a..3603177c47 100644
--- a/test/core/slice/percent_decode_fuzzer.c
+++ b/test/core/slice/percent_decode_fuzzer.cc
@@ -29,10 +29,10 @@
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) {
struct grpc_memory_counters counters;
grpc_memory_counters_init();
- grpc_slice input = grpc_slice_from_copied_buffer((const char *)data, size);
+ grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output;
if (grpc_strict_percent_decode_slice(
input, grpc_url_percent_encoding_unreserved_bytes, &output)) {
diff --git a/test/core/slice/percent_encode_fuzzer.c b/test/core/slice/percent_encode_fuzzer.cc
index db3dc3bb3f..c8e3849fc8 100644
--- a/test/core/slice/percent_encode_fuzzer.c
+++ b/test/core/slice/percent_encode_fuzzer.cc
@@ -29,10 +29,10 @@
bool squelch = true;
bool leak_check = true;
-static void test(const uint8_t *data, size_t size, const uint8_t *dict) {
+static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
struct grpc_memory_counters counters;
grpc_memory_counters_init();
- grpc_slice input = grpc_slice_from_copied_buffer((const char *)data, size);
+ grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output = grpc_percent_encode_slice(input, dict);
grpc_slice decoded_output;
// encoder must always produce decodable output
@@ -51,7 +51,7 @@ static void test(const uint8_t *data, size_t size, const uint8_t *dict) {
GPR_ASSERT(counters.total_size_relative == 0);
}
-int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
test(data, size, grpc_url_percent_encoding_unreserved_bytes);
test(data, size, grpc_compatible_percent_encoding_unreserved_bytes);
return 0;
diff --git a/test/core/slice/percent_encoding_test.c b/test/core/slice/percent_encoding_test.cc
index fcc8d33db3..253240faad 100644
--- a/test/core/slice/percent_encoding_test.c
+++ b/test/core/slice/percent_encoding_test.cc
@@ -33,10 +33,10 @@
permissive_unencoded, \
sizeof(permissive_unencoded) - 1, dict)
-static void test_vector(const char *raw, size_t raw_length, const char *encoded,
- size_t encoded_length, const uint8_t *dict) {
- char *raw_msg = gpr_dump(raw, raw_length, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- char *encoded_msg =
+static void test_vector(const char* raw, size_t raw_length, const char* encoded,
+ size_t encoded_length, const uint8_t* dict) {
+ char* raw_msg = gpr_dump(raw, raw_length, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ char* encoded_msg =
gpr_dump(encoded, encoded_length, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "Trial:\nraw = %s\nencoded = %s", raw_msg, encoded_msg);
gpr_free(raw_msg);
@@ -52,11 +52,11 @@ static void test_vector(const char *raw, size_t raw_length, const char *encoded,
grpc_slice encoded2raw_permissive_slice =
grpc_permissive_percent_decode_slice(encoded_slice);
- char *raw2encoded_msg =
+ char* raw2encoded_msg =
grpc_dump_slice(raw2encoded_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- char *encoded2raw_msg =
+ char* encoded2raw_msg =
grpc_dump_slice(encoded2raw_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- char *encoded2raw_permissive_msg = grpc_dump_slice(
+ char* encoded2raw_permissive_msg = grpc_dump_slice(
encoded2raw_permissive_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG,
"Result:\nraw2encoded = %s\nencoded2raw = %s\nencoded2raw_permissive "
@@ -77,15 +77,15 @@ static void test_vector(const char *raw, size_t raw_length, const char *encoded,
grpc_slice_unref(encoded_slice);
}
-static void test_nonconformant_vector(const char *encoded,
+static void test_nonconformant_vector(const char* encoded,
size_t encoded_length,
- const char *permissive_unencoded,
+ const char* permissive_unencoded,
size_t permissive_unencoded_length,
- const uint8_t *dict) {
- char *permissive_unencoded_msg =
+ const uint8_t* dict) {
+ char* permissive_unencoded_msg =
gpr_dump(permissive_unencoded, permissive_unencoded_length,
GPR_DUMP_HEX | GPR_DUMP_ASCII);
- char *encoded_msg =
+ char* encoded_msg =
gpr_dump(encoded, encoded_length, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "Trial:\nraw = %s\nencoded = %s", permissive_unencoded_msg,
encoded_msg);
@@ -102,7 +102,7 @@ static void test_nonconformant_vector(const char *encoded,
grpc_slice encoded2raw_permissive_slice =
grpc_permissive_percent_decode_slice(encoded_slice);
- char *encoded2raw_permissive_msg = grpc_dump_slice(
+ char* encoded2raw_permissive_msg = grpc_dump_slice(
encoded2raw_permissive_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "Result:\nencoded2raw_permissive = %s",
encoded2raw_permissive_msg);
@@ -116,7 +116,7 @@ static void test_nonconformant_vector(const char *encoded,
grpc_slice_unref(encoded_slice);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
TEST_VECTOR(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",
diff --git a/test/core/slice/slice_buffer_test.c b/test/core/slice/slice_buffer_test.cc
index 2fba496bd0..338e8079dc 100644
--- a/test/core/slice/slice_buffer_test.c
+++ b/test/core/slice/slice_buffer_test.cc
@@ -104,7 +104,7 @@ void test_slice_buffer_move_first() {
GPR_ASSERT(dst.length == dst_len);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_slice_buffer_add();
diff --git a/test/core/slice/slice_hash_table_test.c b/test/core/slice/slice_hash_table_test.cc
index 67748433b1..b5b9c1bb73 100644
--- a/test/core/slice/slice_hash_table_test.c
+++ b/test/core/slice/slice_hash_table_test.cc
@@ -28,8 +28,8 @@
#include "test/core/util/test_config.h"
typedef struct {
- char* key;
- char* value;
+ const char* key;
+ const char* value;
} test_entry;
static void populate_entries(const test_entry* input, size_t num_entries,
@@ -44,7 +44,8 @@ static void check_values(const test_entry* input, size_t num_entries,
grpc_slice_hash_table* table) {
for (size_t i = 0; i < num_entries; ++i) {
grpc_slice key = grpc_slice_from_static_string(input[i].key);
- char* actual = grpc_slice_hash_table_get(table, key);
+ const char* actual =
+ static_cast<const char*>(grpc_slice_hash_table_get(table, key));
GPR_ASSERT(actual != NULL);
GPR_ASSERT(strcmp(actual, input[i].value) == 0);
grpc_slice_unref(key);
@@ -65,7 +66,8 @@ static grpc_slice_hash_table* create_table_from_entries(
int (*value_cmp_fn)(void*, void*)) {
// Construct table.
grpc_slice_hash_table_entry* entries =
- gpr_zalloc(sizeof(*entries) * num_test_entries);
+ static_cast<grpc_slice_hash_table_entry*>(
+ gpr_zalloc(sizeof(*entries) * num_test_entries));
populate_entries(test_entries, num_test_entries, entries);
grpc_slice_hash_table* table = grpc_slice_hash_table_create(
num_test_entries, entries, destroy_string, value_cmp_fn);
@@ -117,14 +119,14 @@ static void test_slice_hash_table() {
check_values(test_entries, num_entries, table);
check_non_existent_value("XX", table);
// Clean up.
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
grpc_slice_hash_table_unref(table);
grpc_exec_ctx_finish();
}
static int value_cmp_fn(void* a, void* b) {
- const char* a_str = a;
- const char* b_str = b;
+ const char* a_str = static_cast<const char*>(a);
+ const char* b_str = static_cast<const char*>(b);
return strcmp(a_str, b_str);
}
@@ -145,7 +147,7 @@ static void test_slice_hash_table_eq() {
create_table_from_entries(test_entries_b, num_entries_b, value_cmp_fn);
GPR_ASSERT(grpc_slice_hash_table_cmp(table_a, table_b) == 0);
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
grpc_slice_hash_table_unref(table_a);
grpc_slice_hash_table_unref(table_b);
grpc_exec_ctx_finish();
@@ -217,7 +219,7 @@ static void test_slice_hash_table_not_eq() {
create_table_from_entries(test_entries_h, num_entries_h, pointer_cmp_fn);
GPR_ASSERT(grpc_slice_hash_table_cmp(table_g, table_h) != 0);
- exec_ctx = GRPC_EXEC_CTX_INIT;
+ ExecCtx _local_exec_ctx;
grpc_slice_hash_table_unref(table_a);
grpc_slice_hash_table_unref(table_b_larger);
grpc_slice_hash_table_unref(table_b_smaller);
diff --git a/test/core/slice/slice_string_helpers_test.c b/test/core/slice/slice_string_helpers_test.cc
index 504acf8f84..260f8c80d5 100644
--- a/test/core/slice/slice_string_helpers_test.c
+++ b/test/core/slice/slice_string_helpers_test.cc
@@ -34,16 +34,16 @@
#define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x)
static void expect_slice_dump(grpc_slice slice, uint32_t flags,
- const char *result) {
- char *got = grpc_dump_slice(slice, flags);
+ const char* result) {
+ char* got = grpc_dump_slice(slice, flags);
GPR_ASSERT(0 == strcmp(got, result));
gpr_free(got);
grpc_slice_unref(slice);
}
static void test_dump_slice(void) {
- static const char *text = "HELLO WORLD!";
- static const char *long_text =
+ static const char* text = "HELLO WORLD!";
+ static const char* long_text =
"It was a bright cold day in April, and the clocks were striking "
"thirteen. Winston Smith, his chin nuzzled into his breast in an effort "
"to escape the vile wind, slipped quickly through the glass doors of "
@@ -62,12 +62,13 @@ static void test_dump_slice(void) {
}
static void test_strsplit(void) {
- grpc_slice_buffer *parts;
+ grpc_slice_buffer* parts;
grpc_slice str;
LOG_TEST_NAME("test_strsplit");
- parts = gpr_malloc(sizeof(grpc_slice_buffer));
+ parts =
+ static_cast<grpc_slice_buffer*>(gpr_malloc(sizeof(grpc_slice_buffer)));
grpc_slice_buffer_init(parts);
str = grpc_slice_from_copied_string("one, two, three, four");
@@ -127,7 +128,7 @@ static void test_strsplit(void) {
gpr_free(parts);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_dump_slice();
test_strsplit();
diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.cc
index cda37fb8d9..aec5636376 100644
--- a/test/core/slice/slice_test.c
+++ b/test/core/slice/slice_test.cc
@@ -43,8 +43,8 @@ static void test_slice_malloc_returns_something_sensible(void) {
slice = grpc_slice_malloc(length);
/* If there is a length, slice.data must be non-NULL. If length is zero
we don't care. */
- if (length) {
- GPR_ASSERT(GRPC_SLICE_START_PTR(slice));
+ if (length > GRPC_SLICE_INLINED_SIZE) {
+ GPR_ASSERT(slice.data.refcounted.bytes);
}
/* Returned slice length must be what was requested. */
GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == length);
@@ -64,7 +64,7 @@ static void test_slice_malloc_returns_something_sensible(void) {
}
}
-static void do_nothing(void *ignored) {}
+static void do_nothing(void* ignored) {}
static void test_slice_new_returns_something_sensible(void) {
uint8_t x;
@@ -77,7 +77,7 @@ static void test_slice_new_returns_something_sensible(void) {
}
/* destroy function that sets a mark to indicate it was called. */
-static void set_mark(void *p) { *((int *)p) = 1; }
+static void set_mark(void* p) { *((int*)p) = 1; }
static void test_slice_new_with_user_data(void) {
int marker = 0;
@@ -99,7 +99,7 @@ static void test_slice_new_with_user_data(void) {
static int do_nothing_with_len_1_calls = 0;
-static void do_nothing_with_len_1(void *ignored, size_t len) {
+static void do_nothing_with_len_1(void* ignored, size_t len) {
GPR_ASSERT(len == 1);
do_nothing_with_len_1_calls++;
}
@@ -228,7 +228,7 @@ static void test_slice_split_tail_works(size_t length) {
}
static void test_slice_from_copied_string_works(void) {
- static const char *text = "HELLO WORLD!";
+ static const char* text = "HELLO WORLD!";
grpc_slice slice;
LOG_TEST_NAME("test_slice_from_copied_string_works");
@@ -289,7 +289,7 @@ static void test_static_slice_copy_interning(void) {
grpc_shutdown();
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
unsigned length;
grpc_test_init(argc, argv);
test_slice_malloc_returns_something_sensible();