From 018294112409b22aba909071e0acb9a2fbc2f6c6 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 16 Apr 2022 00:04:50 -0500 Subject: [PATCH] Progress: Continue implementing f_file unit tests. The unit tests for f_file_mode_determine() are very minimal. There are quite a lot of permutations that I should test but will not get to. These additional permutations will have to be done in some distant date, probably after the first stable release of the 0.6.x series. --- level_0/f_file/data/build/settings-mocks | 3 + level_0/f_file/tests/unit/c/mock-file.c | 34 ++- level_0/f_file/tests/unit/c/mock-file.h | 2 + level_0/f_file/tests/unit/c/test-file-is.c | 111 ++++++--- level_0/f_file/tests/unit/c/test-file-is_at.c | 103 ++++++--- level_0/f_file/tests/unit/c/test-file-link.c | 75 +++++- level_0/f_file/tests/unit/c/test-file-link_at.c | 79 +++++-- level_0/f_file/tests/unit/c/test-file-link_hard.c | 77 +++++-- .../f_file/tests/unit/c/test-file-link_hard_at.c | 79 +++++-- level_0/f_file/tests/unit/c/test-file-link_read.c | 88 +++++-- .../f_file/tests/unit/c/test-file-link_read_at.c | 88 +++++-- .../f_file/tests/unit/c/test-file-mode_determine.c | 254 ++++++++++++++++++--- .../f_file/tests/unit/c/test-file-mode_determine.h | 16 +- level_0/f_file/tests/unit/c/test-file.c | 30 ++- 14 files changed, 852 insertions(+), 187 deletions(-) diff --git a/level_0/f_file/data/build/settings-mocks b/level_0/f_file/data/build/settings-mocks index 51a03da..e45ccaf 100644 --- a/level_0/f_file/data/build/settings-mocks +++ b/level_0/f_file/data/build/settings-mocks @@ -76,6 +76,8 @@ flags -Wl,--wrap=fsync flags -Wl,--wrap=funlockfile flags -Wl,--wrap=fwrite flags -Wl,--wrap=lchown +flags -Wl,--wrap=link +flags -Wl,--wrap=linkat flags -Wl,--wrap=lstat flags -Wl,--wrap=makedev flags -Wl,--wrap=mkdir @@ -88,6 +90,7 @@ flags -Wl,--wrap=open flags -Wl,--wrap=openat flags -Wl,--wrap=read flags -Wl,--wrap=readlink +flags -Wl,--wrap=readlinkat flags -Wl,--wrap=remove flags -Wl,--wrap=stat flags -Wl,--wrap=symlink 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 6045cbf..884cb09 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -269,6 +269,32 @@ int __wrap_lchown(const char *pathname, uid_t owner, gid_t group) { return mock_type(int); } +int __wrap_link(const char *oldpath, const char *newpath) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_linkat(const char *oldpath, const char *newpath) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + int __wrap_lstat(const char *pathname, struct stat *statbuf) { const bool failure = mock_type(bool); @@ -427,7 +453,9 @@ ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz) { return -1; } - buf = mock_type(char *); + char *buffer = mock_type(char *); + + memcpy(buf, buffer, bufsiz); return mock_type(int); } @@ -442,7 +470,9 @@ ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t buf return -1; } - buf = mock_type(char *); + char *buffer = mock_type(char *); + + memcpy(buf, buffer, bufsiz); return mock_type(int); } diff --git a/level_0/f_file/tests/unit/c/mock-file.h b/level_0/f_file/tests/unit/c/mock-file.h index 744f14b..7c08cd5 100644 --- a/level_0/f_file/tests/unit/c/mock-file.h +++ b/level_0/f_file/tests/unit/c/mock-file.h @@ -48,6 +48,8 @@ extern int __wrap_fsync(int fd); extern void __wrap_funlockfile(FILE *filehandle); extern size_t __wrap_fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream); extern int __wrap_lchown(const char *pathname, uid_t owner, gid_t group); +extern int __wrap_link(const char *oldpath, const char *newpath); +extern int __wrap_linkat(const char *oldpath, const char *newpath); extern int __wrap_lstat(const char *pathname, struct stat *statbuf); extern int __wrap_mkdir(const char *pathname, mode_t mode); extern int __wrap_mkdirat(int dirfd, const char *pathname, mode_t mode); diff --git a/level_0/f_file/tests/unit/c/test-file-is.c b/level_0/f_file/tests/unit/c/test-file-is.c index 9ea517d..da63c9a 100644 --- a/level_0/f_file/tests/unit/c/test-file-is.c +++ b/level_0/f_file/tests/unit/c/test-file-is.c @@ -28,23 +28,46 @@ void test__f_file_is__fails(void **state) { F_name, F_file_found_not, F_memory_not, - F_false, + F_directory_not, F_number_overflow, F_file_stat, }; - // @todo an outer loop is needed to run this against all types. f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, }; - for (int i = 0; i < 9; ++i) { + for (int j = 0; j < 8; ++j) { - //will_return(__wrap_stat, true); - //will_return(__wrap_stat, errnos[i]); + for (int i = 0; i < 9; ++i) { - //const f_status_t status = f_file_is(path); + will_return(__wrap_lstat, true); + will_return(__wrap_lstat, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_is(path, types[j], F_false); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } // for + + for (int j = 0; j < 8; ++j) { + + for (int i = 0; i < 9; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_file_is(path, types[j], F_true); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for } // for } @@ -58,45 +81,75 @@ void test__f_file_is__returns_data_not(void **state) { } void test__f_file_is__returns_false(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - struct stat statistics; + f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, + }; + + for (int j = 0; j < 8; ++j) { - memset(&statistics, 0, sizeof(struct stat)); + struct stat statistics; - { - will_return(__wrap_stat, false); - will_return(__wrap_stat, &statistics); - will_return(__wrap_stat, 0); + memset(&statistics, 0, sizeof(struct stat)); - const f_status_t status = f_file_is(path); + statistics.st_mode = 1 | types[j]; - assert_int_equal(status, F_false); - } - */ + for (int i = 0; i < 8; ++i) { + + // Skip what would return true. + if (j == i) continue; + + will_return(__wrap_lstat, false); + will_return(__wrap_lstat, &statistics); + will_return(__wrap_lstat, 0); + + const f_status_t status = f_file_is(path, types[i], F_false); + + assert_int_equal(status, F_false); + } // for + } // for } void test__f_file_is__returns_true(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - struct stat statistics; + f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, + }; - memset(&statistics, 0, sizeof(struct stat)); + for (int i = 0; i < 8; ++i) { - statistics.st_mode = 1 | F_file_type_directory_d; + struct stat statistics; - { - will_return(__wrap_stat, false); - will_return(__wrap_stat, &statistics); - will_return(__wrap_stat, 0); + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | types[i]; - const f_status_t status = f_file_is(path); + will_return(__wrap_lstat, false); + will_return(__wrap_lstat, &statistics); + will_return(__wrap_lstat, 0); + + const f_status_t status = f_file_is(path, types[i], F_false); assert_int_equal(status, F_true); - } - */ + } // for } #ifdef __cplusplus 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 9511341..203f944 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 @@ -1,12 +1,12 @@ #include "test-file.h" -#include "test-file-is_at.h" +#include "test-file-is.h" #ifdef __cplusplus extern "C" { #endif void test__f_file_is_at__fails(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { @@ -24,78 +24,121 @@ void test__f_file_is_at__fails(void **state) { f_status_t statuss[] = { F_access_denied, - F_file_descriptor, + F_directory_descriptor, F_buffer, F_loop, F_name, F_file_found_not, F_memory_not, - F_false, + F_directory_not, F_number_overflow, F_file_stat, }; - for (int i = 0; i < 10; ++i) { + f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, + }; + + for (int j = 0; j < 8; ++j) { - will_return(__wrap_fstatat, true); - will_return(__wrap_fstatat, errnos[i]); + for (int i = 0; i < 10; ++i) { - const f_status_t status = f_file_is_at(0, path, 0); + will_return(__wrap_fstatat, true); + will_return(__wrap_fstatat, errnos[i]); - assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_is_at(0, path, types[j], 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for } // for - */ } void test__f_file_is_at__returns_data_not(void **state) { -/* + { - const f_status_t status = f_file_is_at(0, f_string_empty_s, 0); + const f_status_t status = f_file_is_at(0, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } - */ } void test__f_file_is_at__returns_false(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - struct stat statistics; + f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, + }; - memset(&statistics, 0, sizeof(struct stat)); + for (int j = 0; j < 8; ++j) { - { - will_return(__wrap_fstatat, false); - will_return(__wrap_fstatat, &statistics); - will_return(__wrap_fstatat, 0); + struct stat statistics; - const f_status_t status = f_file_is_at(0, path, 0); + memset(&statistics, 0, sizeof(struct stat)); - assert_int_equal(status, F_false); - } + statistics.st_mode = 1 | types[j]; + + for (int i = 0; i < 8; ++i) { + + // Skip what would return true. + if (j == i) continue; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); + + const f_status_t status = f_file_is_at(0, path, types[i], 0); + + assert_int_equal(status, F_false); + } // for + } // for } void test__f_file_is_at__returns_true(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - struct stat statistics; + f_status_t types[] = { + F_file_type_block_d, + F_file_type_character_d, + F_file_type_directory_d, + F_file_type_fifo_d, + F_file_type_link_d, + F_file_type_mask_d, + F_file_type_regular_d, + F_file_type_socket_d, + }; - memset(&statistics, 0, sizeof(struct stat)); + for (int i = 0; i < 8; ++i) { - statistics.st_mode = 1 | F_file_type_directory_d; + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | types[i]; - { will_return(__wrap_fstatat, false); will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_is_at(0, path, 0); + const f_status_t status = f_file_is_at(0, path, types[i], 0); assert_int_equal(status, F_true); - } - */ + } // for } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-link.c b/level_0/f_file/tests/unit/c/test-file-link.c index 9ce9e2f..62843aa 100644 --- a/level_0/f_file/tests/unit/c/test-file-link.c +++ b/level_0/f_file/tests/unit/c/test-file-link.c @@ -7,44 +7,95 @@ extern "C" { void test__f_file_link__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EOVERFLOW, + EPERM, + EROFS, + ETXTBSY, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_number_overflow, + F_prohibited, + F_read_only, + F_busy, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 18; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_symlink, true); + will_return(__wrap_symlink, errnos[i]); - //const f_status_t status = f_file_link(path, F_false, &id); + const f_status_t status = f_file_link(path, path); - //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_link__returns_data_not(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_link(f_string_empty_s, f_string_empty_s); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_link(f_string_empty_s); + const f_status_t status = f_file_link(path, f_string_empty_s); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_link(f_string_empty_s, path); + + assert_int_equal(status, F_data_not); } } void test__f_file_link__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); + will_return(__wrap_symlink, false); + will_return(__wrap_symlink, 0); - //const f_status_t status = f_file_link(); + const f_status_t status = f_file_link(path, path); - //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-link_at.c b/level_0/f_file/tests/unit/c/test-file-link_at.c index a5d0c81..8d9c664 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 @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-link_at.h" +#include "test-file-link.h" #ifdef __cplusplus extern "C" { @@ -7,44 +7,97 @@ extern "C" { void test__f_file_link_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EOVERFLOW, + EPERM, + EROFS, + ETXTBSY, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_number_overflow, + F_prohibited, + F_read_only, + F_busy, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 19; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_symlinkat, true); + will_return(__wrap_symlinkat, errnos[i]); - //const f_status_t status = f_file_link_at(path, F_false, &id); + const f_status_t status = f_file_link_at(0, path, path); - //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_link_at__returns_data_not(void **state) { + 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); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_link_at(f_string_empty_s); + const f_status_t status = f_file_link_at(0, path, f_string_empty_s); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_link_at(0, f_string_empty_s, path); + + assert_int_equal(status, F_data_not); } } void test__f_file_link_at__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); + will_return(__wrap_symlinkat, false); + will_return(__wrap_symlinkat, 0); - //const f_status_t status = f_file_link_at(); + const f_status_t status = f_file_link_at(0, path, path); - //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-link_hard.c b/level_0/f_file/tests/unit/c/test-file-link_hard.c index 99f7c23..3cec4e6 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_hard.c +++ b/level_0/f_file/tests/unit/c/test-file-link_hard.c @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-link_hard.h" +#include "test-file-link.h" #ifdef __cplusplus extern "C" { @@ -7,44 +7,95 @@ extern "C" { void test__f_file_link_hard__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EOVERFLOW, + EPERM, + EROFS, + ETXTBSY, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_number_overflow, + F_prohibited, + F_read_only, + F_busy, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 18; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_link, true); + will_return(__wrap_link, errnos[i]); - //const f_status_t status = f_file_link_hard(path, F_false, &id); + const f_status_t status = f_file_link_hard(path, path); - //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_link_hard__returns_data_not(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_file_link_hard(f_string_empty_s, f_string_empty_s); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_link_hard(f_string_empty_s); + const f_status_t status = f_file_link_hard(path, f_string_empty_s); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_link_hard(f_string_empty_s, path); + + assert_int_equal(status, F_data_not); } } void test__f_file_link_hard__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); + will_return(__wrap_link, false); + will_return(__wrap_link, 0); - //const f_status_t status = f_file_link_hard(); + const f_status_t status = f_file_link_hard(path, path); - //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-link_hard_at.c b/level_0/f_file/tests/unit/c/test-file-link_hard_at.c index d6c9b39..2619a42 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 @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-link_hard_at.h" +#include "test-file-link.h" #ifdef __cplusplus extern "C" { @@ -7,44 +7,97 @@ extern "C" { void test__f_file_link_hard_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EDQUOT, + EEXIST, + EFAULT, + EFBIG, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EOVERFLOW, + EPERM, + EROFS, + ETXTBSY, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_file_descriptor, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_number_overflow, + F_prohibited, + F_read_only, + F_busy, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 19; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_linkat, true); + will_return(__wrap_linkat, errnos[i]); - //const f_status_t status = f_file_link_hard_at(path, F_false, &id); + const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0); - //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_link_hard_at__returns_data_not(void **state) { + 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); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_link_hard_at(f_string_empty_s); + const f_status_t status = f_file_link_hard_at(0, 0, path, f_string_empty_s, 0); - //assert_int_equal(status, F_data_not); + 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); + + assert_int_equal(status, F_data_not); } } void test__f_file_link_hard_at__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); + will_return(__wrap_linkat, false); + will_return(__wrap_linkat, 0); - //const f_status_t status = f_file_link_hard_at(); + const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0); - //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-link_read.c b/level_0/f_file/tests/unit/c/test-file-link_read.c index a642475..8519a9a 100644 --- a/level_0/f_file/tests/unit/c/test-file-link_read.c +++ b/level_0/f_file/tests/unit/c/test-file-link_read.c @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-link_read.h" +#include "test-file-link.h" #ifdef __cplusplus extern "C" { @@ -7,23 +7,55 @@ extern "C" { void test__f_file_link_read__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EFAULT, + EINVAL, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_parameter, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, F_failure, }; - for (int i = 0; i < 1; ++i) { + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_size = 1; + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + for (int i = 0; i < 10; ++i) { + + buffer.used = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_readlink, true); + will_return(__wrap_readlink, errnos[i]); - //const f_status_t status = f_file_link_read(path, F_false, &id); + const f_status_t status = f_file_link_read(path, statistics, &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_ @@ -33,40 +65,64 @@ void test__f_file_link_read__fails(void **state) { memset(&statistics, 0, sizeof(struct stat)); + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { const f_status_t status = f_file_link_read(f_string_empty_s, statistics, 0); 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_link_read__returns_data_not(void **state) { - struct stat statistics; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - memset(&statistics, 0, sizeof(struct stat)); + struct stat statistics; - { - f_string_dynamic_t string = f_string_dynamic_t_initialize; + memset(&statistics, 0, sizeof(struct stat)); - const f_status_t status = f_file_link_read(f_string_empty_s, statistics, &string); + statistics.st_size = 1; + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_file_link_read(f_string_empty_s, statistics, &buffer); assert_int_equal(status, F_data_not); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_link_read__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_size = 1; + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + char source[2] = { 'x', 0 }; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_readlink, false); + will_return(__wrap_readlink, source); + will_return(__wrap_readlink, 0); - //const f_status_t status = f_file_link_read(); + const f_status_t status = f_file_link_read(path, statistics, &buffer); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus 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 98b5d3b..253ab4c 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 @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-link_read_at.h" +#include "test-file-link.h" #ifdef __cplusplus extern "C" { @@ -7,23 +7,55 @@ extern "C" { void test__f_file_link_read_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EINVAL, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_parameter, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, F_failure, }; - for (int i = 0; i < 1; ++i) { + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_size = 1; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - //const f_status_t status = f_file_link_read_at(path, F_false, &id); + for (int i = 0; i < 11; ++i) { - //assert_int_equal(F_status_set_fine(status), statuss[i]); + will_return(__wrap_readlinkat, true); + will_return(__wrap_readlinkat, errnos[i]); + + const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ @@ -33,40 +65,64 @@ void test__f_file_link_read_at__fails(void **state) { memset(&statistics, 0, sizeof(struct stat)); + 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, statistics, 0); 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_link_read_at__returns_data_not(void **state) { - struct stat statistics; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - memset(&statistics, 0, sizeof(struct stat)); + struct stat statistics; - { - f_string_dynamic_t string = f_string_dynamic_t_initialize; + memset(&statistics, 0, sizeof(struct stat)); - const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, &string); + statistics.st_size = 1; + + 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, statistics, &buffer); assert_int_equal(status, F_data_not); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_link_read_at__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_size = 1; + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + char source[2] = { 'x', 0 }; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_readlinkat, false); + will_return(__wrap_readlinkat, source); + will_return(__wrap_readlinkat, 0); - //const f_status_t status = f_file_link_read_at(); + const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-mode_determine.c b/level_0/f_file/tests/unit/c/test-file-mode_determine.c index e6122e4..411bd34 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_determine.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_determine.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_file_mode_determine__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_determine(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_determine__parameter_checking(void **state) { @@ -40,16 +19,237 @@ void test__f_file_mode_determine__fails(void **state) { } #endif // _di_level_0_parameter_checking_ -void test__f_file_mode_determine__works(void **state) { +void test__f_file_mode_determine__works_basic(void **state) { + + const mode_t existing = 0; + + { + f_file_mode_t changes[] = { + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + }; + + mode_t changeds[] = { + F_file_mode_all_x_d, + 0, + F_file_mode_all_r_d, + F_file_mode_special_set_group_d, + F_file_mode_special_set_user_d, + F_file_mode_special_sticky_d, + F_file_mode_all_w_d, + F_file_mode_owner_x_d, + 0, + F_file_mode_owner_r_d, + F_file_mode_owner_w_d, + F_file_mode_group_x_d, + 0, + F_file_mode_group_r_d, + F_file_mode_group_w_d, + F_file_mode_world_x_d, + 0, + F_file_mode_world_r_d, + F_file_mode_world_w_d, + }; + + for (uint8_t i = 0; i < 19; ++i) { + + mode_t changed = 0; + + const f_status_t status = f_file_mode_determine(existing, changes[i], 0, F_false, &changed); + + assert_int_equal(status, F_none); + assert_int_equal(changed, changeds[i]); + } // for + } { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_mode_t changes[] = { + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + }; + + mode_t changeds[] = { + F_file_mode_all_x_d, + F_file_mode_all_x_d, + F_file_mode_all_r_d, + F_file_mode_special_set_group_d, + F_file_mode_special_set_user_d, + F_file_mode_special_sticky_d, + F_file_mode_all_w_d, + F_file_mode_owner_x_d, + F_file_mode_owner_x_d, + F_file_mode_owner_r_d, + F_file_mode_owner_w_d, + F_file_mode_group_x_d, + F_file_mode_group_x_d, + F_file_mode_group_r_d, + F_file_mode_group_w_d, + F_file_mode_world_x_d, + F_file_mode_world_x_d, + F_file_mode_world_r_d, + F_file_mode_world_w_d, + }; + + for (uint8_t i = 0; i < 19; ++i) { + + mode_t changed = 0; + + const f_status_t status = f_file_mode_determine(existing, changes[i], 0, F_true, &changed); + + assert_int_equal(status, F_none); + assert_int_equal(changed, changeds[i]); + } // for + } +} + +void test__f_file_mode_determine__works_basic_replace(void **state) { + + const mode_t existing = F_file_mode_all_rwx_d; + + { + f_file_mode_t changes[] = { + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + }; + + mode_t changeds[] = { + F_file_mode_all_x_d, + F_file_mode_all_x_d, + F_file_mode_all_r_d, + F_file_mode_special_set_group_d, + F_file_mode_special_set_user_d, + F_file_mode_special_sticky_d, + F_file_mode_all_w_d, + F_file_mode_owner_x_d, + F_file_mode_owner_x_d, + F_file_mode_owner_r_d, + F_file_mode_owner_w_d, + F_file_mode_group_x_d, + F_file_mode_group_x_d, + F_file_mode_group_r_d, + F_file_mode_group_w_d, + F_file_mode_world_x_d, + F_file_mode_world_x_d, + F_file_mode_world_r_d, + F_file_mode_world_w_d, + }; + + for (uint8_t i = 0; i < 19; ++i) { + + mode_t changed = 0; + + const f_status_t status = f_file_mode_determine(existing, changes[i], F_file_mode_t_replace_all_d, F_false, &changed); + + assert_int_equal(status, F_none); + assert_int_equal(changed, changeds[i]); + } // for + } + + { + f_file_mode_t changes[] = { + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d, + F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d, + F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d, + }; + + mode_t changeds[] = { + F_file_mode_all_x_d, + F_file_mode_all_x_d, + F_file_mode_all_r_d, + F_file_mode_special_set_group_d, + F_file_mode_special_set_user_d, + F_file_mode_special_sticky_d, + F_file_mode_all_w_d, + F_file_mode_owner_x_d, + F_file_mode_owner_x_d, + F_file_mode_owner_r_d, + F_file_mode_owner_w_d, + F_file_mode_group_x_d, + F_file_mode_group_x_d, + F_file_mode_group_r_d, + F_file_mode_group_w_d, + F_file_mode_world_x_d, + F_file_mode_world_x_d, + F_file_mode_world_r_d, + F_file_mode_world_w_d, + }; + + for (uint8_t i = 0; i < 19; ++i) { + + mode_t changed = 0; - //const f_status_t status = f_file_mode_determine(); + const f_status_t status = f_file_mode_determine(existing, changes[i], F_file_mode_t_replace_all_d, F_true, &changed); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(changed, changeds[i]); + } // for } } diff --git a/level_0/f_file/tests/unit/c/test-file-mode_determine.h b/level_0/f_file/tests/unit/c/test-file-mode_determine.h index cb444d9..2dd1def 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_determine.h +++ b/level_0/f_file/tests/unit/c/test-file-mode_determine.h @@ -11,26 +11,26 @@ #define _TEST__F_file_mode_determine_h /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_file_mode_determine() */ -extern void test__f_file_mode_determine__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_file_mode_determine__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that parameter checking works as expected. + * Test that function works for basic combinations. * * @see f_file_mode_determine() */ -#ifndef _di_level_0_parameter_checking_ - extern void test__f_file_mode_determine__parameter_checking(void **state); -#endif // _di_level_0_parameter_checking_ +extern void test__f_file_mode_determine__works_basic(void **state); /** - * Test that function works. + * Test that function works for basic combinations using replace. * * @see f_file_mode_determine() */ -extern void test__f_file_mode_determine__works(void **state); +extern void test__f_file_mode_determine__works_basic_replace(void **state); #endif // _TEST__F_file_mode_determine_h 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 cfef2d4..51ab0f0 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -114,8 +114,6 @@ int main(void) { cmocka_unit_test(test__f_file_group_read__returns_data_not), cmocka_unit_test(test__f_file_group_read__works), -/* - cmocka_unit_test(test__f_file_is__fails), cmocka_unit_test(test__f_file_is__returns_data_not), cmocka_unit_test(test__f_file_is__returns_false), @@ -126,17 +124,32 @@ int main(void) { cmocka_unit_test(test__f_file_is_at__returns_false), cmocka_unit_test(test__f_file_is_at__returns_true), - // f_file_link + cmocka_unit_test(test__f_file_link__fails), + cmocka_unit_test(test__f_file_link__returns_data_not), + cmocka_unit_test(test__f_file_link__works), - // f_file_link_at + 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__works), - // f_file_link_hard + cmocka_unit_test(test__f_file_link_hard__fails), + cmocka_unit_test(test__f_file_link_hard__returns_data_not), + cmocka_unit_test(test__f_file_link_hard__works), - // f_file_link_hard_at + 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__works), - // f_file_link_read + cmocka_unit_test(test__f_file_link_read__fails), + cmocka_unit_test(test__f_file_link_read__returns_data_not), + cmocka_unit_test(test__f_file_link_read__works), - // f_file_link_read_at + 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__works), + + cmocka_unit_test(test__f_file_mode_determine__works_basic), + cmocka_unit_test(test__f_file_mode_determine__works_basic_replace), // f_file_mode_determine @@ -156,6 +169,7 @@ int main(void) { // f_file_name_directory +/* 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), -- 1.8.3.1