]> Kevux Git Server - fll/commitdiff
Progress: Continue implementing f_file unit tests.
authorKevin Day <thekevinday@gmail.com>
Sat, 16 Apr 2022 05:04:50 +0000 (00:04 -0500)
committerKevin Day <thekevinday@gmail.com>
Sat, 16 Apr 2022 05:05:44 +0000 (00:05 -0500)
The unit tests for f_file_mode_determine() are very minimal.
There are quite a lot of permutations that I should test but will not get to.
These additional permutations will have to be done in some distant date, probably after the first stable release of the 0.6.x series.

14 files changed:
level_0/f_file/data/build/settings-mocks
level_0/f_file/tests/unit/c/mock-file.c
level_0/f_file/tests/unit/c/mock-file.h
level_0/f_file/tests/unit/c/test-file-is.c
level_0/f_file/tests/unit/c/test-file-is_at.c
level_0/f_file/tests/unit/c/test-file-link.c
level_0/f_file/tests/unit/c/test-file-link_at.c
level_0/f_file/tests/unit/c/test-file-link_hard.c
level_0/f_file/tests/unit/c/test-file-link_hard_at.c
level_0/f_file/tests/unit/c/test-file-link_read.c
level_0/f_file/tests/unit/c/test-file-link_read_at.c
level_0/f_file/tests/unit/c/test-file-mode_determine.c
level_0/f_file/tests/unit/c/test-file-mode_determine.h
level_0/f_file/tests/unit/c/test-file.c

index 51a03da82d732bdd6a93c6c8f008a4204a534f44..e45ccaffbc408eca794a470341a9722b7f568f22 100644 (file)
@@ -76,6 +76,8 @@ flags -Wl,--wrap=fsync
 flags -Wl,--wrap=funlockfile
 flags -Wl,--wrap=fwrite
 flags -Wl,--wrap=lchown
+flags -Wl,--wrap=link
+flags -Wl,--wrap=linkat
 flags -Wl,--wrap=lstat
 flags -Wl,--wrap=makedev
 flags -Wl,--wrap=mkdir
@@ -88,6 +90,7 @@ flags -Wl,--wrap=open
 flags -Wl,--wrap=openat
 flags -Wl,--wrap=read
 flags -Wl,--wrap=readlink
+flags -Wl,--wrap=readlinkat
 flags -Wl,--wrap=remove
 flags -Wl,--wrap=stat
 flags -Wl,--wrap=symlink
index 6045cbf574aab32e67ec491f234aad2cefb9ed82..884cb0900f47456f3f242512f84a9527a1797d46 100644 (file)
@@ -269,6 +269,32 @@ int __wrap_lchown(const char *pathname, uid_t owner, gid_t group) {
   return mock_type(int);
 }
 
+int __wrap_link(const char *oldpath, const char *newpath) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return mock_type(int);
+}
+
+int __wrap_linkat(const char *oldpath, const char *newpath) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return mock_type(int);
+}
+
 int __wrap_lstat(const char *pathname, struct stat *statbuf) {
 
   const bool failure = mock_type(bool);
@@ -427,7 +453,9 @@ ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz) {
     return -1;
   }
 
-  buf = mock_type(char *);
+  char *buffer = mock_type(char *);
+
+  memcpy(buf, buffer, bufsiz);
 
   return mock_type(int);
 }
@@ -442,7 +470,9 @@ ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t buf
     return -1;
   }
 
-  buf = mock_type(char *);
+  char *buffer = mock_type(char *);
+
+  memcpy(buf, buffer, bufsiz);
 
   return mock_type(int);
 }
index 744f14bf326e356ee855e970f96963e89fe3b104..7c08cd5a99566181bf313fcab20d4a178c287f47 100644 (file)
@@ -48,6 +48,8 @@ extern int __wrap_fsync(int fd);
 extern void __wrap_funlockfile(FILE *filehandle);
 extern size_t __wrap_fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream);
 extern int __wrap_lchown(const char *pathname, uid_t owner, gid_t group);
+extern int __wrap_link(const char *oldpath, const char *newpath);
+extern int __wrap_linkat(const char *oldpath, const char *newpath);
 extern int __wrap_lstat(const char *pathname, struct stat *statbuf);
 extern int __wrap_mkdir(const char *pathname, mode_t mode);
 extern int __wrap_mkdirat(int dirfd, const char *pathname, mode_t mode);
