From: Kevin Day Date: Wed, 19 Apr 2023 03:21:32 +0000 (-0500) Subject: Progress: Unit tests and other minor changes. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=36764c8c51d1da45bcb4401793813aee4d571f5c;p=fll Progress: Unit tests and other minor changes. Get more of the unit tests up to date. I did not finish working on the f_file unit tests. I specifically stopped on the stream functions, namely the f_stream_write(). Fix the file defaults, such as _di_f_type_file_defaults_ that should be _di_f_type_file_defaults_d_. The file flags (wrapped by _di_f_file_flag_d_) must be located with the f_type type_file.h file. --- diff --git a/build/disable/level_0/f_type.h b/build/disable/level_0/f_type.h index 80f0c71..634e5db 100644 --- a/build/disable/level_0/f_type.h +++ b/build/disable/level_0/f_type.h @@ -30,7 +30,7 @@ #define _di_f_status_t_ #define _di_f_time_spec_t_ #define _di_f_time_t_ -#define _di_f_type_file_defaults_ +#define _di_f_type_file_defaults_d_ #define _di_f_type_input_output_d_ #define _di_f_type_number_64_t_ #define _di_f_type_sizes_d_ diff --git a/build/stand_alone/fake.config.h b/build/stand_alone/fake.config.h index 08cb93e..5bd320e 100644 --- a/build/stand_alone/fake.config.h +++ b/build/stand_alone/fake.config.h @@ -397,7 +397,6 @@ #define _di_f_file_descriptor_ //#define _di_f_file_exists_ #define _di_f_file_exists_at_ -//#define _di_f_file_flag_d_ //#define _di_f_file_flush_ //#define _di_f_file_group_read_ //#define _di_f_file_is_ @@ -1941,7 +1940,8 @@ #define _di_f_time_t_ //#define _di_f_type_d_ -//#define _di_f_type_file_defaults_ +//#define _di_f_type_file_defaults_d_ +//#define _di_f_type_file_flag_d_ //#define _di_f_type_number_64_t_ //#define _di_f_type_sizes_d_ diff --git a/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c b/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c index ba1928c..e8218c6 100644 --- a/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c +++ b/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c @@ -7,6 +7,8 @@ extern "C" { void test__f_conversion_number_signed_print__fails(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -14,7 +16,7 @@ void test__f_conversion_number_signed_print__fails(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(1, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -22,6 +24,8 @@ void test__f_conversion_number_signed_print__fails(void **state) { void test__f_conversion_number_signed_print__fails_for_prepend(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, F_conversion_data_flag_base_prepend_d, 0); @@ -29,7 +33,7 @@ void test__f_conversion_number_signed_print__fails_for_prepend(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(1, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -37,6 +41,8 @@ void test__f_conversion_number_signed_print__fails_for_prepend(void **state) { void test__f_conversion_number_signed_print__fails_for_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -44,7 +50,7 @@ void test__f_conversion_number_signed_print__fails_for_zero(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(0, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -52,19 +58,22 @@ void test__f_conversion_number_signed_print__fails_for_zero(void **state) { void test__f_conversion_number_signed_print__parameter_checking(void **state) { + f_file_t output = macro_f_file_t_initialize2(0, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(2, 0, 0); - const f_status_t status = f_conversion_number_signed_print(0, data, 0); + const f_status_t status = f_conversion_number_signed_print(0, data, output); assert_int_equal(status, F_status_set_error(F_parameter)); } { - FILE *file = 0; const f_conversion_data_t data = macro_f_conversion_data_t_initialize(1, 0, 0); - const f_status_t status = f_conversion_number_signed_print(0, data, file); + output.stream = F_type_output_d; + + const f_status_t status = f_conversion_number_signed_print(0, data, output); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -72,6 +81,8 @@ void test__f_conversion_number_signed_print__parameter_checking(void **state) { void test__f_conversion_number_signed_print__works(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -81,7 +92,7 @@ void test__f_conversion_number_signed_print__works(void **state) { expect_string(__wrap_fwrite_unlocked, ptr, "1"); - const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(1, data, output); assert_int_equal(status, F_none); } @@ -89,6 +100,8 @@ void test__f_conversion_number_signed_print__works(void **state) { void test__f_conversion_number_signed_print__works_for_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -98,7 +111,7 @@ void test__f_conversion_number_signed_print__works_for_zero(void **state) { expect_string(__wrap_fwrite_unlocked, ptr, "0"); - const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(0, data, output); assert_int_equal(status, F_none); } @@ -106,10 +119,12 @@ void test__f_conversion_number_signed_print__works_for_zero(void **state) { void test__f_conversion_number_signed_print__works_for_zero_with_width_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0); - const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_signed_print(0, data, output); assert_int_equal(status, F_none); } diff --git a/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c b/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c index fb7396b..36fe479 100644 --- a/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c +++ b/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c @@ -7,6 +7,8 @@ extern "C" { void test__f_conversion_number_unsigned_print__fails(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -14,7 +16,7 @@ void test__f_conversion_number_unsigned_print__fails(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(1, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -22,6 +24,8 @@ void test__f_conversion_number_unsigned_print__fails(void **state) { void test__f_conversion_number_unsigned_print__fails_for_prepend(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, F_conversion_data_flag_base_prepend_d, 0); @@ -29,7 +33,7 @@ void test__f_conversion_number_unsigned_print__fails_for_prepend(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(1, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -37,6 +41,8 @@ void test__f_conversion_number_unsigned_print__fails_for_prepend(void **state) { void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -44,7 +50,7 @@ void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) { will_return(__wrap_fwrite_unlocked, 0); will_return(__wrap_ferror_unlocked, true); - const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(0, data, output); assert_int_equal(status, F_status_set_error(F_output)); } @@ -52,19 +58,22 @@ void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) { void test__f_conversion_number_unsigned_print__parameter_checking(void **state) { + f_file_t output = macro_f_file_t_initialize2(0, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(2, 0, 0); - const f_status_t status = f_conversion_number_unsigned_print(0, data, 0); + const f_status_t status = f_conversion_number_unsigned_print(0, data, output); assert_int_equal(status, F_status_set_error(F_parameter)); } { - FILE *file = 0; const f_conversion_data_t data = macro_f_conversion_data_t_initialize(1, 0, 0); - const f_status_t status = f_conversion_number_unsigned_print(0, data, file); + output.stream = F_type_output_d; + + const f_status_t status = f_conversion_number_unsigned_print(0, data, output); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -72,6 +81,8 @@ void test__f_conversion_number_unsigned_print__parameter_checking(void **state) void test__f_conversion_number_unsigned_print__works(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -81,7 +92,7 @@ void test__f_conversion_number_unsigned_print__works(void **state) { expect_string(__wrap_fwrite_unlocked, ptr, "1"); - const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(1, data, output); assert_int_equal(status, F_none); } @@ -89,6 +100,8 @@ void test__f_conversion_number_unsigned_print__works(void **state) { void test__f_conversion_number_unsigned_print__works_for_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1); @@ -98,7 +111,7 @@ void test__f_conversion_number_unsigned_print__works_for_zero(void **state) { expect_string(__wrap_fwrite_unlocked, ptr, "0"); - const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(0, data, output); assert_int_equal(status, F_none); } @@ -106,10 +119,12 @@ void test__f_conversion_number_unsigned_print__works_for_zero(void **state) { void test__f_conversion_number_unsigned_print__works_for_zero_with_width_zero(void **state) { + const f_file_t output = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0); - const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d); + const f_status_t status = f_conversion_number_unsigned_print(0, data, output); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 944d069..fbf2f78 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -92,7 +92,7 @@ extern "C" { if (F_status_is_error(status)) return status; } - return private_f_file_copy_content(source, destination, size_block == 0 ? F_file_default_read_size_d : size_block); + return private_f_file_copy_content(source, destination, size_block == 0 ? F_file_default_size_read_d : size_block); } if (macro_f_file_type_is_link(source_stat.st_mode)) { @@ -152,7 +152,7 @@ extern "C" { status = private_f_file_mode_set(destination, (~F_file_type_mask_d) & mode.regular); if (F_status_is_error(status)) return status; - return private_f_file_copy_content(source, destination, size_block == 0 ? F_file_default_read_size_d : size_block); + return private_f_file_copy_content(source, destination, size_block == 0 ? F_file_default_size_read_d : size_block); } if (macro_f_file_type_is_directory(source_stat.st_mode)) { diff --git a/level_0/f_file/c/file/common.h b/level_0/f_file/c/file/common.h index eb54770..52643da 100644 --- a/level_0/f_file/c/file/common.h +++ b/level_0/f_file/c/file/common.h @@ -221,109 +221,6 @@ extern "C" { #endif // _di_f_file_at_d_ /** - * File flag related functionality. - */ -#ifndef _di_f_file_flag_d_ - - // file open flags - #define F_file_flag_append_d O_APPEND - #define F_file_flag_asynchronous_d O_ASYNC - #define F_file_flag_create_d O_CREAT - #define F_file_flag_close_execute_d O_CLOEXEC - #define F_file_flag_direct_d O_DIRECT - #define F_file_flag_directory_d O_DIRECTORY - #define F_file_flag_exclusive_d O_EXCL - #define F_file_flag_large_file_d O_LARGEFILE - #define F_file_flag_no_access_time_d O_NOATIME - #define F_file_flag_no_follow_d O_NOFOLLOW - #define F_file_flag_no_tty_d O_NOCTTY - #define F_file_flag_non_blocking_d O_NONBLOCK - #define F_file_flag_path_d 010000000 - #define F_file_flag_read_only_d O_RDONLY - #define F_file_flag_read_write_d O_RDWR - #define F_file_flag_synchronous_d O_SYNC - #define F_file_flag_synchronous_direct_d O_DSYNC - #define F_file_flag_temporary_d O_TMPFILE - #define F_file_flag_truncate_d O_TRUNC - #define F_file_flag_write_only_d O_WRONLY - - // File open flags pre-combined with create. - #define F_file_flag_create_ro_d (O_CREAT | O_RDONLY) - #define F_file_flag_create_wo_d (O_CREAT | O_WRONLY) - #define F_file_flag_create_rw_d (O_CREAT | O_RDRW) - - // File open flags pre-combined will fail if file exists. - #define F_file_flag_create_new_ro_d (O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_create_new_wo_d (O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_create_new_rw_d (O_CREAT | O_EXCL | O_RDRW) - - // File open flags pre-combined will truncate any existing files to 0. - #define F_file_flag_truncate_ro_d (O_CREAT | O_TRUNC | O_RDONLY) - #define F_file_flag_truncate_rw_d (O_CREAT | O_TRUNC | O_RDRW) - #define F_file_flag_truncate_wo_d (O_CREAT | O_TRUNC | O_WRONLY) - - // File open flags pre-combined will truncate any existing files to 0. - #define F_file_flag_append_rw_d (O_CREAT | O_APPEND | O_RDRW) - #define F_file_flag_append_wo_d (O_CREAT | O_APPEND | O_WRONLY) - - // File open flags pre-combined with synchronous io. - #define F_file_flag_sync_ro_d (O_SYNC | O_RDONLY) - #define F_file_flag_sync_wo_d (O_SYNC | O_WRONLY) - #define F_file_flag_sync_rw_d (O_SYNC | O_RDRW) - #define F_file_flag_sync_create_ro_d (O_SYNC | O_CREAT | O_RDONLY) - #define F_file_flag_sync_create_wo_d (O_SYNC | O_CREAT | O_WRONLY) - #define F_file_flag_sync_create_rw_d (O_SYNC | O_CREAT | O_RDRW) - #define F_file_flag_sync_create_new_ro_d (O_SYNC | O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_sync_create_new_wo_d (O_SYNC | O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_sync_create_new_rw_d (O_SYNC | O_CREAT | O_EXCL | O_RDRW) - - // File open flags pre-combined with asynchronous io. - #define F_file_flag_async_ro_d (O_ASYNC | O_RDONLY) - #define F_file_flag_async_wo_d (O_ASYNC | O_WRONLY) - #define F_file_flag_async_rw_d (O_ASYNC | O_RDRW) - #define F_file_flag_async_create_ro_d (O_ASYNC | O_CREAT | O_RDONLY) - #define F_file_flag_async_create_wo_d (O_ASYNC | O_CREAT | O_WRONLY) - #define F_file_flag_async_create_rw_d (O_ASYNC | O_CREAT | O_RDRW) - #define F_file_flag_async_create_new_ro_d (O_ASYNC | O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_async_create_new_wo_d (O_ASYNC | O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_async_create_new_rw_d (O_ASYNC | O_CREAT | O_EXCL | O_RDRW) - - // File open flags pre-combined with direct io (which works synchronously). - #define F_file_flag_direct_ro_d (O_DIRECT | O_RDONLY) - #define F_file_flag_direct_wo_d (O_DIRECT | O_WRONLY) - #define F_file_flag_direct_rw_d (O_DIRECT | O_RDRW) - #define F_file_flag_direct_create_ro_d (O_DIRECT | O_CREAT | O_RDONLY) - #define F_file_flag_direct_create_wo_d (O_DIRECT | O_CREAT | O_WRONLY) - #define F_file_flag_direct_create_rw_d (O_DIRECT | O_CREAT | O_RDRW) - #define F_file_flag_direct_create_new_ro_d (O_DIRECT | O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_direct_create_new_wo_d (O_DIRECT | O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_direct_create_new_rw_d (O_DIRECT | O_CREAT | O_EXCL | O_RDRW) - - // File open flags pre-combined with large_file. - #define F_file_flag_large_ro_d (O_LARGEFILE | O_RDONLY) - #define F_file_flag_large_wo_d (O_LARGEFILE | O_WRONLY) - #define F_file_flag_large_rw_d (O_LARGEFILE | O_RDRW) - #define F_file_flag_large_sync_ro_d (O_LARGEFILE | O_SYNC | O_RDONLY) - #define F_file_flag_large_sync_wo_d (O_LARGEFILE | O_SYNC | O_WRONLY) - #define F_file_flag_large_sync_rw_d (O_LARGEFILE | O_SYNC | O_RDRW) - #define F_file_flag_large_sync_create_ro_d (O_LARGEFILE | O_SYNC | O_CREAT | O_RDONLY) - #define F_file_flag_large_sync_create_wo_d (O_LARGEFILE | O_SYNC | O_CREAT | O_WRONLY) - #define F_file_flag_large_sync_create_rw_d (O_LARGEFILE | O_SYNC | O_CREAT | O_RDRW) - #define F_file_flag_large_sync_create_new_ro_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_large_sync_create_new_wo_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_large_sync_create_new_rw_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_RDRW) - #define F_file_flag_large_async_ro_d (O_LARGEFILE | O_ASYNC | O_RDONLY) - #define F_file_flag_large_async_wo_d (O_LARGEFILE | O_ASYNC | O_WRONLY) - #define F_file_flag_large_async_rw_d (O_LARGEFILE | O_ASYNC | O_RDRW) - #define F_file_flag_large_async_create_ro_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_RDONLY) - #define F_file_flag_large_async_create_wo_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_WRONLY) - #define F_file_flag_large_async_create_rw_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_RDRW) - #define F_file_flag_large_async_create_new_ro_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_RDONLY) - #define F_file_flag_large_async_create_new_wo_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_WRONLY) - #define F_file_flag_large_async_create_new_rw_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_RDRW) -#endif // _di_f_file_flag_d_ - -/** * File mode related functionality. * * There are two types of file modes that the f_file_mode_t macros are associated with. diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 2691cde..0be7546 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -5,7 +5,7 @@ extern "C" { #endif -#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) f_status_t private_f_file_close(f_file_t * const file) { if (close(file->id) < 0) { @@ -28,7 +28,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) #if !defined(_di_f_file_copy_) || !defined(_di_f_file_clone_) f_status_t private_f_file_copy_content(const f_string_static_t source, const f_string_static_t destination, const f_number_unsigned_t size_block) { @@ -234,7 +234,7 @@ extern "C" { } #endif // !defined(_di_f_file_create_device_at_) || !defined(_di_f_file_create_node_at_) -#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) f_status_t private_f_file_flush(const f_file_t file) { if (fsync(file.id) < 0) { @@ -250,7 +250,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) #if !defined(_di_f_file_link_) || !defined(_di_f_file_copy_) f_status_t private_f_file_link(const f_string_static_t target, const f_string_static_t point) { diff --git a/level_0/f_file/c/private-file.h b/level_0/f_file/c/private-file.h index e0763a8..baa6307 100644 --- a/level_0/f_file/c/private-file.h +++ b/level_0/f_file/c/private-file.h @@ -41,15 +41,14 @@ extern "C" { * @see f_file_clone() * @see f_file_clone_at() * @see f_file_close() - * @see f_file_close_flush() * @see f_file_copy() * @see f_file_create() * @see f_file_create_at() * @see f_file_stream_close() */ -#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) extern f_status_t private_f_file_close(f_file_t * const file) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) /** * Copy a file. @@ -377,15 +376,14 @@ extern "C" { * @see f_file_clone() * @see f_file_clone_at() * @see f_file_close() - * @see f_file_close_flush() * @see f_file_copy() * @see f_file_create() * @see f_file_create_at() * @see f_file_stream_close() */ -#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#if !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) extern f_status_t private_f_file_flush(const f_file_t file) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_close_flush_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) +#endif // !defined(_di_f_file_clone_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_stream_close_) /** * Private implementation of f_file_link(). diff --git a/level_0/f_file/data/build/settings-tests b/level_0/f_file/data/build/settings-tests index 5d8d733..a382816 100644 --- a/level_0/f_file/data/build/settings-tests +++ b/level_0/f_file/data/build/settings-tests @@ -25,7 +25,7 @@ build_language c build_libraries -lc -lcmocka build_libraries-individual -lf_memory -lf_string -lf_file -build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-close_flush.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-is_stat.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-seek.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_open_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c +build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-is_stat.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-seek.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_open_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c build_sources_program test-file.c build_script no diff --git a/level_0/f_file/tests/unit/c/test-file-access_at.c b/level_0/f_file/tests/unit/c/test-file-access_at.c index 62a8584..abb6ed2 100644 --- a/level_0/f_file/tests/unit/c/test-file-access_at.c +++ b/level_0/f_file/tests/unit/c/test-file-access_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_access_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -43,7 +44,7 @@ void test__f_file_access_at__fails(void **state) { will_return(__wrap_faccessat, true); will_return(__wrap_faccessat, errnos[i]); - const f_status_t status = f_file_access_at(0, path, F_file_access_mode_exist_d, 0); + const f_status_t status = f_file_access_at(file, path, F_file_access_mode_exist_d, 0); assert_int_equal(status, statuss[i]); } // for @@ -91,7 +92,7 @@ void test__f_file_access_at__fails(void **state) { will_return(__wrap_faccessat, true); will_return(__wrap_faccessat, errnos[i]); - const f_status_t status = f_file_access_at(0, path, modes[j], 0); + const f_status_t status = f_file_access_at(file, path, modes[j], 0); assert_int_equal(status, statuss[i]); } // for @@ -101,22 +102,36 @@ void test__f_file_access_at__fails(void **state) { void test__f_file_access_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_access_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_access_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_access_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_access_at(file, f_string_empty_s, 0, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_access_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { will_return(__wrap_faccessat, false); will_return(__wrap_faccessat, 0); - const f_status_t status = f_file_access_at(0, path, F_file_access_mode_exist_d, 0); + const f_status_t status = f_file_access_at(file, path, F_file_access_mode_exist_d, 0); assert_int_equal(status, F_true); } diff --git a/level_0/f_file/tests/unit/c/test-file-access_at.h b/level_0/f_file/tests/unit/c/test-file-access_at.h index d7702e6..d385424 100644 --- a/level_0/f_file/tests/unit/c/test-file-access_at.h +++ b/level_0/f_file/tests/unit/c/test-file-access_at.h @@ -25,6 +25,13 @@ extern void test__f_file_access_at__fails(void **state); extern void test__f_file_access_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_access_at() + */ +extern void test__f_file_access_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_access_at() diff --git a/level_0/f_file/tests/unit/c/test-file-close.c b/level_0/f_file/tests/unit/c/test-file-close.c index a0a4349..8dd5a3d 100644 --- a/level_0/f_file/tests/unit/c/test-file-close.c +++ b/level_0/f_file/tests/unit/c/test-file-close.c @@ -28,20 +28,20 @@ void test__f_file_close__fails(void **state) { for (int i = 0; i < 6; ++i) { - int id = 0; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); will_return(__wrap_close, true); will_return(__wrap_close, errnos[i]); - const f_status_t status = f_file_close(&id); + const f_status_t status = f_file_close(&file); assert_int_equal(status, F_status_set_error(statuss[i])); if (errnos[i] == EBADF || errnos[i] == EINTR) { - assert_int_equal(id, 0); + assert_int_equal(file.id, F_type_descriptor_output_d); } else { - assert_int_equal(id, -1); + assert_int_equal(file.id, -1); } } // for } @@ -56,30 +56,30 @@ void test__f_file_close__parameter_checking(void **state) { } } -void test__f_file_close__works(void **state) { - - { - int id = 0; +void test__f_file_close__returns_file_descriptor_not(void **state) { - will_return(__wrap_close, false); - will_return(__wrap_close, 0); + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); - const f_status_t status = f_file_close(&id); + { + const f_status_t status = f_file_close(&file); - assert_int_equal(status, F_none); - assert_int_equal(id, -1); + assert_int_equal(status, F_file_descriptor_not); } } -void test__f_file_close__works_already_closed(void **state) { +void test__f_file_close__works(void **state) { + + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { - int id = -1; - const f_status_t status = f_file_close(&id); + will_return(__wrap_close, false); + will_return(__wrap_close, 0); + + const f_status_t status = f_file_close(&file); assert_int_equal(status, F_none); - assert_int_equal(id, -1); + assert_int_equal(file.id, -1); } } diff --git a/level_0/f_file/tests/unit/c/test-file-close.h b/level_0/f_file/tests/unit/c/test-file-close.h index a21cf13..5746d83 100644 --- a/level_0/f_file/tests/unit/c/test-file-close.h +++ b/level_0/f_file/tests/unit/c/test-file-close.h @@ -25,17 +25,17 @@ extern void test__f_file_close__fails(void **state); extern void test__f_file_close__parameter_checking(void **state); /** - * Test that function works. + * Test that function works but the descriptor is not valid. * * @see f_file_close() */ -extern void test__f_file_close__works(void **state); +extern void test__f_file_close__returns_file_descriptor_not(void **state); /** - * Test that function works when already closed. + * Test that function works. * * @see f_file_close() */ -extern void test__f_file_close__works_already_closed(void **state); +extern void test__f_file_close__works(void **state); #endif // _TEST__F_file_close_h diff --git a/level_0/f_file/tests/unit/c/test-file-close_flush.c b/level_0/f_file/tests/unit/c/test-file-close_flush.c deleted file mode 100644 index fc7f370..0000000 --- a/level_0/f_file/tests/unit/c/test-file-close_flush.c +++ /dev/null @@ -1,94 +0,0 @@ -#include "test-file.h" -#include "test-file-close_flush.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_file_close_flush__fails(void **state) { - - { - int errnos[] = { - EBADF, - EINTR, - EIO, - ENOSPC, - EDQUOT, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_file_descriptor, - F_interrupt, - F_input_output, - F_space_not, - F_filesystem_quota_block, - F_file_close, - }; - - for (int i = 0; i < 6; ++i) { - - int id = 0; - - will_return(__wrap_fsync, false); - will_return(__wrap_fsync, 0); - - will_return(__wrap_close, true); - will_return(__wrap_close, errnos[i]); - - const f_status_t status = f_file_close_flush(&id); - - assert_int_equal(status, F_status_set_error(statuss[i])); - - if (errnos[i] == EBADF || errnos[i] == EINTR) { - assert_int_equal(id, 0); - } - else { - assert_int_equal(id, -1); - } - } // for - } -} - -void test__f_file_close_flush__parameter_checking(void **state) { - - { - const f_status_t status = f_file_close_flush(0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - } -} - -void test__f_file_close_flush__works(void **state) { - - { - int id = 0; - - will_return(__wrap_fsync, false); - will_return(__wrap_fsync, 0); - - will_return(__wrap_close, false); - will_return(__wrap_close, 0); - - const f_status_t status = f_file_close_flush(&id); - - assert_int_equal(status, F_none); - assert_int_equal(id, -1); - } -} - -void test__f_file_close_flush__works_already_closed(void **state) { - - { - int id = -1; - - const f_status_t status = f_file_close_flush(&id); - - assert_int_equal(status, F_none); - assert_int_equal(id, -1); - } -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_file/tests/unit/c/test-file-close_flush.h b/level_0/f_file/tests/unit/c/test-file-close_flush.h deleted file mode 100644 index dd709e9..0000000 --- a/level_0/f_file/tests/unit/c/test-file-close_flush.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: File - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the file project. - */ -#ifndef _TEST__F_file_close_flush_h -#define _TEST__F_file_close_flush_h - -/** - * Test that function fails. - * - * @see f_file_close_flush() - */ -extern void test__f_file_close_flush__fails(void **state); - -/** - * Test that parameter checking works as expected. - * - * @see f_file_close_flush() - */ -extern void test__f_file_close_flush__parameter_checking(void **state); - -/** - * Test that function works. - * - * @see f_file_close_flush() - */ -extern void test__f_file_close_flush__works(void **state); - -/** - * Test that function works. - * - * @see f_file_close_flush() - */ -extern void test__f_file_close_flush__works_already_closed(void **state); - -#endif // _TEST__F_file_close_flush_h diff --git a/level_0/f_file/tests/unit/c/test-file-create_at.c b/level_0/f_file/tests/unit/c/test-file-create_at.c index 056fe85..5e3e04c 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_at.c +++ b/level_0/f_file/tests/unit/c/test-file-create_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_create_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -65,7 +66,7 @@ void test__f_file_create_at__fails(void **state) { will_return(__wrap_openat, true); will_return(__wrap_openat, errnos[i]); - const f_status_t status = f_file_create_at(0, path, 0, F_false); + const f_status_t status = f_file_create_at(file, path, 0, F_false); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -101,7 +102,7 @@ void test__f_file_create_at__fails(void **state) { will_return(__wrap_close, true); will_return(__wrap_close, errnos[i]); - const f_status_t status = f_file_create_at(0, path, 0, F_false); + const f_status_t status = f_file_create_at(file, path, 0, F_false); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -110,15 +111,29 @@ void test__f_file_create_at__fails(void **state) { void test__f_file_create_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_create_at(0, f_string_empty_s, 0, F_false); + const f_status_t status = f_file_create_at(file, f_string_empty_s, 0, F_false); assert_int_equal(status, F_data_not); } } +void test__f_file_create_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_create_at(file, f_string_empty_s, 0, F_false); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_create_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -131,7 +146,7 @@ void test__f_file_create_at__works(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_create_at(0, path, 0, F_false); + const f_status_t status = f_file_create_at(file, path, 0, F_false); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-create_at.h b/level_0/f_file/tests/unit/c/test-file-create_at.h index 2aaf173..3c9badd 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_at.h +++ b/level_0/f_file/tests/unit/c/test-file-create_at.h @@ -25,6 +25,13 @@ extern void test__f_file_create_at__fails(void **state); extern void test__f_file_create_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_create_at() + */ +extern void test__f_file_create_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_create_at() diff --git a/level_0/f_file/tests/unit/c/test-file-create_device_at.c b/level_0/f_file/tests/unit/c/test-file-create_device_at.c index 970d615..a04e8b5 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_device_at.c +++ b/level_0/f_file/tests/unit/c/test-file-create_device_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_create_device_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -61,7 +62,7 @@ void test__f_file_create_device_at__fails(void **state) { will_return(__wrap_mknodat, true); will_return(__wrap_mknodat, errnos[i]); - const f_status_t status = f_file_create_device_at(0, path, modes[j], 1, 1); + const f_status_t status = f_file_create_device_at(file, path, modes[j], 1, 1); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -71,15 +72,29 @@ void test__f_file_create_device_at__fails(void **state) { void test__f_file_create_device_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_create_device_at(0, f_string_empty_s, 0, 0, 0); + const f_status_t status = f_file_create_device_at(file, f_string_empty_s, 0, 0, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_create_device_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_create_device_at(file, f_string_empty_s, 0, 0, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_create_device_at__returns_supported_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int modes[] = { @@ -93,7 +108,7 @@ void test__f_file_create_device_at__returns_supported_not(void **state) { { for (uint8_t i = 0; i < 5; ++i) { - const f_status_t status = f_file_create_device_at(0, path, modes[i], 0, 0); + const f_status_t status = f_file_create_device_at(file, path, modes[i], 0, 0); assert_int_equal(F_status_set_fine(status), F_support_not); } // for @@ -102,6 +117,7 @@ void test__f_file_create_device_at__returns_supported_not(void **state) { void test__f_file_create_device_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int modes[] = { @@ -116,7 +132,7 @@ void test__f_file_create_device_at__works(void **state) { will_return(__wrap_mknodat, false); will_return(__wrap_mknodat, 0); - const f_status_t status = f_file_create_device_at(0, path, modes[i], 1, 1); + const f_status_t status = f_file_create_device_at(file, path, modes[i], 1, 1); assert_int_equal(status, F_none); } // for diff --git a/level_0/f_file/tests/unit/c/test-file-create_device_at.h b/level_0/f_file/tests/unit/c/test-file-create_device_at.h index 78b3a0a..beeb179 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_device_at.h +++ b/level_0/f_file/tests/unit/c/test-file-create_device_at.h @@ -25,6 +25,13 @@ extern void test__f_file_create_device_at__fails(void **state); extern void test__f_file_create_device_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_create_device_at() + */ +extern void test__f_file_create_device_at__returns_file_descriptor_not(void **state); + +/** * Test that function works but the file type is not supported (specified via mode). * * @see f_file_create_device_at() diff --git a/level_0/f_file/tests/unit/c/test-file-create_fifo_at.c b/level_0/f_file/tests/unit/c/test-file-create_fifo_at.c index a30d6f5..a2e1f72 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_fifo_at.c +++ b/level_0/f_file/tests/unit/c/test-file-create_fifo_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_create_fifo_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -43,7 +44,7 @@ void test__f_file_create_fifo_at__fails(void **state) { will_return(__wrap_mkfifoat, true); will_return(__wrap_mkfifoat, errnos[i]); - const f_status_t status = f_file_create_fifo_at(0, path, 0); + const f_status_t status = f_file_create_fifo_at(file, path, 0); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -52,15 +53,29 @@ void test__f_file_create_fifo_at__fails(void **state) { void test__f_file_create_fifo_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_create_fifo_at(0, f_string_empty_s, 0); + const f_status_t status = f_file_create_fifo_at(file, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_create_fifo_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_create_fifo_at(file, f_string_empty_s, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_create_fifo_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); for (uint8_t i = 0; i < 3; ++i) { @@ -68,7 +83,7 @@ void test__f_file_create_fifo_at__works(void **state) { will_return(__wrap_mkfifoat, false); will_return(__wrap_mkfifoat, 0); - const f_status_t status = f_file_create_fifo_at(0, path, 0); + const f_status_t status = f_file_create_fifo_at(file, path, 0); assert_int_equal(status, F_none); } // for diff --git a/level_0/f_file/tests/unit/c/test-file-create_fifo_at.h b/level_0/f_file/tests/unit/c/test-file-create_fifo_at.h index 963b797..189cabf 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_fifo_at.h +++ b/level_0/f_file/tests/unit/c/test-file-create_fifo_at.h @@ -25,6 +25,13 @@ extern void test__f_file_create_fifo_at__fails(void **state); extern void test__f_file_create_fifo_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_create_fifo_at() + */ +extern void test__f_file_create_fifo_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_create_fifo_at() diff --git a/level_0/f_file/tests/unit/c/test-file-create_node_at.c b/level_0/f_file/tests/unit/c/test-file-create_node_at.c index 952984d..027e9d0 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_node_at.c +++ b/level_0/f_file/tests/unit/c/test-file-create_node_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_create_node_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -61,7 +62,7 @@ void test__f_file_create_node_at__fails(void **state) { will_return(__wrap_mknodat, true); will_return(__wrap_mknodat, errnos[i]); - const f_status_t status = f_file_create_node_at(0, path, modes[j], 1); + const f_status_t status = f_file_create_node_at(file, path, modes[j], 1); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -71,15 +72,29 @@ void test__f_file_create_node_at__fails(void **state) { void test__f_file_create_node_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_create_node_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_create_node_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_create_node_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_create_node_at(file, f_string_empty_s, 0, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_create_node_at__returns_supported_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int modes[] = { @@ -93,7 +108,7 @@ void test__f_file_create_node_at__returns_supported_not(void **state) { { for (uint8_t i = 0; i < 5; ++i) { - const f_status_t status = f_file_create_node_at(0, path, modes[i], 0); + const f_status_t status = f_file_create_node_at(file, path, modes[i], 0); assert_int_equal(F_status_set_fine(status), F_support_not); } // for @@ -102,6 +117,7 @@ void test__f_file_create_node_at__returns_supported_not(void **state) { void test__f_file_create_node_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int modes[] = { @@ -116,7 +132,7 @@ void test__f_file_create_node_at__works(void **state) { will_return(__wrap_mknodat, false); will_return(__wrap_mknodat, 0); - const f_status_t status = f_file_create_node_at(0, path, modes[i], 1); + const f_status_t status = f_file_create_node_at(file, path, modes[i], 1); assert_int_equal(status, F_none); } // for diff --git a/level_0/f_file/tests/unit/c/test-file-create_node_at.h b/level_0/f_file/tests/unit/c/test-file-create_node_at.h index b3a8ebd..60c4c7e 100644 --- a/level_0/f_file/tests/unit/c/test-file-create_node_at.h +++ b/level_0/f_file/tests/unit/c/test-file-create_node_at.h @@ -25,6 +25,13 @@ extern void test__f_file_create_node_at__fails(void **state); extern void test__f_file_create_node_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_create_node_at() + */ +extern void test__f_file_create_node_at__returns_file_descriptor_not(void **state); + +/** * Test that function works but the file type is not supported (specified via mode). * * @see f_file_create_node_at() diff --git a/level_0/f_file/tests/unit/c/test-file-descriptor.c b/level_0/f_file/tests/unit/c/test-file-descriptor.c index ba2d6bf..03a5395 100644 --- a/level_0/f_file/tests/unit/c/test-file-descriptor.c +++ b/level_0/f_file/tests/unit/c/test-file-descriptor.c @@ -8,13 +8,13 @@ extern "C" { void test__f_file_descriptor__fails(void **state) { { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); will_return(__wrap_fileno, -1); const f_status_t status = f_file_descriptor(&file); - assert_int_equal(F_status_set_fine(status), F_stream_not); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } } @@ -27,18 +27,28 @@ void test__f_file_descriptor__parameter_checking(void **state) { } } +void test__f_file_descriptor__returns_stream_not(void **state) { + + f_file_t file = macro_f_file_t_initialize2(0, F_type_descriptor_output_d, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_descriptor(&file); + + assert_int_equal(status, F_stream_not); + } +} + void test__f_file_descriptor__works(void **state) { { - const int id = 1; - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); - will_return(__wrap_fileno, id); + will_return(__wrap_fileno, F_type_descriptor_output_d); const f_status_t status = f_file_descriptor(&file); assert_int_equal(status, F_none); - assert_int_equal(file.id, id); + assert_int_equal(file.id, F_type_descriptor_output_d); } } diff --git a/level_0/f_file/tests/unit/c/test-file-descriptor.h b/level_0/f_file/tests/unit/c/test-file-descriptor.h index 51eb13b..4c87d2b 100644 --- a/level_0/f_file/tests/unit/c/test-file-descriptor.h +++ b/level_0/f_file/tests/unit/c/test-file-descriptor.h @@ -25,6 +25,13 @@ extern void test__f_file_descriptor__fails(void **state); extern void test__f_file_descriptor__parameter_checking(void **state); /** + * Test that function works but the stream is not valid. + * + * @see f_file_descriptor() + */ +extern void test__f_file_descriptor__returns_stream_not(void **state); + +/** * Test that function works. * * @see f_file_descriptor() diff --git a/level_0/f_file/tests/unit/c/test-file-exists_at.c b/level_0/f_file/tests/unit/c/test-file-exists_at.c index a1bccc1..2e00bdb 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists_at.c +++ b/level_0/f_file/tests/unit/c/test-file-exists_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_exists_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -40,7 +41,7 @@ void test__f_file_exists_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_exists_at(0, path, 0); + const f_status_t status = f_file_exists_at(file, path, 0); assert_int_equal(status, statuss[i]); } // for @@ -48,15 +49,29 @@ void test__f_file_exists_at__fails(void **state) { void test__f_file_exists_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_exists_at(0, f_string_empty_s, 0); + const f_status_t status = f_file_exists_at(file, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_exists_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_exists_at(file, f_string_empty_s, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_exists_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; @@ -70,7 +85,7 @@ void test__f_file_exists_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_exists_at(0, path, 0); + const f_status_t status = f_file_exists_at(file, path, 0); assert_int_equal(status, F_true); } diff --git a/level_0/f_file/tests/unit/c/test-file-exists_at.h b/level_0/f_file/tests/unit/c/test-file-exists_at.h index 6ae3ea3..a7e8122 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists_at.h +++ b/level_0/f_file/tests/unit/c/test-file-exists_at.h @@ -25,6 +25,13 @@ extern void test__f_file_exists_at__fails(void **state); extern void test__f_file_exists_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_exists_at() + */ +extern void test__f_file_exists_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_exists_at() diff --git a/level_0/f_file/tests/unit/c/test-file-flush.c b/level_0/f_file/tests/unit/c/test-file-flush.c index 7641af5..cef7bdb 100644 --- a/level_0/f_file/tests/unit/c/test-file-flush.c +++ b/level_0/f_file/tests/unit/c/test-file-flush.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_flush__fails(void **state) { + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + int errnos[] = { EBADF, EDQUOT, @@ -32,19 +34,32 @@ void test__f_file_flush__fails(void **state) { will_return(__wrap_fsync, true); will_return(__wrap_fsync, errnos[i]); - const f_status_t status = f_file_flush(0); + const f_status_t status = f_file_flush(file); assert_int_equal(status, F_status_set_error(statuss[i])); } // for } +void test__f_file_flush__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_flush(file); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_flush__works(void **state) { + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { will_return(__wrap_fsync, false); will_return(__wrap_fsync, 0); - const f_status_t status = f_file_flush(0); + const f_status_t status = f_file_flush(file); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-flush.h b/level_0/f_file/tests/unit/c/test-file-flush.h index 67ffb38..ccd303a 100644 --- a/level_0/f_file/tests/unit/c/test-file-flush.h +++ b/level_0/f_file/tests/unit/c/test-file-flush.h @@ -18,6 +18,13 @@ extern void test__f_file_flush__fails(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_flush() + */ +extern void test__f_file_flush__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_flush() diff --git a/level_0/f_file/tests/unit/c/test-file-is_at.c b/level_0/f_file/tests/unit/c/test-file-is_at.c index 08684b1..95507e5 100644 --- a/level_0/f_file/tests/unit/c/test-file-is_at.c +++ b/level_0/f_file/tests/unit/c/test-file-is_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_is_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -53,7 +54,7 @@ void test__f_file_is_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_is_at(0, path, types[j], 0); + const f_status_t status = f_file_is_at(file, path, types[j], 0); assert_int_equal(status, statuss[i]); } // for @@ -62,15 +63,29 @@ void test__f_file_is_at__fails(void **state) { void test__f_file_is_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_is_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_is_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_is_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_is_at(file, f_string_empty_s, 0, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_is_at__returns_false(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); f_status_t types[] = { @@ -101,7 +116,7 @@ void test__f_file_is_at__returns_false(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_is_at(0, path, types[i], 0); + const f_status_t status = f_file_is_at(file, path, types[i], 0); assert_int_equal(status, F_false); } // for @@ -110,6 +125,7 @@ void test__f_file_is_at__returns_false(void **state) { void test__f_file_is_at__returns_true(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); f_status_t types[] = { @@ -140,7 +156,7 @@ void test__f_file_is_at__returns_true(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_is_at(0, path, types[i], 0); + const f_status_t status = f_file_is_at(file, path, types[i], 0); assert_int_equal(status, F_true); } // for diff --git a/level_0/f_file/tests/unit/c/test-file-is_at.h b/level_0/f_file/tests/unit/c/test-file-is_at.h index b43810c..1fbb827 100644 --- a/level_0/f_file/tests/unit/c/test-file-is_at.h +++ b/level_0/f_file/tests/unit/c/test-file-is_at.h @@ -25,6 +25,13 @@ extern void test__f_file_is_at__fails(void **state); extern void test__f_file_is_at__returns_data_not(void **state); /** + * Test that function works but the path is empty. + * + * @see f_file_is_at() + */ +extern void test__f_file_is_at__returns_file_descriptor_not(void **state); + +/** * Test that function works and returns F_false. * * @see f_file_is_at() diff --git a/level_0/f_file/tests/unit/c/test-file-is_stat.h b/level_0/f_file/tests/unit/c/test-file-is_stat.h index 6aa8eed..aafcee0 100644 --- a/level_0/f_file/tests/unit/c/test-file-is_stat.h +++ b/level_0/f_file/tests/unit/c/test-file-is_stat.h @@ -11,13 +11,6 @@ #define _TEST__F_file_is_stat_h /** - * Test that function fails. - * - * @see f_file_is_stat() - */ -extern void test__f_file_is_stat__fails(void **state); - -/** * Test that function works and returns F_false. * * @see f_file_is_stat() diff --git a/level_0/f_file/tests/unit/c/test-file-link_at.c b/level_0/f_file/tests/unit/c/test-file-link_at.c index 73993bb..0d1827b 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_at.c +++ b/level_0/f_file/tests/unit/c/test-file-link_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_link_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -58,7 +59,7 @@ void test__f_file_link_at__fails(void **state) { will_return(__wrap_symlinkat, true); will_return(__wrap_symlinkat, errnos[i]); - const f_status_t status = f_file_link_at(0, path, path); + const f_status_t status = f_file_link_at(file, path, path); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -66,36 +67,50 @@ void test__f_file_link_at__fails(void **state) { void test__f_file_link_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - const f_status_t status = f_file_link_at(0, f_string_empty_s, f_string_empty_s); + const f_status_t status = f_file_link_at(file, f_string_empty_s, f_string_empty_s); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_link_at(0, path, f_string_empty_s); + const f_status_t status = f_file_link_at(file, path, f_string_empty_s); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_link_at(0, f_string_empty_s, path); + const f_status_t status = f_file_link_at(file, f_string_empty_s, path); assert_int_equal(status, F_data_not); } } +void test__f_file_link_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_link_at(file, path, path); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_link_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { will_return(__wrap_symlinkat, false); will_return(__wrap_symlinkat, 0); - const f_status_t status = f_file_link_at(0, path, path); + const f_status_t status = f_file_link_at(file, path, path); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-link_at.h b/level_0/f_file/tests/unit/c/test-file-link_at.h index 46ab520..ac32c1f 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_at.h +++ b/level_0/f_file/tests/unit/c/test-file-link_at.h @@ -25,6 +25,13 @@ extern void test__f_file_link_at__fails(void **state); extern void test__f_file_link_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_link_at() + */ +extern void test__f_file_link_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_link_at() diff --git a/level_0/f_file/tests/unit/c/test-file-link_hard_at.c b/level_0/f_file/tests/unit/c/test-file-link_hard_at.c index 23d7c74..f5c596d 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_hard_at.c +++ b/level_0/f_file/tests/unit/c/test-file-link_hard_at.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_link_hard_at__fails(void **state) { + const f_file_t target = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t point = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -58,7 +60,7 @@ void test__f_file_link_hard_at__fails(void **state) { will_return(__wrap_linkat, true); will_return(__wrap_linkat, errnos[i]); - const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0); + const f_status_t status = f_file_link_hard_at(target, point, path, path, 0); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -66,36 +68,62 @@ void test__f_file_link_hard_at__fails(void **state) { void test__f_file_link_hard_at__returns_data_not(void **state) { + const f_file_t target = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t point = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - const f_status_t status = f_file_link_hard_at(0, 0, f_string_empty_s, f_string_empty_s, 0); + const f_status_t status = f_file_link_hard_at(target, point, f_string_empty_s, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_link_hard_at(0, 0, path, f_string_empty_s, 0); + const f_status_t status = f_file_link_hard_at(target, point, path, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_link_hard_at(0, 0, f_string_empty_s, path, 0); + const f_status_t status = f_file_link_hard_at(target, point, f_string_empty_s, path, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_link_hard_at__returns_file_descriptor_not(void **state) { + + f_file_t target = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + f_file_t point = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_link_hard_at(target, point, path, path, 0); + + assert_int_equal(status, F_file_descriptor_not); + } + + { + target.id = F_type_descriptor_output_d; + point.id = -1; + + const f_status_t status = f_file_link_hard_at(target, point, path, path, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_link_hard_at__works(void **state) { + const f_file_t target = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t point = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { will_return(__wrap_linkat, false); will_return(__wrap_linkat, 0); - const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0); + const f_status_t status = f_file_link_hard_at(target, point, path, path, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-link_hard_at.h b/level_0/f_file/tests/unit/c/test-file-link_hard_at.h index 3d8a453..7ad2de1 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_hard_at.h +++ b/level_0/f_file/tests/unit/c/test-file-link_hard_at.h @@ -25,6 +25,13 @@ extern void test__f_file_link_hard_at__fails(void **state); extern void test__f_file_link_hard_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_link_hard_at() + */ +extern void test__f_file_link_hard_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_link_hard_at() diff --git a/level_0/f_file/tests/unit/c/test-file-link_read_at.c b/level_0/f_file/tests/unit/c/test-file-link_read_at.c index 52c10ac..a70c92c 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_read_at.c +++ b/level_0/f_file/tests/unit/c/test-file-link_read_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_link_read_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -54,7 +55,7 @@ void test__f_file_link_read_at__fails(void **state) { will_return(__wrap_readlinkat, true); will_return(__wrap_readlinkat, errnos[i]); - const f_status_t status = f_file_link_read_at(0, path, 0, &buffer); + const f_status_t status = f_file_link_read_at(file, path, 0, &buffer); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -64,10 +65,11 @@ void test__f_file_link_read_at__fails(void **state) { void test__f_file_link_read_at__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); f_string_dynamic_t buffer = f_string_dynamic_t_initialize; { - const f_status_t status = f_file_link_read_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_link_read_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -77,10 +79,11 @@ void test__f_file_link_read_at__parameter_checking(void **state) { void test__f_file_link_read_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); f_string_dynamic_t buffer = f_string_dynamic_t_initialize; { - const f_status_t status = f_file_link_read_at(0, f_string_empty_s, 0, &buffer); + const f_status_t status = f_file_link_read_at(file, f_string_empty_s, 0, &buffer); assert_int_equal(status, F_data_not); } @@ -88,8 +91,23 @@ void test__f_file_link_read_at__returns_data_not(void **state) { f_string_dynamic_resize(0, &buffer); } +void test__f_file_link_read_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_file_link_read_at(file, f_string_empty_s, 0, &buffer); + + assert_int_equal(status, F_file_descriptor_not); + } + + f_string_dynamic_resize(0, &buffer); +} + void test__f_file_link_read_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; @@ -111,7 +129,7 @@ void test__f_file_link_read_at__works(void **state) { will_return(__wrap_readlinkat, source); will_return(__wrap_readlinkat, 0); - const f_status_t status = f_file_link_read_at(0, path, 0, &buffer); + const f_status_t status = f_file_link_read_at(file, path, 0, &buffer); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-link_read_at.h b/level_0/f_file/tests/unit/c/test-file-link_read_at.h index de3f893..6400845 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_read_at.h +++ b/level_0/f_file/tests/unit/c/test-file-link_read_at.h @@ -32,6 +32,13 @@ extern void test__f_file_link_read_at__parameter_checking(void **state); extern void test__f_file_link_read_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_link_read_at() + */ +extern void test__f_file_link_read_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_link_read_at() diff --git a/level_0/f_file/tests/unit/c/test-file-mode_read_at.c b/level_0/f_file/tests/unit/c/test-file-mode_read_at.c index 0b91df0..c24de18 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_read_at.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_read_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_mode_read_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -42,7 +43,7 @@ void test__f_file_mode_read_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_mode_read_at(0, path, 0, &mode); + const f_status_t status = f_file_mode_read_at(file, path, 0, &mode); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -50,8 +51,10 @@ void test__f_file_mode_read_at__fails(void **state) { void test__f_file_mode_read_at__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_mode_read_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -59,17 +62,34 @@ void test__f_file_mode_read_at__parameter_checking(void **state) { void test__f_file_mode_read_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { mode_t mode = 0; - const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, 0, &mode); + const f_status_t status = f_file_mode_read_at(file, f_string_empty_s, 0, &mode); assert_int_equal(status, F_data_not); } } +void test__f_file_mode_read_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + mode_t mode = 0; + + const f_status_t status = f_file_mode_read_at(file, path, 0, &mode); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_mode_read_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; @@ -85,7 +105,7 @@ void test__f_file_mode_read_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_mode_read_at(0, path, 0, &mode); + const f_status_t status = f_file_mode_read_at(file, path, 0, &mode); assert_int_equal(status, F_none); assert_int_equal(mode, statistics.st_mode); diff --git a/level_0/f_file/tests/unit/c/test-file-mode_read_at.h b/level_0/f_file/tests/unit/c/test-file-mode_read_at.h index ae85c84..cb8fd63 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_read_at.h +++ b/level_0/f_file/tests/unit/c/test-file-mode_read_at.h @@ -32,6 +32,13 @@ extern void test__f_file_mode_read_at__parameter_checking(void **state); extern void test__f_file_mode_read_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_mode_read_at() + */ +extern void test__f_file_mode_read_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_mode_read_at() diff --git a/level_0/f_file/tests/unit/c/test-file-mode_set_at.c b/level_0/f_file/tests/unit/c/test-file-mode_set_at.c index 9456b8b..786500f 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_set_at.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_set_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_mode_set_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const mode_t mode = 0; @@ -46,7 +47,7 @@ void test__f_file_mode_set_at__fails(void **state) { will_return(__wrap_fchmodat, true); will_return(__wrap_fchmodat, errnos[i]); - const f_status_t status = f_file_mode_set_at(0, path, mode); + const f_status_t status = f_file_mode_set_at(file, path, mode); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -54,17 +55,31 @@ void test__f_file_mode_set_at__fails(void **state) { void test__f_file_mode_set_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const mode_t mode = 0; { - const f_status_t status = f_file_mode_set_at(0, f_string_empty_s, mode); + const f_status_t status = f_file_mode_set_at(file, f_string_empty_s, mode); assert_int_equal(status, F_data_not); } } +void test__f_file_mode_set_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + const mode_t mode = 0; + + { + const f_status_t status = f_file_mode_set_at(file, f_string_empty_s, mode); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_mode_set_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const mode_t mode = 0; @@ -73,7 +88,7 @@ void test__f_file_mode_set_at__works(void **state) { will_return(__wrap_fchmodat, false); will_return(__wrap_fchmodat, 5); - const f_status_t status = f_file_mode_set_at(0, path, mode); + const f_status_t status = f_file_mode_set_at(file, path, mode); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-mode_set_at.h b/level_0/f_file/tests/unit/c/test-file-mode_set_at.h index be05852..8c40b6c 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_set_at.h +++ b/level_0/f_file/tests/unit/c/test-file-mode_set_at.h @@ -25,6 +25,13 @@ extern void test__f_file_mode_set_at__fails(void **state); extern void test__f_file_mode_set_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_mode_set_at() + */ +extern void test__f_file_mode_set_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_mode_set_at() diff --git a/level_0/f_file/tests/unit/c/test-file-open_at.c b/level_0/f_file/tests/unit/c/test-file-open_at.c index 8111e57..9a75e41 100644 --- a/level_0/f_file/tests/unit/c/test-file-open_at.c +++ b/level_0/f_file/tests/unit/c/test-file-open_at.c @@ -61,12 +61,12 @@ void test__f_file_open_at__fails(void **state) { for (int i = 0; i < 22; ++i) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); will_return(__wrap_openat, true); will_return(__wrap_openat, errnos[i]); - const f_status_t status = f_file_open_at(0, path, 0, &file); + const f_status_t status = f_file_open_at(file, path, 0, &file); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -75,7 +75,9 @@ void test__f_file_open_at__fails(void **state) { void test__f_file_open_at__parameter_checking(void **state) { { - const f_status_t status = f_file_open_at(0, f_string_empty_s, 0, 0); + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + + const f_status_t status = f_file_open_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -84,25 +86,36 @@ void test__f_file_open_at__parameter_checking(void **state) { void test__f_file_open_at__returns_data_not(void **state) { { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); - const f_status_t status = f_file_open_at(0, f_string_empty_s, 0, &file); + const f_status_t status = f_file_open_at(file, f_string_empty_s, 0, &file); assert_int_equal(status, F_data_not); } } +void test__f_file_open_at__returns_file_descriptor_not(void **state) { + + { + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + const f_status_t status = f_file_open_at(file, f_string_empty_s, 0, &file); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_open_at__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); will_return(__wrap_openat, false); will_return(__wrap_openat, 5); - const f_status_t status = f_file_open_at(0, path, F_false, &file); + const f_status_t status = f_file_open_at(file, path, F_false, &file); assert_int_equal(status, F_none); assert_int_equal(file.id, 5); diff --git a/level_0/f_file/tests/unit/c/test-file-open_at.h b/level_0/f_file/tests/unit/c/test-file-open_at.h index bc85e27..ac172e2 100644 --- a/level_0/f_file/tests/unit/c/test-file-open_at.h +++ b/level_0/f_file/tests/unit/c/test-file-open_at.h @@ -32,6 +32,13 @@ extern void test__f_file_open_at__parameter_checking(void **state); extern void test__f_file_open_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_open_at() + */ +extern void test__f_file_open_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_open_at() diff --git a/level_0/f_file/tests/unit/c/test-file-read.c b/level_0/f_file/tests/unit/c/test-file-read.c index 2ccfc15..c5d16b1 100644 --- a/level_0/f_file/tests/unit/c/test-file-read.c +++ b/level_0/f_file/tests/unit/c/test-file-read.c @@ -81,7 +81,7 @@ void test__f_file_read__parameter_checking(void **state) { f_string_dynamic_resize(0, &buffer); } -void test__f_file_read__returns_file_closed(void **state) { +void test__f_file_read__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; @@ -89,7 +89,7 @@ void test__f_file_read__returns_file_closed(void **state) { { const f_status_t status = f_file_read(file, &buffer); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } f_string_dynamic_resize(0, &buffer); diff --git a/level_0/f_file/tests/unit/c/test-file-read.h b/level_0/f_file/tests/unit/c/test-file-read.h index 35a5aa4..9b3a852 100644 --- a/level_0/f_file/tests/unit/c/test-file-read.h +++ b/level_0/f_file/tests/unit/c/test-file-read.h @@ -25,11 +25,11 @@ extern void test__f_file_read__fails(void **state); extern void test__f_file_read__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_read() */ -extern void test__f_file_read__returns_file_closed(void **state); +extern void test__f_file_read__returns_file_descriptor_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-read_block.c b/level_0/f_file/tests/unit/c/test-file-read_block.c index 8b546b6..0d837af 100644 --- a/level_0/f_file/tests/unit/c/test-file-read_block.c +++ b/level_0/f_file/tests/unit/c/test-file-read_block.c @@ -81,7 +81,7 @@ void test__f_file_read_block__parameter_checking(void **state) { f_string_dynamic_resize(0, &buffer); } -void test__f_file_read_block__returns_file_closed(void **state) { +void test__f_file_read_block__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; @@ -89,7 +89,7 @@ void test__f_file_read_block__returns_file_closed(void **state) { { const f_status_t status = f_file_read_block(file, &buffer); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } f_string_dynamic_resize(0, &buffer); diff --git a/level_0/f_file/tests/unit/c/test-file-read_block.h b/level_0/f_file/tests/unit/c/test-file-read_block.h index 14723a9..53628e3 100644 --- a/level_0/f_file/tests/unit/c/test-file-read_block.h +++ b/level_0/f_file/tests/unit/c/test-file-read_block.h @@ -25,11 +25,11 @@ extern void test__f_file_read_block__fails(void **state); extern void test__f_file_read_block__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_read_block() */ -extern void test__f_file_read_block__returns_file_closed(void **state); +extern void test__f_file_read_block__returns_file_descriptor_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-read_until.c b/level_0/f_file/tests/unit/c/test-file-read_until.c index a3fd48e..909b1a0 100644 --- a/level_0/f_file/tests/unit/c/test-file-read_until.c +++ b/level_0/f_file/tests/unit/c/test-file-read_until.c @@ -81,7 +81,7 @@ void test__f_file_read_until__parameter_checking(void **state) { f_string_dynamic_resize(0, &buffer); } -void test__f_file_read_until__returns_file_closed(void **state) { +void test__f_file_read_until__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; @@ -89,7 +89,7 @@ void test__f_file_read_until__returns_file_closed(void **state) { { const f_status_t status = f_file_read_until(file, 1, &buffer); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } f_string_dynamic_resize(0, &buffer); diff --git a/level_0/f_file/tests/unit/c/test-file-read_until.h b/level_0/f_file/tests/unit/c/test-file-read_until.h index c1d5c2d..ffd67be 100644 --- a/level_0/f_file/tests/unit/c/test-file-read_until.h +++ b/level_0/f_file/tests/unit/c/test-file-read_until.h @@ -25,11 +25,11 @@ extern void test__f_file_read_until__fails(void **state); extern void test__f_file_read_until__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_read_until() */ -extern void test__f_file_read_until__returns_file_closed(void **state); +extern void test__f_file_read_until__returns_file_descriptor_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-remove_at.c b/level_0/f_file/tests/unit/c/test-file-remove_at.c index edc42ae..c8bfab1 100644 --- a/level_0/f_file/tests/unit/c/test-file-remove_at.c +++ b/level_0/f_file/tests/unit/c/test-file-remove_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_remove_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -49,7 +50,7 @@ void test__f_file_remove_at__fails(void **state) { will_return(__wrap_unlinkat, true); will_return(__wrap_unlinkat, errnos[i]); - const f_status_t status = f_file_remove_at(0, path, 0); + const f_status_t status = f_file_remove_at(file, path, 0); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -58,22 +59,36 @@ void test__f_file_remove_at__fails(void **state) { void test__f_file_remove_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_remove_at(0, f_string_empty_s, 0); + const f_status_t status = f_file_remove_at(file, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_remove_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + const f_status_t status = f_file_remove_at(file, f_string_empty_s, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_remove_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { will_return(__wrap_unlinkat, false); will_return(__wrap_unlinkat, 0); - const f_status_t status = f_file_remove_at(0, path, 0); + const f_status_t status = f_file_remove_at(file, path, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-remove_at.h b/level_0/f_file/tests/unit/c/test-file-remove_at.h index 8bd5e5c..5342cdf 100644 --- a/level_0/f_file/tests/unit/c/test-file-remove_at.h +++ b/level_0/f_file/tests/unit/c/test-file-remove_at.h @@ -25,6 +25,13 @@ extern void test__f_file_remove_at__fails(void **state); extern void test__f_file_remove_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_remove_at() + */ +extern void test__f_file_remove_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_remove_at() diff --git a/level_0/f_file/tests/unit/c/test-file-rename_at.c b/level_0/f_file/tests/unit/c/test-file-rename_at.c index 9c58ac2..3a3795b 100644 --- a/level_0/f_file/tests/unit/c/test-file-rename_at.c +++ b/level_0/f_file/tests/unit/c/test-file-rename_at.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_rename_at__fails(void **state) { + const f_file_t source = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t destination = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -66,7 +68,7 @@ void test__f_file_rename_at__fails(void **state) { will_return(__wrap_renameat, errnos[i]); #endif // _f_file_rename_use_renameat2_ - const f_status_t status = f_file_rename_at(0, 0, path, path, 0); + const f_status_t status = f_file_rename_at(source, destination, path, path, 0); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -75,29 +77,55 @@ void test__f_file_rename_at__fails(void **state) { void test__f_file_rename_at__returns_data_not(void **state) { + const f_file_t source = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t destination = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, f_string_empty_s, 0); + const f_status_t status = f_file_rename_at(source, destination, f_string_empty_s, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_rename_at(0, 0, path, f_string_empty_s, 0); + const f_status_t status = f_file_rename_at(source, destination, path, f_string_empty_s, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, path, 0); + const f_status_t status = f_file_rename_at(source, destination, f_string_empty_s, path, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_rename_at__returns_file_descriptor_not(void **state) { + + f_file_t source = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + f_file_t destination = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_rename_at(source, destination, path, path, 0); + + assert_int_equal(status, F_file_descriptor_not); + } + + { + source.id = F_type_descriptor_output_d; + destination.id = -1; + + const f_status_t status = f_file_rename_at(source, destination, path, path, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_rename_at__works(void **state) { + const f_file_t source = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + const f_file_t destination = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -109,7 +137,7 @@ void test__f_file_rename_at__works(void **state) { will_return(__wrap_renameat, 0); #endif // _f_file_rename_use_renameat2_ - const f_status_t status = f_file_rename_at(0, 0, path, path, 0); + const f_status_t status = f_file_rename_at(source, destination, path, path, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-rename_at.h b/level_0/f_file/tests/unit/c/test-file-rename_at.h index bf404bb..73c1ace 100644 --- a/level_0/f_file/tests/unit/c/test-file-rename_at.h +++ b/level_0/f_file/tests/unit/c/test-file-rename_at.h @@ -25,6 +25,13 @@ extern void test__f_file_rename_at__fails(void **state); extern void test__f_file_rename_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_rename_at() + */ +extern void test__f_file_rename_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_rename_at() diff --git a/level_0/f_file/tests/unit/c/test-file-role_change_at.c b/level_0/f_file/tests/unit/c/test-file-role_change_at.c index ab69cb0..7533a8a 100644 --- a/level_0/f_file/tests/unit/c/test-file-role_change_at.c +++ b/level_0/f_file/tests/unit/c/test-file-role_change_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_role_change_at__fails_for_dereference(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -59,7 +60,7 @@ void test__f_file_role_change_at__fails_for_dereference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, 0); assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for @@ -72,7 +73,7 @@ void test__f_file_role_change_at__fails_for_dereference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, 0); assert_int_equal(F_status_set_fine(status), status_groups[i]); } // for @@ -82,7 +83,7 @@ void test__f_file_role_change_at__fails_for_dereference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, -1, 0, 0); + const f_status_t status = f_file_role_change_at(file, path, -1, 0, 0); assert_int_equal(F_status_set_fine(status), status_groups[i]); } // for @@ -92,7 +93,7 @@ void test__f_file_role_change_at__fails_for_dereference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, -1, 0); + const f_status_t status = f_file_role_change_at(file, path, 0, -1, 0); assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for @@ -100,6 +101,7 @@ void test__f_file_role_change_at__fails_for_dereference(void **state) { void test__f_file_role_change_at__fails_for_reference(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -152,7 +154,7 @@ void test__f_file_role_change_at__fails_for_reference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, F_file_at_symlink_follow_no_d); assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for @@ -165,7 +167,7 @@ void test__f_file_role_change_at__fails_for_reference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, F_file_at_symlink_follow_no_d); assert_int_equal(F_status_set_fine(status), status_groups[i]); } // for @@ -175,7 +177,7 @@ void test__f_file_role_change_at__fails_for_reference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, -1, 0, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, -1, 0, F_file_at_symlink_follow_no_d); assert_int_equal(F_status_set_fine(status), status_groups[i]); } // for @@ -185,7 +187,7 @@ void test__f_file_role_change_at__fails_for_reference(void **state) { will_return(__wrap_fchownat, true); will_return(__wrap_fchownat, errnos[i]); - const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, 0, -1, F_file_at_symlink_follow_no_d); assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for @@ -193,29 +195,43 @@ void test__f_file_role_change_at__fails_for_reference(void **state) { void test__f_file_role_change_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - const f_status_t status = f_file_role_change_at(0, f_string_empty_s, -1, -1, 0); + const f_status_t status = f_file_role_change_at(file, f_string_empty_s, -1, -1, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_role_change_at(0, path, -1, -1, 0); + const f_status_t status = f_file_role_change_at(file, path, -1, -1, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_role_change_at(0, f_string_empty_s, 0, 0, 0); + const f_status_t status = f_file_role_change_at(file, f_string_empty_s, 0, 0, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_role_change_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_role_change_at(file, path, 0, 0, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_role_change_at__works_for_dereference(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -225,7 +241,7 @@ void test__f_file_role_change_at__works_for_dereference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, 0); assert_int_equal(status, F_none); } @@ -234,7 +250,7 @@ void test__f_file_role_change_at__works_for_dereference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, -1, 0, 0); + const f_status_t status = f_file_role_change_at(file, path, -1, 0, 0); assert_int_equal(status, F_none); } @@ -243,7 +259,7 @@ void test__f_file_role_change_at__works_for_dereference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, 0, -1, 0); + const f_status_t status = f_file_role_change_at(file, path, 0, -1, 0); assert_int_equal(status, F_none); } @@ -251,6 +267,7 @@ void test__f_file_role_change_at__works_for_dereference(void **state) { void test__f_file_role_change_at__works_for_reference(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -260,7 +277,7 @@ void test__f_file_role_change_at__works_for_reference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, 0, 0, F_file_at_symlink_follow_no_d); assert_int_equal(status, F_none); } @@ -269,7 +286,7 @@ void test__f_file_role_change_at__works_for_reference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, -1, 0, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, -1, 0, F_file_at_symlink_follow_no_d); assert_int_equal(status, F_none); } @@ -278,7 +295,7 @@ void test__f_file_role_change_at__works_for_reference(void **state) { will_return(__wrap_fchownat, false); will_return(__wrap_fchownat, 0); - const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d); + const f_status_t status = f_file_role_change_at(file, path, 0, -1, F_file_at_symlink_follow_no_d); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-role_change_at.h b/level_0/f_file/tests/unit/c/test-file-role_change_at.h index b36b7df..b80c796 100644 --- a/level_0/f_file/tests/unit/c/test-file-role_change_at.h +++ b/level_0/f_file/tests/unit/c/test-file-role_change_at.h @@ -32,6 +32,13 @@ extern void test__f_file_role_change_at__fails_for_reference(void **state); extern void test__f_file_role_change_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_role_change_at() + */ +extern void test__f_file_role_change_at__returns_file_descriptor_not(void **state); + +/** * Test that function works for dereferenced files. * * @see f_file_role_change_at() diff --git a/level_0/f_file/tests/unit/c/test-file-seek.c b/level_0/f_file/tests/unit/c/test-file-seek.c index 5ce244a..5b30a84 100644 --- a/level_0/f_file/tests/unit/c/test-file-seek.c +++ b/level_0/f_file/tests/unit/c/test-file-seek.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_seek__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + int errnos[] = { EBADF, EINVAL, @@ -32,7 +34,7 @@ void test__f_file_seek__fails(void **state) { will_return(__wrap_lseek, true); will_return(__wrap_lseek, errnos[i]); - const f_status_t status = f_file_seek(0, 0, 0, &seeked); + const f_status_t status = f_file_seek(file, 0, 0, &seeked); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -40,36 +42,52 @@ void test__f_file_seek__fails(void **state) { void test__f_file_seek__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); off_t seeked = 0; { - const f_status_t status = f_file_seek(0, -1, 0, 0); + const f_status_t status = f_file_seek(file, -1, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } { - const f_status_t status = f_file_seek(0, -1, 0, &seeked); + const f_status_t status = f_file_seek(file, -1, 0, &seeked); assert_int_equal(status, F_status_set_error(F_parameter)); } { - const f_status_t status = f_file_seek(0, 0, 0, 0); + const f_status_t status = f_file_seek(file, 0, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } +void test__f_file_seek__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + off_t seeked = 0; + + const f_status_t status = f_file_seek(file, 0, 0, &seeked); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_seek__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { off_t seeked = 0; will_return(__wrap_lseek, false); will_return(__wrap_lseek, 0); - const f_status_t status = f_file_seek(0, 0, 0, &seeked); + const f_status_t status = f_file_seek(file, 0, 0, &seeked); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-seek.h b/level_0/f_file/tests/unit/c/test-file-seek.h index 38f2c5f..c753c85 100644 --- a/level_0/f_file/tests/unit/c/test-file-seek.h +++ b/level_0/f_file/tests/unit/c/test-file-seek.h @@ -25,6 +25,13 @@ extern void test__f_file_seek__fails(void **state); extern void test__f_file_seek__parameter_checking(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_seek() + */ +extern void test__f_file_seek__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_seek() diff --git a/level_0/f_file/tests/unit/c/test-file-size_at.c b/level_0/f_file/tests/unit/c/test-file-size_at.c index c402e4c..d3de248 100644 --- a/level_0/f_file/tests/unit/c/test-file-size_at.c +++ b/level_0/f_file/tests/unit/c/test-file-size_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_size_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -44,7 +45,7 @@ void test__f_file_size_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_size_at(0, path, F_false, &size); + const f_status_t status = f_file_size_at(file, path, F_false, &size); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -52,8 +53,10 @@ void test__f_file_size_at__fails(void **state) { void test__f_file_size_at__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, 0); + const f_status_t status = f_file_size_at(file, f_string_empty_s, F_false, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -61,17 +64,33 @@ void test__f_file_size_at__parameter_checking(void **state) { void test__f_file_size_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { off_t size = 0; - const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, &size); + const f_status_t status = f_file_size_at(file, f_string_empty_s, F_false, &size); assert_int_equal(status, F_data_not); } } +void test__f_file_size_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + off_t size = 0; + + const f_status_t status = f_file_size_at(file, f_string_empty_s, F_false, &size); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_size_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; @@ -88,7 +107,7 @@ void test__f_file_size_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_size_at(0, path, F_false, &size); + const f_status_t status = f_file_size_at(file, path, F_false, &size); assert_int_equal(status, F_none); assert_int_equal(size, statistics.st_size); @@ -104,7 +123,7 @@ void test__f_file_size_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_size_at(0, path, F_true, &size); + const f_status_t status = f_file_size_at(file, path, F_true, &size); assert_int_equal(status, F_none); assert_int_equal(size, statistics.st_size); diff --git a/level_0/f_file/tests/unit/c/test-file-size_at.h b/level_0/f_file/tests/unit/c/test-file-size_at.h index a09a891..3bb4e3e 100644 --- a/level_0/f_file/tests/unit/c/test-file-size_at.h +++ b/level_0/f_file/tests/unit/c/test-file-size_at.h @@ -32,6 +32,13 @@ extern void test__f_file_size_at__parameter_checking(void **state); extern void test__f_file_size_at__returns_data_not(void **state); /** + * Test that function works but the path is empty. + * + * @see f_file_size_at() + */ +extern void test__f_file_size_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_size_at() diff --git a/level_0/f_file/tests/unit/c/test-file-size_by_id.c b/level_0/f_file/tests/unit/c/test-file-size_by_id.c index ceb8f20..fc82716 100644 --- a/level_0/f_file/tests/unit/c/test-file-size_by_id.c +++ b/level_0/f_file/tests/unit/c/test-file-size_by_id.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_size_by_id__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + int errnos[] = { EACCES, EBADF, @@ -42,7 +44,7 @@ void test__f_file_size_by_id__fails(void **state) { will_return(__wrap_fstat, true); will_return(__wrap_fstat, errnos[i]); - const f_status_t status = f_file_size_by_id(0, &size); + const f_status_t status = f_file_size_by_id(file, &size); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -50,26 +52,32 @@ void test__f_file_size_by_id__fails(void **state) { void test__f_file_size_by_id__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_size_by_id(0, 0); + const f_status_t status = f_file_size_by_id(file, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_file_size_by_id__returns_file_closed(void **state) { +void test__f_file_size_by_id__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); { off_t size = 0; - const f_status_t status = f_file_size_by_id(-1, &size); + const f_status_t status = f_file_size_by_id(file, &size); - assert_int_equal(F_status_set_fine(status), F_file_closed); - } // for + assert_int_equal(status, F_file_descriptor_not); + } } void test__f_file_size_by_id__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + struct stat statistics; memset(&statistics, 0, sizeof(struct stat)); @@ -84,7 +92,7 @@ void test__f_file_size_by_id__works(void **state) { will_return(__wrap_fstat, &statistics); will_return(__wrap_fstat, 0); - const f_status_t status = f_file_size_by_id(0, &size); + const f_status_t status = f_file_size_by_id(file, &size); assert_int_equal(status, F_none); assert_int_equal(size, statistics.st_size); diff --git a/level_0/f_file/tests/unit/c/test-file-size_by_id.h b/level_0/f_file/tests/unit/c/test-file-size_by_id.h index f5d42ab..9b96834 100644 --- a/level_0/f_file/tests/unit/c/test-file-size_by_id.h +++ b/level_0/f_file/tests/unit/c/test-file-size_by_id.h @@ -25,11 +25,11 @@ extern void test__f_file_size_by_id__fails(void **state); extern void test__f_file_size_by_id__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the path is empty. * * @see f_file_size_by_id() */ -extern void test__f_file_size_by_id__returns_file_closed(void **state); +extern void test__f_file_size_by_id__returns_file_descriptor_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stat_at.c b/level_0/f_file/tests/unit/c/test-file-stat_at.c index 284ff71..adedf8c 100644 --- a/level_0/f_file/tests/unit/c/test-file-stat_at.c +++ b/level_0/f_file/tests/unit/c/test-file-stat_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_stat_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -46,7 +47,7 @@ void test__f_file_stat_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_stat_at(0, path, F_false, &result); + const f_status_t status = f_file_stat_at(file, path, F_false, &result); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -54,8 +55,10 @@ void test__f_file_stat_at__fails(void **state) { void test__f_file_stat_at__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, 0); + const f_status_t status = f_file_stat_at(file, f_string_empty_s, F_false, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -63,19 +66,37 @@ void test__f_file_stat_at__parameter_checking(void **state) { void test__f_file_stat_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { struct stat result; memset(&result, 0, sizeof(struct stat)); - const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, &result); + const f_status_t status = f_file_stat_at(file, f_string_empty_s, F_false, &result); assert_int_equal(status, F_data_not); } } +void test__f_file_stat_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + const f_status_t status = f_file_stat_at(file, f_string_empty_s, F_false, &result); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_stat_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; @@ -94,7 +115,7 @@ void test__f_file_stat_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_stat_at(0, path, F_false, &result); + const f_status_t status = f_file_stat_at(file, path, F_false, &result); assert_int_equal(status, F_none); assert_int_equal(result.st_mode, statistics.st_mode); @@ -113,7 +134,7 @@ void test__f_file_stat_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_stat_at(0, path, F_true, &result); + const f_status_t status = f_file_stat_at(file, path, F_true, &result); assert_int_equal(status, F_none); assert_int_equal(result.st_mode, statistics.st_mode); diff --git a/level_0/f_file/tests/unit/c/test-file-stat_at.h b/level_0/f_file/tests/unit/c/test-file-stat_at.h index 91b5abf..3ac21b1 100644 --- a/level_0/f_file/tests/unit/c/test-file-stat_at.h +++ b/level_0/f_file/tests/unit/c/test-file-stat_at.h @@ -32,6 +32,13 @@ extern void test__f_file_stat_at__parameter_checking(void **state); extern void test__f_file_stat_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_stat_at() + */ +extern void test__f_file_stat_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_stat_at() diff --git a/level_0/f_file/tests/unit/c/test-file-stat_by_id.c b/level_0/f_file/tests/unit/c/test-file-stat_by_id.c index 7282fa0..b4a2c14 100644 --- a/level_0/f_file/tests/unit/c/test-file-stat_by_id.c +++ b/level_0/f_file/tests/unit/c/test-file-stat_by_id.c @@ -7,6 +7,8 @@ extern "C" { void test__f_file_stat_by_id__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + int errnos[] = { EACCES, EBADF, @@ -44,7 +46,7 @@ void test__f_file_stat_by_id__fails(void **state) { will_return(__wrap_fstat, true); will_return(__wrap_fstat, errnos[i]); - const f_status_t status = f_file_stat_by_id(0, &result); + const f_status_t status = f_file_stat_by_id(file, &result); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -52,28 +54,34 @@ void test__f_file_stat_by_id__fails(void **state) { void test__f_file_stat_by_id__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_stat_by_id(0, 0); + const f_status_t status = f_file_stat_by_id(file, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_file_stat_by_id__returns_file_closed(void **state) { +void test__f_file_stat_by_id__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); { struct stat result; memset(&result, 0, sizeof(struct stat)); - const f_status_t status = f_file_stat_by_id(-1, &result); + const f_status_t status = f_file_stat_by_id(file, &result); - assert_int_equal(F_status_set_fine(status), F_file_closed); - } // for + assert_int_equal(status, F_file_descriptor_not); + } } void test__f_file_stat_by_id__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + struct stat statistics; memset(&statistics, 0, sizeof(struct stat)); @@ -90,7 +98,7 @@ void test__f_file_stat_by_id__works(void **state) { will_return(__wrap_fstat, &statistics); will_return(__wrap_fstat, 0); - const f_status_t status = f_file_stat_by_id(0, &result); + const f_status_t status = f_file_stat_by_id(file, &result); assert_int_equal(status, F_none); assert_int_equal(result.st_mode, statistics.st_mode); diff --git a/level_0/f_file/tests/unit/c/test-file-stat_by_id.h b/level_0/f_file/tests/unit/c/test-file-stat_by_id.h index 63ffcdd..5e4cf72 100644 --- a/level_0/f_file/tests/unit/c/test-file-stat_by_id.h +++ b/level_0/f_file/tests/unit/c/test-file-stat_by_id.h @@ -25,11 +25,11 @@ extern void test__f_file_stat_by_id__fails(void **state); extern void test__f_file_stat_by_id__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_stat_by_id() */ -extern void test__f_file_stat_by_id__returns_file_closed(void **state); +extern void test__f_file_stat_by_id__returns_file_descriptor_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_close.c b/level_0/f_file/tests/unit/c/test-file-stream_close.c index 26404fc..46fd3b7 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_close.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_close.c @@ -5,72 +5,7 @@ extern "C" { #endif -void test__f_file_stream_close__fails_for_file_descriptor(void **state) { - - int errno_flushs[] = { - EBADF, - EDQUOT, - EINVAL, - EIO, - ENOSPC, - EROFS, - }; - - int errno_closes[] = { - EBADF, - EDQUOT, - EINTR, - EIO, - ENOSPC, - mock_errno_generic, - }; - - f_status_t status_closes[] = { - F_file_descriptor, - F_filesystem_quota_block, - F_interrupt, - F_input_output, - F_space_not, - F_file_close, - }; - - for (uint8_t flush = 0; flush < 2; ++flush) { - - for (int i = 0; i < 6; ++i) { - - f_file_t file = f_file_t_initialize; - file.id = 0; - file.stream = 0; - - if (flush) { - if (flush == 1) { - will_return(__wrap_fsync, true); - will_return(__wrap_fsync, errno_flushs[i]); - } - else { - will_return(__wrap_fsync, false); - will_return(__wrap_fsync, 0); - } - - will_return(__wrap_close, true); - will_return(__wrap_close, errno_closes[i]); - } - else { - will_return(__wrap_close, true); - will_return(__wrap_close, errno_closes[i]); - } - - const f_status_t status = f_file_stream_close(flush, &file); - - assert_int_equal(F_status_set_fine(status), status_closes[i]); - - assert_int_equal(file.id, -1); - assert_int_equal(file.stream, 0); - } // for - } // for -} - -void test__f_file_stream_close__fails_for_stream(void **state) { +void test__f_file_stream_close__fails(void **state) { int errnos[] = { EACCES, @@ -116,119 +51,54 @@ void test__f_file_stream_close__fails_for_stream(void **state) { F_file_close, }; - for (uint8_t flush = 0; flush < 2; ++flush) { - - for (int i = 0; i < 19; ++i) { - - f_file_t file = f_file_t_initialize; - file.id = 0; - file.stream = F_type_input_d; - - if (flush) { - if (flush == 1) { - will_return(__wrap_fflush, true); - will_return(__wrap_fflush, errnos[i]); - } - else { - will_return(__wrap_fflush, false); - will_return(__wrap_fflush, 0); - } - - will_return(__wrap_fclose, true); - will_return(__wrap_fclose, errnos[i]); - } - else { - will_return(__wrap_fclose, true); - will_return(__wrap_fclose, errnos[i]); - } - - const f_status_t status = f_file_stream_close(flush, &file); - - assert_int_equal(F_status_set_fine(status), status_closes[i]); - assert_int_equal(file.id, -1); - assert_int_equal(file.stream, 0); - } // for + for (int i = 0; i < 19; ++i) { + + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + + will_return(__wrap_fclose, true); + will_return(__wrap_fclose, errnos[i]); + + const f_status_t status = f_file_stream_close(&file); + + assert_int_equal(F_status_set_fine(status), status_closes[i]); + assert_int_equal(file.stream, 0); } // for } void test__f_file_stream_close__parameter_checking(void **state) { { - const f_status_t status = f_file_stream_close(F_false, 0); + const f_status_t status = f_file_stream_close(0); assert_int_equal(status, F_status_set_error(F_parameter)); } } -void test__f_file_stream_close__works(void **state) { - - { - f_file_t file = f_file_t_initialize; - - file.id = 0; - file.stream = F_type_input_d; - - will_return(__wrap_fclose, false); - will_return(__wrap_fclose, 0); +void test__f_file_stream_close__returns_stream_not(void **state) { - const f_status_t status = f_file_stream_close(F_false, &file); - - assert_int_equal(status, F_none); - assert_int_equal(file.id, -1); - assert_int_equal(file.stream, 0); - } + f_file_t file = macro_f_file_t_initialize2(0, F_type_descriptor_output_d, F_file_flag_write_only_d); { - f_file_t file = f_file_t_initialize; - - file.id = 0; - file.stream = 0; - - will_return(__wrap_close, false); - will_return(__wrap_close, 0); + const f_status_t status = f_file_stream_close(&file); - const f_status_t status = f_file_stream_close(F_false, &file); - - assert_int_equal(status, F_none); - assert_int_equal(file.id, -1); - assert_int_equal(file.stream, 0); + assert_int_equal(status, F_stream_not); } +} + +void test__f_file_stream_close__works(void **state) { { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.id = 0; file.stream = F_type_input_d; - will_return(__wrap_fflush, false); - will_return(__wrap_fflush, 0); - will_return(__wrap_fclose, false); will_return(__wrap_fclose, 0); - const f_status_t status = f_file_stream_close(F_true, &file); - - assert_int_equal(status, F_none); - assert_int_equal(file.id, -1); - assert_int_equal(file.stream, 0); - } - - { - f_file_t file = f_file_t_initialize; - - file.id = 0; - file.stream = 0; - - will_return(__wrap_fsync, false); - will_return(__wrap_fsync, 0); - - will_return(__wrap_close, false); - will_return(__wrap_close, 0); - - const f_status_t status = f_file_stream_close(F_true, &file); + const f_status_t status = f_file_stream_close(&file); assert_int_equal(status, F_none); - assert_int_equal(file.id, -1); assert_int_equal(file.stream, 0); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_close.h b/level_0/f_file/tests/unit/c/test-file-stream_close.h index ebd4cfd..1600b38 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_close.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_close.h @@ -11,25 +11,25 @@ #define _TEST__F_file_stream_close_h /** - * Test that function fails for a file using the file descriptor. + * Test that function fails. * * @see f_file_stream_close() */ -extern void test__f_file_stream_close__fails_for_file_descriptor(void **state); +extern void test__f_file_stream_close__fails(void **state); /** - * Test that function fails for a file stream. + * Test that parameter checking works as expected. * * @see f_file_stream_close() */ -extern void test__f_file_stream_close__fails_for_stream(void **state); +extern void test__f_file_stream_close__parameter_checking(void **state); /** - * Test that parameter checking works as expected. + * Test that function works but the stream is not valid. * * @see f_file_stream_close() */ -extern void test__f_file_stream_close__parameter_checking(void **state); +extern void test__f_file_stream_close__returns_stream_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_open.c b/level_0/f_file/tests/unit/c/test-file-stream_open.c index 284f6c2..822ec03 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_open.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_open.c @@ -107,7 +107,6 @@ void test__f_file_stream_open__returns_data_not(void **state) { void test__f_file_stream_open__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - const int id = 1; { f_file_t file = f_file_t_initialize; @@ -115,8 +114,6 @@ void test__f_file_stream_open__works(void **state) { will_return(__wrap_fopen, false); will_return(__wrap_fopen, F_type_output_d); - will_return(__wrap_fileno, id); - const f_status_t status = f_file_stream_open(path, path, &file); assert_int_equal(status, F_none); @@ -129,8 +126,6 @@ void test__f_file_stream_open__works(void **state) { will_return(__wrap_fopen, false); will_return(__wrap_fopen, F_type_output_d); - will_return(__wrap_fileno, id); - const f_status_t status = f_file_stream_open(path, f_string_empty_s, &file); assert_int_equal(status, F_none); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read.c b/level_0/f_file/tests/unit/c/test-file-stream_read.c index 72739ba..887a730 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read.c @@ -54,7 +54,7 @@ void test__f_file_stream_read__parameter_checking(void **state) { } } -void test__f_file_stream_read__returns_file_closed(void **state) { +void test__f_file_stream_read__returns_stream_not(void **state) { const f_file_t file = f_file_t_initialize; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; @@ -62,7 +62,7 @@ void test__f_file_stream_read__returns_file_closed(void **state) { { const f_status_t status = f_file_stream_read(file, &buffer); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } f_string_dynamic_resize(0, &buffer); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read.h b/level_0/f_file/tests/unit/c/test-file-stream_read.h index 2db6c2d..fa0a490 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_read.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_read__fails(void **state); extern void test__f_file_stream_read__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_read() */ -extern void test__f_file_stream_read__returns_file_closed(void **state); +extern void test__f_file_stream_read__returns_stream_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c index d974c81..17c1cdf 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c @@ -54,7 +54,7 @@ void test__f_file_stream_read_block__parameter_checking(void **state) { } } -void test__f_file_stream_read_block__returns_file_closed(void **state) { +void test__f_file_stream_read_block__returns_stream_not(void **state) { const f_file_t file = f_file_t_initialize; @@ -63,7 +63,7 @@ void test__f_file_stream_read_block__returns_file_closed(void **state) { const f_status_t status = f_file_stream_read_block(file, &string); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_block.h b/level_0/f_file/tests/unit/c/test-file-stream_read_block.h index f80d256..4a599b7 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_block.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_block.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_read_block__fails(void **state); extern void test__f_file_stream_read_block__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_read_block() */ -extern void test__f_file_stream_read_block__returns_file_closed(void **state); +extern void test__f_file_stream_read_block__returns_stream_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c index 4b0e0c7..ccab7b5 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c @@ -54,7 +54,7 @@ void test__f_file_stream_read_until__parameter_checking(void **state) { } } -void test__f_file_stream_read_until__returns_file_closed(void **state) { +void test__f_file_stream_read_until__returns_stream_not(void **state) { f_file_t file = f_file_t_initialize; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; @@ -64,7 +64,7 @@ void test__f_file_stream_read_until__returns_file_closed(void **state) { { const f_status_t status = f_file_stream_read_until(file, 0, &buffer); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } f_string_dynamic_resize(0, &buffer); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_until.h b/level_0/f_file/tests/unit/c/test-file-stream_read_until.h index 550b73b..ae8a4b7 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_until.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_until.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_read_until__fails(void **state); extern void test__f_file_stream_read_until__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_read_until() */ -extern void test__f_file_stream_read_until__returns_file_closed(void **state); +extern void test__f_file_stream_read_until__returns_stream_not(void **state); /** * Test that function works. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c index e0645fc..41c46e0 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c @@ -101,7 +101,6 @@ void test__f_file_stream_reopen__returns_data_not(void **state) { void test__f_file_stream_reopen__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - const int id = 1; { f_file_t file = f_file_t_initialize; @@ -110,8 +109,6 @@ void test__f_file_stream_reopen__works(void **state) { will_return(__wrap_freopen, false); will_return(__wrap_freopen, F_type_input_d); - will_return(__wrap_fileno, id); - const f_status_t status = f_file_stream_reopen(path, path, &file); assert_int_equal(status, F_none); @@ -124,8 +121,6 @@ void test__f_file_stream_reopen__works(void **state) { will_return(__wrap_freopen, false); will_return(__wrap_freopen, F_type_input_d); - will_return(__wrap_fileno, id); - const f_status_t status = f_file_stream_reopen(path, f_string_empty_s, &file); assert_int_equal(status, F_none); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write.c b/level_0/f_file/tests/unit/c/test-file-stream_write.c index 7046bb1..3a6fd0c 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write.c @@ -10,13 +10,11 @@ void test__f_file_stream_write__fails(void **state) { const f_string_static_t test = macro_f_string_static_t_initialize("test", 0, 4); { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_read = 1; - file.stream = F_type_input_d; + file.size_write = 1; - will_return(__wrap_fwrite_unlocked, true); - will_return(__wrap_fwrite_unlocked, 0); - will_return(__wrap_ferror_unlocked, true); + will_return(__wrap_write, 0); const f_status_t status = f_file_stream_write(file, test, 0); @@ -26,7 +24,7 @@ void test__f_file_stream_write__fails(void **state) { void test__f_file_stream_write__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -36,21 +34,20 @@ void test__f_file_stream_write__parameter_checking(void **state) { } } -void test__f_file_stream_write__returns_file_closed(void **state) { +void test__f_file_stream_write__returns_stream_not(void **state) { const f_file_t file = f_file_t_initialize; { const f_status_t status = f_file_stream_write(file, f_string_empty_s, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } } void test__f_file_stream_write__returns_data_not(void **state) { - f_file_t file = f_file_t_initialize; - file.stream = F_type_input_d; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { const f_status_t status = f_file_stream_write(file, f_string_empty_s, 0); @@ -73,9 +70,8 @@ void test__f_file_stream_write__works(void **state) { const f_string_static_t test = macro_f_string_static_t_initialize("test", 0, 4); { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = test.used; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, test.used); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write.h b/level_0/f_file/tests/unit/c/test-file-stream_write.h index b1c9680..0452a44 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_write.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_write__fails(void **state); extern void test__f_file_stream_write__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_write() */ -extern void test__f_file_stream_write__returns_file_closed(void **state); +extern void test__f_file_stream_write__returns_stream_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c index c98e6d6..0329baa 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c @@ -27,7 +27,7 @@ void test__f_file_stream_write_block__fails(void **state) { void test__f_file_stream_write_block__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -37,21 +37,20 @@ void test__f_file_stream_write_block__parameter_checking(void **state) { } } -void test__f_file_stream_write_block__returns_file_closed(void **state) { +void test__f_file_stream_write_block__returns_stream_not(void **state) { const f_file_t file = f_file_t_initialize; { const f_status_t status = f_file_stream_write_block(file, f_string_empty_s, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } } void test__f_file_stream_write_block__returns_data_not(void **state) { - f_file_t file = f_file_t_initialize; - file.stream = F_type_input_d; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { const f_status_t status = f_file_stream_write_block(file, f_string_empty_s, 0); @@ -76,9 +75,8 @@ void test__f_file_stream_write_block__works(void **state) { { f_array_length_t written = 0; - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 1; - file.stream = F_type_input_d; // The letter 't'. will_return(__wrap_fwrite_unlocked, false); @@ -122,9 +120,8 @@ void test__f_file_stream_write_block__works(void **state) { } { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = test.used; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, test.used); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_block.h b/level_0/f_file/tests/unit/c/test-file-stream_write_block.h index 7b56052..f5f02ec 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_block.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_block.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_write_block__fails(void **state); extern void test__f_file_stream_write_block__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_write_block() */ -extern void test__f_file_stream_write_block__returns_file_closed(void **state); +extern void test__f_file_stream_write_block__returns_stream_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c index 582d554..f13990b 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c @@ -11,10 +11,8 @@ void test__f_file_stream_write_range__fails(void **state) { const f_string_range_t range = macro_f_string_range_t_initialize(0, 0); { - - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_read = 1; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); @@ -28,7 +26,7 @@ void test__f_file_stream_write_range__fails(void **state) { void test__f_file_stream_write_range__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; const f_string_range_t range = f_string_range_t_initialize; @@ -40,7 +38,7 @@ void test__f_file_stream_write_range__parameter_checking(void **state) { } } -void test__f_file_stream_write_range__returns_file_closed(void **state) { +void test__f_file_stream_write_range__returns_stream_not(void **state) { const f_file_t file = f_file_t_initialize; const f_string_range_t range = f_string_range_t_initialize; @@ -48,14 +46,13 @@ void test__f_file_stream_write_range__returns_file_closed(void **state) { { const f_status_t status = f_file_stream_write_range(file, f_string_empty_s, range, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } } void test__f_file_stream_write_range__returns_data_not(void **state) { - f_file_t file = f_file_t_initialize; - file.stream = F_type_input_d; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { const f_string_range_t range = f_string_range_t_initialize; @@ -123,9 +120,8 @@ void test__f_file_stream_write_range__works(void **state) { const f_string_range_t range = macro_f_string_range_t_initialize(0, 0); { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 1; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, 1); @@ -137,9 +133,8 @@ void test__f_file_stream_write_range__works(void **state) { } { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = test.used; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, test.used); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_range.h b/level_0/f_file/tests/unit/c/test-file-stream_write_range.h index e19361f..496a2cd 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_range.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_range.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_write_range__fails(void **state); extern void test__f_file_stream_write_range__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_write_range() */ -extern void test__f_file_stream_write_range__returns_file_closed(void **state); +extern void test__f_file_stream_write_range__returns_stream_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c index 0bf8e2d..7e7b88a 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c @@ -10,10 +10,8 @@ void test__f_file_stream_write_until__fails(void **state) { const f_string_static_t test = macro_f_string_static_t_initialize("test", 0, 4); { - - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_read = 1; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); @@ -27,7 +25,7 @@ void test__f_file_stream_write_until__fails(void **state) { void test__f_file_stream_write_until__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -37,7 +35,7 @@ void test__f_file_stream_write_until__parameter_checking(void **state) { } } -void test__f_file_stream_write_until__returns_file_closed(void **state) { +void test__f_file_stream_write_until__returns_stream_not(void **state) { f_file_t file = f_file_t_initialize; file.stream = 0; @@ -45,7 +43,7 @@ void test__f_file_stream_write_until__returns_file_closed(void **state) { { const f_status_t status = f_file_stream_write_until(file, f_string_empty_s, 0, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_stream_not); } } @@ -53,8 +51,7 @@ void test__f_file_stream_write_until__returns_data_not(void **state) { const f_string_static_t test = macro_f_string_static_t_initialize("test", 0, 4); - f_file_t file = f_file_t_initialize; - file.stream = F_type_input_d; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { const f_status_t status = f_file_stream_write_until(file, f_string_empty_s, 0, 0); @@ -107,9 +104,8 @@ void test__f_file_stream_write_until__works(void **state) { const f_string_static_t test = macro_f_string_static_t_initialize("test", 0, 4); { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 1; - file.stream = F_type_input_d; // The letter 't'. will_return(__wrap_fwrite_unlocked, false); @@ -137,9 +133,8 @@ void test__f_file_stream_write_until__works(void **state) { } { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = test.used; - file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, test.used); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_until.h b/level_0/f_file/tests/unit/c/test-file-stream_write_until.h index 86c441b..13a91fc 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_until.h +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_until.h @@ -25,11 +25,11 @@ extern void test__f_file_stream_write_until__fails(void **state); extern void test__f_file_stream_write_until__parameter_checking(void **state); /** - * Test that function works but the file stream is closed. + * Test that function works but the stream is not valid. * * @see f_file_stream_write_until() */ -extern void test__f_file_stream_write_until__returns_file_closed(void **state); +extern void test__f_file_stream_write_until__returns_stream_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-touch_at.c b/level_0/f_file/tests/unit/c/test-file-touch_at.c index 2e3b72c..7749294 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch_at.c +++ b/level_0/f_file/tests/unit/c/test-file-touch_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_touch_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const mode_t mode = 0; @@ -55,7 +56,7 @@ void test__f_file_touch_at__fails(void **state) { will_return(__wrap_close, 0); } - const f_status_t status = f_file_touch_at(1, path, mode, 0); + const f_status_t status = f_file_touch_at(file, path, mode, 0); if (statuss[i] == F_file_found_not) { assert_int_equal(status, F_none); @@ -112,7 +113,7 @@ void test__f_file_touch_at__fails(void **state) { will_return(__wrap_utimensat, true); will_return(__wrap_utimensat, errnos[i]); - const f_status_t status = f_file_touch_at(1, path, mode, 0); + const f_status_t status = f_file_touch_at(file, path, mode, 0); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -121,17 +122,31 @@ void test__f_file_touch_at__fails(void **state) { void test__f_file_touch_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const mode_t mode = 0; { - const f_status_t status = f_file_touch_at(1, f_string_empty_s, mode, 0); + const f_status_t status = f_file_touch_at(file, f_string_empty_s, mode, 0); assert_int_equal(status, F_data_not); } } +void test__f_file_touch_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + const mode_t mode = 0; + + { + const f_status_t status = f_file_touch_at(file, f_string_empty_s, mode, 0); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_touch_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const mode_t mode = 0; @@ -149,7 +164,7 @@ void test__f_file_touch_at__works(void **state) { will_return(__wrap_utimensat, false); will_return(__wrap_utimensat, 0); - const f_status_t status = f_file_touch_at(1, path, mode, 0); + const f_status_t status = f_file_touch_at(file, path, mode, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-touch_at.h b/level_0/f_file/tests/unit/c/test-file-touch_at.h index 2afd9b0..e77b0eb 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch_at.h +++ b/level_0/f_file/tests/unit/c/test-file-touch_at.h @@ -25,6 +25,13 @@ extern void test__f_file_touch_at__fails(void **state); extern void test__f_file_touch_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_touch_at() + */ +extern void test__f_file_touch_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_touch_at() diff --git a/level_0/f_file/tests/unit/c/test-file-type_at.c b/level_0/f_file/tests/unit/c/test-file-type_at.c index 92d11a0..b53671c 100644 --- a/level_0/f_file/tests/unit/c/test-file-type_at.c +++ b/level_0/f_file/tests/unit/c/test-file-type_at.c @@ -7,6 +7,7 @@ extern "C" { void test__f_file_type_at__fails(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -42,7 +43,7 @@ void test__f_file_type_at__fails(void **state) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_type_at(0, path, 0, &mode); + const f_status_t status = f_file_type_at(file, path, 0, &mode); assert_int_equal(status, F_status_set_error(statuss[i])); } // for @@ -50,8 +51,10 @@ void test__f_file_type_at__fails(void **state) { void test__f_file_type_at__parameter_checking(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { - const f_status_t status = f_file_type_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_type_at(file, f_string_empty_s, 0, 0); assert_int_equal(status, F_status_set_error(F_parameter)); } @@ -59,17 +62,33 @@ void test__f_file_type_at__parameter_checking(void **state) { void test__f_file_type_at__returns_data_not(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); + { int type = 0; - const f_status_t status = f_file_type_at(0, f_string_empty_s, 0, &type); + const f_status_t status = f_file_type_at(file, f_string_empty_s, 0, &type); assert_int_equal(status, F_data_not); } } +void test__f_file_type_at__returns_file_descriptor_not(void **state) { + + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, -1, F_file_flag_write_only_d); + + { + int type = 0; + + const f_status_t status = f_file_type_at(file, f_string_empty_s, 0, &type); + + assert_int_equal(status, F_file_descriptor_not); + } +} + void test__f_file_type_at__works(void **state) { + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -85,7 +104,7 @@ void test__f_file_type_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_type_at(0, path, 0, &type); + const f_status_t status = f_file_type_at(file, path, 0, &type); assert_int_equal(status, F_none); assert_int_equal(type, F_file_type_link_d); @@ -104,7 +123,7 @@ void test__f_file_type_at__works(void **state) { will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_type_at(0, path, 0, &type); + const f_status_t status = f_file_type_at(file, path, 0, &type); assert_int_equal(status, F_none); assert_int_equal(type, F_file_type_regular_d); diff --git a/level_0/f_file/tests/unit/c/test-file-type_at.h b/level_0/f_file/tests/unit/c/test-file-type_at.h index d66f850..830e631 100644 --- a/level_0/f_file/tests/unit/c/test-file-type_at.h +++ b/level_0/f_file/tests/unit/c/test-file-type_at.h @@ -32,6 +32,13 @@ extern void test__f_file_type_at__parameter_checking(void **state); extern void test__f_file_type_at__returns_data_not(void **state); /** + * Test that function works but the descriptor is not valid. + * + * @see f_file_type_at() + */ +extern void test__f_file_type_at__returns_file_descriptor_not(void **state); + +/** * Test that function works. * * @see f_file_type_at() diff --git a/level_0/f_file/tests/unit/c/test-file-write.c b/level_0/f_file/tests/unit/c/test-file-write.c index 3393cbc..02c62ed 100644 --- a/level_0/f_file/tests/unit/c/test-file-write.c +++ b/level_0/f_file/tests/unit/c/test-file-write.c @@ -67,7 +67,7 @@ void test__f_file_write__fails(void **state) { void test__f_file_write__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -77,14 +77,14 @@ void test__f_file_write__parameter_checking(void **state) { } } -void test__f_file_write__returns_file_closed(void **state) { +void test__f_file_write__returns_file_descriptor_not(void **state) { const f_file_t file = f_file_t_initialize; { const f_status_t status = f_file_write(file, f_string_empty_s, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } } diff --git a/level_0/f_file/tests/unit/c/test-file-write.h b/level_0/f_file/tests/unit/c/test-file-write.h index 22098fb..f009664 100644 --- a/level_0/f_file/tests/unit/c/test-file-write.h +++ b/level_0/f_file/tests/unit/c/test-file-write.h @@ -25,11 +25,11 @@ extern void test__f_file_write__fails(void **state); extern void test__f_file_write__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_write() */ -extern void test__f_file_write__returns_file_closed(void **state); +extern void test__f_file_write__returns_file_descriptor_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-write_block.c b/level_0/f_file/tests/unit/c/test-file-write_block.c index 1db4be2..b63f9ee 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_block.c +++ b/level_0/f_file/tests/unit/c/test-file-write_block.c @@ -50,7 +50,7 @@ void test__f_file_write_block__fails(void **state) { void test__f_file_write_block__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -60,7 +60,7 @@ void test__f_file_write_block__parameter_checking(void **state) { } } -void test__f_file_write_block__returns_file_closed(void **state) { +void test__f_file_write_block__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; file.size_write = 1; @@ -68,7 +68,7 @@ void test__f_file_write_block__returns_file_closed(void **state) { { const f_status_t status = f_file_write_block(file, f_string_empty_s, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } } diff --git a/level_0/f_file/tests/unit/c/test-file-write_block.h b/level_0/f_file/tests/unit/c/test-file-write_block.h index b8f66fb..157d752 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_block.h +++ b/level_0/f_file/tests/unit/c/test-file-write_block.h @@ -25,11 +25,11 @@ extern void test__f_file_write_block__fails(void **state); extern void test__f_file_write_block__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_write_block() */ -extern void test__f_file_write_block__returns_file_closed(void **state); +extern void test__f_file_write_block__returns_file_descriptor_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-write_range.c b/level_0/f_file/tests/unit/c/test-file-write_range.c index be95933..e601f6e 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_range.c +++ b/level_0/f_file/tests/unit/c/test-file-write_range.c @@ -51,7 +51,7 @@ void test__f_file_write_range__fails(void **state) { void test__f_file_write_range__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; const f_string_range_t range = f_string_range_t_initialize; @@ -63,7 +63,7 @@ void test__f_file_write_range__parameter_checking(void **state) { } } -void test__f_file_write_range__returns_file_closed(void **state) { +void test__f_file_write_range__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; const f_string_range_t range = f_string_range_t_initialize; @@ -73,14 +73,13 @@ void test__f_file_write_range__returns_file_closed(void **state) { { const f_status_t status = f_file_write_range(file, f_string_empty_s, range, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } } void test__f_file_write_range__returns_data_not(void **state) { - f_file_t file = f_file_t_initialize; - file.id = 0; + const f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); { const f_string_range_t range = f_string_range_t_initialize; diff --git a/level_0/f_file/tests/unit/c/test-file-write_range.h b/level_0/f_file/tests/unit/c/test-file-write_range.h index c74b496..ae91218 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_range.h +++ b/level_0/f_file/tests/unit/c/test-file-write_range.h @@ -25,11 +25,11 @@ extern void test__f_file_write_range__fails(void **state); extern void test__f_file_write_range__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_write_range() */ -extern void test__f_file_write_range__returns_file_closed(void **state); +extern void test__f_file_write_range__returns_file_descriptor_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file-write_until.c b/level_0/f_file/tests/unit/c/test-file-write_until.c index 771b7c2..51c2c0b 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_until.c +++ b/level_0/f_file/tests/unit/c/test-file-write_until.c @@ -50,7 +50,7 @@ void test__f_file_write_until__fails(void **state) { void test__f_file_write_until__parameter_checking(void **state) { - f_file_t file = f_file_t_initialize; + f_file_t file = macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d); file.size_write = 0; { @@ -60,7 +60,7 @@ void test__f_file_write_until__parameter_checking(void **state) { } } -void test__f_file_write_until__returns_file_closed(void **state) { +void test__f_file_write_until__returns_file_descriptor_not(void **state) { f_file_t file = f_file_t_initialize; file.size_write = 1; @@ -68,7 +68,7 @@ void test__f_file_write_until__returns_file_closed(void **state) { { const f_status_t status = f_file_write_until(file, f_string_empty_s, 1, 0); - assert_int_equal(F_status_set_fine(status), F_file_closed); + assert_int_equal(F_status_set_fine(status), F_file_descriptor_not); } } diff --git a/level_0/f_file/tests/unit/c/test-file-write_until.h b/level_0/f_file/tests/unit/c/test-file-write_until.h index ff8f960..0d8a9b2 100644 --- a/level_0/f_file/tests/unit/c/test-file-write_until.h +++ b/level_0/f_file/tests/unit/c/test-file-write_until.h @@ -25,11 +25,11 @@ extern void test__f_file_write_until__fails(void **state); extern void test__f_file_write_until__parameter_checking(void **state); /** - * Test that function works but the file is closed. + * Test that function works but the descriptor is not valid. * * @see f_file_write_until() */ -extern void test__f_file_write_until__returns_file_closed(void **state); +extern void test__f_file_write_until__returns_file_descriptor_not(void **state); /** * Test that function works but the path is empty. diff --git a/level_0/f_file/tests/unit/c/test-file.c b/level_0/f_file/tests/unit/c/test-file.c index a5b22ec..411c09f 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -25,6 +25,7 @@ int main(void) { cmocka_unit_test(test__f_file_access_at__fails), cmocka_unit_test(test__f_file_access_at__returns_data_not), + cmocka_unit_test(test__f_file_access_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_access_at__works), cmocka_unit_test(test__f_file_clone__fails_during_read_write), @@ -36,12 +37,8 @@ int main(void) { cmocka_unit_test(test__f_file_clone__works_for_link), cmocka_unit_test(test__f_file_close__fails), + cmocka_unit_test(test__f_file_close__returns_file_descriptor_not), cmocka_unit_test(test__f_file_close__works), - cmocka_unit_test(test__f_file_close__works_already_closed), - - cmocka_unit_test(test__f_file_close_flush__fails), - cmocka_unit_test(test__f_file_close_flush__works), - cmocka_unit_test(test__f_file_close_flush__works_already_closed), cmocka_unit_test(test__f_file_copy__fails_during_read_write), cmocka_unit_test(test__f_file_copy__fails_for_block), @@ -66,6 +63,7 @@ int main(void) { cmocka_unit_test(test__f_file_create_at__fails), cmocka_unit_test(test__f_file_create_at__returns_data_not), + cmocka_unit_test(test__f_file_create_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_create_at__works), cmocka_unit_test(test__f_file_create_device__fails), @@ -75,6 +73,7 @@ int main(void) { cmocka_unit_test(test__f_file_create_device_at__fails), cmocka_unit_test(test__f_file_create_device_at__returns_data_not), + cmocka_unit_test(test__f_file_create_device_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_create_device_at__returns_supported_not), cmocka_unit_test(test__f_file_create_device_at__works), @@ -84,6 +83,7 @@ int main(void) { cmocka_unit_test(test__f_file_create_fifo_at__fails), cmocka_unit_test(test__f_file_create_fifo_at__returns_data_not), + cmocka_unit_test(test__f_file_create_fifo_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_create_fifo_at__works), cmocka_unit_test(test__f_file_create_node__fails), @@ -93,10 +93,12 @@ int main(void) { cmocka_unit_test(test__f_file_create_node_at__fails), cmocka_unit_test(test__f_file_create_node_at__returns_data_not), + cmocka_unit_test(test__f_file_create_node_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_create_node_at__returns_supported_not), cmocka_unit_test(test__f_file_create_node_at__works), cmocka_unit_test(test__f_file_descriptor__fails), + cmocka_unit_test(test__f_file_descriptor__returns_stream_not), cmocka_unit_test(test__f_file_descriptor__works), cmocka_unit_test(test__f_file_exists__fails), @@ -105,9 +107,11 @@ int main(void) { cmocka_unit_test(test__f_file_exists_at__fails), cmocka_unit_test(test__f_file_exists_at__returns_data_not), + cmocka_unit_test(test__f_file_exists_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_exists_at__works), cmocka_unit_test(test__f_file_flush__fails), + cmocka_unit_test(test__f_file_flush__returns_file_descriptor_not), cmocka_unit_test(test__f_file_flush__works), cmocka_unit_test(test__f_file_group_read__fails), @@ -121,10 +125,10 @@ int main(void) { cmocka_unit_test(test__f_file_is_at__fails), cmocka_unit_test(test__f_file_is_at__returns_data_not), + cmocka_unit_test(test__f_file_is_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_is_at__returns_false), cmocka_unit_test(test__f_file_is_at__returns_true), - cmocka_unit_test(test__f_file_is_stat__fails), cmocka_unit_test(test__f_file_is_stat__returns_false), cmocka_unit_test(test__f_file_is_stat__returns_true), @@ -134,6 +138,7 @@ int main(void) { cmocka_unit_test(test__f_file_link_at__fails), cmocka_unit_test(test__f_file_link_at__returns_data_not), + cmocka_unit_test(test__f_file_link_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_link_at__works), cmocka_unit_test(test__f_file_link_hard__fails), @@ -142,6 +147,7 @@ int main(void) { cmocka_unit_test(test__f_file_link_hard_at__fails), cmocka_unit_test(test__f_file_link_hard_at__returns_data_not), + cmocka_unit_test(test__f_file_link_hard_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_link_hard_at__works), cmocka_unit_test(test__f_file_link_read__fails), @@ -150,6 +156,7 @@ int main(void) { cmocka_unit_test(test__f_file_link_read_at__fails), cmocka_unit_test(test__f_file_link_read_at__returns_data_not), + cmocka_unit_test(test__f_file_link_read_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_link_read_at__works), cmocka_unit_test(test__f_file_mode_determine__works_basic), @@ -166,6 +173,7 @@ int main(void) { cmocka_unit_test(test__f_file_mode_read_at__fails), cmocka_unit_test(test__f_file_mode_read_at__returns_data_not), + cmocka_unit_test(test__f_file_mode_read_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_mode_read_at__works), cmocka_unit_test(test__f_file_mode_set__fails), @@ -174,6 +182,7 @@ int main(void) { cmocka_unit_test(test__f_file_mode_set_at__fails), cmocka_unit_test(test__f_file_mode_set_at__returns_data_not), + cmocka_unit_test(test__f_file_mode_set_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_mode_set_at__works), cmocka_unit_test(test__f_file_mode_to_mode__works), @@ -190,6 +199,7 @@ int main(void) { cmocka_unit_test(test__f_file_open_at__fails), cmocka_unit_test(test__f_file_open_at__returns_data_not), + cmocka_unit_test(test__f_file_open_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_open_at__works), cmocka_unit_test(test__f_file_owner_read__fails), @@ -197,15 +207,15 @@ int main(void) { cmocka_unit_test(test__f_file_owner_read__works), cmocka_unit_test(test__f_file_read__fails), - cmocka_unit_test(test__f_file_read__returns_file_closed), + cmocka_unit_test(test__f_file_read__returns_file_descriptor_not), cmocka_unit_test(test__f_file_read__works), cmocka_unit_test(test__f_file_read_block__fails), - cmocka_unit_test(test__f_file_read_block__returns_file_closed), + cmocka_unit_test(test__f_file_read_block__returns_file_descriptor_not), cmocka_unit_test(test__f_file_read_block__works), cmocka_unit_test(test__f_file_read_until__fails), - cmocka_unit_test(test__f_file_read_until__returns_file_closed), + cmocka_unit_test(test__f_file_read_until__returns_file_descriptor_not), cmocka_unit_test(test__f_file_read_until__works), cmocka_unit_test(test__f_file_remove__fails), @@ -214,6 +224,7 @@ int main(void) { cmocka_unit_test(test__f_file_remove_at__fails), cmocka_unit_test(test__f_file_remove_at__returns_data_not), + cmocka_unit_test(test__f_file_remove_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_remove_at__works), cmocka_unit_test(test__f_file_rename__fails), @@ -222,6 +233,7 @@ int main(void) { cmocka_unit_test(test__f_file_rename_at__fails), cmocka_unit_test(test__f_file_rename_at__returns_data_not), + cmocka_unit_test(test__f_file_rename_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_rename_at__works), cmocka_unit_test(test__f_file_role_change__fails_for_dereference), @@ -233,10 +245,12 @@ int main(void) { cmocka_unit_test(test__f_file_role_change_at__fails_for_dereference), cmocka_unit_test(test__f_file_role_change_at__fails_for_reference), cmocka_unit_test(test__f_file_role_change_at__returns_data_not), + cmocka_unit_test(test__f_file_role_change_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_role_change_at__works_for_dereference), cmocka_unit_test(test__f_file_role_change_at__works_for_reference), cmocka_unit_test(test__f_file_seek__fails), + cmocka_unit_test(test__f_file_seek__returns_file_descriptor_not), cmocka_unit_test(test__f_file_seek__works), cmocka_unit_test(test__f_file_size__fails), @@ -245,10 +259,11 @@ int main(void) { cmocka_unit_test(test__f_file_size_at__fails), cmocka_unit_test(test__f_file_size_at__returns_data_not), + cmocka_unit_test(test__f_file_size_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_size_at__works), - cmocka_unit_test(test__f_file_size_by_id__fails), - cmocka_unit_test(test__f_file_size_by_id__returns_file_closed), + cmocka_unit_test(test__f_file_stat_by_id__fails), + cmocka_unit_test(test__f_file_size_by_id__returns_file_descriptor_not), cmocka_unit_test(test__f_file_size_by_id__works), cmocka_unit_test(test__f_file_stat__fails), @@ -257,14 +272,15 @@ int main(void) { cmocka_unit_test(test__f_file_stat_at__fails), cmocka_unit_test(test__f_file_stat_at__returns_data_not), + cmocka_unit_test(test__f_file_stat_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_stat_at__works), cmocka_unit_test(test__f_file_stat_by_id__fails), - cmocka_unit_test(test__f_file_stat_by_id__returns_file_closed), + cmocka_unit_test(test__f_file_stat_by_id__returns_file_descriptor_not), cmocka_unit_test(test__f_file_stat_by_id__works), - cmocka_unit_test(test__f_file_stream_close__fails_for_file_descriptor), - cmocka_unit_test(test__f_file_stream_close__fails_for_stream), + cmocka_unit_test(test__f_file_stream_close__fails), + cmocka_unit_test(test__f_file_stream_close__returns_stream_not), cmocka_unit_test(test__f_file_stream_close__works), // __wrap_fdopen does not appear to be working. @@ -276,15 +292,15 @@ int main(void) { cmocka_unit_test(test__f_file_stream_open__works), cmocka_unit_test(test__f_file_stream_read__fails), - cmocka_unit_test(test__f_file_stream_read__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read__returns_stream_not), cmocka_unit_test(test__f_file_stream_read__works), cmocka_unit_test(test__f_file_stream_read_block__fails), - cmocka_unit_test(test__f_file_stream_read_block__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read_block__returns_stream_not), cmocka_unit_test(test__f_file_stream_read_block__works), cmocka_unit_test(test__f_file_stream_read_until__fails), - cmocka_unit_test(test__f_file_stream_read_until__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read_until__returns_stream_not), cmocka_unit_test(test__f_file_stream_read_until__works), cmocka_unit_test(test__f_file_stream_reopen__fails), @@ -292,23 +308,23 @@ int main(void) { cmocka_unit_test(test__f_file_stream_reopen__works), cmocka_unit_test(test__f_file_stream_write__fails), - cmocka_unit_test(test__f_file_stream_write__returns_file_closed), cmocka_unit_test(test__f_file_stream_write__returns_data_not), + cmocka_unit_test(test__f_file_stream_write__returns_stream_not), cmocka_unit_test(test__f_file_stream_write__works), cmocka_unit_test(test__f_file_stream_write_block__fails), - cmocka_unit_test(test__f_file_stream_write_block__returns_file_closed), cmocka_unit_test(test__f_file_stream_write_block__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_block__returns_stream_not), cmocka_unit_test(test__f_file_stream_write_block__works), cmocka_unit_test(test__f_file_stream_write_range__fails), - cmocka_unit_test(test__f_file_stream_write_range__returns_file_closed), cmocka_unit_test(test__f_file_stream_write_range__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_range__returns_stream_not), cmocka_unit_test(test__f_file_stream_write_range__works), cmocka_unit_test(test__f_file_stream_write_until__fails), - cmocka_unit_test(test__f_file_stream_write_until__returns_file_closed), cmocka_unit_test(test__f_file_stream_write_until__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_until__returns_stream_not), cmocka_unit_test(test__f_file_stream_write_until__works), cmocka_unit_test(test__f_file_touch__fails), @@ -317,6 +333,7 @@ int main(void) { cmocka_unit_test(test__f_file_touch_at__fails), cmocka_unit_test(test__f_file_touch_at__returns_data_not), + cmocka_unit_test(test__f_file_touch_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_touch_at__works), cmocka_unit_test(test__f_file_type__fails), @@ -325,6 +342,7 @@ int main(void) { cmocka_unit_test(test__f_file_type_at__fails), cmocka_unit_test(test__f_file_type_at__returns_data_not), + cmocka_unit_test(test__f_file_type_at__returns_file_descriptor_not), cmocka_unit_test(test__f_file_type_at__works), cmocka_unit_test(test__f_file_umask_get__works), @@ -332,22 +350,22 @@ int main(void) { cmocka_unit_test(test__f_file_umask_set__works), cmocka_unit_test(test__f_file_write__fails), - cmocka_unit_test(test__f_file_write__returns_file_closed), + cmocka_unit_test(test__f_file_write__returns_file_descriptor_not), cmocka_unit_test(test__f_file_write__returns_data_not), cmocka_unit_test(test__f_file_write__works), cmocka_unit_test(test__f_file_write_block__fails), - cmocka_unit_test(test__f_file_write_block__returns_file_closed), + cmocka_unit_test(test__f_file_write_block__returns_file_descriptor_not), cmocka_unit_test(test__f_file_write_block__returns_data_not), cmocka_unit_test(test__f_file_write_block__works), cmocka_unit_test(test__f_file_write_range__fails), - cmocka_unit_test(test__f_file_write_range__returns_file_closed), + cmocka_unit_test(test__f_file_write_range__returns_file_descriptor_not), cmocka_unit_test(test__f_file_write_range__returns_data_not), cmocka_unit_test(test__f_file_write_range__works), cmocka_unit_test(test__f_file_write_until__fails), - cmocka_unit_test(test__f_file_write_until__returns_file_closed), + cmocka_unit_test(test__f_file_write_until__returns_file_descriptor_not), cmocka_unit_test(test__f_file_write_until__returns_data_not), cmocka_unit_test(test__f_file_write_until__works), @@ -356,7 +374,6 @@ int main(void) { // f_file_access_at() doesn't use parameter checking. // f_file_clone() doesn't use parameter checking. cmocka_unit_test(test__f_file_close__parameter_checking), - cmocka_unit_test(test__f_file_close_flush__parameter_checking), // f_file_copy() doesn't use parameter checking. // f_file_create() doesn't use parameter checking. // f_file_create_at() doesn't use parameter checking. diff --git a/level_0/f_file/tests/unit/c/test-file.h b/level_0/f_file/tests/unit/c/test-file.h index 99f4062..0b841d0 100644 --- a/level_0/f_file/tests/unit/c/test-file.h +++ b/level_0/f_file/tests/unit/c/test-file.h @@ -30,7 +30,6 @@ #include "test-file-access_at.h" #include "test-file-clone.h" #include "test-file-close.h" -#include "test-file-close_flush.h" #include "test-file-copy.h" #include "test-file-create.h" #include "test-file-create_at.h" diff --git a/level_0/f_type/c/type_file.h b/level_0/f_type/c/type_file.h index 8d761ef..b4d9dcd 100644 --- a/level_0/f_type/c/type_file.h +++ b/level_0/f_type/c/type_file.h @@ -17,6 +17,7 @@ // Libc includes. #include +#include #ifdef __cplusplus extern "C" { @@ -31,10 +32,118 @@ extern "C" { * - read_size: Default read size in bytes. * - write_size: Default write size in bytes. */ -#ifndef _di_f_type_file_defaults_ - #define F_file_default_read_size_d 8192 - #define F_file_default_write_size_d 8192 -#endif // _di_f_type_file_defaults_ +#ifndef _di_f_type_file_defaults_d_ + #define F_file_default_size_read_d 8192 + #define F_file_default_size_write_d 8192 +#endif // _di_f_type_file_defaults_d_ + +/** + * File flag related functionality. + */ +#ifndef _di_f_type_file_flag_d_ + + // This is not always defined, so ensure it is defined. + #ifndef O_PATH + #define O_PATH 010000000 + #endif // O_PATH + + // File open flags. + #define F_file_flag_append_d O_APPEND + #define F_file_flag_asynchronous_d O_ASYNC + #define F_file_flag_create_d O_CREAT + #define F_file_flag_close_execute_d O_CLOEXEC + #define F_file_flag_direct_d O_DIRECT + #define F_file_flag_directory_d O_DIRECTORY + #define F_file_flag_exclusive_d O_EXCL + #define F_file_flag_large_file_d O_LARGEFILE + #define F_file_flag_no_access_time_d O_NOATIME + #define F_file_flag_no_follow_d O_NOFOLLOW + #define F_file_flag_no_tty_d O_NOCTTY + #define F_file_flag_non_blocking_d O_NONBLOCK + #define F_file_flag_path_d O_PATH + #define F_file_flag_read_only_d O_RDONLY + #define F_file_flag_read_write_d O_RDWR + #define F_file_flag_synchronous_d O_SYNC + #define F_file_flag_synchronous_direct_d O_DSYNC + #define F_file_flag_temporary_d O_TMPFILE + #define F_file_flag_truncate_d O_TRUNC + #define F_file_flag_write_only_d O_WRONLY + + // File open flags pre-combined with create. + #define F_file_flag_create_ro_d (O_CREAT | O_RDONLY) + #define F_file_flag_create_wo_d (O_CREAT | O_WRONLY) + #define F_file_flag_create_rw_d (O_CREAT | O_RDRW) + + // File open flags pre-combined will fail if file exists. + #define F_file_flag_create_new_ro_d (O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_create_new_wo_d (O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_create_new_rw_d (O_CREAT | O_EXCL | O_RDRW) + + // File open flags pre-combined will truncate any existing files to 0. + #define F_file_flag_truncate_ro_d (O_CREAT | O_TRUNC | O_RDONLY) + #define F_file_flag_truncate_rw_d (O_CREAT | O_TRUNC | O_RDRW) + #define F_file_flag_truncate_wo_d (O_CREAT | O_TRUNC | O_WRONLY) + + // File open flags pre-combined will truncate any existing files to 0. + #define F_file_flag_append_rw_d (O_CREAT | O_APPEND | O_RDRW) + #define F_file_flag_append_wo_d (O_CREAT | O_APPEND | O_WRONLY) + + // File open flags pre-combined with synchronous io. + #define F_file_flag_sync_ro_d (O_SYNC | O_RDONLY) + #define F_file_flag_sync_wo_d (O_SYNC | O_WRONLY) + #define F_file_flag_sync_rw_d (O_SYNC | O_RDRW) + #define F_file_flag_sync_create_ro_d (O_SYNC | O_CREAT | O_RDONLY) + #define F_file_flag_sync_create_wo_d (O_SYNC | O_CREAT | O_WRONLY) + #define F_file_flag_sync_create_rw_d (O_SYNC | O_CREAT | O_RDRW) + #define F_file_flag_sync_create_new_ro_d (O_SYNC | O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_sync_create_new_wo_d (O_SYNC | O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_sync_create_new_rw_d (O_SYNC | O_CREAT | O_EXCL | O_RDRW) + + // File open flags pre-combined with asynchronous io. + #define F_file_flag_async_ro_d (O_ASYNC | O_RDONLY) + #define F_file_flag_async_wo_d (O_ASYNC | O_WRONLY) + #define F_file_flag_async_rw_d (O_ASYNC | O_RDRW) + #define F_file_flag_async_create_ro_d (O_ASYNC | O_CREAT | O_RDONLY) + #define F_file_flag_async_create_wo_d (O_ASYNC | O_CREAT | O_WRONLY) + #define F_file_flag_async_create_rw_d (O_ASYNC | O_CREAT | O_RDRW) + #define F_file_flag_async_create_new_ro_d (O_ASYNC | O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_async_create_new_wo_d (O_ASYNC | O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_async_create_new_rw_d (O_ASYNC | O_CREAT | O_EXCL | O_RDRW) + + // File open flags pre-combined with direct io (which works synchronously). + #define F_file_flag_direct_ro_d (O_DIRECT | O_RDONLY) + #define F_file_flag_direct_wo_d (O_DIRECT | O_WRONLY) + #define F_file_flag_direct_rw_d (O_DIRECT | O_RDRW) + #define F_file_flag_direct_create_ro_d (O_DIRECT | O_CREAT | O_RDONLY) + #define F_file_flag_direct_create_wo_d (O_DIRECT | O_CREAT | O_WRONLY) + #define F_file_flag_direct_create_rw_d (O_DIRECT | O_CREAT | O_RDRW) + #define F_file_flag_direct_create_new_ro_d (O_DIRECT | O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_direct_create_new_wo_d (O_DIRECT | O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_direct_create_new_rw_d (O_DIRECT | O_CREAT | O_EXCL | O_RDRW) + + // File open flags pre-combined with large_file. + #define F_file_flag_large_ro_d (O_LARGEFILE | O_RDONLY) + #define F_file_flag_large_wo_d (O_LARGEFILE | O_WRONLY) + #define F_file_flag_large_rw_d (O_LARGEFILE | O_RDRW) + #define F_file_flag_large_sync_ro_d (O_LARGEFILE | O_SYNC | O_RDONLY) + #define F_file_flag_large_sync_wo_d (O_LARGEFILE | O_SYNC | O_WRONLY) + #define F_file_flag_large_sync_rw_d (O_LARGEFILE | O_SYNC | O_RDRW) + #define F_file_flag_large_sync_create_ro_d (O_LARGEFILE | O_SYNC | O_CREAT | O_RDONLY) + #define F_file_flag_large_sync_create_wo_d (O_LARGEFILE | O_SYNC | O_CREAT | O_WRONLY) + #define F_file_flag_large_sync_create_rw_d (O_LARGEFILE | O_SYNC | O_CREAT | O_RDRW) + #define F_file_flag_large_sync_create_new_ro_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_large_sync_create_new_wo_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_large_sync_create_new_rw_d (O_LARGEFILE | O_SYNC | O_CREAT | O_EXCL | O_RDRW) + #define F_file_flag_large_async_ro_d (O_LARGEFILE | O_ASYNC | O_RDONLY) + #define F_file_flag_large_async_wo_d (O_LARGEFILE | O_ASYNC | O_WRONLY) + #define F_file_flag_large_async_rw_d (O_LARGEFILE | O_ASYNC | O_RDRW) + #define F_file_flag_large_async_create_ro_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_RDONLY) + #define F_file_flag_large_async_create_wo_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_WRONLY) + #define F_file_flag_large_async_create_rw_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_RDRW) + #define F_file_flag_large_async_create_new_ro_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_RDONLY) + #define F_file_flag_large_async_create_new_wo_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_WRONLY) + #define F_file_flag_large_async_create_new_rw_d (O_LARGEFILE | O_ASYNC | O_CREAT | O_EXCL | O_RDRW) +#endif // _di_f_type_file_flag_d_ /** * Commonly used file related properties. @@ -54,12 +163,12 @@ extern "C" { size_t size_write; } f_file_t; - #define f_file_t_initialize { 0, -1, O_RDONLY, F_file_default_read_size_d, F_file_default_write_size_d } + #define f_file_t_initialize { 0, -1, O_RDONLY, F_file_default_size_read_d, F_file_default_size_write_d } #define macro_f_file_t_initialize(stream, id, flag, read_size, write_size) { stream, id, flag, read_size, write_size } - #define macro_f_file_t_initialize2(stream, id, flag) { stream, id, flag, F_file_default_read_size_d, F_file_default_write_size_d } - #define macro_f_file_t_initialize_id(id) { 0, id, O_RDONLY, F_file_default_read_size_d, F_file_default_write_size_d } - #define macro_f_file_t_initialize_stream(stream) { stream, -1, O_RDONLY, F_file_default_read_size_d, F_file_default_write_size_d } + #define macro_f_file_t_initialize2(stream, id, flag) { stream, id, flag, F_file_default_size_read_d, F_file_default_size_write_d } + #define macro_f_file_t_initialize_id(id) { 0, id, O_RDONLY, F_file_default_size_read_d, F_file_default_size_write_d } + #define macro_f_file_t_initialize_stream(stream) { stream, -1, O_RDONLY, F_file_default_size_read_d, F_file_default_size_write_d } #define macro_f_file_t_clear(file) \ file.stream = 0; \ @@ -72,8 +181,8 @@ extern "C" { file.stream = 0; \ file.id = -1; \ file.flag = O_RDONLY; \ - file.size_read = F_file_default_read_size_d; \ - file.size_write = F_file_default_write_size_d; + file.size_read = F_file_default_size_read_d; \ + file.size_write = F_file_default_size_write_d; #endif // _di_f_file_t_ #ifdef __cplusplus diff --git a/level_3/fake/c/main/build.c b/level_3/fake/c/main/build.c index 18ae30e..662ea3e 100644 --- a/level_3/fake/c/main/build.c +++ b/level_3/fake/c/main/build.c @@ -288,7 +288,7 @@ extern "C" { fake_print_verbose_copying(&main->program.message, main->cache_2, main->cache_map.value); - main->setting.state.status = f_file_copy(main->cache_2, main->cache_map.value, mode, F_file_default_read_size_d, f_file_stat_flag_reference_e); + main->setting.state.status = f_file_copy(main->cache_2, main->cache_map.value, mode, F_file_default_size_read_d, f_file_stat_flag_reference_e); if (F_status_is_error(main->setting.state.status)) { fake_print_error_build_operation_file(&main->program.error, macro_fake_f(f_file_copy), f_file_operation_copy_s, main->cache_2, main->cache_map.value, f_file_operation_to_s, F_true); diff --git a/level_3/fake/c/main/fake/do.c b/level_3/fake/c/main/fake/do.c index 8365f41..1350063 100644 --- a/level_3/fake/c/main/fake/do.c +++ b/level_3/fake/c/main/fake/do.c @@ -28,12 +28,12 @@ extern "C" { if (recurse->state.code & fake_state_code_clone_e) { fake_print_verbose_cloning(&local->main->program.message, *recurse->path_top, map->name); - recurse->state.status = f_file_clone(*recurse->path_top, map->name, F_file_default_write_size_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); + recurse->state.status = f_file_clone(*recurse->path_top, map->name, F_file_default_size_write_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); } else { fake_print_verbose_copying(&local->main->program.message, *recurse->path_top, map->name); - recurse->state.status = f_file_copy(*recurse->path_top, map->name, recurse->mode, F_file_default_write_size_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); + recurse->state.status = f_file_copy(*recurse->path_top, map->name, recurse->mode, F_file_default_size_write_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); } if (F_status_is_error(recurse->state.status)) { @@ -86,12 +86,12 @@ extern "C" { if (recurse->state.code & fake_state_code_clone_e) { fake_print_verbose_cloning(&local->main->program.message, recurse->path, recurse->path_cache); - recurse->state.status = f_file_clone(recurse->path, recurse->path_cache, F_file_default_write_size_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); + recurse->state.status = f_file_clone(recurse->path, recurse->path_cache, F_file_default_size_write_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); } else { fake_print_verbose_copying(&local->main->program.message, recurse->path, recurse->path_cache); - recurse->state.status = f_file_copy(recurse->path, recurse->path_cache, recurse->mode, F_file_default_write_size_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); + recurse->state.status = f_file_copy(recurse->path, recurse->path_cache, recurse->mode, F_file_default_size_write_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); } if (F_status_is_error(recurse->state.status)) { @@ -146,12 +146,12 @@ extern "C" { if (recurse->state.code & fake_state_code_clone_e) { fake_print_verbose_cloning(&local->main->program.message, recurse->path, map->value); - recurse->state.status = f_file_clone(recurse->path, map->value, F_file_default_write_size_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); + recurse->state.status = f_file_clone(recurse->path, map->value, F_file_default_size_write_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); } else { fake_print_verbose_copying(&local->main->program.message, recurse->path, map->value); - recurse->state.status = f_file_copy(recurse->path, map->value, recurse->mode, F_file_default_write_size_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); + recurse->state.status = f_file_copy(recurse->path, map->value, recurse->mode, F_file_default_size_write_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); } if (F_status_is_error(recurse->state.status)) { diff --git a/level_3/fake/c/main/make/operate_process_type.c b/level_3/fake/c/main/make/operate_process_type.c index 9e3f93b..c8cd0a9 100644 --- a/level_3/fake/c/main/make/operate_process_type.c +++ b/level_3/fake/c/main/make/operate_process_type.c @@ -305,10 +305,10 @@ extern "C" { } else if (main->setting.state.status == F_false) { if (clone) { - main->setting.state.status = f_file_clone(main->cache_arguments.array[i], main->cache_map.name, F_file_default_write_size_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); + main->setting.state.status = f_file_clone(main->cache_arguments.array[i], main->cache_map.name, F_file_default_size_write_d, f_file_stat_flag_group_e | f_file_stat_flag_owner_e | (f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e)); } else { - main->setting.state.status = f_file_copy(main->cache_arguments.array[i], main->cache_map.name, main->cache_recurse_do.mode, F_file_default_write_size_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); + main->setting.state.status = f_file_copy(main->cache_arguments.array[i], main->cache_map.name, main->cache_recurse_do.mode, F_file_default_size_write_d, f_directory_recurse_do_flag_dereference_e ? 0 : f_file_stat_flag_reference_e); } if (F_status_is_error(main->setting.state.status)) { diff --git a/level_3/utf8/c/main/utf8.c b/level_3/utf8/c/main/utf8.c index 757006d..6fd51eb 100644 --- a/level_3/utf8/c/main/utf8.c +++ b/level_3/utf8/c/main/utf8.c @@ -44,7 +44,7 @@ extern "C" { f_status_t valid = F_true; if (main->program.pipe & fll_program_data_pipe_input_e) { - const f_file_t file = macro_f_file_t_initialize(F_type_input_d, F_type_descriptor_input_d, F_file_flag_read_only_d, 32768, F_file_default_write_size_d); + const f_file_t file = macro_f_file_t_initialize(F_type_input_d, F_type_descriptor_input_d, F_file_flag_read_only_d, 32768, F_file_default_size_write_d); utf8_print_data_section_header_pipe(&main->program.output); @@ -73,7 +73,7 @@ extern "C" { // Process "from" files. if (F_status_is_error_not(main->setting.state.status) && (main->setting.flag & utf8_main_flag_file_from_e)) { - f_file_t file = macro_f_file_t_initialize(0, -1, F_file_flag_read_only_d, 32768, F_file_default_write_size_d); + f_file_t file = macro_f_file_t_initialize(0, -1, F_file_flag_read_only_d, 32768, F_file_default_size_write_d); for (f_array_length_t i = 0; i < main->setting.path_files_from.used && F_status_is_error_not(main->setting.state.status); ++i) {