From: Kevin Day Date: Mon, 18 Apr 2022 03:44:41 +0000 (-0500) Subject: Progress: Continue witing f_file unit tests. X-Git-Tag: 0.5.10~197 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=10ae1049f6941ebfd34d07565388f517471076dd;p=fll Progress: Continue witing f_file unit tests. The __wrap_read() needed to be updated. --- diff --git a/level_0/f_file/tests/unit/c/mock-file.c b/level_0/f_file/tests/unit/c/mock-file.c index 884cb09..0379c1f 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -438,7 +438,12 @@ ssize_t __wrap_read(int fd, void *buf, size_t count) { return -1; } - buf = mock_type(void *); + char *buffer = mock_type(char *); + size_t size = mock_type(size_t); + + if (size) { + memcpy(buf, buffer, size); + } return mock_type(int); } diff --git a/level_0/f_file/tests/unit/c/test-file-clone.c b/level_0/f_file/tests/unit/c/test-file-clone.c index f1dd434..1d9401d 100644 --- a/level_0/f_file/tests/unit/c/test-file-clone.c +++ b/level_0/f_file/tests/unit/c/test-file-clone.c @@ -43,7 +43,8 @@ void test__f_file_clone__fails_during_read_write(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, false); @@ -1090,7 +1091,8 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, true); @@ -1204,14 +1206,16 @@ void test__f_file_clone__works_for_regular(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, false); will_return(__wrap_write, 1); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 0); will_return(__wrap_read, 0); will_return(__wrap_fsync, false); diff --git a/level_0/f_file/tests/unit/c/test-file-copy.c b/level_0/f_file/tests/unit/c/test-file-copy.c index f8ec4ef..490ff6e 100644 --- a/level_0/f_file/tests/unit/c/test-file-copy.c +++ b/level_0/f_file/tests/unit/c/test-file-copy.c @@ -45,7 +45,8 @@ void test__f_file_copy__fails_during_read_write(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, false); @@ -1328,7 +1329,8 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, true); @@ -1706,14 +1708,16 @@ void test__f_file_copy__works_for_regular(void **state) { will_return(__wrap_open, 0); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 1); will_return(__wrap_read, 1); will_return(__wrap_write, false); will_return(__wrap_write, 1); will_return(__wrap_read, false); - will_return(__wrap_read, (void *) buffer); + will_return(__wrap_read, buffer); + will_return(__wrap_read, 0); will_return(__wrap_read, 0); will_return(__wrap_fsync, false); diff --git a/level_0/f_file/tests/unit/c/test-file-mode_to_mode.c b/level_0/f_file/tests/unit/c/test-file-mode_to_mode.c index 8f7cc5a..1fb6113 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_to_mode.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_to_mode.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_file_mode_to_mode__fails(void **state) { - - int errnos[] = { - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_failure, - }; - - for (int i = 0; i < 1; ++i) { - - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); - - //const f_status_t status = f_file_mode_to_mode(path, F_false, &id); - - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for -} - #ifndef _di_level_0_parameter_checking_ void test__f_file_mode_to_mode__parameter_checking(void **state) { @@ -41,15 +20,77 @@ void test__f_file_mode_to_mode__fails(void **state) { void test__f_file_mode_to_mode__works(void **state) { - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_mode_t file_modes[] = { + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d), + F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d), + }; - //const f_status_t status = f_file_mode_to_mode(); + f_file_mode_t modes[] = { + F_file_mode_owner_rwx_d, + F_file_mode_owner_r_d, + F_file_mode_owner_w_d, + F_file_mode_owner_x_d, + F_file_mode_owner_rw_d, + F_file_mode_owner_rx_d, + F_file_mode_owner_wx_d, + F_file_mode_group_rwx_d, + F_file_mode_group_r_d, + F_file_mode_group_w_d, + F_file_mode_group_x_d, + F_file_mode_group_rw_d, + F_file_mode_group_rx_d, + F_file_mode_group_wx_d, + F_file_mode_world_rwx_d, + F_file_mode_world_r_d, + F_file_mode_world_w_d, + F_file_mode_world_x_d, + F_file_mode_world_rw_d, + F_file_mode_world_rx_d, + F_file_mode_world_wx_d, + F_file_mode_all_rwx_d, + F_file_mode_all_r_d, + F_file_mode_all_w_d, + F_file_mode_all_x_d, + F_file_mode_all_rw_d, + F_file_mode_all_rx_d, + F_file_mode_all_wx_d, + }; - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); - } + for (f_array_length_t i = 0; i < 28; ++i) { + + mode_t mode = 0; + + const f_status_t status = f_file_mode_to_mode(file_modes[i], &mode); + + assert_int_equal(status, F_none); + assert_int_equal(mode, modes[i]); + } // for } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-mode_to_mode.h b/level_0/f_file/tests/unit/c/test-file-mode_to_mode.h index 006f8e4..31ca2e3 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_to_mode.h +++ b/level_0/f_file/tests/unit/c/test-file-mode_to_mode.h @@ -11,13 +11,6 @@ #define _TEST__F_file_mode_to_mode_h /** - * Test that function fails. - * - * @see f_file_mode_to_mode() - */ -extern void test__f_file_mode_to_mode__fails(void **state); - -/** * Test that parameter checking works as expected. * * @see f_file_mode_to_mode() diff --git a/level_0/f_file/tests/unit/c/test-file-name_base.c b/level_0/f_file/tests/unit/c/test-file-name_base.c index b1fbafe..2592ff6 100644 --- a/level_0/f_file/tests/unit/c/test-file-name_base.c +++ b/level_0/f_file/tests/unit/c/test-file-name_base.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_file_name_base__fails(void **state) { - - int errnos[] = { - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_failure, - }; - - for (int i = 0; i < 1; ++i) { - - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); - - //const f_status_t status = f_file_name_base(path, F_false, &id); - - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for -} - #ifndef _di_level_0_parameter_checking_ void test__f_file_name_base__parameter_checking(void **state) { @@ -39,24 +18,63 @@ void test__f_file_name_base__fails(void **state) { void test__f_file_name_base__returns_data_not(void **state) { + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { - //const f_status_t status = f_file_name_base(f_string_empty_s); + const f_status_t status = f_file_name_base(f_string_empty_s, &buffer); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_name_base__works(void **state) { - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + f_string_static_t paths[] = { + macro_f_string_static_t_initialize("/a", 0, 2), + macro_f_string_static_t_initialize("/a/b", 0, 4), + macro_f_string_static_t_initialize("/a/b/c", 0, 6), + macro_f_string_static_t_initialize("/a/", 0, 3), + macro_f_string_static_t_initialize("/a/b/", 0, 5), + macro_f_string_static_t_initialize("/a/b/c/", 0, 7), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("a/b", 0, 3), + macro_f_string_static_t_initialize("a/b/c", 0, 5), + macro_f_string_static_t_initialize("a/", 0, 2), + macro_f_string_static_t_initialize("a/b/", 0, 4), + macro_f_string_static_t_initialize("a/b/c/", 0, 6), + }; - //const f_status_t status = f_file_name_base(); + f_string_static_t bases[] = { + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("b", 0, 1), + macro_f_string_static_t_initialize("c", 0, 1), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("b", 0, 1), + macro_f_string_static_t_initialize("c", 0, 1), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("b", 0, 1), + macro_f_string_static_t_initialize("c", 0, 1), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("b", 0, 1), + macro_f_string_static_t_initialize("c", 0, 1), + }; - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); - } + for (uint8_t i = 0; i < 12; ++i) { + + buffer.used = 0; + + const f_status_t status = f_file_name_base(paths[i], &buffer); + + assert_int_equal(status, F_none); + assert_int_equal(buffer.used, bases[i].used); + assert_string_equal(buffer.string, bases[i].string); + } // for + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-name_base.h b/level_0/f_file/tests/unit/c/test-file-name_base.h index 16fe388..a10492a 100644 --- a/level_0/f_file/tests/unit/c/test-file-name_base.h +++ b/level_0/f_file/tests/unit/c/test-file-name_base.h @@ -11,13 +11,6 @@ #define _TEST__F_file_name_base_h /** - * Test that function fails. - * - * @see f_file_name_base() - */ -extern void test__f_file_name_base__fails(void **state); - -/** * Test that parameter checking works as expected. * * @see f_file_name_base() diff --git a/level_0/f_file/tests/unit/c/test-file-name_directory.c b/level_0/f_file/tests/unit/c/test-file-name_directory.c index 0ad533c..238b8ce 100644 --- a/level_0/f_file/tests/unit/c/test-file-name_directory.c +++ b/level_0/f_file/tests/unit/c/test-file-name_directory.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_file_name_directory__fails(void **state) { - - int errnos[] = { - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_failure, - }; - - for (int i = 0; i < 1; ++i) { - - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); - - //const f_status_t status = f_file_name_directory(path, F_false, &id); - - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for -} - #ifndef _di_level_0_parameter_checking_ void test__f_file_name_directory__parameter_checking(void **state) { @@ -39,24 +18,63 @@ void test__f_file_name_directory__fails(void **state) { void test__f_file_name_directory__returns_data_not(void **state) { + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { - //const f_status_t status = f_file_name_directory(f_string_empty_s); + const f_status_t status = f_file_name_directory(f_string_empty_s, &buffer); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_name_directory__works(void **state) { - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + f_string_static_t paths[] = { + macro_f_string_static_t_initialize("/a", 0, 2), + macro_f_string_static_t_initialize("/a/b", 0, 4), + macro_f_string_static_t_initialize("/a/b/c", 0, 6), + macro_f_string_static_t_initialize("/a/", 0, 3), + macro_f_string_static_t_initialize("/a/b/", 0, 5), + macro_f_string_static_t_initialize("/a/b/c/", 0, 7), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("a/b", 0, 3), + macro_f_string_static_t_initialize("a/b/c", 0, 5), + macro_f_string_static_t_initialize("a/", 0, 2), + macro_f_string_static_t_initialize("a/b/", 0, 4), + macro_f_string_static_t_initialize("a/b/c/", 0, 6), + }; - //const f_status_t status = f_file_name_directory(); + f_string_static_t bases[] = { + macro_f_string_static_t_initialize("/", 0, 1), + macro_f_string_static_t_initialize("/a", 0, 2), + macro_f_string_static_t_initialize("/a/b", 0, 4), + macro_f_string_static_t_initialize("/", 0, 1), + macro_f_string_static_t_initialize("/a", 0, 2), + macro_f_string_static_t_initialize("/a/b", 0, 4), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("a/b", 0, 3), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("a", 0, 1), + macro_f_string_static_t_initialize("a/b", 0, 3), + }; - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); - } + for (uint8_t i = 0; i < 12; ++i) { + + buffer.used = 0; + + const f_status_t status = f_file_name_directory(paths[i], &buffer); + + assert_int_equal(status, F_none); + assert_int_equal(buffer.used, bases[i].used); + assert_string_equal(buffer.string, bases[i].string); + } // for + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-name_directory.h b/level_0/f_file/tests/unit/c/test-file-name_directory.h index 7992858..d540b30 100644 --- a/level_0/f_file/tests/unit/c/test-file-name_directory.h +++ b/level_0/f_file/tests/unit/c/test-file-name_directory.h @@ -11,13 +11,6 @@ #define _TEST__F_file_name_directory_h /** - * Test that function fails. - * - * @see f_file_name_directory() - */ -extern void test__f_file_name_directory__fails(void **state); - -/** * Test that parameter checking works as expected. * * @see f_file_name_directory() diff --git a/level_0/f_file/tests/unit/c/test-file-open.c b/level_0/f_file/tests/unit/c/test-file-open.c index 33e0db6..ff6ca9f 100644 --- a/level_0/f_file/tests/unit/c/test-file-open.c +++ b/level_0/f_file/tests/unit/c/test-file-open.c @@ -11,10 +11,10 @@ void test__f_file_open__fails(void **state) { int errnos[] = { EACCES, + EDQUOT, EEXIST, EFAULT, EFBIG, - EDQUOT, EINTR, EINVAL, EISDIR, @@ -35,10 +35,10 @@ void test__f_file_open__fails(void **state) { f_status_t statuss[] = { F_access_denied, + F_filesystem_quota_block, F_file_found, F_buffer, F_number_overflow, - F_filesystem_quota_block, F_interrupt, F_parameter, F_directory, @@ -95,7 +95,7 @@ void test__f_file_open__returns_data_not(void **state) { } void test__f_file_open__works(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { @@ -107,9 +107,8 @@ void test__f_file_open__works(void **state) { const f_status_t status = f_file_open(path, 0, &file); assert_int_equal(status, F_none); - assert_int_equal(id, 5); + assert_int_equal(file.id, 5); } - */ } #ifdef __cplusplus 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 64b7bc8..d18b6b3 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 @@ -6,16 +6,16 @@ extern "C" { #endif void test__f_file_open_at__fails(void **state) { -/* - const int at = 1; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { EACCES, + EBADF, + EDQUOT, EEXIST, EFAULT, EFBIG, - EDQUOT, EINTR, EINVAL, EISDIR, @@ -36,10 +36,11 @@ void test__f_file_open_at__fails(void **state) { f_status_t statuss[] = { F_access_denied, + F_directory_descriptor, + F_filesystem_quota_block, F_file_found, F_buffer, F_number_overflow, - F_filesystem_quota_block, F_interrupt, F_parameter, F_directory, @@ -58,18 +59,17 @@ void test__f_file_open_at__fails(void **state) { F_failure, }; - for (int i = 0; i < 17; ++i) { + for (int i = 0; i < 22; ++i) { - int id = 0; + f_file_t file = f_file_t_initialize; will_return(__wrap_openat, true); will_return(__wrap_openat, errnos[i]); - const f_status_t status = f_file_open_at(at, path, F_false, &id); + const f_status_t status = f_file_open_at(0, path, 0, &file); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for - */ } #ifndef _di_level_0_parameter_checking_ @@ -85,35 +85,30 @@ void test__f_file_open_at__fails(void **state) { void test__f_file_open_at__returns_data_not(void **state) { - const int at = 1; - { f_file_t file = f_file_t_initialize; - const f_status_t status = f_file_open_at(at, f_string_empty_s, 0, &file); + const f_status_t status = f_file_open_at(0, f_string_empty_s, 0, &file); assert_int_equal(status, F_data_not); } } void test__f_file_open_at__works(void **state) { -/* - const int at = 1; const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - int id = 0; + f_file_t file = f_file_t_initialize; will_return(__wrap_openat, false); will_return(__wrap_openat, 5); - const f_status_t status = f_file_open_at(at, path, F_false, &id); + const f_status_t status = f_file_open_at(0, path, F_false, &file); assert_int_equal(status, F_none); - assert_int_equal(id, 5); + assert_int_equal(file.id, 5); } - */ } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-owner_read.c b/level_0/f_file/tests/unit/c/test-file-owner_read.c index 0cfc114..6f3cd29 100644 --- a/level_0/f_file/tests/unit/c/test-file-owner_read.c +++ b/level_0/f_file/tests/unit/c/test-file-owner_read.c @@ -7,22 +7,42 @@ extern "C" { void test__f_file_owner_read__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_number_overflow, + F_file_stat, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 9; ++i) { + + gid_t id = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); - //const f_status_t status = f_file_owner_read(path, F_false, &id); + const f_status_t status = f_file_owner_read(path, F_true, &id); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -40,7 +60,7 @@ void test__f_file_owner_read__fails(void **state) { void test__f_file_owner_read__returns_data_not(void **state) { { - uid_t id = 0; + gid_t id = 0; const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, &id); @@ -50,14 +70,25 @@ void test__f_file_owner_read__returns_data_not(void **state) { void test__f_file_owner_read__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + gid_t id = 0; + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_uid = 5; + + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - //const f_status_t status = f_file_owner_read(); + const f_status_t status = f_file_owner_read(path, F_true, &id); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(id, 5); } } 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 20eee79..1834674 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 @@ -7,29 +7,55 @@ extern "C" { void test__f_file_read__fails(void **state) { + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; + int errnos[] = { + EAGAIN, + EBADF, + EFAULT, + EINTR, + EINVAL, + EIO, + EISDIR, + EWOULDBLOCK, mock_errno_generic, }; f_status_t statuss[] = { + F_block, + F_file_descriptor, + F_buffer, + F_interrupt, + F_parameter, + F_input_output, + F_file_type_directory, + F_block, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 9; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_read, true); + will_return(__wrap_read, errnos[i]); - //const f_status_t status = f_file_read(path, F_false, &id); + const f_status_t status = f_file_read(file, &buffer); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ void test__f_file_read__parameter_checking(void **state) { f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; { const f_status_t status = f_file_read(file, 0); @@ -52,33 +78,61 @@ void test__f_file_read__fails(void **state) { assert_int_equal(F_status_set_fine(status), F_parameter); } + + f_string_dynamic_resize(0, &buffer); } #endif // _di_level_0_parameter_checking_ void test__f_file_read__returns_file_closed(void **state) { - const f_file_t file = f_file_t_initialize; + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; { - f_string_dynamic_t string = f_string_dynamic_t_initialize; + const f_status_t status = f_file_read(file, &buffer); - const f_status_t status = f_file_read(file, &string); - - assert_int_equal(status, F_data_not); + assert_int_equal(F_status_set_fine(status), F_file_closed); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_read__works(void **state) { - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - //const f_status_t status = f_file_read(); + file.id = 1; + file.size_read = 4; - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + { + will_return(__wrap_read, false); + will_return(__wrap_read, "abcd"); + will_return(__wrap_read, 4); + will_return(__wrap_read, 4); + + will_return(__wrap_read, false); + will_return(__wrap_read, "ef"); + will_return(__wrap_read, 2); + will_return(__wrap_read, 2); + + will_return(__wrap_read, false); + will_return(__wrap_read, ""); + will_return(__wrap_read, 0); + will_return(__wrap_read, 0); + + const f_status_t status = f_file_read(file, &buffer); + + // Ensure string ends in NULL so that assert_string_equal() can be used. + f_string_dynamic_increase_by(1, &buffer); + buffer.string[buffer.used] = 0; + + assert_int_equal(status, F_none_eof); + assert_int_equal(buffer.used, 6); + assert_string_equal(buffer.string, "abcdef"); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus 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 0bfc613..74ad895 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 @@ -7,29 +7,55 @@ extern "C" { void test__f_file_read_block__fails(void **state) { + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; + int errnos[] = { + EAGAIN, + EBADF, + EFAULT, + EINTR, + EINVAL, + EIO, + EISDIR, + EWOULDBLOCK, mock_errno_generic, }; f_status_t statuss[] = { + F_block, + F_file_descriptor, + F_buffer, + F_interrupt, + F_parameter, + F_input_output, + F_file_type_directory, + F_block, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 9; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_read, true); + will_return(__wrap_read, errnos[i]); - //const f_status_t status = f_file_read_block(path, F_false, &id); + const f_status_t status = f_file_read_block(file, &buffer); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ void test__f_file_read_block__parameter_checking(void **state) { f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; { const f_status_t status = f_file_read_block(file, 0); @@ -52,33 +78,64 @@ void test__f_file_read_block__fails(void **state) { assert_int_equal(F_status_set_fine(status), F_parameter); } + + f_string_dynamic_resize(0, &buffer); } #endif // _di_level_0_parameter_checking_ void test__f_file_read_block__returns_file_closed(void **state) { - const f_file_t file = f_file_t_initialize; + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; { - f_string_dynamic_t string = f_string_dynamic_t_initialize; - - const f_status_t status = f_file_read_block(file, &string); + const f_status_t status = f_file_read_block(file, &buffer); - assert_int_equal(status, F_data_not); + assert_int_equal(F_status_set_fine(status), F_file_closed); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_read_block__works(void **state) { + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; + file.size_read = 4; + + { + will_return(__wrap_read, false); + will_return(__wrap_read, "abcd"); + will_return(__wrap_read, 4); + will_return(__wrap_read, 4); + + const f_status_t status = f_file_read_block(file, &buffer); + + // Ensure string ends in NULL so that assert_string_equal() can be used. + f_string_dynamic_increase_by(1, &buffer); + buffer.string[buffer.used] = 0; + + assert_int_equal(status, F_none); + assert_int_equal(buffer.used, 4); + assert_string_equal(buffer.string, "abcd"); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_read, false); + will_return(__wrap_read, ""); + will_return(__wrap_read, 0); + will_return(__wrap_read, 0); - //const f_status_t status = f_file_read_block(); + const f_status_t status = f_file_read_block(file, &buffer); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none_eof); + assert_int_equal(buffer.used, 4); + assert_string_equal(buffer.string, "abcd"); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus 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 9af5839..796f391 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 @@ -7,32 +7,58 @@ extern "C" { void test__f_file_read_until__fails(void **state) { + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; + int errnos[] = { + EAGAIN, + EBADF, + EFAULT, + EINTR, + EINVAL, + EIO, + EISDIR, + EWOULDBLOCK, mock_errno_generic, }; f_status_t statuss[] = { + F_block, + F_file_descriptor, + F_buffer, + F_interrupt, + F_parameter, + F_input_output, + F_file_type_directory, + F_block, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 9; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_read, true); + will_return(__wrap_read, errnos[i]); - //const f_status_t status = f_file_read_until(path, F_false, &id); + const f_status_t status = f_file_read_until(file, 1, &buffer); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ void test__f_file_read_until__parameter_checking(void **state) { f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; { - const f_status_t status = f_file_read_until(file, 0, 0); + const f_status_t status = f_file_read_until(file, 1, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -40,7 +66,7 @@ void test__f_file_read_until__fails(void **state) { file.size_read = 0; { - const f_status_t status = f_file_read_until(file, 0, 0); + const f_status_t status = f_file_read_until(file, 1, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -48,37 +74,84 @@ void test__f_file_read_until__fails(void **state) { { f_string_dynamic_t string = f_string_dynamic_t_initialize; - const f_status_t status = f_file_read_until(file, 0, &string); + const f_status_t status = f_file_read_until(file, 1, &string); assert_int_equal(F_status_set_fine(status), F_parameter); } + + f_string_dynamic_resize(0, &buffer); } #endif // _di_level_0_parameter_checking_ void test__f_file_read_until__returns_file_closed(void **state) { - const f_file_t file = f_file_t_initialize; + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; { - f_string_dynamic_t string = f_string_dynamic_t_initialize; + const f_status_t status = f_file_read_until(file, 1, &buffer); - const f_status_t status = f_file_read_until(file, 0, &string); - - assert_int_equal(status, F_data_not); + assert_int_equal(F_status_set_fine(status), F_file_closed); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_read_until__works(void **state) { + f_file_t file = f_file_t_initialize; + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + file.id = 1; + file.size_read = 4; + + { + will_return(__wrap_read, false); + will_return(__wrap_read, "abcd"); + will_return(__wrap_read, 4); + will_return(__wrap_read, 4); + + will_return(__wrap_read, false); + will_return(__wrap_read, "ef"); + will_return(__wrap_read, 2); + will_return(__wrap_read, 2); + + const f_status_t status = f_file_read_until(file, 6, &buffer); + + // Ensure string ends in NULL so that assert_string_equal() can be used. + f_string_dynamic_increase_by(1, &buffer); + buffer.string[buffer.used] = 0; + + assert_int_equal(status, F_none_stop); + assert_int_equal(buffer.used, 6); + assert_string_equal(buffer.string, "abcdef"); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + buffer.used = 0; + + will_return(__wrap_read, false); + will_return(__wrap_read, "abcd"); + will_return(__wrap_read, 4); + will_return(__wrap_read, 4); + + will_return(__wrap_read, false); + will_return(__wrap_read, ""); + will_return(__wrap_read, 0); + will_return(__wrap_read, 0); - //const f_status_t status = f_file_read_until(); + const f_status_t status = f_file_read_until(file, 6, &buffer); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + // Ensure string ends in NULL so that assert_string_equal() can be used. + f_string_dynamic_increase_by(1, &buffer); + buffer.string[buffer.used] = 0; + + assert_int_equal(status, F_none_eof); + assert_int_equal(buffer.used, 4); + assert_string_equal(buffer.string, "abcd"); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus 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 b10eeeb..38df2ef 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -172,13 +172,14 @@ int main(void) { 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 + cmocka_unit_test(test__f_file_mode_to_mode__works), - // f_file_name_base + cmocka_unit_test(test__f_file_name_base__returns_data_not), + cmocka_unit_test(test__f_file_name_base__works), - // f_file_name_directory + cmocka_unit_test(test__f_file_name_directory__returns_data_not), + cmocka_unit_test(test__f_file_name_directory__works), -/* cmocka_unit_test(test__f_file_open__fails), cmocka_unit_test(test__f_file_open__returns_data_not), cmocka_unit_test(test__f_file_open__works), @@ -187,14 +188,23 @@ int main(void) { cmocka_unit_test(test__f_file_open_at__returns_data_not), cmocka_unit_test(test__f_file_open_at__works), - // f_file_owner_read + cmocka_unit_test(test__f_file_owner_read__fails), + cmocka_unit_test(test__f_file_owner_read__returns_data_not), + cmocka_unit_test(test__f_file_owner_read__works), - // f_file_read + 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__works), - // f_file_read_block + 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__works), - // f_file_read_until + 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__works), +/* cmocka_unit_test(test__f_file_remove__fails), cmocka_unit_test(test__f_file_remove__returns_data_not), cmocka_unit_test(test__f_file_remove__works),