diff options
author | Julien Boeuf <jboeuf@google.com> | 2015-02-03 21:58:53 -0800 |
---|---|---|
committer | Julien Boeuf <jboeuf@google.com> | 2015-02-03 23:17:12 -0800 |
commit | 05618967516ca807d4deadea05e90b439c3f2e7c (patch) | |
tree | f8ca8ce2ea0791c47beac372d103d36d937701b5 /test/core | |
parent | 026a417defcd13d0ae5e8a8ddb67c18ff02fa142 (diff) |
Addressing comments.
The new gpr_tmpfile API is actually much nicer to use. Thanks Nico!
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c | 3 | ||||
-rw-r--r-- | test/core/support/file_test.c | 24 |
2 files changed, 14 insertions, 13 deletions
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c index 876d35a74b..149ac8c07b 100644 --- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c +++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c @@ -139,9 +139,8 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); /* Set the SSL roots env var. */ - roots_filename = gpr_strdup("chttp2_simple_ssl_fullstack_test_XXXXXX"); + roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename); GPR_ASSERT(roots_filename != NULL); - roots_file = gpr_tmpfile(roots_filename); GPR_ASSERT(roots_file != NULL); GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size); fclose(roots_file); diff --git a/test/core/support/file_test.c b/test/core/support/file_test.c index 1d9fb3ff95..b089954186 100644 --- a/test/core/support/file_test.c +++ b/test/core/support/file_test.c @@ -44,17 +44,18 @@ #define LOG_TEST_NAME() gpr_log(GPR_INFO, "%s", __FUNCTION__) -static const char template[] = "file_test_XXXXXX"; +static const char prefix[] = "file_test"; static void test_load_empty_file(void) { FILE *tmp = NULL; gpr_slice slice; int success; - char *tmp_name = gpr_strdup(template); + char *tmp_name; LOG_TEST_NAME(); - tmp = gpr_tmpfile(tmp_name); + tmp = gpr_tmpfile(prefix, &tmp_name); + GPR_ASSERT(tmp_name != NULL); GPR_ASSERT(tmp != NULL); fclose(tmp); @@ -71,17 +72,16 @@ static void test_load_failure(void) { FILE *tmp = NULL; gpr_slice slice; int success; - char *tmp_name = gpr_strdup(template); + char *tmp_name; LOG_TEST_NAME(); - tmp = gpr_tmpfile(tmp_name); + tmp = gpr_tmpfile(prefix, &tmp_name); + GPR_ASSERT(tmp_name != NULL); GPR_ASSERT(tmp != NULL); fclose(tmp); remove(tmp_name); - GPR_ASSERT(tmp_name != NULL); - slice = gpr_load_file(tmp_name, &success); GPR_ASSERT(success == 0); GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0); @@ -93,12 +93,13 @@ static void test_load_small_file(void) { FILE *tmp = NULL; gpr_slice slice; int success; - char *tmp_name = gpr_strdup(template); + char *tmp_name; const char *blah = "blah"; LOG_TEST_NAME(); - tmp = gpr_tmpfile(tmp_name); + tmp = gpr_tmpfile(prefix, &tmp_name); + GPR_ASSERT(tmp_name != NULL); GPR_ASSERT(tmp != NULL); GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah)); fclose(tmp); @@ -117,7 +118,7 @@ static void test_load_big_file(void) { FILE *tmp = NULL; gpr_slice slice; int success; - char *tmp_name = gpr_strdup(template); + char *tmp_name; unsigned char buffer[124631]; unsigned char *current; size_t i; @@ -128,8 +129,9 @@ static void test_load_big_file(void) { buffer[i] = 42; } - tmp = gpr_tmpfile(tmp_name); + tmp = gpr_tmpfile(prefix, &tmp_name); GPR_ASSERT(tmp != NULL); + GPR_ASSERT(tmp_name != NULL); GPR_ASSERT(fwrite(buffer, 1, sizeof(buffer), tmp) == sizeof(buffer)); fclose(tmp); |