index 9ea517d3bd62f26565efdd7a5482125d0a993a98..da63c9a91e94bf10b18c493e67077f4c874b7947 100644 (file)
@@ -28,23 +28,46 @@ void test__f_file_is__fails(void **state) {
     F_name,
     F_file_found_not,
     F_memory_not,
-    F_false,
+    F_directory_not,
     F_number_overflow,
     F_file_stat,
   };
 
-  // @todo an outer loop is needed to run this against all types.
   f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
   };
 
-  for (int i = 0; i < 9; ++i) {
+  for (int j = 0; j < 8; ++j) {
 
-    //will_return(__wrap_stat, true);
-    //will_return(__wrap_stat, errnos[i]);
+    for (int i = 0; i < 9; ++i) {
 
-    //const f_status_t status = f_file_is(path);
+      will_return(__wrap_lstat, true);
+      will_return(__wrap_lstat, errnos[i]);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+      const f_status_t status = f_file_is(path, types[j], F_false);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  } // for
+
+  for (int j = 0; j < 8; ++j) {
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_stat, true);
+      will_return(__wrap_stat, errnos[i]);
+
+      const f_status_t status = f_file_is(path, types[j], F_true);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
   } // for
 }
 
@@ -58,45 +81,75 @@ void test__f_file_is__returns_data_not(void **state) {
 }
 
 void test__f_file_is__returns_false(void **state) {
-/*
+
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-  struct stat statistics;
+  f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
+  };
+
+  for (int j = 0; j < 8; ++j) {
 
-  memset(&statistics, 0, sizeof(struct stat));
+    struct stat statistics;
 
-  {
-    will_return(__wrap_stat, false);
-    will_return(__wrap_stat, &statistics);
-    will_return(__wrap_stat, 0);
+    memset(&statistics, 0, sizeof(struct stat));
 
-    const f_status_t status = f_file_is(path);
+    statistics.st_mode = 1 | types[j];
 
-    assert_int_equal(status, F_false);
-  }
-  */
+    for (int i = 0; i < 8; ++i) {
+
+      // Skip what would return true.
+      if (j == i) continue;
+
+      will_return(__wrap_lstat, false);
+      will_return(__wrap_lstat, &statistics);
+      will_return(__wrap_lstat, 0);
+
+      const f_status_t status = f_file_is(path, types[i], F_false);
+
+      assert_int_equal(status, F_false);
+    } // for
+  } // for
 }
 
 void test__f_file_is__returns_true(void **state) {
-/*
+
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-  struct stat statistics;
+  f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
+  };
 
-  memset(&statistics, 0, sizeof(struct stat));
+  for (int i = 0; i < 8; ++i) {
 
-  statistics.st_mode = 1 | F_file_type_directory_d;
+    struct stat statistics;
 
-  {
-    will_return(__wrap_stat, false);
-    will_return(__wrap_stat, &statistics);
-    will_return(__wrap_stat, 0);
+    memset(&statistics, 0, sizeof(struct stat));
+
+    statistics.st_mode = 1 | types[i];
 
-    const f_status_t status = f_file_is(path);
+    will_return(__wrap_lstat, false);
+    will_return(__wrap_lstat, &statistics);
+    will_return(__wrap_lstat, 0);
+
+    const f_status_t status = f_file_is(path, types[i], F_false);
 
     assert_int_equal(status, F_true);
-  }
-  */
+  } // for
 }
 
 #ifdef __cplusplus
index 95113411d29b9b033a7a78f8ce51d430088e0cf1..203f9448ba5d633080c951bc40072d40f88aeddb 100644 (file)
@@ -1,12 +1,12 @@
 #include "test-file.h"
