From: Kevin Day Date: Sun, 3 Apr 2022 15:59:05 +0000 (-0500) Subject: Update: Add f_directory tests then fix problems discovered problems and perform appro... X-Git-Tag: 0.5.9^0 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ac127de14acc691cab01a235f38b25ba2a10f3e1;p=fll Update: Add f_directory tests then fix problems discovered problems and perform appropriate cleanups. The "preserve_path_headers" in settings-mocks and settings-tests should be set to "yes". Add missing dependencies-tests file for any project providing tests. Remove at_id <= 0 parameter checks because this is already handled by EBADF. Fix alphabetic ordering of errno returns for f_directory. I started doing this for f_file as well until I realized how much there is to do. I won't continue this for f_file because I don't plan on adding tests for f_file for this next release. The ENOTDIR should return F_directory_not rather than F_directory. Unable to perform many of the tests because the dynamic linker wrapper is not properlly handling stat() and scandir() as expected. These tests are commented out, incomplete, and comments are added describing why. --- diff --git a/level_0/f_account/data/build/settings-mocks b/level_0/f_account/data/build/settings-mocks index bfd4413..c6c2767 100644 --- a/level_0/f_account/data/build/settings-mocks +++ b/level_0/f_account/data/build/settings-mocks @@ -41,7 +41,7 @@ path_library_shared shared path_library_static static has_path_standard yes -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_account/data/build/settings-tests b/level_0/f_account/data/build/settings-tests index 3a140bb..2a1dbeb 100644 --- a/level_0/f_account/data/build/settings-tests +++ b/level_0/f_account/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_capability/data/build/settings-mocks b/level_0/f_capability/data/build/settings-mocks index 1b263d0..6e6e0f9 100644 --- a/level_0/f_capability/data/build/settings-mocks +++ b/level_0/f_capability/data/build/settings-mocks @@ -50,7 +50,7 @@ path_sources path_sources_object has_path_standard yes -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_capability/data/build/settings-tests b/level_0/f_capability/data/build/settings-tests index 3820e47..22b74ed 100644 --- a/level_0/f_capability/data/build/settings-tests +++ b/level_0/f_capability/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_color/data/build/settings-mocks b/level_0/f_color/data/build/settings-mocks index 46a7a3b..770530a 100644 --- a/level_0/f_color/data/build/settings-mocks +++ b/level_0/f_color/data/build/settings-mocks @@ -45,7 +45,7 @@ path_sources path_sources_object has_path_standard yes -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_color/data/build/settings-tests b/level_0/f_color/data/build/settings-tests index eb44c88..da9af6f 100644 --- a/level_0/f_color/data/build/settings-tests +++ b/level_0/f_color/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_console/data/build/settings-tests b/level_0/f_console/data/build/settings-tests index 422e789..d77362f 100644 --- a/level_0/f_console/data/build/settings-tests +++ b/level_0/f_console/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_control_group/data/build/dependencies-tests b/level_0/f_control_group/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_control_group/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_control_group/data/build/settings-tests b/level_0/f_control_group/data/build/settings-tests index 9b6e344..c4150ac 100644 --- a/level_0/f_control_group/data/build/settings-tests +++ b/level_0/f_control_group/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_conversion/data/build/dependencies-tests b/level_0/f_conversion/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_conversion/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_conversion/data/build/settings-mocks b/level_0/f_conversion/data/build/settings-mocks index 5d079b4..f643f76 100644 --- a/level_0/f_conversion/data/build/settings-mocks +++ b/level_0/f_conversion/data/build/settings-mocks @@ -45,7 +45,7 @@ path_sources path_sources_object has_path_standard yes -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_conversion/data/build/settings-tests b/level_0/f_conversion/data/build/settings-tests index 312c455..42236bb 100644 --- a/level_0/f_conversion/data/build/settings-tests +++ b/level_0/f_conversion/data/build/settings-tests @@ -29,7 +29,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_directory/c/directory.c b/level_0/f_directory/c/directory.c index 915d23c..de24798 100644 --- a/level_0/f_directory/c/directory.c +++ b/level_0/f_directory/c/directory.c @@ -18,9 +18,6 @@ extern "C" { #ifndef _di_f_directory_create_at_ f_status_t f_directory_create_at(const int at_id, const f_string_static_t path, const mode_t mode) { - #ifndef _di_level_0_parameter_checking_ - if (at_id <= 0) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ if (!path.used) { return F_data_not; @@ -109,12 +106,12 @@ extern "C" { if (stat(path.string, &file_stat) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_file_found_not; if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_false; if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); - if (errno == ELOOP) return F_status_set_error(F_loop); return F_status_set_error(F_file_stat); } @@ -142,12 +139,12 @@ extern "C" { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_file_found_not; if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_false; if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); - if (errno == ELOOP) return F_status_set_error(F_loop); return F_status_set_error(F_file_stat); } @@ -179,7 +176,8 @@ extern "C" { if (length == -1) { if (errno == ENOMEM) return F_status_set_error(F_memory_not); - else return F_status_set_error(F_failure); + + return F_status_set_error(F_failure); } for (; i < length; ++i) { @@ -271,7 +269,6 @@ extern "C" { #ifndef _di_f_directory_open_at_ f_status_t f_directory_open_at(const int at_id, const f_string_static_t path, const bool dereference, int *id) { #ifndef _di_level_0_parameter_checking_ - if (at_id <= 0) return F_status_set_error(F_parameter); if (!id) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -353,7 +350,7 @@ extern "C" { if (errno == ENFILE) return F_status_set_error(F_file_open_max); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); @@ -407,7 +404,7 @@ extern "C" { if (errno == ENFILE) return F_status_set_error(F_file_open_max); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); @@ -435,13 +432,13 @@ extern "C" { return private_f_directory_create(path, mode); } - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOMEM) return F_status_set_error(F_memory_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); - if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ELOOP) return F_status_set_error(F_loop); return F_status_set_error(F_file_stat); } @@ -454,7 +451,7 @@ extern "C" { if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ESRCH) return F_status_set_error(F_search); @@ -485,7 +482,7 @@ extern "C" { if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return private_f_directory_create_at(at_id, path, mode); if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); return F_status_set_error(F_file_stat); @@ -499,7 +496,7 @@ extern "C" { if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ESRCH) return F_status_set_error(F_search); diff --git a/level_0/f_directory/c/directory.h b/level_0/f_directory/c/directory.h index b7bb93a..25a32fc 100644 --- a/level_0/f_directory/c/directory.h +++ b/level_0/f_directory/c/directory.h @@ -57,7 +57,7 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_link_max (with error bit) max links limit reached or exceeded. * F_file_found (with error bit) of a directory aleady exists at the path. * F_file_found_not (with error bit) if a file within the path is not found (such as a broken symbolic link). @@ -92,7 +92,7 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_directory_link_max (with error bit) max links limit reached or exceeded. * F_file_found (with error bit) of a directory aleady exists at the path. @@ -360,7 +360,7 @@ extern "C" { * * F_access_denied (with error bit) on access denied. * F_busy (with error bit) if file is busy. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_empty_not (with error bit) if the directory is not empty. * F_file_descriptor_max (with error bit) if max file descriptors is reached. * F_file_found_not (with error bit) if file not found. @@ -404,7 +404,7 @@ extern "C" { * * F_access_denied (with error bit) on access denied. * F_busy (with error bit) if file is busy. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_empty_not (with error bit) if the directory is not empty. * F_file_descriptor_max (with error bit) if max file descriptors is reached. * F_file_found_not (with error bit) if file not found. @@ -443,7 +443,7 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_buffer (with error bit) if the buffer is invalid. * F_busy (with error bit) if file system is too busy to perform write. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file aleady exists at the path. * F_file_open_max (with error bit) when system-wide max open files is reached. @@ -487,7 +487,7 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_buffer (with error bit) if the buffer is invalid. * F_busy (with error bit) if file system is too busy to perform write. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file aleady exists at the path (when calling utimensat()). * F_file_open_max (with error bit) when system-wide max open files is reached. diff --git a/level_0/f_directory/c/directory/type.h b/level_0/f_directory/c/directory/type.h index 3488a12..d2bbbc8 100644 --- a/level_0/f_directory/c/directory/type.h +++ b/level_0/f_directory/c/directory/type.h @@ -20,6 +20,15 @@ extern "C" { * A structure representing a listing of paths found within a directory. * * Each property represents a set of paths grouped by directory entity file type. + * + * block: For S_IFBLK. + * character: For S_IFCHR. + * directory: For S_IFDIR. + * regular: For S_IFREG. + * link: For S_IFLNK. + * fifo: For S_IFIFO. + * socket: For S_IFSOCK. + * unknown: For anything else. */ #ifndef _di_f_directory_listing_t_ typedef struct { diff --git a/level_0/f_directory/c/private-directory.c b/level_0/f_directory/c/private-directory.c index 7330794..a007138 100644 --- a/level_0/f_directory/c/private-directory.c +++ b/level_0/f_directory/c/private-directory.c @@ -20,7 +20,7 @@ extern "C" { if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); @@ -47,7 +47,7 @@ extern "C" { if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); diff --git a/level_0/f_directory/data/build/dependencies-tests b/level_0/f_directory/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_directory/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_directory/data/build/settings-mocks b/level_0/f_directory/data/build/settings-mocks new file mode 100644 index 0000000..9d49959 --- /dev/null +++ b/level_0/f_directory/data/build/settings-mocks @@ -0,0 +1,80 @@ +# fss-0001 + +build_name f_directory + +version_major 0 +version_minor 5 +version_micro 9 +version_file micro +version_target minor + +environment + +process_pre +process_post + +modes individual level monolithic clang test +modes_default individual + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c +build_libraries -lc +build_libraries-individual -lf_memory -lf_string +build_libraries_shared +build_libraries_static +build_sources_library directory.c directory/common.c private-directory.c ../../tests/unit/c/mock-directory.c +build_sources_library_shared +build_sources_library_static +build_sources_headers directory.h directory/common.h directory/type.h +build_sources_headers_shared +build_sources_headers_static +build_script yes +build_shared yes +build_static no + +path_headers fll/level_0 +path_library_script script +path_library_shared shared +path_library_static static + +has_path_standard yes +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +defines +defines_library +defines_library_shared +defines_library_static +defines_static +defines_shared + +flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector +flags_library -fPIC +flags_library_shared +flags_library_static +flags_shared +flags_static + +# Inject mocks. +flags -Wl,--wrap=alphasort +flags -Wl,--wrap=fstatat +flags -Wl,--wrap=mkdir +flags -Wl,--wrap=mkdirat +flags -Wl,--wrap=nftw +flags -Wl,--wrap=open +flags -Wl,--wrap=openat +flags -Wl,--wrap=remove +flags -Wl,--wrap=scandir +flags -Wl,--wrap=stat +flags -Wl,--wrap=strncmp +flags -Wl,--wrap=strnlen +flags -Wl,--wrap=utimensat +flags -Wl,--wrap=versionsort diff --git a/level_0/f_directory/data/build/settings-tests b/level_0/f_directory/data/build/settings-tests new file mode 100644 index 0000000..1d17bdc --- /dev/null +++ b/level_0/f_directory/data/build/settings-tests @@ -0,0 +1,51 @@ +# fss-0001 + +build_name test-f_directory + +version_major 0 +version_minor 5 +version_micro 9 +version_file major +version_target major + +modes individual level monolithic clang test +modes_default individual + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c +build_libraries -lc -lcmocka +build_libraries-individual -lf_memory -lf_string -lf_directory +build_libraries-level -lfll_0 +build_libraries-monolithic -lfll +build_sources_program test-directory-create.c test-directory-create_at.c test-directory-exists.c test-directory-exists_at.c test-directory-is.c test-directory-is_at.c test-directory-list.c test-directory-open.c test-directory-open_at.c test-directory-remove.c test-directory-remove_custom.c test-directory-touch.c test-directory-touch_at.c test-directory.c + +build_script no +build_shared yes +build_static no + +path_headers tests/unit/c +path_sources tests/unit/c + +has_path_standard no +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +defines +defines -Ibuild/includes +defines_static -Lbuild/libraries/static +defines_shared -Lbuild/libraries/shared + +flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector +flags_program -fPIE +flags_program_shared +flags_program_static +flags_shared +flags_static diff --git a/level_0/f_directory/data/build/testfile b/level_0/f_directory/data/build/testfile new file mode 100644 index 0000000..6b96d79 --- /dev/null +++ b/level_0/f_directory/data/build/testfile @@ -0,0 +1,45 @@ +# fss-0005 iki-0002 + +settings: + load_build yes + fail exit + + environment LD_LIBRARY_PATH + +main: + build settings-mocks + build settings-tests + + operate ld_library_path + + if exists build/programs/shared/test-f_directory + shell build/programs/shared/test-f_directory + + if exists build/programs/static/test-f_directory + shell build/programs/static/test-f_directory + + if not exists build/programs/shared/test-f_directory + and not exists build/programs/static/test-f_directory + operate not_created + +not_created: + print + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' + + exit failure + +ld_library_path: + if defined environment LD_LIBRARY_PATH + and defined parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if defined environment LD_LIBRARY_PATH + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:define:"LD_LIBRARY_PATH"' + + else + if defined parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared' + + else + define LD_LIBRARY_PATH build/libraries/shared diff --git a/level_0/f_directory/tests/unit/c/mock-directory.c b/level_0/f_directory/tests/unit/c/mock-directory.c new file mode 100644 index 0000000..4396552 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/mock-directory.c @@ -0,0 +1,193 @@ +#include "mock-directory.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int __wrap_alphasort(const struct dirent **a, const struct dirent **b) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + struct stat * const mocked_stat = mock_type(struct stat *); + + statbuf->st_dev = mocked_stat->st_dev; + statbuf->st_ino = mocked_stat->st_ino; + statbuf->st_mode = mocked_stat->st_mode; + statbuf->st_nlink = mocked_stat->st_nlink; + statbuf->st_uid = mocked_stat->st_uid; + statbuf->st_gid = mocked_stat->st_gid; + statbuf->st_rdev = mocked_stat->st_rdev; + statbuf->st_size = mocked_stat->st_size; + statbuf->st_blksize = mocked_stat->st_blksize; + statbuf->st_blocks = mocked_stat->st_blocks; + statbuf->st_atime = mocked_stat->st_atime; + statbuf->st_mtime = mocked_stat->st_mtime; + statbuf->st_ctime = mocked_stat->st_ctime; + + return mock_type(int); +} + +int __wrap_mkdir(const char *pathname, mode_t mode) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_mkdirat(int dirfd, const char *pathname, mode_t mode) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_nftw(const char *dirpath, int (*fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf), int nopenfd, int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_open(const char *pathname, int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_openat(int dirfd, const char *pathname, int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_remove(const char *pathname) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_scandir(const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + *namelist = mock_type(struct dirent **); + + return mock_type(int); +} + +int __wrap_stat(const char *pathname, struct stat *statbuf) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_strncmp(const char *s1, const char *s2, size_t n) { + + return mock_type(size_t); +} + +size_t __wrap_strnlen(const char *s, size_t maxlen) { + + return mock_type(size_t); +} + +int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +int __wrap_versionsort(const struct dirent **a, const struct dirent **b) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/mock-directory.h b/level_0/f_directory/tests/unit/c/mock-directory.h new file mode 100644 index 0000000..d714d10 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/mock-directory.h @@ -0,0 +1,50 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _MOCK__directory_h +#define _MOCK__directory_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +#ifdef __cplusplus +extern "C" { +#endif + +const static int mock_errno_generic = 32767; + +extern int __wrap_alphasort(const struct dirent **a, const struct dirent **b); +extern int __wrap_fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags); +extern int __wrap_mkdir(const char *pathname, mode_t mode); +extern int __wrap_mkdirat(int dirfd, const char *pathname, mode_t mode); +extern int __wrap_nftw(const char *dirpath, int (*fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf), int nopenfd, int flags); +extern int __wrap_open(const char *pathname, int flags); +extern int __wrap_openat(int dirfd, const char *pathname, int flags); +extern int __wrap_remove(const char *pathname); +extern int __wrap_scandir(const char *dirp, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); +extern int __wrap_stat(const char *pathname, struct stat *statbuf); +extern int __wrap_strncmp(const char *s1, const char *s2, size_t n); +extern size_t __wrap_strnlen(const char *s, size_t maxlen); +extern int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags); +extern int __wrap_versionsort(const struct dirent **a, const struct dirent **b); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _MOCK__directory_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-create.c b/level_0/f_directory/tests/unit/c/test-directory-create.c new file mode 100644 index 0000000..4878ee1 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-create.c @@ -0,0 +1,84 @@ +#include "test-directory.h" +#include "test-directory-create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_create__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + EFAULT, + EINVAL, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_parameter, + F_loop, + F_directory_link_max, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 15; ++i) { + + will_return(__wrap_mkdir, true); + will_return(__wrap_mkdir, errnos[i]); + + const f_status_t status = f_directory_create(path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_create__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_create(f_string_empty_s, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_create__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + + const f_status_t status = f_directory_create(path, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-create.h b/level_0/f_directory/tests/unit/c/test-directory-create.h new file mode 100644 index 0000000..6d9c3cd --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-create.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_create_h +#define _TEST__F_directory_create_h + +/** + * Test that function fails. + * + * @see f_directory_create() + */ +extern void test__f_directory_create__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_create() + */ +extern void test__f_directory_create__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_create() + */ +extern void test__f_directory_create__works(void **state); + +#endif // _TEST__F_directory_create_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-create_at.c b/level_0/f_directory/tests/unit/c/test-directory-create_at.c new file mode 100644 index 0000000..1ec4fd6 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-create_at.c @@ -0,0 +1,86 @@ +#include "test-directory.h" +#include "test-directory-create.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_create_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, + EINVAL, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_parameter, + F_loop, + F_directory_link_max, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 16; ++i) { + + will_return(__wrap_mkdirat, true); + will_return(__wrap_mkdirat, errnos[i]); + + const f_status_t status = f_directory_create_at(0, path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_create_at__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_create_at(0, f_string_empty_s, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_create_at__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_mkdirat, false); + will_return(__wrap_mkdirat, 0); + + const f_status_t status = f_directory_create_at(0, path, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-create_at.h b/level_0/f_directory/tests/unit/c/test-directory-create_at.h new file mode 100644 index 0000000..edb3ce1 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-create_at.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_create_at_h +#define _TEST__F_directory_create_at_h + +/** + * Test that function fails. + * + * @see f_directory_create_at() + */ +extern void test__f_directory_create_at__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_create_at() + */ +extern void test__f_directory_create_at__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_create_at() + */ +extern void test__f_directory_create_at__works(void **state); + +#endif // _TEST__F_directory_create_at_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists.c b/level_0/f_directory/tests/unit/c/test-directory-exists.c new file mode 100644 index 0000000..d3dcca6 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-exists.c @@ -0,0 +1,98 @@ +#include "test-directory.h" +#include "test-directory-exists.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_exists__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_false, + F_number_overflow, + F_file_stat, + }; + + for (int i = 0; i < 9; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_exists(path); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_exists__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_exists(f_string_empty_s); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_exists__returns_false(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_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_exists(path); + + assert_int_equal(status, F_false); + } +} + +void test__f_directory_exists__returns_true(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_mode = 1 | S_IFDIR; + + { + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_exists(path); + + assert_int_equal(status, F_true); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists.h b/level_0/f_directory/tests/unit/c/test-directory-exists.h new file mode 100644 index 0000000..54f2d01 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-exists.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_exists_h +#define _TEST__F_directory_exists_h + +/** + * Test that function fails. + * + * @see f_directory_exists() + */ +extern void test__f_directory_exists__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_exists() + */ +extern void test__f_directory_exists__returns_data_not(void **state); + +/** + * Test that function works and returns F_false. + * + * @see f_directory_exists() + */ +extern void test__f_directory_exists__returns_false(void **state); + +/** + * Test that function works and returns F_true. + * + * @see f_directory_exists() + */ +extern void test__f_directory_exists__returns_true(void **state); + +#endif // _TEST__F_directory_exists_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists_at.c b/level_0/f_directory/tests/unit/c/test-directory-exists_at.c new file mode 100644 index 0000000..1ed62c2 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-exists_at.c @@ -0,0 +1,100 @@ +#include "test-directory.h" +#include "test-directory-exists_at.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_exists_at__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EBADF, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_false, + F_number_overflow, + F_file_stat, + }; + + for (int i = 0; i < 10; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_exists_at(0, path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_exists_at__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_exists_at(0, f_string_empty_s, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_exists_at__returns_false(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_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_exists_at(0, path, 0); + + assert_int_equal(status, F_false); + } +} + +void test__f_directory_exists_at__returns_true(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_mode = 1 | S_IFDIR; + + { + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_exists_at(0, path, 0); + + assert_int_equal(status, F_true); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists_at.h b/level_0/f_directory/tests/unit/c/test-directory-exists_at.h new file mode 100644 index 0000000..04de9c2 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-exists_at.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_exists_at_h +#define _TEST__F_directory_exists_at_h + +/** + * Test that function fails. + * + * @see f_directory_exists_at() + */ +extern void test__f_directory_exists_at__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_exists_at() + */ +extern void test__f_directory_exists_at__returns_data_not(void **state); + +/** + * Test that function works and returns F_false. + * + * @see f_directory_exists_at() + */ +extern void test__f_directory_exists_at__returns_false(void **state); + +/** + * Test that function works and returns F_true. + * + * @see f_directory_exists_at() + */ +extern void test__f_directory_exists_at__returns_true(void **state); + +#endif // _TEST__F_directory_exists_at_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-is.c b/level_0/f_directory/tests/unit/c/test-directory-is.c new file mode 100644 index 0000000..fcc3507 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-is.c @@ -0,0 +1,97 @@ +#include "test-directory.h" +#include "test-directory-is.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_is__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EFAULT, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_false, + F_number_overflow, + F_file_stat, + }; + + for (int i = 0; i < 8; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_is(path); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_is__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_is(f_string_empty_s); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_is__returns_false(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_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_is(path); + + assert_int_equal(status, F_false); + } +} + +void test__f_directory_is__returns_true(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_mode = 1 | S_IFDIR; + + { + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_is(path); + + assert_int_equal(status, F_true); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-is.h b/level_0/f_directory/tests/unit/c/test-directory-is.h new file mode 100644 index 0000000..38da2e5 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-is.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_is_h +#define _TEST__F_directory_is_h + +/** + * Test that function fails. + * + * @see f_directory_is() + */ +extern void test__f_directory_is__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_is() + */ +extern void test__f_directory_is__returns_data_not(void **state); + +/** + * Test that function works and returns F_false. + * + * @see f_directory_is() + */ +extern void test__f_directory_is__returns_false(void **state); + +/** + * Test that function works and returns F_true. + * + * @see f_directory_is() + */ +extern void test__f_directory_is__returns_true(void **state); + +#endif // _TEST__F_directory_is_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-is_at.c b/level_0/f_directory/tests/unit/c/test-directory-is_at.c new file mode 100644 index 0000000..f690237 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-is_at.c @@ -0,0 +1,100 @@ +#include "test-directory.h" +#include "test-directory-is_at.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_is_at__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EBADF, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_false, + F_number_overflow, + F_file_stat, + }; + + for (int i = 0; i < 10; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_is_at(0, path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +void test__f_directory_is_at__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_is_at(0, f_string_empty_s, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_is_at__returns_false(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_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_is_at(0, path, 0); + + assert_int_equal(status, F_false); + } +} + +void test__f_directory_is_at__returns_true(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_mode = 1 | S_IFDIR; + + { + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); + + const f_status_t status = f_directory_is_at(0, path, 0); + + assert_int_equal(status, F_true); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-is_at.h b/level_0/f_directory/tests/unit/c/test-directory-is_at.h new file mode 100644 index 0000000..fede9ec --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-is_at.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_is_at_h +#define _TEST__F_directory_is_at_h + +/** + * Test that function fails. + * + * @see f_directory_is_at() + */ +extern void test__f_directory_is_at__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_is_at() + */ +extern void test__f_directory_is_at__returns_data_not(void **state); + +/** + * Test that function works and returns F_false. + * + * @see f_directory_is_at() + */ +extern void test__f_directory_is_at__returns_false(void **state); + +/** + * Test that function works and returns F_true. + * + * @see f_directory_is_at() + */ +extern void test__f_directory_is_at__returns_true(void **state); + +#endif // _TEST__F_directory_is_at_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-list.c b/level_0/f_directory/tests/unit/c/test-directory-list.c new file mode 100644 index 0000000..e36f715 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-list.c @@ -0,0 +1,114 @@ +#include "test-directory.h" +#include "test-directory-list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_list__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + f_string_dynamics_t names = f_string_dynamics_t_initialize; + + { + int errnos[] = { + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_memory_not, + F_failure, + }; + + for (int i = 0; i < 2; ++i) { + + will_return(__wrap_scandir, true); + will_return(__wrap_scandir, errnos[i]); + + const f_status_t status = f_directory_list(path, 0, 0, &names); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + f_string_dynamics_resize(0, &names); +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_directory_list__parameter_checking(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_directory_list(path, 0, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_directory_list__returns_data_not(void **state) { + + f_string_dynamics_t names = f_string_dynamics_t_initialize; + + { + const f_status_t status = f_directory_list(f_string_empty_s, 0, 0, &names); + + assert_int_equal(status, F_data_not); + } + + f_string_dynamics_resize(0, &names); +} + +void test__f_directory_list__returns_directory_empty(void **state) { + + f_string_dynamics_t names = f_string_dynamics_t_initialize; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_scandir, false); + will_return(__wrap_scandir, 0); + + const f_status_t status = f_directory_list(path, 0, 0, &names); + + assert_int_equal(status, F_directory_empty); + } + + f_string_dynamics_resize(0, &names); +} + +void test__f_directory_list__works(void **state) { + + f_string_dynamics_t names = f_string_dynamics_t_initialize; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + struct dirent directory; + memset(&directory, 0, sizeof(struct dirent)); + + struct dirent directories[2]; + + memset(directories, 0, sizeof(struct dirent) * 2); + + directories[0] = directory; + + will_return(__wrap_scandir, false); + will_return(__wrap_scandir, &directories); + will_return(__wrap_strnlen, 1); + will_return(__wrap_strncmp, 1); + will_return(__wrap_strncmp, 1); + + const f_status_t status = f_directory_list(path, 0, 0, &names); + + assert_int_equal(status, F_none); + } + + f_string_dynamics_resize(0, &names); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-list.h b/level_0/f_directory/tests/unit/c/test-directory-list.h new file mode 100644 index 0000000..e79f07d --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-list.h @@ -0,0 +1,50 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_list_h +#define _TEST__F_directory_list_h + +/** + * Test that function fails. + * + * @see f_directory_list() + */ +extern void test__f_directory_list__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_directory_list() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_directory_list__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works but the path is empty. + * + * @see f_directory_list() + */ +extern void test__f_directory_list__returns_data_not(void **state); + +/** + * Test that function works but returns F_directory_empty. + * + * @see f_directory_list() + */ +extern void test__f_directory_list__returns_directory_empty(void **state); + +/** + * Test that function works. + * + * @see f_directory_list() + */ +extern void test__f_directory_list__works(void **state); + +#endif // _TEST__F_directory_list_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-open.c b/level_0/f_directory/tests/unit/c/test-directory-open.c new file mode 100644 index 0000000..4aee77c --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-open.c @@ -0,0 +1,106 @@ +#include "test-directory.h" +#include "test-directory-open.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_open__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EFAULT, + EFBIG, + EOVERFLOW, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENFILE, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_number_overflow, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_open_max, + F_directory_found_not, + F_memory_not, + F_space_not, + F_file_type_not_directory, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 16; ++i) { + + int id = 0; + + will_return(__wrap_open, true); + will_return(__wrap_open, errnos[i]); + + const f_status_t status = f_directory_open(path, F_false, &id); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_directory_open__parameter_checking(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_directory_open(path, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_directory_open__returns_data_not(void **state) { + + { + int id = 0; + + const f_status_t status = f_directory_open(f_string_empty_s, F_false, &id); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_open__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + int id = 0; + + will_return(__wrap_open, false); + will_return(__wrap_open, 5); + + const f_status_t status = f_directory_open(path, F_false, &id); + + assert_int_equal(status, F_none); + assert_int_equal(id, 5); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-open.h b/level_0/f_directory/tests/unit/c/test-directory-open.h new file mode 100644 index 0000000..d625e14 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-open.h @@ -0,0 +1,43 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_open_h +#define _TEST__F_directory_open_h + +/** + * Test that function fails. + * + * @see f_directory_open() + */ +extern void test__f_directory_open__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_directory_open() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_directory_open__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works but the path is empty. + * + * @see f_directory_open() + */ +extern void test__f_directory_open__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_open() + */ +extern void test__f_directory_open__works(void **state); + +#endif // _TEST__F_directory_open_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-open_at.c b/level_0/f_directory/tests/unit/c/test-directory-open_at.c new file mode 100644 index 0000000..601c5c6 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-open_at.c @@ -0,0 +1,113 @@ +#include "test-directory.h" +#include "test-directory-open_at.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_open_at__fails(void **state) { + + const int at = 1; + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EFBIG, + EOVERFLOW, + EINTR, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENFILE, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_number_overflow, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_name, + F_file_open_max, + F_directory_found_not, + F_memory_not, + F_space_not, + F_file_type_not_directory, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 17; ++i) { + + int id = 0; + + will_return(__wrap_openat, true); + will_return(__wrap_openat, errnos[i]); + + const f_status_t status = f_directory_open_at(at, path, F_false, &id); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_directory_open_at__parameter_checking(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_directory_open_at(0, path, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_directory_open_at__returns_data_not(void **state) { + + const int at = 1; + + { + int id = 0; + + const f_status_t status = f_directory_open_at(at, f_string_empty_s, F_false, &id); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_open_at__works(void **state) { + + const int at = 1; + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + int id = 0; + + will_return(__wrap_openat, false); + will_return(__wrap_openat, 5); + + const f_status_t status = f_directory_open_at(at, path, F_false, &id); + + assert_int_equal(status, F_none); + assert_int_equal(id, 5); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-open_at.h b/level_0/f_directory/tests/unit/c/test-directory-open_at.h new file mode 100644 index 0000000..410e749 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-open_at.h @@ -0,0 +1,43 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_open_at_h +#define _TEST__F_directory_open_at_h + +/** + * Test that function fails. + * + * @see f_directory_open_at() + */ +extern void test__f_directory_open_at__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_directory_open_at() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_directory_open_at__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works but the path is empty. + * + * @see f_directory_open_at() + */ +extern void test__f_directory_open_at__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_open_at() + */ +extern void test__f_directory_open_at__works(void **state); + +#endif // _TEST__F_directory_open_at_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-remove.c b/level_0/f_directory/tests/unit/c/test-directory-remove.c new file mode 100644 index 0000000..1860364 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-remove.c @@ -0,0 +1,155 @@ +#include "test-directory.h" +#include "test-directory-remove.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_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, + }; + + f_status_t statuss[] = { + 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_directory_not, + F_directory_empty_not, + F_prohibited, + F_read_only, + F_failure, + }; + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_remove, true); + will_return(__wrap_remove, errnos[i]); + + const f_status_t status = f_directory_remove(path, 0, F_false); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + will_return(__wrap_remove, true); + will_return(__wrap_remove, errnos[i]); + + const f_status_t status = f_directory_remove(path, 1, F_false); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_nftw, true); + will_return(__wrap_nftw, errnos[i]); + + const f_status_t status = f_directory_remove(path, 1, F_true); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_directory_remove__parameter_checking(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_directory_remove(path, -1, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_directory_remove__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_remove(f_string_empty_s, 0, F_false); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_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); + + const f_status_t status = f_directory_remove(path, 0, F_false); + + assert_int_equal(status, F_none); + } + + { + const f_status_t status = f_directory_remove(path, 0, F_true); + + assert_int_equal(F_status_set_fine(status), F_none); + } + + { + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + will_return(__wrap_remove, false); + will_return(__wrap_remove, 0); + + const f_status_t status = f_directory_remove(path, 1, F_false); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + + const f_status_t status = f_directory_remove(path, 1, F_true); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-remove.h b/level_0/f_directory/tests/unit/c/test-directory-remove.h new file mode 100644 index 0000000..d8dd9fa --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-remove.h @@ -0,0 +1,43 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_remove_h +#define _TEST__F_directory_remove_h + +/** + * Test that function fails. + * + * @see f_directory_remove() + */ +extern void test__f_directory_remove__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_directory_remove() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_directory_remove__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works but the path is empty. + * + * @see f_directory_remove() + */ +extern void test__f_directory_remove__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_remove() + */ +extern void test__f_directory_remove__works(void **state); + +#endif // _TEST__F_directory_remove_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-remove_custom.c b/level_0/f_directory/tests/unit/c/test-directory-remove_custom.c new file mode 100644 index 0000000..e9b41f5 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-remove_custom.c @@ -0,0 +1,155 @@ +#include "test-directory.h" +#include "test-directory-remove_custom.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_remove_custom__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, + }; + + f_status_t statuss[] = { + 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_directory_not, + F_directory_empty_not, + F_prohibited, + F_read_only, + F_failure, + }; + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_remove, true); + will_return(__wrap_remove, errnos[i]); + + const f_status_t status = f_directory_remove_custom(path, 0, F_false, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + will_return(__wrap_remove, true); + will_return(__wrap_remove, errnos[i]); + + const f_status_t status = f_directory_remove_custom(path, 1, F_false, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + for (int i = 0; i < 17; ++i) { + + will_return(__wrap_nftw, true); + will_return(__wrap_nftw, errnos[i]); + + const f_status_t status = f_directory_remove_custom(path, 1, F_true, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_directory_remove_custom__parameter_checking(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + const f_status_t status = f_directory_remove_custom(path, -1, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_directory_remove_custom__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_remove_custom(f_string_empty_s, 0, F_false, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_remove_custom__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); + + const f_status_t status = f_directory_remove_custom(path, 0, F_false, 0); + + assert_int_equal(status, F_none); + } + + { + const f_status_t status = f_directory_remove_custom(path, 0, F_true, 0); + + assert_int_equal(F_status_set_fine(status), F_none); + } + + { + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + will_return(__wrap_remove, false); + will_return(__wrap_remove, 0); + + const f_status_t status = f_directory_remove_custom(path, 1, F_false, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_nftw, false); + will_return(__wrap_nftw, 0); + + const f_status_t status = f_directory_remove_custom(path, 1, F_true, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-remove_custom.h b/level_0/f_directory/tests/unit/c/test-directory-remove_custom.h new file mode 100644 index 0000000..6ad2fc5 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-remove_custom.h @@ -0,0 +1,43 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_remove_custom_h +#define _TEST__F_directory_remove_custom_h + +/** + * Test that function fails. + * + * @see f_directory_remove_custom() + */ +extern void test__f_directory_remove_custom__fails(void **state); + +/** + * Test that parameter checking works as expected. + * + * @see f_directory_remove_custom() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_directory_remove_custom__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works but the path is empty. + * + * @see f_directory_remove_custom() + */ +extern void test__f_directory_remove_custom__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_remove_custom() + */ +extern void test__f_directory_remove_custom__works(void **state); + +#endif // _TEST__F_directory_remove_custom_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch.c b/level_0/f_directory/tests/unit/c/test-directory-touch.c new file mode 100644 index 0000000..866e91f --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-touch.c @@ -0,0 +1,179 @@ +#include "test-directory.h" +#include "test-directory-touch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_touch__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + int errnos[] = { + EACCES, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_loop, + F_name, + F_memory_not, + F_directory_not, + F_number_overflow, + F_failure, + }; + + for (int i = 0; i < 8; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_touch(path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + EFAULT, + EINVAL, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_parameter, + F_loop, + F_directory_link_max, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 15; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, ENOENT); + will_return(__wrap_mkdir, true); + will_return(__wrap_mkdir, errnos[i]); + + const f_status_t status = f_directory_touch(path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } // for + + { + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOTDIR, + EPERM, + EROFS, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_directory_not, + F_prohibited, + F_read_only, + F_search, + F_failure, + }; + + for (int i = 0; i < 12; ++i) { + + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + will_return(__wrap_utimensat, true); + will_return(__wrap_utimensat, errnos[i]); + + const f_status_t status = f_directory_touch(path, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } +} + +void test__f_directory_touch__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_touch(f_string_empty_s, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_touch__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + will_return(__wrap_utimensat, false); + will_return(__wrap_utimensat, 0); + + const f_status_t status = f_directory_touch(path, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_mkdir, true); + will_return(__wrap_mkdir, ENOENT); + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + + const f_status_t status = f_directory_touch(path, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch.h b/level_0/f_directory/tests/unit/c/test-directory-touch.h new file mode 100644 index 0000000..917dcac --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-touch.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_touch_h +#define _TEST__F_directory_touch_h + +/** + * Test that function fails. + * + * @see f_directory_touch() + */ +extern void test__f_directory_touch__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_touch() + */ +extern void test__f_directory_touch__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_touch() + */ +extern void test__f_directory_touch__works(void **state); + +#endif // _TEST__F_directory_touch_h diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch_at.c b/level_0/f_directory/tests/unit/c/test-directory-touch_at.c new file mode 100644 index 0000000..3102ab2 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-touch_at.c @@ -0,0 +1,179 @@ +#include "test-directory.h" +#include "test-directory-touch_at.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_directory_touch_at__fails(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + int errnos[] = { + EACCES, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOMEM, + ENOTDIR, + EOVERFLOW, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_buffer, + F_loop, + F_name, + F_memory_not, + F_directory_not, + F_number_overflow, + F_failure, + }; + + for (int i = 0; i < 8; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); + + const f_status_t status = f_directory_touch_at(1, path, 0, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } + + { + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + EFAULT, + EINVAL, + ELOOP, + EMLINK, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOSPC, + ENOTDIR, + EPERM, + EROFS, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_buffer, + F_parameter, + F_loop, + F_directory_link_max, + F_name, + F_file_found_not, + F_memory_not, + F_space_not, + F_directory_not, + F_prohibited, + F_read_only, + F_failure, + }; + + for (int i = 0; i < 15; ++i) { + + will_return(__wrap_stat, true); + will_return(__wrap_stat, ENOENT); + will_return(__wrap_mkdir, true); + will_return(__wrap_mkdir, errnos[i]); + + const f_status_t status = f_directory_touch_at(1, path, 0, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } // for + + { + int errnos[] = { + EACCES, + EBADF, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOTDIR, + EPERM, + EROFS, + ESRCH, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_access_denied, + F_directory_descriptor, + F_buffer, + F_parameter, + F_loop, + F_name, + F_file_found_not, + F_directory_not, + F_prohibited, + F_read_only, + F_search, + F_failure, + }; + + for (int i = 0; i < 12; ++i) { + + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + will_return(__wrap_utimensat, true); + will_return(__wrap_utimensat, errnos[i]); + + const f_status_t status = f_directory_touch_at(1, path, 0, 0); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + } +} + +void test__f_directory_touch_at__returns_data_not(void **state) { + + { + const f_status_t status = f_directory_touch_at(1, f_string_empty_s, 0, 0); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_directory_touch_at__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + will_return(__wrap_utimensat, false); + will_return(__wrap_utimensat, 0); + + const f_status_t status = f_directory_touch_at(1, path, 0, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_mkdir, true); + will_return(__wrap_mkdir, ENOENT); + will_return(__wrap_mkdir, false); + will_return(__wrap_mkdir, 0); + + const f_status_t status = f_directory_touch_at(1, path, 0, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch_at.h b/level_0/f_directory/tests/unit/c/test-directory-touch_at.h new file mode 100644 index 0000000..6c0c844 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory-touch_at.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_touch_at_h +#define _TEST__F_directory_touch_at_h + +/** + * Test that function fails. + * + * @see f_directory_touch_at() + */ +extern void test__f_directory_touch_at__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_directory_touch_at() + */ +extern void test__f_directory_touch_at__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_directory_touch_at() + */ +extern void test__f_directory_touch_at__works(void **state); + +#endif // _TEST__F_directory_touch_at_h diff --git a/level_0/f_directory/tests/unit/c/test-directory.c b/level_0/f_directory/tests/unit/c/test-directory.c new file mode 100644 index 0000000..ff117b6 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory.c @@ -0,0 +1,108 @@ +#include "test-directory.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int setup(void **state) { + + return 0; +} + +int setdown(void **state) { + + errno = 0; + + return 0; +} + +int main(void) { + + const struct CMUnitTest tests[] = { + cmocka_unit_test(test__f_directory_create__fails), + cmocka_unit_test(test__f_directory_create__returns_data_not), + cmocka_unit_test(test__f_directory_create__works), + + cmocka_unit_test(test__f_directory_create_at__fails), + cmocka_unit_test(test__f_directory_create_at__returns_data_not), + cmocka_unit_test(test__f_directory_create_at__works), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_exists__fails), + //cmocka_unit_test(test__f_directory_exists__returns_data_not), + //cmocka_unit_test(test__f_directory_exists__returns_false), + //cmocka_unit_test(test__f_directory_exists__returns_true), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_exists_at__fails), + //cmocka_unit_test(test__f_directory_exists_at__returns_data_not), + //cmocka_unit_test(test__f_directory_exists_at__returns_false), + //cmocka_unit_test(test__f_directory_exists_at__returns_true), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_is__fails), + //cmocka_unit_test(test__f_directory_is__returns_data_not), + //cmocka_unit_test(test__f_directory_is__returns_false), + //cmocka_unit_test(test__f_directory_is__returns_true), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_is_at__fails), + //cmocka_unit_test(test__f_directory_is_at__returns_data_not), + //cmocka_unit_test(test__f_directory_is_at__returns_false), + //cmocka_unit_test(test__f_directory_is_at__returns_true), + + // Unable to perform tests because scandir() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_list__fails), + //cmocka_unit_test(test__f_directory_list__returns_data_not), + //cmocka_unit_test(test__f_directory_list__returns_directory_empty), + //cmocka_unit_test(test__f_directory_list__works), + + cmocka_unit_test(test__f_directory_open__fails), + cmocka_unit_test(test__f_directory_open__returns_data_not), + cmocka_unit_test(test__f_directory_open__works), + + cmocka_unit_test(test__f_directory_open_at__fails), + cmocka_unit_test(test__f_directory_open_at__returns_data_not), + cmocka_unit_test(test__f_directory_open_at__works), + + cmocka_unit_test(test__f_directory_remove__fails), + cmocka_unit_test(test__f_directory_remove__returns_data_not), + cmocka_unit_test(test__f_directory_remove__works), + + cmocka_unit_test(test__f_directory_remove_custom__fails), + cmocka_unit_test(test__f_directory_remove_custom__returns_data_not), + cmocka_unit_test(test__f_directory_remove_custom__works), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_touch__fails), + //cmocka_unit_test(test__f_directory_touch__returns_data_not), + //cmocka_unit_test(test__f_directory_touch__works), + + // Unable to perform tests because stat() appears to not properly get mocked. + //cmocka_unit_test(test__f_directory_touch_at__fails), + //cmocka_unit_test(test__f_directory_touch_at__returns_data_not), + //cmocka_unit_test(test__f_directory_touch_at__works), + + #ifndef _di_level_0_parameter_checking_ + // f_directory_create() doesn't use parameter checking. + // f_directory_create_at() doesn't use parameter checking. + // f_directory_exists() doesn't use parameter checking. + // f_directory_exists_at() doesn't use parameter checking. + // f_directory_is() doesn't use parameter checking. + // f_directory_is_at() doesn't use parameter checking. + cmocka_unit_test(test__f_directory_list__parameter_checking), + cmocka_unit_test(test__f_directory_open__parameter_checking), + cmocka_unit_test(test__f_directory_open_at__parameter_checking), + cmocka_unit_test(test__f_directory_remove__parameter_checking), + cmocka_unit_test(test__f_directory_remove_custom__parameter_checking), + // f_directory_touch() doesn't use parameter checking. + // f_directory_touch_at() doesn't use parameter checking. + #endif // _di_level_0_parameter_checking_ + }; + + return cmocka_run_group_tests(tests, setup, setdown); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/tests/unit/c/test-directory.h b/level_0/f_directory/tests/unit/c/test-directory.h new file mode 100644 index 0000000..bd99785 --- /dev/null +++ b/level_0/f_directory/tests/unit/c/test-directory.h @@ -0,0 +1,84 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the directory project. + */ +#ifndef _TEST__F_directory_h +#define _TEST__F_directory_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +// Mock includes. +#include "mock-directory.h" + +// Test includes. +#include "test-directory-create.h" +#include "test-directory-create_at.h" +#include "test-directory-exists.h" +#include "test-directory-exists_at.h" +#include "test-directory-is.h" +#include "test-directory-is_at.h" +#include "test-directory-list.h" +#include "test-directory-open.h" +#include "test-directory-open_at.h" +#include "test-directory-remove.h" +#include "test-directory-remove_custom.h" +#include "test-directory-touch.h" +#include "test-directory-touch_at.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform any setup operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setup(void **state); + +/** + * Peform any setdown operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setdown(void **state); + +/** + * Run all tests. + * + * @return + * The final result of the tests. + * + * @see cmocka_run_group_tests() + * @see cmocka_unit_test() + */ +extern int main(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _TEST__F_directory_h diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index bd4a8d6..4f427de 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -1841,7 +1841,6 @@ extern "C" { #ifndef _di_f_file_size_at_ f_status_t f_file_size_at(const int at_id, const f_string_static_t path, const bool dereference, f_array_length_t * const size) { #ifndef _di_level_0_parameter_checking_ - if (at_id <= 0) return F_status_set_error(F_parameter); if (!size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -1903,7 +1902,6 @@ extern "C" { #ifndef _di_f_file_stat_at_ f_status_t f_file_stat_at(const int at_id, const f_string_static_t path, const int flag, struct stat * const stat_file) { #ifndef _di_level_0_parameter_checking_ - if (at_id <= 0) return F_status_set_error(F_parameter); if (!stat_file) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 06c6745..6a93944 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -332,10 +332,10 @@ extern "C" { if (fsync(id) < 0) { if (errno == EBADF) return F_status_set_error(F_file_descriptor); + if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EIO) return F_status_set_error(F_input_output); if (errno == ENOSPC) return F_status_set_error(F_space_not); if (errno == EROFS) return F_status_set_error(F_supported_not); - if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); return F_status_set_error(F_failure); } @@ -349,18 +349,18 @@ extern "C" { if (symlink(target.string, point.string) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); - if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == EINTR) return F_status_set_error(F_interrupt); if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ETXTBSY) return F_status_set_error(F_busy); @@ -377,19 +377,19 @@ extern "C" { if (symlinkat(target.string, at_id, point.string) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); - if (errno == EEXIST) return F_status_set_error(F_file_found); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EEXIST) return F_status_set_error(F_file_found); if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == EINTR) return F_status_set_error(F_interrupt); if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ETXTBSY) return F_status_set_error(F_busy); @@ -455,6 +455,7 @@ extern "C" { if (readlinkat(at_id, path.string, target->string, target->used) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == EIO) return F_status_set_error(F_input_output); @@ -463,7 +464,6 @@ extern "C" { if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); return F_status_set_error(F_failure); } @@ -477,15 +477,15 @@ extern "C" { if (chmod(path.string, mode) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EIO) return F_status_set_error(F_input_output); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory); if (errno == EPERM) return F_status_set_error(F_access_mode); if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EIO) return F_status_set_error(F_input_output); return F_status_set_error(F_failure); } @@ -499,16 +499,16 @@ extern "C" { if (fchmodat(at_id, path.string, mode, 0) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EIO) return F_status_set_error(F_input_output); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EPERM) return F_status_set_error(F_access_mode); if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EIO) return F_status_set_error(F_input_output); return F_status_set_error(F_failure); } @@ -529,24 +529,24 @@ extern "C" { if (file->id == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); + if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EINTR) return F_status_set_error(F_interrupt); if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EISDIR) return F_status_set_error(F_directory); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENFILE) return F_status_set_error(F_file_open_max); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory); + if (errno == EOPNOTSUPP) return F_status_set_error(F_supported_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ETXTBSY) return F_status_set_error(F_busy); - if (errno == EISDIR) return F_status_set_error(F_directory); - if (errno == EOPNOTSUPP) return F_status_set_error(F_supported_not); return F_status_set_error(F_failure); } @@ -567,25 +567,25 @@ extern "C" { if (file->id == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == EINTR) return F_status_set_error(F_interrupt); if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EISDIR) return F_status_set_error(F_directory); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENFILE) return F_status_set_error(F_file_open_max); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory); + if (errno == EOPNOTSUPP) return F_status_set_error(F_supported_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ETXTBSY) return F_status_set_error(F_busy); - if (errno == EISDIR) return F_status_set_error(F_directory); - if (errno == EOPNOTSUPP) return F_status_set_error(F_supported_not); return F_status_set_error(F_failure); } @@ -636,14 +636,14 @@ extern "C" { if (result < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EIO) return F_status_set_error(F_input_output); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory); if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EIO) return F_status_set_error(F_input_output); return F_status_set_error(F_failure); } @@ -675,15 +675,15 @@ extern "C" { if (result < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EIO) return F_status_set_error(F_input_output); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EIO) return F_status_set_error(F_input_output); return F_status_set_error(F_failure); } @@ -696,14 +696,14 @@ extern "C" { f_status_t private_f_file_stat(const f_string_static_t path, const bool dereference, struct stat * const file_stat) { if ((dereference ? stat(path.string, file_stat) : lstat(path.string, file_stat)) < 0) { - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); return F_status_set_error(F_file_stat); } @@ -716,16 +716,15 @@ extern "C" { f_status_t private_f_file_stat_at(const int at_id, const f_string_static_t path, const int flag, struct stat * const file_stat) { if (fstatat(at_id, path.string, file_stat, flag) < 0) { - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); - if (errno == EFAULT) return F_status_set_error(F_buffer); - if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); - if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == EBADF) return F_status_set_error(F_directory_descriptor); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); + if (errno == ENOMEM) return F_status_set_error(F_memory_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); return F_status_set_error(F_file_stat); } @@ -740,14 +739,14 @@ extern "C" { const int result = fstat(id, file_stat); if (result < 0) { - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == ENOENT) return F_file_found_not; if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == ENOENT) return F_file_found_not; - if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); return F_status_set_error(F_file_stat); } diff --git a/level_0/f_iki/data/build/dependencies-tests b/level_0/f_iki/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_iki/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_iki/data/build/settings-tests b/level_0/f_iki/data/build/settings-tests index e015d53..2d2fb95 100644 --- a/level_0/f_iki/data/build/settings-tests +++ b/level_0/f_iki/data/build/settings-tests @@ -31,7 +31,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_memory/data/build/settings-tests b/level_0/f_memory/data/build/settings-tests index 7f1363d..5e2a310 100644 --- a/level_0/f_memory/data/build/settings-tests +++ b/level_0/f_memory/data/build/settings-tests @@ -27,7 +27,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_string/data/build/dependencies-tests b/level_0/f_string/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_string/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_string/data/build/settings-tests b/level_0/f_string/data/build/settings-tests index 937b288..35932e0 100644 --- a/level_0/f_string/data/build/settings-tests +++ b/level_0/f_string/data/build/settings-tests @@ -52,7 +52,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_type_array/data/build/settings-tests b/level_0/f_type_array/data/build/settings-tests index 8873b42..1d5f4cb 100644 --- a/level_0/f_type_array/data/build/settings-tests +++ b/level_0/f_type_array/data/build/settings-tests @@ -59,7 +59,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes diff --git a/level_0/f_utf/data/build/dependencies-tests b/level_0/f_utf/data/build/dependencies-tests new file mode 100644 index 0000000..dea3179 --- /dev/null +++ b/level_0/f_utf/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_0/f_utf/data/build/settings-tests b/level_0/f_utf/data/build/settings-tests index f8a5ce5..c39b19b 100644 --- a/level_0/f_utf/data/build/settings-tests +++ b/level_0/f_utf/data/build/settings-tests @@ -50,7 +50,7 @@ path_headers tests/unit/c path_sources tests/unit/c has_path_standard no -preserve_path_headers no +preserve_path_headers yes search_exclusive yes search_shared yes