]> Kevux Git Server - fll/commitdiff
Update: Add f_directory tests then fix problems discovered problems and perform appro... 0.5.9
authorKevin Day <thekevinday@gmail.com>
Sun, 3 Apr 2022 15:59:05 +0000 (10:59 -0500)
committerKevin Day <thekevinday@gmail.com>
Sun, 3 Apr 2022 15:59:05 +0000 (10:59 -0500)
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.

60 files changed:
level_0/f_account/data/build/settings-mocks
level_0/f_account/data/build/settings-tests
level_0/f_capability/data/build/settings-mocks
level_0/f_capability/data/build/settings-tests
level_0/f_color/data/build/settings-mocks
level_0/f_color/data/build/settings-tests
level_0/f_console/data/build/settings-tests
level_0/f_control_group/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_control_group/data/build/settings-tests
level_0/f_conversion/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_conversion/data/build/settings-mocks
level_0/f_conversion/data/build/settings-tests
level_0/f_directory/c/directory.c
level_0/f_directory/c/directory.h
level_0/f_directory/c/directory/type.h
level_0/f_directory/c/private-directory.c
level_0/f_directory/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_directory/data/build/settings-mocks [new file with mode: 0644]
level_0/f_directory/data/build/settings-tests [new file with mode: 0644]
level_0/f_directory/data/build/testfile [new file with mode: 0644]
level_0/f_directory/tests/unit/c/mock-directory.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/mock-directory.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-create.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-create.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-create_at.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-create_at.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-exists.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-exists.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-exists_at.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-exists_at.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-is.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-is.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-is_at.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-is_at.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-list.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-list.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-open.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-open.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-open_at.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-open_at.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-remove.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-remove.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-remove_custom.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-remove_custom.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-touch.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-touch.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-touch_at.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory-touch_at.h [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory.c [new file with mode: 0644]
level_0/f_directory/tests/unit/c/test-directory.h [new file with mode: 0644]
level_0/f_file/c/file.c
level_0/f_file/c/private-file.c
level_0/f_iki/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_iki/data/build/settings-tests
level_0/f_memory/data/build/settings-tests
level_0/f_string/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_string/data/build/settings-tests
level_0/f_type_array/data/build/settings-tests
level_0/f_utf/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_utf/data/build/settings-tests

index bfd44137d6926e3454c12a86779f0df3d956b288..c6c2767b3103a99905aa700ecf1a13cced4578b5 100644 (file)
@@ -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
index 3a140bb8e8890434adcee8f6e76ff77a71a0dce2..2a1dbeb3e173710b89d1bdf0d91d5ccba7bce67f 100644 (file)
@@ -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
index 1b263d0d60a96925f09fe80594d94317a65cff1b..6e6e0f9612842cc15a8a005e6877ee4178083ab0 100644 (file)
@@ -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
index 3820e47f51f5dfe15b89cbf1f00d6fb2420ce211..22b74ed34985ef8afd5b9cdaca0297317e8a77ed 100644 (file)
@@ -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
index 46a7a3bebd2cb26ed0420dca7c4c227c041a3318..770530a35acb2eacb97932f3684eebddf5b4bed1 100644 (file)
@@ -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
index eb44c88ce7a7615656432a4ea8b4e9658e3719cb..da9af6f3804e074c79c7ed0981317549801c76d2 100644 (file)
@@ -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
index 422e789502066b8be0a559d36700fda1627a00fd..d77362f41f6445b2a03c8d37490445aaa327a02b 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
index 9b6e344bf771c3748358fbc3f10abe2ef288307c..c4150aca9a5a0732a581293f23fc28d6b7ef3fb9 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
index 5d079b4373bde60ac8c731d7f46ae5ab898cd552..f643f7666a29a9cba883f197bbf345050d5dff35 100644 (file)
@@ -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
index 312c455a4bb71bf38bc0187d69352e279aa8b77a..42236bbabd23c391c9e40dcff0b16123ff89db93 100644 (file)
@@ -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
index 915d23cbc075fd1ad28e268fd95ce032026f8995..de247986b8a4443e6b2cad91c449717998452958 100644 (file)
@@ -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);
index b7bb93aa383302db3c8b4be4bb729cacd6f8434a..25a32fc148f622fb2bb21c1970ee7d53071b26a8 100644 (file)
@@ -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.
index 3488a126355c9a6a0a99518cc68281411655f5b3..d2bbbc8679359860272a4f3733624d7f49ad58dd 100644 (file)
@@ -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 {
index 7330794d20f61d0e61eba0b3ffb182e04bfcc820..a007138386e0db09e58d80c97ca50c6cba703058 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -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 (file)
index 0000000..9d49959
--- /dev/null
@@ -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 (file)
index 0000000..1d17bdc
--- /dev/null
@@ -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 (file)
index 0000000..6b96d79
--- /dev/null
@@ -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 (file)
index 0000000..4396552
--- /dev/null
@@ -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 (file)
index 0000000..d714d10
--- /dev/null
@@ -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 <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+
+// cmocka includes.
+#include <cmocka.h>
+
+// FLL-0 includes.
+#include <fll/level_0/directory.h>
+
+#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 (file)
index 0000000..4878ee1
--- /dev/null
@@ -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 (file)
index 0000000..6d9c3cd
--- /dev/null
@@ -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 (file)
index 0000000..1ec4fd6
--- /dev/null
@@ -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 (file)
index 0000000..edb3ce1
--- /dev/null
@@ -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 (file)
index 0000000..d3dcca6
--- /dev/null
@@ -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 (file)
index 0000000..54f2d01
--- /dev/null
@@ -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 (file)
index 0000000..1ed62c2
--- /dev/null
@@ -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 (file)
index 0000000..04de9c2
--- /dev/null
@@ -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 (file)
index 0000000..fcc3507
--- /dev/null
@@ -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 (file)
index 0000000..38da2e5
--- /dev/null
@@ -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 (file)
index 0000000..f690237
--- /dev/null
@@ -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 (file)
index 0000000..fede9ec
--- /dev/null
@@ -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 (file)
index 0000000..e36f715
--- /dev/null
@@ -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 (file)
index 0000000..e79f07d
--- /dev/null
@@ -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 (file)
index 0000000..4aee77c
--- /dev/null
@@ -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 (file)
index 0000000..d625e14
--- /dev/null
@@ -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 (file)
index 0000000..601c5c6
--- /dev/null
@@ -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 (file)
index 0000000..410e749
--- /dev/null
@@ -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 (file)
index 0000000..1860364
--- /dev/null
@@ -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 (file)
index 0000000..d8dd9fa
--- /dev/null
@@ -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 (file)
index 0000000..e9b41f5
--- /dev/null
@@ -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 (file)
index 0000000..6ad2fc5
--- /dev/null
@@ -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 (file)
index 0000000..866e91f
--- /dev/null
@@ -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 (file)
index 0000000..917dcac
--- /dev/null
@@ -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 (file)
index 0000000..3102ab2
--- /dev/null
@@ -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 (file)
index 0000000..6c0c844
--- /dev/null
@@ -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 (file)
index 0000000..ff117b6
--- /dev/null
@@ -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 (file)
index 0000000..bd99785
--- /dev/null
@@ -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 <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+
+// cmocka includes.
+#include <cmocka.h>
+
+// FLL-0 includes.
+#include <fll/level_0/directory.h>
+
+// 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
index bd4a8d635330dc397e015c5e70a76c590ae02d12..4f427de51c355ca160e7ff01c86904780859831e 100644 (file)
@@ -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_
 
index 06c6745df3f25af3cc5169c538ae674b556ee593..6a9394409566808ddc0d9f24adb6c31390819d1c 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
index e015d53782b6f2a9b0162adf43a48b2915181067..2d2fb956a58fb746789d157bfa3073b87c7278ea 100644 (file)
@@ -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
index 7f1363d346f73a9db121ee5b1c79d597ee2edeef..5e2a310148cd1a3ba0bde3417a51b5dd82fc09dd 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
index 937b288a3b143a07967e88b7a3603b4edac5629e..35932e0b3b39f98b6e701ba94d70124e4ac9736d 100644 (file)
@@ -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
index 8873b420f95e8fc680dd35a0b624323413691da6..1d5f4cb146d16fcd16e5747983b057794eaa5502 100644 (file)
@@ -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 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
index f8a5ce5c95f306185b10056140d5d2ca64ea2e41..c39b19b4aed2d366dcf0fabb224b3cc0f26f6868 100644 (file)
@@ -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