-#include "test-file-is_at.h"
+#include "test-file-is.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 void test__f_file_is_at__fails(void **state) {
-/*
+
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
   int errnos[] = {
@@ -24,78 +24,121 @@ void test__f_file_is_at__fails(void **state) {
 
   f_status_t statuss[] = {
     F_access_denied,
-    F_file_descriptor,
+    F_directory_descriptor,
     F_buffer,
     F_loop,
     F_name,
     F_file_found_not,
     F_memory_not,
-    F_false,
+    F_directory_not,
     F_number_overflow,
     F_file_stat,
   };
 
-  for (int i = 0; i < 10; ++i) {
+  f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
+  };
+
+  for (int j = 0; j < 8; ++j) {
 
-    will_return(__wrap_fstatat, true);
-    will_return(__wrap_fstatat, errnos[i]);
+    for (int i = 0; i < 10; ++i) {
 
-    const f_status_t status = f_file_is_at(0, path, 0);
+      will_return(__wrap_fstatat, true);
+      will_return(__wrap_fstatat, errnos[i]);
 
-    assert_int_equal(F_status_set_fine(status), statuss[i]);
+      const f_status_t status = f_file_is_at(0, path, types[j], 0);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
   } // for
-  */
 }
 
 void test__f_file_is_at__returns_data_not(void **state) {
-/*
+
   {
-    const f_status_t status = f_file_is_at(0, f_string_empty_s, 0);
+    const f_status_t status = f_file_is_at(0, f_string_empty_s, 0, 0);
 
     assert_int_equal(status, F_data_not);
   }
-  */
 }
 
 void test__f_file_is_at__returns_false(void **state) {
-/*
+
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-  struct stat statistics;
+  f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
+  };
 
-  memset(&statistics, 0, sizeof(struct stat));
+  for (int j = 0; j < 8; ++j) {
 
-  {
-    will_return(__wrap_fstatat, false);
-    will_return(__wrap_fstatat, &statistics);
-    will_return(__wrap_fstatat, 0);
+    struct stat statistics;
 
-    const f_status_t status = f_file_is_at(0, path, 0);
+    memset(&statistics, 0, sizeof(struct stat));
 
-    assert_int_equal(status, F_false);
-  }
+    statistics.st_mode = 1 | types[j];
+
+    for (int i = 0; i < 8; ++i) {
+
+      // Skip what would return true.
+      if (j == i) continue;
+
+      will_return(__wrap_fstatat, false);
+      will_return(__wrap_fstatat, &statistics);
+      will_return(__wrap_fstatat, 0);
+
+      const f_status_t status = f_file_is_at(0, path, types[i], 0);
+
+      assert_int_equal(status, F_false);
+    } // for
+  } // for
 }
 
 void test__f_file_is_at__returns_true(void **state) {
 
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-  struct stat statistics;
+  f_status_t types[] = {
+    F_file_type_block_d,
+    F_file_type_character_d,
+    F_file_type_directory_d,
+    F_file_type_fifo_d,
+    F_file_type_link_d,
+    F_file_type_mask_d,
+    F_file_type_regular_d,
+    F_file_type_socket_d,
+  };
 
-  memset(&statistics, 0, sizeof(struct stat));
+  for (int i = 0; i < 8; ++i) {
 
-  statistics.st_mode = 1 | F_file_type_directory_d;
+    struct stat statistics;
+
+    memset(&statistics, 0, sizeof(struct stat));
+
+    statistics.st_mode = 1 | types[i];
 
-  {
     will_return(__wrap_fstatat, false);
     will_return(__wrap_fstatat, &statistics);
     will_return(__wrap_fstatat, 0);
 
-    const f_status_t status = f_file_is_at(0, path, 0);
+    const f_status_t status = f_file_is_at(0, path, types[i], 0);
 
     assert_int_equal(status, F_true);
-  }
-  */
+  } // for
 }
 
 #ifdef __cplusplus
index 9ce9e2f93b36fee2f2682bbb30fedf9316b5b199..62843aa4b729248bd6873811930dafbfc0a06d71 100644 (file)
@@ -7,44 +7,95 @@ extern "C" {
 
 void test__f_file_link__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EDQUOT,
+    EEXIST,
+    EFAULT,
+    EFBIG,
+    EINTR,
+    EINVAL,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOSPC,
+    ENOTDIR,
+    EOVERFLOW,
+    EPERM,
+    EROFS,
+    ETXTBSY,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_filesystem_quota_block,
+    F_file_found,
+    F_buffer,
+    F_number_overflow,
+    F_interrupt,
+    F_parameter,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_space_not,
+    F_directory_not,
+    F_number_overflow,
+    F_prohibited,
+    F_read_only,
+    F_busy,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 18; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_symlink, true);
+    will_return(__wrap_symlink, errnos[i]);
 
