]> Kevux Git Server - fll/commitdiff
Progress: Continue witing f_file unit tests.
authorKevin Day <thekevinday@gmail.com>
Mon, 18 Apr 2022 03:44:41 +0000 (22:44 -0500)
committerKevin Day <thekevinday@gmail.com>
Mon, 18 Apr 2022 03:44:41 +0000 (22:44 -0500)
The __wrap_read() needed to be updated.

16 files changed:
level_0/f_file/tests/unit/c/mock-file.c
level_0/f_file/tests/unit/c/test-file-clone.c
level_0/f_file/tests/unit/c/test-file-copy.c
level_0/f_file/tests/unit/c/test-file-mode_to_mode.c
level_0/f_file/tests/unit/c/test-file-mode_to_mode.h
level_0/f_file/tests/unit/c/test-file-name_base.c
level_0/f_file/tests/unit/c/test-file-name_base.h
level_0/f_file/tests/unit/c/test-file-name_directory.c
level_0/f_file/tests/unit/c/test-file-name_directory.h
level_0/f_file/tests/unit/c/test-file-open.c
level_0/f_file/tests/unit/c/test-file-open_at.c
level_0/f_file/tests/unit/c/test-file-owner_read.c
level_0/f_file/tests/unit/c/test-file-read.c
level_0/f_file/tests/unit/c/test-file-read_block.c
level_0/f_file/tests/unit/c/test-file-read_until.c
level_0/f_file/tests/unit/c/test-file.c

index 884cb0900f47456f3f242512f84a9527a1797d46..0379c1f3e9bb8d99b16f603ecaa1f43efd45f1c7 100644 (file)
@@ -438,7 +438,12 @@ ssize_t __wrap_read(int fd, void *buf, size_t count) {
     return -1;
   }
 
-  buf = mock_type(void *);
+  char *buffer = mock_type(char *);
+  size_t size = mock_type(size_t);
+
+  if (size) {
+    memcpy(buf, buffer, size);
+  }
 
   return mock_type(int);
 }
index f1dd434ec89dcf5cd608886a4195b25d78eaf6d0..1d9401d6d90e5a19d17a67568138521553ba370c 100644 (file)
@@ -43,7 +43,8 @@ void test__f_file_clone__fails_during_read_write(void **state) {
     will_return(__wrap_open, 0);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 1);
     will_return(__wrap_read, 1);
 
     will_return(__wrap_write, false);
@@ -1090,7 +1091,8 @@ void test__f_file_clone__fails_for_regular(void **state) {
       will_return(__wrap_open, 0);
 
       will_return(__wrap_read, false);
-      will_return(__wrap_read, (void *) buffer);
+      will_return(__wrap_read, buffer);
+      will_return(__wrap_read, 1);
       will_return(__wrap_read, 1);
 
       will_return(__wrap_write, true);
@@ -1204,14 +1206,16 @@ void test__f_file_clone__works_for_regular(void **state) {
     will_return(__wrap_open, 0);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 1);
     will_return(__wrap_read, 1);
 
     will_return(__wrap_write, false);
     will_return(__wrap_write, 1);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 0);
     will_return(__wrap_read, 0);
 
     will_return(__wrap_fsync, false);
index f8ec4ef64bd5a5ab76f6e6637d94a63ecf38b7f6..490ff6e7e3319a74a4f351217f77dbb1c2963dfc 100644 (file)
@@ -45,7 +45,8 @@ void test__f_file_copy__fails_during_read_write(void **state) {
     will_return(__wrap_open, 0);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 1);
     will_return(__wrap_read, 1);
 
     will_return(__wrap_write, false);
