From 630de6f9fe5fda1edd0bab89714b8c112e23a3c4 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 18 Apr 2022 22:31:45 -0500 Subject: [PATCH] Progress: Continue implementing f_file unit tests. --- level_0/f_file/data/build/settings-mocks | 4 + level_0/f_file/tests/unit/c/mock-file.c | 41 +++- level_0/f_file/tests/unit/c/mock-file.h | 5 +- level_0/f_file/tests/unit/c/test-file-exists.c | 4 +- level_0/f_file/tests/unit/c/test-file-is.c | 4 +- level_0/f_file/tests/unit/c/test-file-mode_read.c | 4 +- level_0/f_file/tests/unit/c/test-file-remove.c | 26 +- level_0/f_file/tests/unit/c/test-file-remove_at.c | 53 +++- level_0/f_file/tests/unit/c/test-file-rename.c | 63 ++++- level_0/f_file/tests/unit/c/test-file-rename_at.c | 81 +++++-- .../f_file/tests/unit/c/test-file-role_change.c | 260 ++++++++++++++++++-- .../f_file/tests/unit/c/test-file-role_change.h | 22 +- .../f_file/tests/unit/c/test-file-role_change_at.c | 266 +++++++++++++++++++-- .../f_file/tests/unit/c/test-file-role_change_at.h | 22 +- level_0/f_file/tests/unit/c/test-file-seek.c | 47 +++- level_0/f_file/tests/unit/c/test-file-size.c | 56 ++++- level_0/f_file/tests/unit/c/test-file-size_at.c | 78 +++++- level_0/f_file/tests/unit/c/test-file-size_by_id.c | 71 +++++- level_0/f_file/tests/unit/c/test-file-size_by_id.h | 7 + level_0/f_file/tests/unit/c/test-file-stat.c | 69 ++++-- level_0/f_file/tests/unit/c/test-file-stat_at.c | 92 +++++-- level_0/f_file/tests/unit/c/test-file-stat_by_id.c | 80 ++++++- level_0/f_file/tests/unit/c/test-file-stat_by_id.h | 7 + level_0/f_file/tests/unit/c/test-file.c | 50 +++- 24 files changed, 1218 insertions(+), 194 deletions(-) diff --git a/level_0/f_file/data/build/settings-mocks b/level_0/f_file/data/build/settings-mocks index e45ccaf..be55dfe 100644 --- a/level_0/f_file/data/build/settings-mocks +++ b/level_0/f_file/data/build/settings-mocks @@ -78,6 +78,7 @@ flags -Wl,--wrap=fwrite flags -Wl,--wrap=lchown flags -Wl,--wrap=link flags -Wl,--wrap=linkat +flags -Wl,--wrap=lseek flags -Wl,--wrap=lstat flags -Wl,--wrap=makedev flags -Wl,--wrap=mkdir @@ -91,6 +92,9 @@ flags -Wl,--wrap=openat flags -Wl,--wrap=read flags -Wl,--wrap=readlink flags -Wl,--wrap=readlinkat +flags -Wl,--wrap=rename +flags -Wl,--wrap=renameat +flags -Wl,--wrap=renameat2 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 0379c1f..8e2e2aa 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -295,6 +295,19 @@ int __wrap_linkat(const char *oldpath, const char *newpath) { return mock_type(int); } +off_t __wrap_lseek(int fd, off_t offset, int whence) { + + 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); @@ -482,7 +495,33 @@ ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t buf return mock_type(int); } -int __wrap_remove(const char *pathname) { +int __wrap_rename(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_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) { const bool failure = mock_type(bool); 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 7c08cd5..11029b3 100644 --- a/level_0/f_file/tests/unit/c/mock-file.h +++ b/level_0/f_file/tests/unit/c/mock-file.h @@ -50,6 +50,7 @@ extern size_t __wrap_fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, 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 off_t __wrap_lseek(int fd, off_t offset, int whence); 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); @@ -62,7 +63,9 @@ extern int __wrap_openat(int dirfd, const char *pathname, int flags, mode_t mode extern ssize_t __wrap_read(int fd, void *buf, size_t count); extern ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz); extern ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); -extern int __wrap_remove(const char *pathname); +extern int __wrap_rename(const char *oldpath, const char *newpath); +extern int __wrap_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); +extern int __wrap_renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); extern int __wrap_stat(const char *pathname, struct stat *statbuf); extern int __wrap_symlink(const char *target, const char *linkpath); extern int __wrap_symlinkat(const char *target, int newdirfd, const char *linkpath); diff --git a/level_0/f_file/tests/unit/c/test-file-exists.c b/level_0/f_file/tests/unit/c/test-file-exists.c index 52ca779..01e9e03 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists.c +++ b/level_0/f_file/tests/unit/c/test-file-exists.c @@ -12,6 +12,7 @@ void test__f_file_exists__fails(void **state) { int errnos[] = { EACCES, EFAULT, + EINVAL, ELOOP, ENAMETOOLONG, ENOENT, @@ -24,6 +25,7 @@ void test__f_file_exists__fails(void **state) { f_status_t statuss[] = { F_access_denied, F_buffer, + F_parameter, F_loop, F_name, F_false, @@ -33,7 +35,7 @@ void test__f_file_exists__fails(void **state) { F_file_stat, }; - for (int i = 0; i < 9; ++i) { + for (int i = 0; i < 10; ++i) { will_return(__wrap_lstat, true); will_return(__wrap_lstat, errnos[i]); 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 da63c9a..2786cc8 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 @@ -12,6 +12,7 @@ void test__f_file_is__fails(void **state) { int errnos[] = { EACCES, EFAULT, + EINVAL, ELOOP, ENAMETOOLONG, ENOENT, @@ -24,6 +25,7 @@ void test__f_file_is__fails(void **state) { f_status_t statuss[] = { F_access_denied, F_buffer, + F_parameter, F_loop, F_name, F_file_found_not, @@ -46,7 +48,7 @@ void test__f_file_is__fails(void **state) { for (int j = 0; j < 8; ++j) { - for (int i = 0; i < 9; ++i) { + for (int i = 0; i < 10; ++i) { will_return(__wrap_lstat, true); will_return(__wrap_lstat, errnos[i]); diff --git a/level_0/f_file/tests/unit/c/test-file-mode_read.c b/level_0/f_file/tests/unit/c/test-file-mode_read.c index 4cbc416..876bb25 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_read.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_read.c @@ -12,6 +12,7 @@ void test__f_file_mode_read__fails(void **state) { int errnos[] = { EACCES, EFAULT, + EINVAL, ELOOP, ENAMETOOLONG, ENOENT, @@ -24,6 +25,7 @@ void test__f_file_mode_read__fails(void **state) { f_status_t statuss[] = { F_access_denied, F_buffer, + F_parameter, F_loop, F_name, F_file_found_not, @@ -33,7 +35,7 @@ void test__f_file_mode_read__fails(void **state) { F_file_stat, }; - for (int i = 0; i < 9; ++i) { + for (int i = 0; i < 10; ++i) { mode_t mode = 0; diff --git a/level_0/f_file/tests/unit/c/test-file-remove.c b/level_0/f_file/tests/unit/c/test-file-remove.c index 251627f..bd3db21 100644 --- a/level_0/f_file/tests/unit/c/test-file-remove.c +++ b/level_0/f_file/tests/unit/c/test-file-remove.c @@ -6,24 +6,20 @@ extern "C" { #endif void test__f_file_remove__fails(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { EACCES, EBUSY, EFAULT, - EINVAL, EIO, EISDIR, ELOOP, - EMFILE, ENAMETOOLONG, - ENFILE, ENOENT, ENOMEM, ENOTDIR, - ENOTEMPTY, EPERM, EROFS, mock_errno_generic, @@ -33,34 +29,29 @@ void test__f_file_remove__fails(void **state) { F_access_denied, F_busy, F_buffer, - F_parameter, F_input_output, F_file_type_directory, F_loop, - F_file_descriptor_max, F_name, - F_file_open_max, F_file_found_not, F_memory_not, - F_file_not, - F_file_empty_not, + F_directory_not, F_prohibited, F_read_only, F_failure, }; { - for (int i = 0; i < 17; ++i) { + for (int i = 0; i < 13; ++i) { - will_return(__wrap_remove, true); - will_return(__wrap_remove, errnos[i]); + will_return(__wrap_unlink, true); + will_return(__wrap_unlink, errnos[i]); const f_status_t status = f_file_remove(path); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } - */ } void test__f_file_remove__returns_data_not(void **state) { @@ -73,18 +64,17 @@ void test__f_file_remove__returns_data_not(void **state) { } void test__f_file_remove__works(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - will_return(__wrap_remove, false); - will_return(__wrap_remove, 0); + will_return(__wrap_unlink, false); + will_return(__wrap_unlink, 0); const f_status_t status = f_file_remove(path); assert_int_equal(status, F_none); } - */ } #ifdef __cplusplus 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 71df150..aac3ca8 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,23 +7,53 @@ extern "C" { void test__f_file_remove_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EBUSY, + EFAULT, + EIO, + EISDIR, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_busy, + F_buffer, + F_input_output, + F_file_type_directory, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_prohibited, + F_read_only, F_failure, }; - for (int i = 0; i < 1; ++i) { + { + for (int i = 0; i < 14; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_unlinkat, true); + will_return(__wrap_unlinkat, errnos[i]); - //const f_status_t status = f_file_remove_at(path, F_false, &id); + const f_status_t status = f_file_remove_at(0, path, 0); - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } } void test__f_file_remove_at__returns_data_not(void **state) { @@ -37,14 +67,15 @@ void test__f_file_remove_at__returns_data_not(void **state) { void test__f_file_remove_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_unlinkat, false); + will_return(__wrap_unlinkat, 0); - //const f_status_t status = f_file_remove_at(); + const f_status_t status = f_file_remove_at(0, 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-rename.c b/level_0/f_file/tests/unit/c/test-file-rename.c index 1922d39..e38fb26 100644 --- a/level_0/f_file/tests/unit/c/test-file-rename.c +++ b/level_0/f_file/tests/unit/c/test-file-rename.c @@ -7,23 +7,63 @@ extern "C" { void test__f_file_rename__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBUSY, + EDQUOT, + EFAULT, + EINVAL, + EISDIR, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + ENOTEMPTY, + EEXIST, + EPERM, + EROFS, + EXDEV, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_busy, + F_filesystem_quota_block, + F_buffer, + F_parameter, + F_file_type_directory, + F_loop, + F_link, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_directory_empty_not, + F_directory_empty_not, + F_prohibited, + F_read_only, + F_mount, 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_rename, true); + will_return(__wrap_rename, errnos[i]); - //const f_status_t status = f_file_rename(path, F_false, &id); + const f_status_t status = f_file_rename(path, path); - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } } void test__f_file_rename__returns_data_not(void **state) { @@ -51,14 +91,15 @@ void test__f_file_rename__returns_data_not(void **state) { void test__f_file_rename__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_rename, false); + will_return(__wrap_rename, 0); - //const f_status_t status = f_file_rename(); + const f_status_t status = f_file_rename(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-rename_at.c b/level_0/f_file/tests/unit/c/test-file-rename_at.c index 123f913..0373bf0 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,23 +7,70 @@ extern "C" { void test__f_file_rename_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EBUSY, + EDQUOT, + EFAULT, + EINVAL, + EISDIR, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + ENOTEMPTY, + EEXIST, + EPERM, + EROFS, + EXDEV, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_busy, + F_filesystem_quota_block, + F_buffer, + F_parameter, + F_file_type_directory, + F_loop, + F_link, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_directory_empty_not, + F_directory_empty_not, + F_prohibited, + F_read_only, + F_mount, F_failure, }; - for (int i = 0; i < 1; ++i) { + { + for (int i = 0; i < 20; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + #ifdef _f_file_rename_use_renameat2_ + will_return(__wrap_renameat2, true); + will_return(__wrap_renameat2, errnos[i]); + #else + will_return(__wrap_renameat, true); + will_return(__wrap_renameat, errnos[i]); + #endif // _f_file_rename_use_renameat2_ - //const f_status_t status = f_file_rename_at(path, F_false, &id); + const f_status_t status = f_file_rename_at(0, 0, path, path, 0); - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } } void test__f_file_rename_at__returns_data_not(void **state) { @@ -31,19 +78,19 @@ void test__f_file_rename_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_rename_at(0, 0, f_string_empty_s, f_string_empty_s); + const f_status_t status = f_file_rename_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_rename_at(0, 0, path, f_string_empty_s); + const f_status_t status = f_file_rename_at(0, 0, 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); + const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, path, 0); assert_int_equal(status, F_data_not); } @@ -51,14 +98,20 @@ void test__f_file_rename_at__returns_data_not(void **state) { void test__f_file_rename_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); + #ifdef _f_file_rename_use_renameat2_ + will_return(__wrap_renameat2, false); + will_return(__wrap_renameat2, 0); + #else + will_return(__wrap_renameat, false); + will_return(__wrap_renameat, 0); + #endif // _f_file_rename_use_renameat2_ - //const f_status_t status = f_file_rename_at(); + const f_status_t status = f_file_rename_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-role_change.c b/level_0/f_file/tests/unit/c/test-file-role_change.c index 43aec90..61eb9c6 100644 --- a/level_0/f_file/tests/unit/c/test-file-role_change.c +++ b/level_0/f_file/tests/unit/c/test-file-role_change.c @@ -5,46 +5,276 @@ extern "C" { #endif -void test__f_file_role_change__fails(void **state) { +void test__f_file_role_change__fails_for_dereference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { + EACCES, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, mock_errno_generic, }; - f_status_t statuss[] = { + f_status_t status_owners[] = { + F_access_denied, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_owner, + F_read_only, + F_failure, + }; + + f_status_t status_groups[] = { + F_access_denied, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_group, + F_read_only, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_chown, true); + will_return(__wrap_chown, errnos[i]); + + const f_status_t status = f_file_role_change(path, 0, 0, F_true); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_chown, false); + will_return(__wrap_chown, 0); + + will_return(__wrap_chown, true); + will_return(__wrap_chown, errnos[i]); + + const f_status_t status = f_file_role_change(path, 0, 0, F_true); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_chown, true); + will_return(__wrap_chown, errnos[i]); + + const f_status_t status = f_file_role_change(path, -1, 0, F_true); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_chown, true); + will_return(__wrap_chown, errnos[i]); + + const f_status_t status = f_file_role_change(path, 0, -1, F_true); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for +} + +void test__f_file_role_change__fails_for_reference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t status_owners[] = { + F_access_denied, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_owner, + F_read_only, + F_failure, + }; + + f_status_t status_groups[] = { + F_access_denied, + F_buffer, + F_input_output, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_access_group, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_lchown, true); + will_return(__wrap_lchown, errnos[i]); + + const f_status_t status = f_file_role_change(path, 0, 0, F_false); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_lchown, false); + will_return(__wrap_lchown, 0); + + will_return(__wrap_lchown, true); + will_return(__wrap_lchown, errnos[i]); + + const f_status_t status = f_file_role_change(path, 0, 0, F_false); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 11; ++i) { + + will_return(__wrap_lchown, true); + will_return(__wrap_lchown, errnos[i]); + + const f_status_t status = f_file_role_change(path, -1, 0, F_false); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + for (int i = 0; i < 11; ++i) { - //const f_status_t status = f_file_role_change(path, F_false, &id); + will_return(__wrap_lchown, true); + will_return(__wrap_lchown, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_role_change(path, 0, -1, F_false); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for } void test__f_file_role_change__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_role_change(f_string_empty_s, -1, -1, F_true); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_role_change(f_string_empty_s); + const f_status_t status = f_file_role_change(path, -1, -1, F_true); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_role_change(f_string_empty_s, 0, 0, F_true); + + assert_int_equal(status, F_data_not); } } -void test__f_file_role_change__works(void **state) { +void test__f_file_role_change__works_for_dereference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_chown, false); + will_return(__wrap_chown, 0); + + will_return(__wrap_chown, false); + will_return(__wrap_chown, 0); + + const f_status_t status = f_file_role_change(path, 0, 0, F_true); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_chown, false); + will_return(__wrap_chown, 0); + + const f_status_t status = f_file_role_change(path, -1, 0, F_true); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_chown, false); + will_return(__wrap_chown, 0); + + const f_status_t status = f_file_role_change(path, 0, -1, F_true); + + assert_int_equal(status, F_none); + } +} + +void test__f_file_role_change__works_for_reference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_lchown, false); + will_return(__wrap_lchown, 0); + + will_return(__wrap_lchown, false); + will_return(__wrap_lchown, 0); + + const f_status_t status = f_file_role_change(path, 0, 0, F_false); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_lchown, false); + will_return(__wrap_lchown, 0); + + const f_status_t status = f_file_role_change(path, -1, 0, F_false); + + assert_int_equal(status, F_none); + } { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_lchown, false); + will_return(__wrap_lchown, 0); - //const f_status_t status = f_file_role_change(); + const f_status_t status = f_file_role_change(path, 0, -1, F_false); - //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-role_change.h b/level_0/f_file/tests/unit/c/test-file-role_change.h index 37e16f9..4d20319 100644 --- a/level_0/f_file/tests/unit/c/test-file-role_change.h +++ b/level_0/f_file/tests/unit/c/test-file-role_change.h @@ -11,11 +11,18 @@ #define _TEST__F_file_role_change_h /** - * Test that function fails. + * Test that function fails for dereferenced files. * * @see f_file_role_change() */ -extern void test__f_file_role_change__fails(void **state); +extern void test__f_file_role_change__fails_for_dereference(void **state); + +/** + * Test that function fails for referenced files. + * + * @see f_file_role_change() + */ +extern void test__f_file_role_change__fails_for_reference(void **state); /** * Test that function works but the path is empty. @@ -25,10 +32,17 @@ extern void test__f_file_role_change__fails(void **state); extern void test__f_file_role_change__returns_data_not(void **state); /** - * Test that function works. + * Test that function works for dereferenced files. + * + * @see f_file_role_change() + */ +extern void test__f_file_role_change__works_for_dereference(void **state); + +/** + * Test that function works for referenced files. * * @see f_file_role_change() */ -extern void test__f_file_role_change__works(void **state); +extern void test__f_file_role_change__works_for_reference(void **state); #endif // _TEST__F_file_role_change_h 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 74a9a05..ab69cb0 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 @@ -5,46 +5,282 @@ extern "C" { #endif -void test__f_file_role_change_at__fails(void **state) { +void test__f_file_role_change_at__fails_for_dereference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { + EACCES, + EBADF, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, mock_errno_generic, }; - f_status_t statuss[] = { + f_status_t status_owners[] = { + 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_owner, + F_read_only, + F_failure, + }; + + f_status_t status_groups[] = { + 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_group, + F_read_only, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 12; ++i) { + + 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); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for + + for (int i = 0; i < 12; ++i) { + + will_return(__wrap_fchownat, false); + will_return(__wrap_fchownat, 0); + + 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); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 12; ++i) { + + 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); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 12; ++i) { + + 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); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for +} + +void test__f_file_role_change_at__fails_for_reference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EIO, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t status_owners[] = { + 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_owner, + F_read_only, + F_failure, + }; + + f_status_t status_groups[] = { + 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_group, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 12; ++i) { + + 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); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); + } // for + + for (int i = 0; i < 12; ++i) { + + will_return(__wrap_fchownat, false); + will_return(__wrap_fchownat, 0); + + 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); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for + + for (int i = 0; i < 12; ++i) { + + 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); + + assert_int_equal(F_status_set_fine(status), status_groups[i]); + } // for - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + for (int i = 0; i < 12; ++i) { - //const f_status_t status = f_file_role_change_at(path, F_false, &id); + will_return(__wrap_fchownat, true); + will_return(__wrap_fchownat, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d); + + assert_int_equal(F_status_set_fine(status), status_owners[i]); } // for } void test__f_file_role_change_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_role_change_at(0, f_string_empty_s, -1, -1, 0); + + assert_int_equal(status, F_data_not); + } + { - //const f_status_t status = f_file_role_change_at(f_string_empty_s); + const f_status_t status = f_file_role_change_at(0, path, -1, -1, 0); - //assert_int_equal(status, F_data_not); + 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); + + assert_int_equal(status, F_data_not); } } -void test__f_file_role_change_at__works(void **state) { +void test__f_file_role_change_at__works_for_dereference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_fchownat, false); + will_return(__wrap_fchownat, 0); + + 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); + + assert_int_equal(status, F_none); + } + + { + 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); + + assert_int_equal(status, F_none); + } + + { + 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); + + assert_int_equal(status, F_none); + } +} + +void test__f_file_role_change_at__works_for_reference(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_fchownat, false); + will_return(__wrap_fchownat, 0); + + 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); + + assert_int_equal(status, F_none); + } + + { + 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); + + assert_int_equal(status, F_none); + } { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_fchownat, false); + will_return(__wrap_fchownat, 0); - //const f_status_t status = f_file_role_change_at(); + const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d); - //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-role_change_at.h b/level_0/f_file/tests/unit/c/test-file-role_change_at.h index c4e8f48..5ba8f48 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 @@ -11,11 +11,18 @@ #define _TEST__F_file_role_change_at_h /** - * Test that function fails. + * Test that function fails for dereferenced files. * * @see f_file_role_change_at() */ -extern void test__f_file_role_change_at__fails(void **state); +extern void test__f_file_role_change_at__fails_for_dereference(void **state); + +/** + * Test that function fails for referenced files. + * + * @see f_file_role_change_at() + */ +extern void test__f_file_role_change_at__fails_for_reference(void **state); /** * Test that function works but the path is empty. @@ -25,10 +32,17 @@ extern void test__f_file_role_change_at__fails(void **state); extern void test__f_file_role_change_at__returns_data_not(void **state); /** - * Test that function works. + * Test that function works for dereferenced files. + * + * @see f_file_role_change_at() + */ +extern void test__f_file_role_change_at__works_for_dereference(void **state); + +/** + * Test that function works for referenced files. * * @see f_file_role_change_at() */ -extern void test__f_file_role_change_at__works(void **state); +extern void test__f_file_role_change_at__works_for_reference(void **state); #endif // _TEST__F_file_role_change_at_h 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 0e2e2e4..a1bae7f 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 @@ -8,27 +8,53 @@ extern "C" { void test__f_file_seek__fails(void **state) { int errnos[] = { + EBADF, + EINVAL, + ENXIO, + EOVERFLOW, + ESPIPE, mock_errno_generic, }; f_status_t statuss[] = { + F_file_descriptor, + F_parameter, + F_bound_not, + F_number_overflow, + F_file_type_pipe, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 6; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + off_t seeked = 0; - //const f_status_t status = f_file_seek(path, F_false, &id); + will_return(__wrap_lseek, true); + will_return(__wrap_lseek, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_seek(0, 0, 0, &seeked); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } #ifndef _di_level_0_parameter_checking_ void test__f_file_seek__parameter_checking(void **state) { + off_t seeked = 0; + + { + const f_status_t status = f_file_seek(0, -1, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + + { + const f_status_t status = f_file_seek(0, -1, 0, &seeked); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + { const f_status_t status = f_file_seek(0, 0, 0, 0); @@ -40,13 +66,14 @@ void test__f_file_seek__fails(void **state) { void test__f_file_seek__works(void **state) { { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + off_t seeked = 0; + + will_return(__wrap_lseek, false); + will_return(__wrap_lseek, 0); - //const f_status_t status = f_file_seek(); + const f_status_t status = f_file_seek(0, 0, 0, &seeked); - //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-size.c b/level_0/f_file/tests/unit/c/test-file-size.c index a09198b..7a8eab3 100644 --- a/level_0/f_file/tests/unit/c/test-file-size.c +++ b/level_0/f_file/tests/unit/c/test-file-size.c @@ -7,22 +7,44 @@ extern "C" { void test__f_file_size__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_buffer, + F_parameter, + 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 < 10; ++i) { + + off_t size = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_lstat, true); + will_return(__wrap_lstat, errnos[i]); - //const f_status_t status = f_file_size(path, F_false, &id); + const f_status_t status = f_file_size(path, F_false, &size); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -50,14 +72,26 @@ void test__f_file_size__returns_data_not(void **state) { void test__f_file_size__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)); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + off_t size = 0; + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - //const f_status_t status = f_file_size(); + const f_status_t status = f_file_size(path, F_true, &size); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + 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.c b/level_0/f_file/tests/unit/c/test-file-size_at.c index 551ab06..3de4ad8 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,22 +7,46 @@ extern "C" { void test__f_file_size_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, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_directory_descriptor, + F_buffer, + F_parameter, + 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 < 11; ++i) { + + off_t size = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fstatat, true); + will_return(__wrap_fstatat, errnos[i]); - //const f_status_t status = f_file_size_at(path, F_false, &id); + const f_status_t status = f_file_size_at(0, path, F_false, &size); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -40,7 +64,9 @@ void test__f_file_size_at__fails(void **state) { void test__f_file_size_at__returns_data_not(void **state) { { - const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, 0); + off_t size = 0; + + const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, &size); assert_int_equal(status, F_data_not); } @@ -48,14 +74,42 @@ void test__f_file_size_at__returns_data_not(void **state) { void test__f_file_size_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)); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + off_t size = 0; + + statistics.st_mode = 1 | F_file_type_link_d; + statistics.st_size = 1; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); + + const f_status_t status = f_file_size_at(0, path, F_false, &size); + + assert_int_equal(status, F_none); + assert_int_equal(size, statistics.st_size); + } + + { + off_t size = 0; + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); - //const f_status_t status = f_file_size_at(); + const f_status_t status = f_file_size_at(0, path, F_true, &size); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + 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.c b/level_0/f_file/tests/unit/c/test-file-size_by_id.c index d54be26..2b289fb 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,22 +7,48 @@ extern "C" { void test__f_file_size_by_id__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_file_descriptor, + F_buffer, + F_parameter, + 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 < 11; ++i) { + + off_t size = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + printf("\nDEBUG: i=%d\n", i); - //const f_status_t status = f_file_size_by_id(path, F_false, &id); + will_return(__wrap_fstat, true); + will_return(__wrap_fstat, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_size_by_id(0, &size); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -37,16 +63,39 @@ void test__f_file_size_by_id__fails(void **state) { } #endif // _di_level_0_parameter_checking_ +void test__f_file_size_by_id__returns_file_closed(void **state) { + + { + off_t size = 0; + + const f_status_t status = f_file_size_by_id(-1, &size); + + assert_int_equal(F_status_set_fine(status), F_file_closed); + } // for +} + void test__f_file_size_by_id__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)); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + off_t size = 0; + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_fstat, false); + will_return(__wrap_fstat, &statistics); + will_return(__wrap_fstat, 0); - //const f_status_t status = f_file_size_by_id(); + const f_status_t status = f_file_size_by_id(0, &size); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + 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 bc095b2..088faa6 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 @@ -27,6 +27,13 @@ extern void test__f_file_size_by_id__fails(void **state); #endif // _di_level_0_parameter_checking_ /** + * Test that function works but the file is closed. + * + * @see f_file_size_by_id() + */ +extern void test__f_file_size_by_id__returns_file_closed(void **state); + +/** * Test that function works. * * @see f_file_size_by_id() diff --git a/level_0/f_file/tests/unit/c/test-file-stat.c b/level_0/f_file/tests/unit/c/test-file-stat.c index edc1396..c19228c 100644 --- a/level_0/f_file/tests/unit/c/test-file-stat.c +++ b/level_0/f_file/tests/unit/c/test-file-stat.c @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-stat.h" +#include "test-file-size.h" #ifdef __cplusplus extern "C" { @@ -7,22 +7,46 @@ extern "C" { void test__f_file_stat__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_buffer, + F_parameter, + 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 < 10; ++i) { + + struct stat result; + + memset(&result, 0, sizeof(struct stat)); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_lstat, true); + will_return(__wrap_lstat, errnos[i]); - //const f_status_t status = f_file_stat(path, F_false, &id); + const f_status_t status = f_file_stat(path, F_false, &result); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -40,9 +64,11 @@ void test__f_file_stat__fails(void **state) { void test__f_file_stat__returns_data_not(void **state) { { - struct stat statistics; + struct stat result; - const f_status_t status = f_file_stat(f_string_empty_s, F_false, &statistics); + memset(&result, 0, sizeof(struct stat)); + + const f_status_t status = f_file_stat(f_string_empty_s, F_false, &result); assert_int_equal(status, F_data_not); } @@ -50,14 +76,29 @@ void test__f_file_stat__returns_data_not(void **state) { void test__f_file_stat__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)); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - //const f_status_t status = f_file_stat(); + const f_status_t status = f_file_stat(path, F_true, &result); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(result.st_mode, statistics.st_mode); + assert_int_equal(result.st_size, statistics.st_size); } } 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 06d25bc..ba565f1 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 @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-stat_at.h" +#include "test-file-size_at.h" #ifdef __cplusplus extern "C" { @@ -7,22 +7,48 @@ extern "C" { void test__f_file_stat_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, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_directory_descriptor, + F_buffer, + F_parameter, + 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 < 11; ++i) { + + struct stat result; + + memset(&result, 0, sizeof(struct stat)); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fstatat, true); + will_return(__wrap_fstatat, errnos[i]); - //const f_status_t status = f_file_stat_at(path, F_false, &id); + const f_status_t status = f_file_stat_at(0, path, F_false, &result); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -30,7 +56,7 @@ void test__f_file_stat_at__fails(void **state) { void test__f_file_stat_at__parameter_checking(void **state) { { - const f_status_t status = f_file_stat_at(0, f_string_empty_s, 0, 0); + const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -40,9 +66,11 @@ void test__f_file_stat_at__fails(void **state) { void test__f_file_stat_at__returns_data_not(void **state) { { - struct stat statistics; + struct stat result; - const f_status_t status = f_file_stat_at(0, f_string_empty_s, 0, &statistics); + memset(&result, 0, sizeof(struct stat)); + + const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, &result); assert_int_equal(status, F_data_not); } @@ -50,14 +78,48 @@ void test__f_file_stat_at__returns_data_not(void **state) { void test__f_file_stat_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)); + + { + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_link_d; + statistics.st_size = 1; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); + + const f_status_t status = f_file_stat_at(0, path, F_false, &result); + + assert_int_equal(status, F_none); + assert_int_equal(result.st_mode, statistics.st_mode); + assert_int_equal(result.st_size, statistics.st_size); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); - //const f_status_t status = f_file_stat_at(); + const f_status_t status = f_file_stat_at(0, path, F_true, &result); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(result.st_mode, statistics.st_mode); + assert_int_equal(result.st_size, statistics.st_size); } } 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 2730563..6fd4a08 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 @@ -1,5 +1,5 @@ #include "test-file.h" -#include "test-file-stat_by_id.h" +#include "test-file-size_by_id.h" #ifdef __cplusplus extern "C" { @@ -7,22 +7,50 @@ extern "C" { void test__f_file_stat_by_id__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_file_descriptor, + F_buffer, + F_parameter, + 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 < 11; ++i) { + + struct stat result; + + memset(&result, 0, sizeof(struct stat)); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + printf("\nDEBUG: i=%d\n", i); - //const f_status_t status = f_file_stat_by_id(path, F_false, &id); + will_return(__wrap_fstat, true); + will_return(__wrap_fstat, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_stat_by_id(0, &result); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -37,16 +65,44 @@ void test__f_file_stat_by_id__fails(void **state) { } #endif // _di_level_0_parameter_checking_ +void test__f_file_stat_by_id__returns_file_closed(void **state) { + + { + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + const f_status_t status = f_file_stat_by_id(-1, &result); + + assert_int_equal(F_status_set_fine(status), F_file_closed); + } // for +} + void test__f_file_stat_by_id__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)); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + struct stat result; + + memset(&result, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_regular_d; + statistics.st_size = 1; + + will_return(__wrap_fstat, false); + will_return(__wrap_fstat, &statistics); + will_return(__wrap_fstat, 0); - //const f_status_t status = f_file_stat_by_id(); + const f_status_t status = f_file_stat_by_id(0, &result); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(result.st_mode, statistics.st_mode); + assert_int_equal(result.st_size, statistics.st_size); } } 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 c845894..2565d26 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 @@ -27,6 +27,13 @@ extern void test__f_file_stat_by_id__fails(void **state); #endif // _di_level_0_parameter_checking_ /** + * Test that function works but the file is closed. + * + * @see f_file_stat_by_id() + */ +extern void test__f_file_stat_by_id__returns_file_closed(void **state); + +/** * Test that function works. * * @see f_file_stat_by_id() 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 38df2ef..1ef2b7d 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -204,7 +204,6 @@ int main(void) { 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), @@ -213,27 +212,54 @@ int main(void) { cmocka_unit_test(test__f_file_remove_at__returns_data_not), cmocka_unit_test(test__f_file_remove_at__works), - // f_file_rename + cmocka_unit_test(test__f_file_rename__fails), + cmocka_unit_test(test__f_file_rename__returns_data_not), + cmocka_unit_test(test__f_file_rename__works), + + 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__works), - // f_file_rename_at + cmocka_unit_test(test__f_file_role_change__fails_for_dereference), + cmocka_unit_test(test__f_file_role_change__fails_for_reference), + cmocka_unit_test(test__f_file_role_change__returns_data_not), + cmocka_unit_test(test__f_file_role_change__works_for_dereference), + cmocka_unit_test(test__f_file_role_change__works_for_reference), - // f_file_role_change + 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__works_for_dereference), + cmocka_unit_test(test__f_file_role_change_at__works_for_reference), - // f_file_role_change_at + cmocka_unit_test(test__f_file_seek__fails), + cmocka_unit_test(test__f_file_seek__works), - // f_file_seek + cmocka_unit_test(test__f_file_size__fails), + cmocka_unit_test(test__f_file_size__returns_data_not), + cmocka_unit_test(test__f_file_size__works), - // f_file_size + 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__works), - // f_file_size_at + 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_size_by_id__works), - // f_file_size_by_id + cmocka_unit_test(test__f_file_stat__fails), + cmocka_unit_test(test__f_file_stat__returns_data_not), + cmocka_unit_test(test__f_file_stat__works), - // f_file_stat + 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__works), - // f_file_stat_at + 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__works), - // f_file_stat_by_id +/* // f_file_stream_close -- 1.8.3.1