-    //const f_status_t status = f_file_link(path, F_false, &id);
+    const f_status_t status = f_file_link(path, path);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
 void test__f_file_link__returns_data_not(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_file_link(f_string_empty_s, f_string_empty_s);
+
+    assert_int_equal(status, F_data_not);
+  }
+
   {
-    //const f_status_t status = f_file_link(f_string_empty_s);
+    const f_status_t status = f_file_link(path, f_string_empty_s);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
+  }
+
+  {
+    const f_status_t status = f_file_link(f_string_empty_s, path);
+
+    assert_int_equal(status, F_data_not);
   }
 }
 
 void test__f_file_link__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_symlink, false);
+    will_return(__wrap_symlink, 0);
 
-    //const f_status_t status = f_file_link();
+    const f_status_t status = f_file_link(path, path);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
 }
 
index a5d0c8129750e925df7ec0a669a11d85bc39c9de..8d9c664bd3e15981cc0fd6df1da8a3b38dac16b0 100644 (file)
@@ -1,5 +1,5 @@
 #include "test-file.h"
-#include "test-file-link_at.h"
+#include "test-file-link.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,44 +7,97 @@ extern "C" {
 
 void test__f_file_link_at__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EBADF,
+    EDQUOT,
+    EEXIST,
+    EFAULT,
+    EFBIG,
+    EINTR,
+    EINVAL,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOSPC,
+    ENOTDIR,
+    EOVERFLOW,
+    EPERM,
+    EROFS,
+    ETXTBSY,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_directory_descriptor,
+    F_filesystem_quota_block,
+    F_file_found,
+    F_buffer,
+    F_number_overflow,
+    F_interrupt,
+    F_parameter,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_space_not,
+    F_directory_not,
+    F_number_overflow,
+    F_prohibited,
+    F_read_only,
+    F_busy,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 19; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_symlinkat, true);
+    will_return(__wrap_symlinkat, errnos[i]);
 
-    //const f_status_t status = f_file_link_at(path, F_false, &id);
+    const f_status_t status = f_file_link_at(0, path, path);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
 void test__f_file_link_at__returns_data_not(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_file_link_at(0, f_string_empty_s, f_string_empty_s);
+
+    assert_int_equal(status, F_data_not);
+  }
+
   {
-    //const f_status_t status = f_file_link_at(f_string_empty_s);
+    const f_status_t status = f_file_link_at(0, path, f_string_empty_s);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
+  }
+
+  {
+    const f_status_t status = f_file_link_at(0, f_string_empty_s, path);
+
+    assert_int_equal(status, F_data_not);
   }
 }
 
 void test__f_file_link_at__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_symlinkat, false);
+    will_return(__wrap_symlinkat, 0);
 
-    //const f_status_t status = f_file_link_at();
+    const f_status_t status = f_file_link_at(0, path, path);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
 }
 
index 99f7c23cc94d4b7f5e7f9c39d2e2512cfbff043c..3cec4e6a64aa44bc38961bbeb96dc1dce8c6c0ac 100644 (file)
@@ -1,5 +1,5 @@
 #include "test-file.h"
-#include "test-file-link_hard.h"
+#include "test-file-link.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,44 +7,95 @@ extern "C" {
 
 void test__f_file_link_hard__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EDQUOT,
+    EEXIST,
+    EFAULT,
+    EFBIG,
+    EINTR,
+    EINVAL,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOSPC,
+    ENOTDIR,
+    EOVERFLOW,
+    EPERM,
+    EROFS,
+    ETXTBSY,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_filesystem_quota_block,
+    F_file_found,
+    F_buffer,
+    F_number_overflow,
+    F_interrupt,
+    F_parameter,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_space_not,
+    F_directory_not,
+    F_number_overflow,
+    F_prohibited,
+    F_read_only,
+    F_busy,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 18; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_link, true);
+    will_return(__wrap_link, errnos[i]);
 
-    //const f_status_t status = f_file_link_hard(path, F_false, &id);
+    const f_status_t status = f_file_link_hard(path, path);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
 void test__f_file_link_hard__returns_data_not(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_file_link_hard(f_string_empty_s, f_string_empty_s);
+
+    assert_int_equal(status, F_data_not);
+  }
+
   {
-    //const f_status_t status = f_file_link_hard(f_string_empty_s);
+    const f_status_t status = f_file_link_hard(path, f_string_empty_s);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
+  }
+
+  {
+    const f_status_t status = f_file_link_hard(f_string_empty_s, path);
+
+    assert_int_equal(status, F_data_not);
   }
 }
 
 void test__f_file_link_hard__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_link, false);
