From c5b7f36f4d7f93ad5e38a45c34e0b27b544c7507 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 18 May 2016 07:18:47 -0700 Subject: [PATCH] Fix load file test --- Makefile | 6 ++-- build.yaml | 1 + test/core/support/load_file_test.c | 33 ++++++++++--------- tools/run_tests/sources_and_headers.json | 3 +- vsprojects/buildtests_c.sln | 1 + .../gpr_load_file_test.vcxproj | 3 ++ 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 13df968e32b..c0908c0698f 100644 --- a/Makefile +++ b/Makefile @@ -7070,14 +7070,14 @@ else -$(BINDIR)/$(CONFIG)/gpr_load_file_test: $(GPR_LOAD_FILE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/gpr_load_file_test: $(GPR_LOAD_FILE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GPR_LOAD_FILE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/gpr_load_file_test + $(Q) $(LD) $(LDFLAGS) $(GPR_LOAD_FILE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/gpr_load_file_test endif -$(OBJDIR)/$(CONFIG)/test/core/support/load_file_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/support/load_file_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_gpr_load_file_test: $(GPR_LOAD_FILE_TEST_OBJS:.o=.dep) diff --git a/build.yaml b/build.yaml index e06c5ad419e..c87641652ff 100644 --- a/build.yaml +++ b/build.yaml @@ -1479,6 +1479,7 @@ targets: src: - test/core/support/load_file_test.c deps: + - grpc - gpr_test_util - gpr - name: gpr_log_test diff --git a/test/core/support/load_file_test.c b/test/core/support/load_file_test.c index 0125fd94fd3..9874db3d9a1 100644 --- a/test/core/support/load_file_test.c +++ b/test/core/support/load_file_test.c @@ -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++) { diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 325028dc000..85c5a37a511 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -539,7 +539,8 @@ { "deps": [ "gpr", - "gpr_test_util" + "gpr_test_util", + "grpc" ], "headers": [], "language": "c", diff --git a/vsprojects/buildtests_c.sln b/vsprojects/buildtests_c.sln index be8b5d40ace..95a7f17e521 100644 --- a/vsprojects/buildtests_c.sln +++ b/vsprojects/buildtests_c.sln @@ -394,6 +394,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr_load_file_test", "vcxpr lib = "False" EndProjectSection ProjectSection(ProjectDependencies) = postProject + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection diff --git a/vsprojects/vcxproj/test/gpr_load_file_test/gpr_load_file_test.vcxproj b/vsprojects/vcxproj/test/gpr_load_file_test/gpr_load_file_test.vcxproj index 4182969f500..504ef8815cf 100644 --- a/vsprojects/vcxproj/test/gpr_load_file_test/gpr_load_file_test.vcxproj +++ b/vsprojects/vcxproj/test/gpr_load_file_test/gpr_load_file_test.vcxproj @@ -162,6 +162,9 @@ + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037}