]> Kevux Git Server - fll/commitdiff
Update: Finish writing unit tests for f_file.
authorKevin Day <thekevinday@gmail.com>
Thu, 21 Apr 2022 23:53:05 +0000 (18:53 -0500)
committerKevin Day <thekevinday@gmail.com>
Thu, 21 Apr 2022 23:53:05 +0000 (18:53 -0500)
12 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-umask_get.c
level_0/f_file/tests/unit/c/test-file-umask_get.h
level_0/f_file/tests/unit/c/test-file-umask_set.c
level_0/f_file/tests/unit/c/test-file-umask_set.h
level_0/f_file/tests/unit/c/test-file-write.c
level_0/f_file/tests/unit/c/test-file-write_block.c
level_0/f_file/tests/unit/c/test-file-write_range.c
level_0/f_file/tests/unit/c/test-file-write_until.c
level_0/f_file/tests/unit/c/test-file.c

index 59a86e732292a5df771d4a9180abf4edcd02d7bc..729cf57da6119cd869ded0992137fcf8dac7c855 100644 (file)
@@ -107,4 +107,5 @@ flags -Wl,--wrap=symlinkat
 flags -Wl,--wrap=unlink
 flags -Wl,--wrap=unlinkat
 flags -Wl,--wrap=utimensat
+flags -Wl,--wrap=umask
 flags -Wl,--wrap=write
index 992b19dd3fed5a328d3e42ed0296a14e58b2f6be..34056e6416c2f43b30acdb65c95355b8e75f8e98 100644 (file)
@@ -693,6 +693,11 @@ int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec time
   return mock_type(int);
 }
 
+mode_t __wrap_umask(mode_t mask) {
+
+  return mock_type(mode_t);
+}
+
 ssize_t __wrap_write(int fd, const void *buf, size_t count) {
 
   const bool failure = mock_type(bool);
index 955978459ab654fe3449dfe4d7cf985c8e3f191e..a33f1341eaa0de85d9db647314024703eab5ba0d 100644 (file)
@@ -76,6 +76,7 @@ extern int __wrap_symlink(const char *target, const char *linkpath);
 extern int __wrap_symlinkat(const char *target, int newdirfd, const char *linkpath);
 extern int __wrap_unlink(const char *pathname);
 extern int __wrap_unlinkat(int dirfd, const char *pathname, int flags);
+extern mode_t __wrap_umask(mode_t mask);
 extern int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
 extern ssize_t __wrap_write(int fd, const void *buf, size_t count);
 
index c31f88ddbbf3d24b63f50036b95176b6bea4c8f7..9f405d00ac212e130f1b17812d7719cff7cd307a 100644 (file)
@@ -5,46 +5,29 @@
 extern "C" {
 #endif
 
-void test__f_file_umask_get__fails(void **state) {
+#ifndef _di_level_0_parameter_checking_
+  void test__f_file_umask_get__parameter_checking(void **state) {
 
-  int errnos[] = {
-    mock_errno_generic,
-  };
+    {
+      const f_status_t status = f_file_umask_get(0);
 
-  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_umask_get(path, F_false, &id);
-
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
-  } // for
-}
-
-void test__f_file_umask_get__returns_data_not(void **state) {
-
-  {
-    //const f_status_t status = f_file_umask_get(f_string_empty_s);
-
-    //assert_int_equal(status, F_data_not);
+      assert_int_equal(F_status_set_fine(status), F_parameter);
+    }
   }
-}
+#endif // _di_level_0_parameter_checking_
 
 void test__f_file_umask_get__works(void **state) {
 
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_umask, F_file_mode_all_rw_d);
+    will_return(__wrap_umask, 0);
+
+    mode_t mode = 0;
 
-    //const f_status_t status = f_file_umask_get();
+    const mode_t status = f_file_umask_get(&mode);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
+    assert_int_equal(mode, F_file_mode_all_rw_d);
   }
 }
 
index 664517e861e9e5f2d4f67b887fd1c605c0272237..b3574e84bab3bc19b20e3dc5cec06b04c5a0170e 100644 (file)
 #define _TEST__F_file_umask_get_h
 
 /**
- * Test that function fails.
+ * Test that parameter checking works as expected.
  *
  * @see f_file_umask_get()
  */