+    will_return(__wrap_link, 0);
 
-    //const f_status_t status = f_file_link_hard();
+    const f_status_t status = f_file_link_hard(path, path);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
 }
 
index d6c9b396dcdb1f1afd7455796a8cd466b74a827f..2619a42adb3cbbbf19a4db3bc80e03a1c0c53da8 100644 (file)
@@ -1,5 +1,5 @@
 #include "test-file.h"
-#include "test-file-link_hard_at.h"
+#include "test-file-link.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,44 +7,97 @@ extern "C" {
 
 void test__f_file_link_hard_at__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EBADF,
+    EDQUOT,
+    EEXIST,
+    EFAULT,
+    EFBIG,
+    EINTR,
+    EINVAL,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOSPC,
+    ENOTDIR,
+    EOVERFLOW,
+    EPERM,
+    EROFS,
+    ETXTBSY,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_file_descriptor,
+    F_filesystem_quota_block,
+    F_file_found,
+    F_buffer,
+    F_number_overflow,
+    F_interrupt,
+    F_parameter,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_space_not,
+    F_directory_not,
+    F_number_overflow,
+    F_prohibited,
+    F_read_only,
+    F_busy,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 19; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_linkat, true);
+    will_return(__wrap_linkat, errnos[i]);
 
-    //const f_status_t status = f_file_link_hard_at(path, F_false, &id);
+    const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
 void test__f_file_link_hard_at__returns_data_not(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_file_link_hard_at(0, 0, f_string_empty_s, f_string_empty_s, 0);
+
+    assert_int_equal(status, F_data_not);
+  }
+
   {
-    //const f_status_t status = f_file_link_hard_at(f_string_empty_s);
+    const f_status_t status = f_file_link_hard_at(0, 0, path, f_string_empty_s, 0);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
+  }
+
+  {
+    const f_status_t status = f_file_link_hard_at(0, 0, f_string_empty_s, path, 0);
+
+    assert_int_equal(status, F_data_not);
   }
 }
 
 void test__f_file_link_hard_at__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_linkat, false);
+    will_return(__wrap_linkat, 0);
 
-    //const f_status_t status = f_file_link_hard_at();
+    const f_status_t status = f_file_link_hard_at(0, 0, path, path, 0);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
 }
 
index a642475453274e642e89e6619b5fe0ff92d40544..8519a9acf6baba9f31e966e4a0624996d730bd31 100644 (file)
@@ -1,5 +1,5 @@
 #include "test-file.h"
-#include "test-file-link_read.h"
+#include "test-file-link.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,23 +7,55 @@ extern "C" {
 
 void test__f_file_link_read__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EFAULT,
+    EINVAL,
+    EIO,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOTDIR,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_buffer,
+    F_parameter,
+    F_input_output,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_directory_not,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  struct stat statistics;
+
+  memset(&statistics, 0, sizeof(struct stat));
+
+  statistics.st_size = 1;
+
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  for (int i = 0; i < 10; ++i) {
+
+    buffer.used = 0;
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_readlink, true);
+    will_return(__wrap_readlink, errnos[i]);
 