@@ -1328,7 +1329,8 @@ void test__f_file_copy__fails_for_regular(void **state) {
       will_return(__wrap_open, 0);
 
       will_return(__wrap_read, false);
-      will_return(__wrap_read, (void *) buffer);
+      will_return(__wrap_read, buffer);
+      will_return(__wrap_read, 1);
       will_return(__wrap_read, 1);
 
       will_return(__wrap_write, true);
@@ -1706,14 +1708,16 @@ void test__f_file_copy__works_for_regular(void **state) {
     will_return(__wrap_open, 0);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 1);
     will_return(__wrap_read, 1);
 
     will_return(__wrap_write, false);
     will_return(__wrap_write, 1);
 
     will_return(__wrap_read, false);
-    will_return(__wrap_read, (void *) buffer);
+    will_return(__wrap_read, buffer);
+    will_return(__wrap_read, 0);
     will_return(__wrap_read, 0);
 
     will_return(__wrap_fsync, false);
index 8f7cc5af27bb3462c7ca3f2946c842c688c4c311..1fb61131fd52431078521e8db8a753154ae44347 100644 (file)
@@ -5,27 +5,6 @@
 extern "C" {
 #endif
 
-void test__f_file_mode_to_mode__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_to_mode(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_to_mode__parameter_checking(void **state) {
 
@@ -41,15 +20,77 @@ void test__f_file_mode_to_mode__fails(void **state) {
 
 void test__f_file_mode_to_mode__works(void **state) {
 
-  {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+  f_file_mode_t file_modes[] = {
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_read_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_write_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_execute_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_read_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_write_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_execute_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_read_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_write_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_execute_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_read_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_write_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_execute_d,
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+    F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+  };
 
-    //const f_status_t status = f_file_mode_to_mode();
+  f_file_mode_t modes[] = {
+    F_file_mode_owner_rwx_d,
+    F_file_mode_owner_r_d,
+    F_file_mode_owner_w_d,
+    F_file_mode_owner_x_d,
+    F_file_mode_owner_rw_d,
+    F_file_mode_owner_rx_d,
+    F_file_mode_owner_wx_d,
+    F_file_mode_group_rwx_d,
+    F_file_mode_group_r_d,
+    F_file_mode_group_w_d,
+    F_file_mode_group_x_d,
+    F_file_mode_group_rw_d,
+    F_file_mode_group_rx_d,
+    F_file_mode_group_wx_d,
+    F_file_mode_world_rwx_d,
+    F_file_mode_world_r_d,
+    F_file_mode_world_w_d,
+    F_file_mode_world_x_d,
+    F_file_mode_world_rw_d,
+    F_file_mode_world_rx_d,
+    F_file_mode_world_wx_d,
+    F_file_mode_all_rwx_d,
+    F_file_mode_all_r_d,
+    F_file_mode_all_w_d,
+    F_file_mode_all_x_d,
+    F_file_mode_all_rw_d,
+    F_file_mode_all_rx_d,
+    F_file_mode_all_wx_d,
+  };
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
-  }
+  for (f_array_length_t i = 0; i < 28; ++i) {
+
+    mode_t mode = 0;
+
+    const f_status_t status = f_file_mode_to_mode(file_modes[i], &mode);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(mode, modes[i]);
+  } // for
 }
 
 #ifdef __cplusplus
index 006f8e48e9ad3e28e5fbc20da6e6c9c7ccd234ca..31ca2e386ec55c95fa2ad3a533fb57e759320be6 100644 (file)
 #define _TEST__F_file_mode_to_mode_h
 
 /**
- * Test that function fails.
- *
- * @see f_file_mode_to_mode()
- */
-extern void test__f_file_mode_to_mode__fails(void **state);
-
-/**
  * Test that parameter checking works as expected.
  *
  * @see f_file_mode_to_mode()
index b1fbafea3bcc161d28299c35f8d7d80d4886669a..2592ff67e8d638d8899dc48ffdf0da9c2eaefc0b 100644 (file)
@@ -5,27 +5,6 @@
 extern "C" {
 #endif
 
-void test__f_file_name_base__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_name_base(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_name_base__parameter_checking(void **state) {
 
@@ -39,24 +18,63 @@ void test__f_file_name_base__fails(void **state) {
 
 void test__f_file_name_base__returns_data_not(void **state) {
 
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
   {
-    //const f_status_t status = f_file_name_base(f_string_empty_s);
+    const f_status_t status = f_file_name_base(f_string_empty_s, &buffer);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_name_base__works(void **state) {
 
-  {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  f_string_static_t paths[] = {
+    macro_f_string_static_t_initialize("/a", 0, 2),
+    macro_f_string_static_t_initialize("/a/b", 0, 4),
+    macro_f_string_static_t_initialize("/a/b/c", 0, 6),
+    macro_f_string_static_t_initialize("/a/", 0, 3),
+    macro_f_string_static_t_initialize("/a/b/", 0, 5),
+    macro_f_string_static_t_initialize("/a/b/c/", 0, 7),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("a/b", 0, 3),
+    macro_f_string_static_t_initialize("a/b/c", 0, 5),
+    macro_f_string_static_t_initialize("a/", 0, 2),
+    macro_f_string_static_t_initialize("a/b/", 0, 4),
+    macro_f_string_static_t_initialize("a/b/c/", 0, 6),
+  };
 
-    //const f_status_t status = f_file_name_base();
+  f_string_static_t bases[] = {
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("b", 0, 1),
+    macro_f_string_static_t_initialize("c", 0, 1),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("b", 0, 1),
+    macro_f_string_static_t_initialize("c", 0, 1),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("b", 0, 1),
+    macro_f_string_static_t_initialize("c", 0, 1),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("b", 0, 1),
+    macro_f_string_static_t_initialize("c", 0, 1),
+  };
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
-  }
+  for (uint8_t i = 0; i < 12; ++i) {
+
+    buffer.used = 0;
+
+    const f_status_t status = f_file_name_base(paths[i], &buffer);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(buffer.used, bases[i].used);
+    assert_string_equal(buffer.string, bases[i].string);
+  } // for
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index 16fe388e5dfddff27d317d70b205f5f6e6fe5bb5..a10492a44ccaabc3f9b7ed2c76298dbbb441fcc5 100644 (file)
 #define _TEST__F_file_name_base_h
 
 /**
- * Test that function fails.
- *
- * @see f_file_name_base()
- */
-extern void test__f_file_name_base__fails(void **state);
-
-/**
  * Test that parameter checking works as expected.
  *
  * @see f_file_name_base()
index 0ad533c38385b8ad905fa0705ff2a5bb50413df2..238b8cebcbe68181b37ab919614be5b69def7f33 100644 (file)
@@ -5,27 +5,6 @@
 extern "C" {
 #endif
 
-void test__f_file_name_directory__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_name_directory(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_name_directory__parameter_checking(void **state) {
 
@@ -39,24 +18,63 @@ void test__f_file_name_directory__fails(void **state) {
 
 void test__f_file_name_directory__returns_data_not(void **state) {
 
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
   {
-    //const f_status_t status = f_file_name_directory(f_string_empty_s);
+    const f_status_t status = f_file_name_directory(f_string_empty_s, &buffer);
 
-    //assert_int_equal(status, F_data_not);
+    assert_int_equal(status, F_data_not);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_name_directory__works(void **state) {
 
-  {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  f_string_static_t paths[] = {
+    macro_f_string_static_t_initialize("/a", 0, 2),
+    macro_f_string_static_t_initialize("/a/b", 0, 4),
+    macro_f_string_static_t_initialize("/a/b/c", 0, 6),
+    macro_f_string_static_t_initialize("/a/", 0, 3),
+    macro_f_string_static_t_initialize("/a/b/", 0, 5),
+    macro_f_string_static_t_initialize("/a/b/c/", 0, 7),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("a/b", 0, 3),
+    macro_f_string_static_t_initialize("a/b/c", 0, 5),
+    macro_f_string_static_t_initialize("a/", 0, 2),
+    macro_f_string_static_t_initialize("a/b/", 0, 4),
+    macro_f_string_static_t_initialize("a/b/c/", 0, 6),
+  };
 
-    //const f_status_t status = f_file_name_directory();
+  f_string_static_t bases[] = {
+    macro_f_string_static_t_initialize("/", 0, 1),
+    macro_f_string_static_t_initialize("/a", 0, 2),
+    macro_f_string_static_t_initialize("/a/b", 0, 4),
+    macro_f_string_static_t_initialize("/", 0, 1),
+    macro_f_string_static_t_initialize("/a", 0, 2),
+    macro_f_string_static_t_initialize("/a/b", 0, 4),
+    macro_f_string_static_t_initialize("", 0, 0),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("a/b", 0, 3),
+    macro_f_string_static_t_initialize("", 0, 0),
+    macro_f_string_static_t_initialize("a", 0, 1),
+    macro_f_string_static_t_initialize("a/b", 0, 3),
+  };
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
-  }
+  for (uint8_t i = 0; i < 12; ++i) {
+
+    buffer.used = 0;
+
+    const f_status_t status = f_file_name_directory(paths[i], &buffer);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(buffer.used, bases[i].used);
+    assert_string_equal(buffer.string, bases[i].string);
+  } // for
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index 7992858afc9d64e766b4155c91502cfe4930785a..d540b309abe3781889ce3cf6b6af4a4b7cb28794 100644 (file)
 #define _TEST__F_file_name_directory_h
 
 /**
- * Test that function fails.
- *
- * @see f_file_name_directory()
- */
-extern void test__f_file_name_directory__fails(void **state);
-
-/**
  * Test that parameter checking works as expected.
  *
  * @see f_file_name_directory()
index 33e0db687da0664bfde0a9ca83f8c5a149664a04..ff6ca9f06fc78a797fb89545e19923becf87e222 100644 (file)
@@ -11,10 +11,10 @@ void test__f_file_open__fails(void **state) {
 
   int errnos[] = {
     EACCES,
+    EDQUOT,
     EEXIST,
     EFAULT,
     EFBIG,
-    EDQUOT,
     EINTR,
     EINVAL,
     EISDIR,
@@ -35,10 +35,10 @@ void test__f_file_open__fails(void **state) {
 
   f_status_t statuss[] = {
     F_access_denied,
+    F_filesystem_quota_block,
     F_file_found,
     F_buffer,
     F_number_overflow,
-    F_filesystem_quota_block,
     F_interrupt,
     F_parameter,
     F_directory,
@@ -95,7 +95,7 @@ void test__f_file_open__returns_data_not(void **state) {
 }
 
 void test__f_file_open__works(void **state) {
-/*
+
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
   {
@@ -107,9 +107,8 @@ void test__f_file_open__works(void **state) {
     const f_status_t status = f_file_open(path, 0, &file);
 
     assert_int_equal(status, F_none);
-    assert_int_equal(id, 5);
+    assert_int_equal(file.id, 5);
   }
-  */
 }
 
 #ifdef __cplusplus
index 64b7bc8e79edff0ad8bcbd342daa80698ca45d96..d18b6b354088bf3a7c9998034d9e8d8744458a50 100644 (file)
@@ -6,16 +6,16 @@ extern "C" {
 #endif
 
 void test__f_file_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,
+    EDQUOT,
     EEXIST,
     EFAULT,
     EFBIG,
-    EDQUOT,
     EINTR,
     EINVAL,
     EISDIR,
@@ -36,10 +36,11 @@ void test__f_file_open_at__fails(void **state) {
 
   f_status_t statuss[] = {
     F_access_denied,
+    F_directory_descriptor,
+    F_filesystem_quota_block,
     F_file_found,
     F_buffer,
     F_number_overflow,
-    F_filesystem_quota_block,
     F_interrupt,
     F_parameter,
     F_directory,
@@ -58,18 +59,17 @@ void test__f_file_open_at__fails(void **state) {
     F_failure,
   };
 
-  for (int i = 0; i < 17; ++i) {
+  for (int i = 0; i < 22; ++i) {
 
-    int id = 0;
+    f_file_t file = f_file_t_initialize;
 
     will_return(__wrap_openat, true);
     will_return(__wrap_openat, errnos[i]);
 
-    const f_status_t status = f_file_open_at(at, path, F_false, &id);
+    const f_status_t status = f_file_open_at(0, path, 0, &file);
 
     assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
-  */
 }
 
 #ifndef _di_level_0_parameter_checking_
@@ -85,35 +85,30 @@ void test__f_file_open_at__fails(void **state) {
 
 void test__f_file_open_at__returns_data_not(void **state) {
 
-  const int at = 1;
-
   {
     f_file_t file = f_file_t_initialize;
 
-    const f_status_t status = f_file_open_at(at, f_string_empty_s, 0, &file);
+    const f_status_t status = f_file_open_at(0, f_string_empty_s, 0, &file);
 
     assert_int_equal(status, F_data_not);
   }
 }
 
 void test__f_file_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;
+    f_file_t file = f_file_t_initialize;
 
     will_return(__wrap_openat, false);
     will_return(__wrap_openat, 5);
 
-    const f_status_t status = f_file_open_at(at, path, F_false, &id);
+    const f_status_t status = f_file_open_at(0, path, F_false, &file);
 
     assert_int_equal(status, F_none);
-    assert_int_equal(id, 5);
+    assert_int_equal(file.id, 5);
   }
-  */
 }
 
 #ifdef __cplusplus
index 0cfc114cfd07da7d6cb36ae9513bd2b807760d40..6f3cd29ecb1306c29470a682285f053a864f9c9b 100644 (file)
@@ -7,22 +7,42 @@ extern "C" {
 
 void test__f_file_owner_read__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_failure,
+    F_access_denied,
+    F_buffer,
+    F_loop,
+    F_name,
+    F_file_found_not,
+    F_memory_not,
+    F_directory_not,
+    F_number_overflow,
+    F_file_stat,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
+
+    gid_t id = 0;
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_stat, true);
+    will_return(__wrap_stat, errnos[i]);
 
-    //const f_status_t status = f_file_owner_read(path, F_false, &id);
+    const f_status_t status = f_file_owner_read(path, F_true, &id);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
@@ -40,7 +60,7 @@ void test__f_file_owner_read__fails(void **state) {
 void test__f_file_owner_read__returns_data_not(void **state) {
 
   {
-    uid_t id = 0;
+    gid_t id = 0;
 
     const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, &id);
 
@@ -50,14 +70,25 @@ void test__f_file_owner_read__returns_data_not(void **state) {
 
 void test__f_file_owner_read__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);
+    gid_t id = 0;
+
+    struct stat statistics;
+
+    memset(&statistics, 0, sizeof(struct stat));
+
+    statistics.st_uid = 5;
+
+    will_return(__wrap_stat, false);
+    will_return(__wrap_stat, &statistics);
+    will_return(__wrap_stat, 0);
 
-    //const f_status_t status = f_file_owner_read();
+    const f_status_t status = f_file_owner_read(path, F_true, &id);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
+    assert_int_equal(id, 5);
   }
 }
 
index 20eee794a6f6cebc3e3f4dc9cf9074bb575625b6..18346745cfb781dab22c2fdc67e8dfa19d3a7d5d 100644 (file)
@@ -7,29 +7,55 @@ extern "C" {
 
 void test__f_file_read__fails(void **state) {
 
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  file.id = 1;
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_read, true);
+    will_return(__wrap_read, errnos[i]);
 
-    //const f_status_t status = f_file_read(path, F_false, &id);
+    const f_status_t status = f_file_read(file, &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_
   void test__f_file_read__parameter_checking(void **state) {
 
     f_file_t file = f_file_t_initialize;
+    f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+    file.id = 1;
 
     {
       const f_status_t status = f_file_read(file, 0);
@@ -52,33 +78,61 @@ void test__f_file_read__fails(void **state) {
 
       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_read__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
   {
-    f_string_dynamic_t string = f_string_dynamic_t_initialize;
+    const f_status_t status = f_file_read(file, &buffer);
 
-    const f_status_t status = f_file_read(file, &string);
-
-    assert_int_equal(status, F_data_not);
+    assert_int_equal(F_status_set_fine(status), F_file_closed);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_read__works(void **state) {
 
-  {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
-    //const f_status_t status = f_file_read();
+  file.id = 1;
+  file.size_read = 4;
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+  {
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "abcd");
+    will_return(__wrap_read, 4);
+    will_return(__wrap_read, 4);
+
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "ef");
+    will_return(__wrap_read, 2);
+    will_return(__wrap_read, 2);
+
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "");
+    will_return(__wrap_read, 0);
+    will_return(__wrap_read, 0);
+
+    const f_status_t status = f_file_read(file, &buffer);
+
+    // Ensure string ends in NULL so that assert_string_equal() can be used.
+    f_string_dynamic_increase_by(1, &buffer);
+    buffer.string[buffer.used] = 0;
+
+    assert_int_equal(status, F_none_eof);
+    assert_int_equal(buffer.used, 6);
+    assert_string_equal(buffer.string, "abcdef");
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index 0bfc61337b8f7162777c38bdbcffb65b0a009cf1..74ad8957ed08ef286f382729b9b2777f3b66b971 100644 (file)
@@ -7,29 +7,55 @@ extern "C" {
 
 void test__f_file_read_block__fails(void **state) {
 
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  file.id = 1;
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_read, true);
+    will_return(__wrap_read, errnos[i]);
 
-    //const f_status_t status = f_file_read_block(path, F_false, &id);
+    const f_status_t status = f_file_read_block(file, &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_
   void test__f_file_read_block__parameter_checking(void **state) {
 
     f_file_t file = f_file_t_initialize;
+    f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+    file.id = 1;
 
     {
       const f_status_t status = f_file_read_block(file, 0);
@@ -52,33 +78,64 @@ void test__f_file_read_block__fails(void **state) {
 
       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_read_block__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
   {
-    f_string_dynamic_t string = f_string_dynamic_t_initialize;
-
-    const f_status_t status = f_file_read_block(file, &string);
+    const f_status_t status = f_file_read_block(file, &buffer);
 
-    assert_int_equal(status, F_data_not);
+    assert_int_equal(F_status_set_fine(status), F_file_closed);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_read_block__works(void **state) {
 
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  file.id = 1;
+  file.size_read = 4;
+
+  {
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "abcd");
+    will_return(__wrap_read, 4);
+    will_return(__wrap_read, 4);
+
+    const f_status_t status = f_file_read_block(file, &buffer);
+
+    // Ensure string ends in NULL so that assert_string_equal() can be used.
+    f_string_dynamic_increase_by(1, &buffer);
+    buffer.string[buffer.used] = 0;
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(buffer.used, 4);
+    assert_string_equal(buffer.string, "abcd");
+  }
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "");
+    will_return(__wrap_read, 0);
+    will_return(__wrap_read, 0);
 
-    //const f_status_t status = f_file_read_block();
+    const f_status_t status = f_file_read_block(file, &buffer);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none_eof);
+    assert_int_equal(buffer.used, 4);
+    assert_string_equal(buffer.string, "abcd");
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index 9af58397da0684f7eed77693399c161caff3d8c0..796f391e449c27441dce76f99d7bf08462324995 100644 (file)
@@ -7,32 +7,58 @@ extern "C" {
 
 void test__f_file_read_until__fails(void **state) {
 
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  file.id = 1;
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
     F_failure,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_read, true);
+    will_return(__wrap_read, errnos[i]);
 
-    //const f_status_t status = f_file_read_until(path, F_false, &id);
+    const f_status_t status = f_file_read_until(file, 1, &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_
   void test__f_file_read_until__parameter_checking(void **state) {
 
     f_file_t file = f_file_t_initialize;
+    f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+    file.id = 1;
 
     {
-      const f_status_t status = f_file_read_until(file, 0, 0);
+      const f_status_t status = f_file_read_until(file, 1, 0);
 
       assert_int_equal(F_status_set_fine(status), F_parameter);
     }
@@ -40,7 +66,7 @@ void test__f_file_read_until__fails(void **state) {
     file.size_read = 0;
 
     {
-      const f_status_t status = f_file_read_until(file, 0, 0);
+      const f_status_t status = f_file_read_until(file, 1, 0);
 
       assert_int_equal(F_status_set_fine(status), F_parameter);
     }
@@ -48,37 +74,84 @@ void test__f_file_read_until__fails(void **state) {
     {
       f_string_dynamic_t string = f_string_dynamic_t_initialize;
 
-      const f_status_t status = f_file_read_until(file, 0, &string);
+      const f_status_t status = f_file_read_until(file, 1, &string);
 
       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_read_until__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
   {
-    f_string_dynamic_t string = f_string_dynamic_t_initialize;
+    const f_status_t status = f_file_read_until(file, 1, &buffer);
 
-    const f_status_t status = f_file_read_until(file, 0, &string);
-
-    assert_int_equal(status, F_data_not);
+    assert_int_equal(F_status_set_fine(status), F_file_closed);
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 void test__f_file_read_until__works(void **state) {
 
+  f_file_t file = f_file_t_initialize;
+  f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+  file.id = 1;
+  file.size_read = 4;
+
+  {
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "abcd");
+    will_return(__wrap_read, 4);
+    will_return(__wrap_read, 4);
+
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "ef");
+    will_return(__wrap_read, 2);
+    will_return(__wrap_read, 2);
+
+    const f_status_t status = f_file_read_until(file, 6, &buffer);
+
+    // Ensure string ends in NULL so that assert_string_equal() can be used.
+    f_string_dynamic_increase_by(1, &buffer);
+    buffer.string[buffer.used] = 0;
+
+    assert_int_equal(status, F_none_stop);
+    assert_int_equal(buffer.used, 6);
+    assert_string_equal(buffer.string, "abcdef");
+  }
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    buffer.used = 0;
+
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "abcd");
+    will_return(__wrap_read, 4);
+    will_return(__wrap_read, 4);
+
+    will_return(__wrap_read, false);
+    will_return(__wrap_read, "");
+    will_return(__wrap_read, 0);
+    will_return(__wrap_read, 0);
 
-    //const f_status_t status = f_file_read_until();
+    const f_status_t status = f_file_read_until(file, 6, &buffer);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    // Ensure string ends in NULL so that assert_string_equal() can be used.
+    f_string_dynamic_increase_by(1, &buffer);
+    buffer.string[buffer.used] = 0;
+
+    assert_int_equal(status, F_none_eof);
+    assert_int_equal(buffer.used, 4);
+    assert_string_equal(buffer.string, "abcd");
   }
+
+  f_string_dynamic_resize(0, &buffer);
 }
 
 #ifdef __cplusplus
index b10eeeb35a4af36ecb83eb08c878107c333e0190..38df2ef098e1186e17019edcc3e03d5059a2d900 100644 (file)
@@ -172,13 +172,14 @@ int main(void) {
     cmocka_unit_test(test__f_file_mode_set_at__returns_data_not),
     cmocka_unit_test(test__f_file_mode_set_at__works),
 
-    // f_file_mode_to_mode
+    cmocka_unit_test(test__f_file_mode_to_mode__works),
 
-    // f_file_name_base
+    cmocka_unit_test(test__f_file_name_base__returns_data_not),
+    cmocka_unit_test(test__f_file_name_base__works),
 
-    // f_file_name_directory
+    cmocka_unit_test(test__f_file_name_directory__returns_data_not),
+    cmocka_unit_test(test__f_file_name_directory__works),
 
-/*
     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),
@@ -187,14 +188,23 @@ int main(void) {
     cmocka_unit_test(test__f_file_open_at__returns_data_not),
     cmocka_unit_test(test__f_file_open_at__works),
 
-    // f_file_owner_read
+    cmocka_unit_test(test__f_file_owner_read__fails),
+    cmocka_unit_test(test__f_file_owner_read__returns_data_not),
+    cmocka_unit_test(test__f_file_owner_read__works),
 
-    // f_file_read
+    cmocka_unit_test(test__f_file_read__fails),
+    cmocka_unit_test(test__f_file_read__returns_file_closed),
+    cmocka_unit_test(test__f_file_read__works),
 
-    // f_file_read_block
+    cmocka_unit_test(test__f_file_read_block__fails),
+    cmocka_unit_test(test__f_file_read_block__returns_file_closed),
+    cmocka_unit_test(test__f_file_read_block__works),
 
-    // f_file_read_until
+    cmocka_unit_test(test__f_file_read_until__fails),
+    cmocka_unit_test(test__f_file_read_until__returns_file_closed),
+    cmocka_unit_test(test__f_file_read_until__works),
 
+/*
     cmocka_unit_test(test__f_file_remove__fails),
     cmocka_unit_test(test__f_file_remove__returns_data_not),
     cmocka_unit_test(test__f_file_remove__works),