From: Kevin Day Date: Sun, 17 Apr 2022 23:54:31 +0000 (-0500) Subject: Progress: Continue implementing f_file unit tests. X-Git-Tag: 0.5.10~199 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=90106d3a3c46871acc5cca463cf6a440e619a69c;p=fll Progress: Continue implementing f_file unit tests. --- diff --git a/level_0/f_file/tests/unit/c/test-file-mode_set.c b/level_0/f_file/tests/unit/c/test-file-mode_set.c index c73d612..1d4c2f4 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_set.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_set.c @@ -7,44 +7,73 @@ extern "C" { void test__f_file_mode_set__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + const mode_t mode = 0; + int errnos[] = { + EACCES, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_mode, + F_read_only, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 11; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_chmod, true); + will_return(__wrap_chmod, errnos[i]); - //const f_status_t status = f_file_mode_set(path, F_false, &id); + const f_status_t status = f_file_mode_set(path, mode); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } void test__f_file_mode_set__returns_data_not(void **state) { + const mode_t mode = 0; + { - //const f_status_t status = f_file_mode_set(f_string_empty_s); + const f_status_t status = f_file_mode_set(f_string_empty_s, mode); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); } } void test__f_file_mode_set__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + const mode_t mode = 0; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_chmod, false); + will_return(__wrap_chmod, 0); - //const f_status_t status = f_file_mode_set(); + const f_status_t status = f_file_mode_set(path, mode); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); } } 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 f5a0116..4611286 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,44 +7,75 @@ extern "C" { void test__f_file_mode_set_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + const mode_t mode = 0; + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_mode, + F_read_only, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 12; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fchmodat, true); + will_return(__wrap_fchmodat, errnos[i]); - //const f_status_t status = f_file_mode_set_at(path, F_false, &id); + const f_status_t status = f_file_mode_set_at(0, path, mode); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } void test__f_file_mode_set_at__returns_data_not(void **state) { + const mode_t mode = 0; + { - //const f_status_t status = f_file_mode_set_at(f_string_empty_s); + const f_status_t status = f_file_mode_set_at(0, f_string_empty_s, mode); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); } } void test__f_file_mode_set_at__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + const mode_t mode = 0; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_fchmodat, false); + will_return(__wrap_fchmodat, 5); - //const f_status_t status = f_file_mode_set_at(); + const f_status_t status = f_file_mode_set_at(0, path, mode); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); } } 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 2e15f6b..b10eeeb 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -164,9 +164,13 @@ int main(void) { cmocka_unit_test(test__f_file_mode_read_at__returns_data_not), cmocka_unit_test(test__f_file_mode_read_at__works), - // f_file_mode_set + cmocka_unit_test(test__f_file_mode_set__fails), + cmocka_unit_test(test__f_file_mode_set__returns_data_not), + cmocka_unit_test(test__f_file_mode_set__works), - // f_file_mode_set_at + 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__works), // f_file_mode_to_mode