Fix load file test

pull/6897/head
Craig Tiller 9 years ago
parent 4727b9be84
commit c5b7f36f4d
  1. 6
      Makefile
  2. 1
      build.yaml
  3. 33
      test/core/support/load_file_test.c
  4. 3
      tools/run_tests/sources_and_headers.json
  5. 1
      vsprojects/buildtests_c.sln
  6. 3
      vsprojects/vcxproj/test/gpr_load_file_test/gpr_load_file_test.vcxproj

@ -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 $@" $(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@` $(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 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) deps_gpr_load_file_test: $(GPR_LOAD_FILE_TEST_OBJS:.o=.dep)

@ -1479,6 +1479,7 @@ targets:
src: src:
- test/core/support/load_file_test.c - test/core/support/load_file_test.c
deps: deps:
- grpc
- gpr_test_util - gpr_test_util
- gpr - gpr
- name: gpr_log_test - name: gpr_log_test

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

@ -539,7 +539,8 @@
{ {
"deps": [ "deps": [
"gpr", "gpr",
"gpr_test_util" "gpr_test_util",
"grpc"
], ],
"headers": [], "headers": [],
"language": "c", "language": "c",

@ -394,6 +394,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr_load_file_test", "vcxpr
lib = "False" lib = "False"
EndProjectSection EndProjectSection
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9}
{EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037}
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
EndProjectSection EndProjectSection

@ -162,6 +162,9 @@
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\grpc\grpc.vcxproj">
<Project>{29D16885-7228-4C31-81ED-5F9187C7F2A9}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\gpr_test_util\gpr_test_util.vcxproj"> <ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\gpr_test_util\gpr_test_util.vcxproj">
<Project>{EAB0A629-17A9-44DB-B5FF-E91A721FE037}</Project> <Project>{EAB0A629-17A9-44DB-B5FF-E91A721FE037}</Project>
</ProjectReference> </ProjectReference>

Loading…
Cancel
Save