@ -49,6 +49,7 @@ static const char prefix[] = "file_test";
static void test_load_empty_file ( void ) {
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 ;
int success ;
int success ;
char * tmp_name ;
char * tmp_name ;
@ -59,13 +60,19 @@ 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 , & success ) ;
slice = gpr_load_file ( tmp_name , 0 , & success ) ;
GPR_ASSERT ( success = = 1 ) ;
GPR_ASSERT ( success = = 1 ) ;
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 ) ;
GPR_ASSERT ( success = = 1 ) ;
GPR_ASSERT ( GPR_SLICE_LENGTH ( slice_with_null_term ) = = 1 ) ;
GPR_ASSERT ( GPR_SLICE_START_PTR ( slice_with_null_term ) [ 0 ] = = 0 ) ;
remove ( tmp_name ) ;
remove ( tmp_name ) ;
gpr_free ( tmp_name ) ;
gpr_free ( tmp_name ) ;
gpr_slice_unref ( slice ) ;
gpr_slice_unref ( slice ) ;
gpr_slice_unref ( slice_with_null_term ) ;
}
}
static void test_load_failure ( void ) {
static void test_load_failure ( void ) {
@ -82,7 +89,7 @@ static void test_load_failure(void) {
fclose ( tmp ) ;
fclose ( tmp ) ;
remove ( tmp_name ) ;
remove ( tmp_name ) ;
slice = gpr_load_file ( tmp_name , & success ) ;
slice = gpr_load_file ( tmp_name , 0 , & success ) ;
GPR_ASSERT ( success = = 0 ) ;
GPR_ASSERT ( success = = 0 ) ;
GPR_ASSERT ( GPR_SLICE_LENGTH ( slice ) = = 0 ) ;
GPR_ASSERT ( GPR_SLICE_LENGTH ( slice ) = = 0 ) ;
gpr_free ( tmp_name ) ;
gpr_free ( tmp_name ) ;
@ -92,6 +99,7 @@ static void test_load_failure(void) {
static void test_load_small_file ( void ) {
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 ;
int success ;
int success ;
char * tmp_name ;
char * tmp_name ;
const char * blah = " blah " ;
const char * blah = " blah " ;
@ -104,14 +112,21 @@ 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 , & success ) ;
slice = gpr_load_file ( tmp_name , 0 , & success ) ;
GPR_ASSERT ( success = = 1 ) ;
GPR_ASSERT ( success = = 1 ) ;
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 ) ;
GPR_ASSERT ( success = = 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 ) ,
blah ) = = 0 ) ;
remove ( tmp_name ) ;
remove ( tmp_name ) ;
gpr_free ( tmp_name ) ;
gpr_free ( tmp_name ) ;
gpr_slice_unref ( slice ) ;
gpr_slice_unref ( slice ) ;
gpr_slice_unref ( slice_with_null_term ) ;
}
}
static void test_load_big_file ( void ) {
static void test_load_big_file ( void ) {
@ -135,7 +150,7 @@ static void test_load_big_file(void) {
GPR_ASSERT ( fwrite ( buffer , 1 , sizeof ( buffer ) , tmp ) = = sizeof ( buffer ) ) ;
GPR_ASSERT ( fwrite ( buffer , 1 , sizeof ( buffer ) , tmp ) = = sizeof ( buffer ) ) ;
fclose ( tmp ) ;
fclose ( tmp ) ;
slice = gpr_load_file ( tmp_name , & success ) ;
slice = gpr_load_file ( tmp_name , 0 , & success ) ;
GPR_ASSERT ( success = = 1 ) ;
GPR_ASSERT ( success = = 1 ) ;
GPR_ASSERT ( GPR_SLICE_LENGTH ( slice ) = = sizeof ( buffer ) ) ;
GPR_ASSERT ( GPR_SLICE_LENGTH ( slice ) = = sizeof ( buffer ) ) ;
current = GPR_SLICE_START_PTR ( slice ) ;
current = GPR_SLICE_START_PTR ( slice ) ;