-    //const f_status_t status = f_file_link_read(path, F_false, &id);
+    const f_status_t status = f_file_link_read(path, statistics, &buffer);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifndef _di_level_0_parameter_checking_
@@ -33,40 +65,64 @@ void test__f_file_link_read__fails(void **state) {
 
     memset(&statistics, 0, sizeof(struct stat));
 
+    f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
     {
       const f_status_t status = f_file_link_read(f_string_empty_s, statistics, 0);
 
       assert_int_equal(F_status_set_fine(status), F_parameter);
     }
+
+    f_string_dynamic_resize(0, &buffer);
   }
 #endif // _di_level_0_parameter_checking_
 
 void test__f_file_link_read__returns_data_not(void **state) {
 
-    struct stat statistics;
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-    memset(&statistics, 0, sizeof(struct stat));
+  struct stat statistics;
 
-  {
-    f_string_dynamic_t string = f_string_dynamic_t_initialize;
+  memset(&statistics, 0, sizeof(struct stat));
 
-    const f_status_t status = f_file_link_read(f_string_empty_s, statistics, &string);
+  statistics.st_size = 1;
+
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  {
+    const f_status_t status = f_file_link_read(f_string_empty_s, statistics, &buffer);
 
     assert_int_equal(status, F_data_not);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_link_read__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  struct stat statistics;
+
+  memset(&statistics, 0, sizeof(struct stat));
+
+  statistics.st_size = 1;
+
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  char source[2] = { 'x', 0 };
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_readlink, false);
+    will_return(__wrap_readlink, source);
+    will_return(__wrap_readlink, 0);
 
-    //const f_status_t status = f_file_link_read();
+    const f_status_t status = f_file_link_read(path, statistics, &buffer);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index 98b5d3b184c1adc364a54b75b8e29304933947bb..253ab4c5567e0fe0709e4db5487c19a94ecd12a2 100644 (file)
@@ -1,5 +1,5 @@
 #include "test-file.h"
-#include "test-file-link_read_at.h"
+#include "test-file-link.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,23 +7,55 @@ extern "C" {
 
 void test__f_file_link_read_at__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EACCES,
+    EBADF,
+    EFAULT,
+    EINVAL,
+    EIO,
+    ELOOP,
+    ENAMETOOLONG,
+    ENOENT,
+    ENOMEM,
+    ENOTDIR,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_access_denied,
+    F_directory_descriptor,
+    F_buffer,
+    F_parameter,
+    F_input_output,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_directory_not,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  struct stat statistics;
+
+  memset(&statistics, 0, sizeof(struct stat));
+
+  statistics.st_size = 1;
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
-    //const f_status_t status = f_file_link_read_at(path, F_false, &id);
+  for (int i = 0; i < 11; ++i) {
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    will_return(__wrap_readlinkat, true);
+    will_return(__wrap_readlinkat, errnos[i]);
+
+    const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer);
+
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifndef _di_level_0_parameter_checking_
@@ -33,40 +65,64 @@ void test__f_file_link_read_at__fails(void **state) {
 
     memset(&statistics, 0, sizeof(struct stat));
 
+    f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
     {
       const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, 0);
 
       assert_int_equal(F_status_set_fine(status), F_parameter);
     }
+
+    f_string_dynamic_resize(0, &buffer);
   }
 #endif // _di_level_0_parameter_checking_
 
 void test__f_file_link_read_at__returns_data_not(void **state) {
 
-    struct stat statistics;
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
-    memset(&statistics, 0, sizeof(struct stat));
+  struct stat statistics;
 
-  {
-    f_string_dynamic_t string = f_string_dynamic_t_initialize;
+  memset(&statistics, 0, sizeof(struct stat));
 
-    const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, &string);
+  statistics.st_size = 1;
+
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  {
+    const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, &buffer);
 
     assert_int_equal(status, F_data_not);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_link_read_at__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  struct stat statistics;
+
+  memset(&statistics, 0, sizeof(struct stat));
+
+  statistics.st_size = 1;
+
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  char source[2] = { 'x', 0 };
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_readlinkat, false);
+    will_return(__wrap_readlinkat, source);
+    will_return(__wrap_readlinkat, 0);
 
-    //const f_status_t status = f_file_link_read_at();
+    const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index e6122e4f6ca29f4d6043ecf393eae71a0d91cc86..411bd34ec2a74674077ac60e5bdfa50d18b213c1 100644 (file)
@@ -5,27 +5,6 @@
 extern "C" {
 #endif
 
-void test__f_file_mode_determine__fails(void **state) {
-
-  int errnos[] = {
-    mock_errno_generic,
-  };
-
-  f_status_t statuss[] = {
-    F_failure,
-  };
-
-  for (int i = 0; i < 1; ++i) {
-
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
-
-    //const f_status_t status = f_file_mode_determine(path, F_false, &id);
-
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
-  } // for
-}
-
 #ifndef _di_level_0_parameter_checking_
   void test__f_file_mode_determine__parameter_checking(void **state) {
 
@@ -40,16 +19,237 @@ void test__f_file_mode_determine__fails(void **state) {
   }
 #endif // _di_level_0_parameter_checking_
 
-void test__f_file_mode_determine__works(void **state) {
+void test__f_file_mode_determine__works_basic(void **state) {
+
+  const mode_t existing = 0;
+
+  {
+    f_file_mode_t changes[] = {
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+    };
+
+    mode_t changeds[] = {
+      F_file_mode_all_x_d,
+      0,
+      F_file_mode_all_r_d,
+      F_file_mode_special_set_group_d,
+      F_file_mode_special_set_user_d,
+      F_file_mode_special_sticky_d,
+      F_file_mode_all_w_d,
+      F_file_mode_owner_x_d,
+      0,
+      F_file_mode_owner_r_d,
+      F_file_mode_owner_w_d,
+      F_file_mode_group_x_d,
+      0,
+      F_file_mode_group_r_d,
+      F_file_mode_group_w_d,
+      F_file_mode_world_x_d,
+      0,
+      F_file_mode_world_r_d,
+      F_file_mode_world_w_d,
+    };
+
+    for (uint8_t i = 0; i < 19; ++i) {
+
+      mode_t changed = 0;
+
+      const f_status_t status = f_file_mode_determine(existing, changes[i], 0, F_false, &changed);
+
+      assert_int_equal(status, F_none);
+      assert_int_equal(changed, changeds[i]);
+    } // for
+  }
 
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    f_file_mode_t changes[] = {
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+    };
+
+    mode_t changeds[] = {
+      F_file_mode_all_x_d,
+      F_file_mode_all_x_d,
+      F_file_mode_all_r_d,
+      F_file_mode_special_set_group_d,
+      F_file_mode_special_set_user_d,
+      F_file_mode_special_sticky_d,
+      F_file_mode_all_w_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_r_d,
+      F_file_mode_owner_w_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_r_d,
+      F_file_mode_group_w_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_r_d,
+      F_file_mode_world_w_d,
+    };
+
+    for (uint8_t i = 0; i < 19; ++i) {
+
+      mode_t changed = 0;
+
+      const f_status_t status = f_file_mode_determine(existing, changes[i], 0, F_true, &changed);
+
+      assert_int_equal(status, F_none);
+      assert_int_equal(changed, changeds[i]);
+    } // for
+  }
+}
+
+void test__f_file_mode_determine__works_basic_replace(void **state) {
+
+  const mode_t existing = F_file_mode_all_rwx_d;
+
+  {
+    f_file_mode_t changes[] = {
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+    };
+
+    mode_t changeds[] = {
+      F_file_mode_all_x_d,
+      F_file_mode_all_x_d,
+      F_file_mode_all_r_d,
+      F_file_mode_special_set_group_d,
+      F_file_mode_special_set_user_d,
+      F_file_mode_special_sticky_d,
+      F_file_mode_all_w_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_r_d,
+      F_file_mode_owner_w_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_r_d,
+      F_file_mode_group_w_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_r_d,
+      F_file_mode_world_w_d,
+    };
+
+    for (uint8_t i = 0; i < 19; ++i) {
+
+      mode_t changed = 0;
+
+      const f_status_t status = f_file_mode_determine(existing, changes[i], F_file_mode_t_replace_all_d, F_false, &changed);
+
+      assert_int_equal(status, F_none);
+      assert_int_equal(changed, changeds[i]);
+    } // for
+  }
+
+  {
+    f_file_mode_t changes[] = {
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_group_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_set_owner_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_sticky_d,
+      F_file_mode_t_block_all_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_owner_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_group_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_execute_only_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_read_d,
+      F_file_mode_t_block_world_d & F_file_mode_t_mask_how_add_d & F_file_mode_t_mask_bit_write_d,
+    };
+
+    mode_t changeds[] = {
+      F_file_mode_all_x_d,
+      F_file_mode_all_x_d,
+      F_file_mode_all_r_d,
+      F_file_mode_special_set_group_d,
+      F_file_mode_special_set_user_d,
+      F_file_mode_special_sticky_d,
+      F_file_mode_all_w_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_x_d,
+      F_file_mode_owner_r_d,
+      F_file_mode_owner_w_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_x_d,
+      F_file_mode_group_r_d,
+      F_file_mode_group_w_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_x_d,
+      F_file_mode_world_r_d,
+      F_file_mode_world_w_d,
+    };
+
+    for (uint8_t i = 0; i < 19; ++i) {
+
+      mode_t changed = 0;
 
-    //const f_status_t status = f_file_mode_determine();
+      const f_status_t status = f_file_mode_determine(existing, changes[i], F_file_mode_t_replace_all_d, F_true, &changed);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+      assert_int_equal(status, F_none);
+      assert_int_equal(changed, changeds[i]);
+    } // for
   }
 }
 
index cb444d98cad808f75616a17e1bcd8971902f1ef2..2dd1def54d6fae1f1d876cfb47ea399814fe8d6f 100644 (file)
 #define _TEST__F_file_mode_determine_h
 
 /**
- * Test that function fails.
+ * Test that parameter checking works as expected.
  *
  * @see f_file_mode_determine()
  */
-extern void test__f_file_mode_determine__fails(void **state);
+#ifndef _di_level_0_parameter_checking_
+  extern void test__f_file_mode_determine__parameter_checking(void **state);
+#endif // _di_level_0_parameter_checking_
 
 /**
- * Test that parameter checking works as expected.
+ * Test that function works for basic combinations.
  *
  * @see f_file_mode_determine()
  */
-#ifndef _di_level_0_parameter_checking_
-  extern void test__f_file_mode_determine__parameter_checking(void **state);
-#endif // _di_level_0_parameter_checking_
+extern void test__f_file_mode_determine__works_basic(void **state);
 
 /**
- * Test that function works.
+ * Test that function works for basic combinations using replace.
  *
  * @see f_file_mode_determine()
  */
-extern void test__f_file_mode_determine__works(void **state);
+extern void test__f_file_mode_determine__works_basic_replace(void **state);
 
 #endif // _TEST__F_file_mode_determine_h
index cfef2d40bf11c1a7af5639b5131cdeda6e5e371f..51ab0f08cb7ea211c28807c491624d6d10c9bfee 100644 (file)
@@ -114,8 +114,6 @@ int main(void) {
     cmocka_unit_test(test__f_file_group_read__returns_data_not),
     cmocka_unit_test(test__f_file_group_read__works),
 
-/*
-
     cmocka_unit_test(test__f_file_is__fails),
     cmocka_unit_test(test__f_file_is__returns_data_not),
     cmocka_unit_test(test__f_file_is__returns_false),
@@ -126,17 +124,32 @@ int main(void) {
     cmocka_unit_test(test__f_file_is_at__returns_false),
     cmocka_unit_test(test__f_file_is_at__returns_true),
 
-    // f_file_link
+    cmocka_unit_test(test__f_file_link__fails),
+    cmocka_unit_test(test__f_file_link__returns_data_not),
+    cmocka_unit_test(test__f_file_link__works),
 
-    // f_file_link_at
+    cmocka_unit_test(test__f_file_link_at__fails),
+    cmocka_unit_test(test__f_file_link_at__returns_data_not),
+    cmocka_unit_test(test__f_file_link_at__works),
 
-    // f_file_link_hard
+    cmocka_unit_test(test__f_file_link_hard__fails),
+    cmocka_unit_test(test__f_file_link_hard__returns_data_not),
+    cmocka_unit_test(test__f_file_link_hard__works),
 
-    // f_file_link_hard_at
+    cmocka_unit_test(test__f_file_link_hard_at__fails),
+    cmocka_unit_test(test__f_file_link_hard_at__returns_data_not),
+    cmocka_unit_test(test__f_file_link_hard_at__works),
 
-    // f_file_link_read
+    cmocka_unit_test(test__f_file_link_read__fails),
+    cmocka_unit_test(test__f_file_link_read__returns_data_not),
+    cmocka_unit_test(test__f_file_link_read__works),
 
-    // f_file_link_read_at
+    cmocka_unit_test(test__f_file_link_read_at__fails),
+    cmocka_unit_test(test__f_file_link_read_at__returns_data_not),
+    cmocka_unit_test(test__f_file_link_read_at__works),
+
+    cmocka_unit_test(test__f_file_mode_determine__works_basic),
+    cmocka_unit_test(test__f_file_mode_determine__works_basic_replace),
 
     // f_file_mode_determine
 
@@ -156,6 +169,7 @@ int main(void) {
 
     // f_file_name_directory
 
+/*
     cmocka_unit_test(test__f_file_open__fails),
     cmocka_unit_test(test__f_file_open__returns_data_not),
     cmocka_unit_test(test__f_file_open__works),