|
|
|
@ -51,7 +51,7 @@ static void test_load_empty_file(void) { |
|
|
|
|
FILE *tmp = NULL; |
|
|
|
|
gpr_slice slice; |
|
|
|
|
gpr_slice slice_with_null_term; |
|
|
|
|
int success; |
|
|
|
|
grpc_error *error; |
|
|
|
|
char *tmp_name; |
|
|
|
|
|
|
|
|
|
LOG_TEST_NAME("test_load_empty_file"); |
|
|
|
@ -61,12 +61,12 @@ static void test_load_empty_file(void) { |
|
|
|
|
GPR_ASSERT(tmp != NULL); |
|
|
|
|
fclose(tmp); |
|
|
|
|
|
|
|
|
|
slice = gpr_load_file(tmp_name, 0, &success); |
|
|
|
|
GPR_ASSERT(success == 1); |
|
|
|
|
error = gpr_load_file(tmp_name, 0, &slice); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0); |
|
|
|
|
|
|
|
|
|
slice_with_null_term = gpr_load_file(tmp_name, 1, &success); |
|
|
|
|
GPR_ASSERT(success == 1); |
|
|
|
|
error = gpr_load_file(tmp_name, 1, &slice_with_null_term); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice_with_null_term) == 1); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_START_PTR(slice_with_null_term)[0] == 0); |
|
|
|
|
|
|
|
|
@ -79,7 +79,7 @@ static void test_load_empty_file(void) { |
|
|
|
|
static void test_load_failure(void) { |
|
|
|
|
FILE *tmp = NULL; |
|
|
|
|
gpr_slice slice; |
|
|
|
|
int success; |
|
|
|
|
grpc_error *error; |
|
|
|
|
char *tmp_name; |
|
|
|
|
|
|
|
|
|
LOG_TEST_NAME("test_load_failure"); |
|
|
|
@ -90,8 +90,9 @@ static void test_load_failure(void) { |
|
|
|
|
fclose(tmp); |
|
|
|
|
remove(tmp_name); |
|
|
|
|
|
|
|
|
|
slice = gpr_load_file(tmp_name, 0, &success); |
|
|
|
|
GPR_ASSERT(success == 0); |
|
|
|
|
error = gpr_load_file(tmp_name, 0, &slice); |
|
|
|
|
GPR_ASSERT(error != GRPC_ERROR_NONE); |
|
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0); |
|
|
|
|
gpr_free(tmp_name); |
|
|
|
|
gpr_slice_unref(slice); |
|
|
|
@ -101,7 +102,7 @@ static void test_load_small_file(void) { |
|
|
|
|
FILE *tmp = NULL; |
|
|
|
|
gpr_slice slice; |
|
|
|
|
gpr_slice slice_with_null_term; |
|
|
|
|
int success; |
|
|
|
|
grpc_error *error; |
|
|
|
|
char *tmp_name; |
|
|
|
|
const char *blah = "blah"; |
|
|
|
|
|
|
|
|
@ -113,13 +114,13 @@ static void test_load_small_file(void) { |
|
|
|
|
GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah)); |
|
|
|
|
fclose(tmp); |
|
|
|
|
|
|
|
|
|
slice = gpr_load_file(tmp_name, 0, &success); |
|
|
|
|
GPR_ASSERT(success == 1); |
|
|
|
|
error = gpr_load_file(tmp_name, 0, &slice); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == strlen(blah)); |
|
|
|
|
GPR_ASSERT(!memcmp(GPR_SLICE_START_PTR(slice), blah, strlen(blah))); |
|
|
|
|
|
|
|
|
|
slice_with_null_term = gpr_load_file(tmp_name, 1, &success); |
|
|
|
|
GPR_ASSERT(success == 1); |
|
|
|
|
error = gpr_load_file(tmp_name, 1, &slice_with_null_term); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice_with_null_term) == (strlen(blah) + 1)); |
|
|
|
|
GPR_ASSERT(strcmp((const char *)GPR_SLICE_START_PTR(slice_with_null_term), |
|
|
|
|
blah) == 0); |
|
|
|
@ -133,7 +134,7 @@ static void test_load_small_file(void) { |
|
|
|
|
static void test_load_big_file(void) { |
|
|
|
|
FILE *tmp = NULL; |
|
|
|
|
gpr_slice slice; |
|
|
|
|
int success; |
|
|
|
|
grpc_error *error; |
|
|
|
|
char *tmp_name; |
|
|
|
|
static const size_t buffer_size = 124631; |
|
|
|
|
unsigned char *buffer = gpr_malloc(buffer_size); |
|
|
|
@ -150,8 +151,8 @@ static void test_load_big_file(void) { |
|
|
|
|
GPR_ASSERT(fwrite(buffer, 1, buffer_size, tmp) == buffer_size); |
|
|
|
|
fclose(tmp); |
|
|
|
|
|
|
|
|
|
slice = gpr_load_file(tmp_name, 0, &success); |
|
|
|
|
GPR_ASSERT(success == 1); |
|
|
|
|
error = gpr_load_file(tmp_name, 0, &slice); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
GPR_ASSERT(GPR_SLICE_LENGTH(slice) == buffer_size); |
|
|
|
|
current = GPR_SLICE_START_PTR(slice); |
|
|
|
|
for (i = 0; i < buffer_size; i++) { |
|
|
|
|