-extern void test__f_file_umask_get__fails(void **state);
-
-/**
- * Test that function works but the path is empty.
- *
- * @see f_file_umask_get()
- */
-extern void test__f_file_umask_get__returns_data_not(void **state);
+#ifndef _di_level_0_parameter_checking_
+  extern void test__f_file_umask_get__parameter_checking(void **state);
+#endif // _di_level_0_parameter_checking_
 
 /**
  * Test that function works.
index 1ba5e86a0316b24db7680095132d86b3d17f8333..7fe792f91e622686abdfc9da7c0bd0ea405029ea 100644 (file)
@@ -5,46 +5,14 @@
 extern "C" {
 #endif
 
-void test__f_file_umask_set__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_umask_set(path, F_false, &id);
-
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
-  } // for
-}
-
-void test__f_file_umask_set__returns_data_not(void **state) {
-
-  {
-    //const f_status_t status = f_file_umask_set(f_string_empty_s);
-
-    //assert_int_equal(status, F_data_not);
-  }
-}
-
 void test__f_file_umask_set__works(void **state) {
 
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    will_return(__wrap_umask, 0);
 
-    //const f_status_t status = f_file_umask_set();
+    const mode_t status = f_file_umask_set(F_file_mode_all_rw_d);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
   }
 }
 
index e177fdba45a235c95ae70feb4c6bea72b34059c0..483119a100ae317d06d4e949ea83d6926a4be617 100644 (file)
 #define _TEST__F_file_umask_set_h
 
 /**
- * Test that function fails.
- *
- * @see f_file_umask_set()
- */
-extern void test__f_file_umask_set__fails(void **state);
-
-/**
- * Test that function works but the path is empty.
- *
- * @see f_file_umask_set()
- */
-extern void test__f_file_umask_set__returns_data_not(void **state);
-
-/**
  * Test that function works.
  *
  * @see f_file_umask_set()
index 4b1158ee4efd343ab40ec2035333cb6b18675890..3830b4fd8af22a51688528b97dae99a973829802 100644 (file)
@@ -7,22 +7,61 @@ extern "C" {
 
 void test__f_file_write__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
-    F_failure,
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
+    F_file_write,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
+
+    will_return(__wrap_write, true);
+    will_return(__wrap_write, errnos[i]);
+
+    const f_status_t status = f_file_write(file, path, 0);
+
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
+  } // for
+
+  for (int i = 0; i < 9; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, 1);
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_write, true);
+    will_return(__wrap_write, errnos[i]);
 
-    //const f_status_t status = f_file_write(path, F_false, &id);
+    const f_status_t status = f_file_write(file, path, 0);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
@@ -74,14 +113,35 @@ void test__f_file_write__returns_data_not(void **state) {
 
 void test__f_file_write__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);
+    f_file_t file = f_file_t_initialize;
+    file.size_write = path.used;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    const f_status_t status = f_file_write(file, path, 0);
+
+    assert_int_equal(status, F_none_eos);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+    file.size_write = path.used / 2;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, path.used / 2);
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, path.used / 2);
 
-    //const f_status_t status = f_file_write();
+    const f_status_t status = f_file_write(file, path, 0);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none_eos);
   }
 }
 
index a821e43a336f6e275586853c9d956de09fbe613f..ef7bd8cd8f888379671529446905cdcb6c96e15e 100644 (file)
@@ -7,22 +7,44 @@ extern "C" {
 
 void test__f_file_write_block__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
-    F_failure,
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
+    F_file_write,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_write, true);
+    will_return(__wrap_write, errnos[i]);
 
-    //const f_status_t status = f_file_write_block(path, F_false, &id);
+    const f_status_t status = f_file_write_block(file, path, 0);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
@@ -42,7 +64,8 @@ void test__f_file_write_block__fails(void **state) {
 
 void test__f_file_write_block__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
+  file.size_write = 1;
 
   {
     const f_status_t status = f_file_write_block(file, f_string_empty_s, 0);
@@ -74,14 +97,32 @@ void test__f_file_write_block__returns_data_not(void **state) {
 
 void test__f_file_write_block__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, 1);
+
+    const f_status_t status = f_file_write_block(file, path, 0);
+
+    assert_int_equal(status, F_none_stop);
+  }
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    f_file_t file = f_file_t_initialize;
+    file.size_write = path.used;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
 
-    //const f_status_t status = f_file_write_block();
+    const f_status_t status = f_file_write_block(file, path, 0);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none_eos);
   }
 }
 
index 3ad84235d0e2d04a20393c523a68a4fe12d5d326..5c3bcb3405668732a52f034a243b3b8c0a1199c1 100644 (file)
@@ -7,22 +7,45 @@ extern "C" {
 
 void test__f_file_write_range__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+  const f_string_range_t range = macro_f_string_range_t_initialize(0, 0);
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
-    F_failure,
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
+    F_file_write,
   };
 
-  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]);
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
 
-    //const f_status_t status = f_file_write_range(path, F_false, &id);
+    will_return(__wrap_write, true);
+    will_return(__wrap_write, errnos[i]);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    const f_status_t status = f_file_write_range(file, path, range, 0);
+
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
@@ -44,9 +67,11 @@ void test__f_file_write_range__fails(void **state) {
 
 void test__f_file_write_range__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
   const f_string_range_t range = f_string_range_t_initialize;
 
+  file.size_write = 1;
+
   {
     const f_status_t status = f_file_write_range(file, f_string_empty_s, range, 0);
 
@@ -121,14 +146,33 @@ void test__f_file_write_range__returns_data_not(void **state) {
 
 void test__f_file_write_range__works(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+  const f_string_range_t range = macro_f_string_range_t_initialize(0, 0);
+
+  {
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    const f_status_t status = f_file_write_range(file, path, range, 0);
+
+    assert_int_equal(status, F_none_stop);
+  }
+
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    f_file_t file = f_file_t_initialize;
+    file.size_write = path.used;
+    file.id = 0;
 
-    //const f_status_t status = f_file_write_range();
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    const f_status_t status = f_file_write_range(file, path, range, 0);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none_eos);
   }
 }
 
index 70412e19682b248f30b45f7c5a0e197b53df89c8..efcb9327c8517973d1f82e93a6774ba1d501fc15 100644 (file)
@@ -7,22 +7,44 @@ extern "C" {
 
 void test__f_file_write_until__fails(void **state) {
 
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
   int errnos[] = {
+    EAGAIN,
+    EBADF,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EISDIR,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
   f_status_t statuss[] = {
-    F_failure,
+    F_block,
+    F_file_descriptor,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_type_directory,
+    F_block,
+    F_file_write,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (int i = 0; i < 9; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+    will_return(__wrap_write, true);
+    will_return(__wrap_write, errnos[i]);
 
-    //const f_status_t status = f_file_write_until(path, F_false, &id);
+    const f_status_t status = f_file_write_until(file, path, 1, 0);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
   } // for
 }
 
@@ -42,10 +64,11 @@ void test__f_file_write_until__fails(void **state) {
 
 void test__f_file_write_until__returns_file_closed(void **state) {
 
-  const f_file_t file = f_file_t_initialize;
+  f_file_t file = f_file_t_initialize;
+  file.size_write = 1;
 
   {
-    const f_status_t status = f_file_write_until(file, f_string_empty_s, 0, 0);
+    const f_status_t status = f_file_write_until(file, f_string_empty_s, 1, 0);
 
     assert_int_equal(F_status_set_fine(status), F_file_closed);
   }
@@ -106,14 +129,41 @@ void test__f_file_write_until__returns_data_not(void **state) {
 
 void test__f_file_write_until__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);
+    f_file_t file = f_file_t_initialize;
+    file.size_write = 1;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
+
+    const f_status_t status = f_file_write_until(file, path, path.used, 0);
+
+    assert_int_equal(status, F_none_eos);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+    file.size_write = path.used;
+    file.id = 0;
+
+    will_return(__wrap_write, false);
+    will_return(__wrap_write, file.size_write);
 
-    //const f_status_t status = f_file_write_until();
+    const f_status_t status = f_file_write_until(file, path, path.used, 0);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none_eos);
   }
 }
 
index 774047026020e9f61829174e9db5826a65505d13..d540b9307c384bef974b48b78bb7acb949afac1f 100644 (file)
@@ -323,19 +323,30 @@ int main(void) {
     cmocka_unit_test(test__f_file_type_at__returns_data_not),
     cmocka_unit_test(test__f_file_type_at__works),
 
-/*
-    // f_file_umask_get
+    cmocka_unit_test(test__f_file_umask_get__works),
 
-    // f_file_umask_set
+    cmocka_unit_test(test__f_file_umask_set__works),
 
-    // f_file_write
+    cmocka_unit_test(test__f_file_write__fails),
+    cmocka_unit_test(test__f_file_write__returns_file_closed),
+    cmocka_unit_test(test__f_file_write__returns_data_not),
+    cmocka_unit_test(test__f_file_write__works),
 
-    // f_file_write_block
+    cmocka_unit_test(test__f_file_write_block__fails),
+    cmocka_unit_test(test__f_file_write_block__returns_file_closed),
+    cmocka_unit_test(test__f_file_write_block__returns_data_not),
+    cmocka_unit_test(test__f_file_write_block__works),
 
-    // f_file_write_until
+    cmocka_unit_test(test__f_file_write_range__fails),
+    cmocka_unit_test(test__f_file_write_range__returns_file_closed),
+    cmocka_unit_test(test__f_file_write_range__returns_data_not),
+    cmocka_unit_test(test__f_file_write_range__works),
+
+    cmocka_unit_test(test__f_file_write_until__fails),
+    cmocka_unit_test(test__f_file_write_until__returns_file_closed),
+    cmocka_unit_test(test__f_file_write_until__returns_data_not),
+    cmocka_unit_test(test__f_file_write_until__works),
 
-    // f_file_write_range
-*/
     #ifndef _di_level_0_parameter_checking_
       // f_file_access() doesn't use parameter checking.
       // f_file_access_at() doesn't use parameter checking.
@@ -407,7 +418,7 @@ int main(void) {
       // f_file_touch_at() doesn't use parameter checking.
       cmocka_unit_test(test__f_file_type__parameter_checking),
       cmocka_unit_test(test__f_file_type_at__parameter_checking),
-      // f_file_umask_get() doesn't use parameter checking.
+      cmocka_unit_test(test__f_file_umask_get__parameter_checking),
       // f_file_umask_set() doesn't use parameter checking.
       cmocka_unit_test(test__f_file_write__parameter_checking),
       cmocka_unit_test(test__f_file_write_block__parameter_checking),