]> Kevux Git Server - fll/commitdiff
Progress: Continue witing f_file unit tests.
authorKevin Day <thekevinday@gmail.com>
Wed, 20 Apr 2022 03:22:55 +0000 (22:22 -0500)
committerKevin Day <thekevinday@gmail.com>
Wed, 20 Apr 2022 03:22:55 +0000 (22:22 -0500)
19 files changed:
level_0/f_file/data/build/settings-mocks
level_0/f_file/data/build/settings-tests
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-clone.c
level_0/f_file/tests/unit/c/test-file-copy.c
level_0/f_file/tests/unit/c/test-file-create.c
level_0/f_file/tests/unit/c/test-file-create_at.c
level_0/f_file/tests/unit/c/test-file-flush.c
level_0/f_file/tests/unit/c/test-file-size_by_id.c
level_0/f_file/tests/unit/c/test-file-stat_by_id.c
level_0/f_file/tests/unit/c/test-file-stream_close.c
level_0/f_file/tests/unit/c/test-file-stream_close.h
level_0/f_file/tests/unit/c/test-file-stream_descriptor.c [deleted file]
level_0/f_file/tests/unit/c/test-file-stream_descriptor.h [deleted file]
level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.c [new file with mode: 0644]
level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.h [new file with mode: 0644]
level_0/f_file/tests/unit/c/test-file.c
level_0/f_file/tests/unit/c/test-file.h

index be55dfe20ca5d9e58fd5d946a3aa52c4e0c8126a..c566667a2c18059a8bca976b2be8f9985614bc80 100644 (file)
@@ -65,11 +65,16 @@ flags -Wl,--wrap=close
 flags -Wl,--wrap=faccessat
 flags -Wl,--wrap=fchmodat
 flags -Wl,--wrap=fchownat
+flags -Wl,--wrap=fclose
+flags -Wl,--wrap=fdopen
 flags -Wl,--wrap=feof
 flags -Wl,--wrap=ferror
+flags -Wl,--wrap=fflush
 flags -Wl,--wrap=fileno
 flags -Wl,--wrap=flockfile
+flags -Wl,--wrap=fopen
 flags -Wl,--wrap=fread_unlocked
+flags -Wl,--wrap=freopen
 flags -Wl,--wrap=fstat
 flags -Wl,--wrap=fstatat
 flags -Wl,--wrap=fsync
index ed6919e0de2c0c6fc67e4ecd3216f98cc3664385..9108db4a225ff3d0945143f4818bc25c4bb0a465 100644 (file)
@@ -25,7 +25,7 @@ build_language c
 build_libraries -lc -lcmocka
 build_libraries-individual -lf_memory -lf_string -lf_file
 
-build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-close_flush.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-seek.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c
+build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-close_flush.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-seek.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_open_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c
 build_sources_program test-file.c
 
 build_script no
index 8e2e2aaf9376e53e4f3c5835868125decb4189a5..d976f429632bcbc69780bda14024558380a34007 100644 (file)
@@ -121,6 +121,58 @@ int __wrap_fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, i
   return mock_type(int);
 }
 
+int __wrap_fclose(FILE *stream) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return EOF;
+  }
+
+  return mock_type(int);
+}
+
+FILE *__wrap_fopen(const char *pathname, const char *mode) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return 0;
+  }
+
+  return mock_type(FILE *);
+}
+
+FILE *__wrap_fdopen(int fd, const char *mode) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return 0;
+  }
+
+  return mock_type(FILE *);
+}
+
+FILE *__wrap_freopen(const char *pathname, const char *mode, FILE *stream) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return 0;
+  }
+
+  return mock_type(FILE *);
+}
+
 int __wrap_feof_unlocked(FILE *stream) {
 
   const bool failure = mock_type(bool);
@@ -147,6 +199,19 @@ int __wrap_ferror_unlocked(FILE *stream) {
   return mock_type(int);
 }
 
+int __wrap_fflush(FILE *stream) {
+
+  const bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return EOF;
+  }
+
+  return mock_type(int);
+}
+
 int __wrap_fileno(FILE *stream) {
   return mock_type(int);
 }
index 11029b32473678c6d8ed2df0099bc6afb23a4230..6a0bd9817e7893735efc0300e58db8108df661ad 100644 (file)
@@ -37,8 +37,13 @@ extern int __wrap_fchmod(const char *pathname, mode_t mode);
 extern int __wrap_fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
 extern int __wrap_fchown(int fd, uid_t owner, gid_t group);
 extern int __wrap_fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
+extern int __wrap_fclose(FILE *stream);
+extern FILE *__wrap_fopen(const char *pathname, const char *mode);
+extern FILE *__wrap_fdopen(int fd, const char *mode);
+extern FILE *__wrap_freopen(const char *pathname, const char *mode, FILE *stream);
 extern int __wrap_feof_unlocked(FILE *stream);
 extern int __wrap_ferror_unlocked(FILE *stream);
+extern int __wrap_fflush(FILE *stream);
 extern int __wrap_fileno(FILE *stream);
 extern void __wrap_flockfile(FILE *filehandle);
 extern size_t __wrap_fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream);
index 1d9401d6d90e5a19d17a67568138521553ba370c..1bc42db379a330be6e1370c858144b4feea53d63 100644 (file)
@@ -495,49 +495,6 @@ void test__f_file_clone__fails_for_regular(void **state) {
     int errnos[] = {
       EBADF,
       EDQUOT,
-      EIO,
-      ENOSPC,
-      EROFS,
-      mock_errno_generic,
-    };
-
-    f_status_t statuss[] = {
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-    };
-
-    struct stat statistics;
-
-    memset(&statistics, 0, sizeof(struct stat));
-
-    statistics.st_mode = 1 | F_file_type_regular_d;
-
-    for (int i = 0; i < 6; ++i) {
-
-      will_return(__wrap_stat, false);
-      will_return(__wrap_stat, &statistics);
-      will_return(__wrap_stat, 0);
-
-      will_return(__wrap_open, false);
-      will_return(__wrap_open, 0);
-
-      will_return(__wrap_fsync, true);
-      will_return(__wrap_fsync, errnos[i]);
-
-      const f_status_t status = f_file_clone(path, path, 0, 0);
-
-      assert_int_equal(F_status_set_fine(status), statuss[i]);
-    } // for
-  }
-
-  {
-    int errnos[] = {
-      EBADF,
-      EDQUOT,
       EINTR,
       EIO,
       ENOSPC,
index 490ff6e7e3319a74a4f351217f77dbb1c2963dfc..cadcc348ed6db32b72dd536590036a03a4b55279 100644 (file)
@@ -852,50 +852,6 @@ void test__f_file_copy__fails_for_regular(void **state) {
   {
     int errnos[] = {
       EBADF,
-      EDQUOT,
-      EIO,
-      ENOSPC,
-      EROFS,
-      mock_errno_generic,
-    };
-
-    f_status_t statuss[] = {
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-    };
-
-    struct stat statistics;
-
-    memset(&statistics, 0, sizeof(struct stat));
-
-    statistics.st_mode = 1 | F_file_type_regular_d;
-    statistics.st_size = 1;
-
-    for (int i = 0; i < 6; ++i) {
-
-      will_return(__wrap_stat, false);
-      will_return(__wrap_stat, &statistics);
-      will_return(__wrap_stat, 0);
-
-      will_return(__wrap_open, false);
-      will_return(__wrap_open, 0);
-
-      will_return(__wrap_fsync, true);
-      will_return(__wrap_fsync, errnos[i]);
-
-      const f_status_t status = f_file_copy(path, path, mode, 0, 0);
-
-      assert_int_equal(F_status_set_fine(status), statuss[i]);
-    } // for
-  }
-
-  {
-    int errnos[] = {
-      EBADF,
       EINTR,
       EIO,
       ENOSPC,
index e11fc49fcae8e192cf24432c1e04551d02cc0aea..5713f65443720b7422dd86b837b30bcad7fb1044 100644 (file)
@@ -73,39 +73,6 @@ void test__f_file_create__fails(void **state) {
     int errnos[] = {
       EBADF,
       EDQUOT,
-      EIO,
-      ENOSPC,
-      EROFS,
-      mock_errno_generic,
-    };
-
-    f_status_t statuss[] = {
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-    };
-
-    for (int i = 0; i < 6; ++i) {
-
-      will_return(__wrap_open, false);
-      will_return(__wrap_open, 0);
-
-      will_return(__wrap_fsync, true);
-      will_return(__wrap_fsync, errnos[i]);
-
-      const f_status_t status = f_file_create(path, 0, F_false);
-
-      assert_int_equal(F_status_set_fine(status), statuss[i]);
-    } // for
-  }
-
-  {
-    int errnos[] = {
-      EBADF,
-      EDQUOT,
       EINTR,
       EIO,
       ENOSPC,
index d398f185e844c7b755ecc824ac3f4b0990c2d146..84f0ce3fb68e338a01ce79e97c80b26d07beae07 100644 (file)
@@ -74,39 +74,6 @@ void test__f_file_create_at__fails(void **state) {
   {
     int errnos[] = {
       EBADF,
-      EDQUOT,
-      EIO,
-      ENOSPC,
-      EROFS,
-      mock_errno_generic,
-    };
-
-    f_status_t statuss[] = {
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-      F_file_synchronize,
-    };
-
-    for (int i = 0; i < 6; ++i) {
-
-      will_return(__wrap_openat, false);
-      will_return(__wrap_openat, 0);
-
-      will_return(__wrap_fsync, true);
-      will_return(__wrap_fsync, errnos[i]);
-
-      const f_status_t status = f_file_create_at(0, path, 0, F_false);
-
-      assert_int_equal(F_status_set_fine(status), statuss[i]);
-    } // for
-  }
-
-  {
-    int errnos[] = {
-      EBADF,
       EINTR,
       EIO,
       ENOSPC,
index 73bc941ce5da64b5aeb937861f9b086031436c2a..7e4362c91065e62d4aa19224d430d2e6e3f701b9 100644 (file)
@@ -10,6 +10,7 @@ void test__f_file_flush__fails(void **state) {
   int errnos[] = {
     EBADF,
     EDQUOT,
+    EINVAL,
     EIO,
     ENOSPC,
     EROFS,
@@ -19,13 +20,14 @@ void test__f_file_flush__fails(void **state) {
   f_status_t statuss[] = {
     F_file_descriptor,
     F_filesystem_quota_block,
+    F_supported_not,
     F_input_output,
     F_space_not,
     F_supported_not,
-    F_failure,
+    F_file_synchronize,
   };
 
-  for (int i = 0; i < 6; ++i) {
+  for (int i = 0; i < 7; ++i) {
 
     will_return(__wrap_fsync, true);
     will_return(__wrap_fsync, errnos[i]);
index 2b289fb8978022aa7541d38c45e96680dc792c98..16bfd1bab9a279b8963a34772b7773cd72139df3 100644 (file)
@@ -41,8 +41,6 @@ void test__f_file_size_by_id__fails(void **state) {
 
     off_t size = 0;
 
-    printf("\nDEBUG: i=%d\n", i);
-
     will_return(__wrap_fstat, true);
     will_return(__wrap_fstat, errnos[i]);
 
index 6fd4a0823088cd55eaf07dd4a808876ccbf0b96a..723b2f9779d78599b446c18ce6f83cf4e05d4ac6 100644 (file)
@@ -43,8 +43,6 @@ void test__f_file_stat_by_id__fails(void **state) {
 
     memset(&result, 0, sizeof(struct stat));
 
-    printf("\nDEBUG: i=%d\n", i);
-
     will_return(__wrap_fstat, true);
     will_return(__wrap_fstat, errnos[i]);
 
index 07360c5830264735498aaba4e6dd031437cdaa5b..a860c350baa4fb685e98a0fd00a22d3f58a221bc 100644 (file)
 extern "C" {
 #endif
 
-void test__f_file_stream_close__fails(void **state) {
+void test__f_file_stream_close__fails_for_file_descriptor(void **state) {
+
+  int errno_flushs[] = {
+    EBADF,
+    EDQUOT,
+    EINVAL,
+    EIO,
+    ENOSPC,
+    EROFS,
+  };
+
+  int errno_closes[] = {
+    EBADF,
+    EDQUOT,
+    EINTR,
+    EIO,
+    ENOSPC,
+    mock_errno_generic,
+  };
+
+  f_status_t status_flushs[] = {
+    F_file_descriptor,
+    F_filesystem_quota_block,
+    F_supported_not,
+    F_input_output,
+    F_space_not,
+    F_supported_not,
+  };
+
+  f_status_t status_closes[] = {
+    F_file_descriptor,
+    F_filesystem_quota_block,
+    F_interrupt,
+    F_input_output,
+    F_space_not,
+    F_file_close,
+  };
+
+  for (uint8_t flush = 0; flush < 2; ++flush) {
+
+    for (int i = 0; i < 6; ++i) {
+
+      f_file_t file = f_file_t_initialize;
+      file.id = 0;
+      file.stream = 0;
+
+      if (flush) {
+        if (flush == 1) {
+          will_return(__wrap_fsync, true);
+          will_return(__wrap_fsync, errno_flushs[i]);
+        }
+        else {
+          will_return(__wrap_fsync, false);
+          will_return(__wrap_fsync, 0);
+        }
+
+        will_return(__wrap_close, true);
+        will_return(__wrap_close, errno_closes[i]);
+      }
+      else {
+        will_return(__wrap_close, true);
+        will_return(__wrap_close, errno_closes[i]);
+      }
+
+      const f_status_t status = f_file_stream_close(flush, &file);
+
+      assert_int_equal(F_status_set_fine(status), status_closes[i]);
+
+      assert_int_equal(file.id, -1);
+      assert_int_equal(file.stream, 0);
+    } // for
+  } // for
+}
+
+void test__f_file_stream_close__fails_for_stream(void **state) {
 
   int errnos[] = {
+    EACCES,
+    EAGAIN,
+    EBADF,
+    EFBIG,
+    EDEADLK,
+    EDESTADDRREQ,
+    EDQUOT,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EMFILE,
+    ENOLCK,
+    ENOSPC,
+    ENOTDIR,
+    EPERM,
+    EPIPE,
+    EWOULDBLOCK,
     mock_errno_generic,
   };
 
-  f_status_t statuss[] = {
-    F_failure,
+  f_status_t status_flushs[] = {
+    F_access_denied,
+    F_block,
+    F_file_descriptor,
+    F_file_overflow,
+    F_deadlock,
+    F_socket_not,
+    F_space_not,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_descriptor_max,
+    F_lock,
+    F_space_not,
+    F_file_type_not_directory,
+    F_prohibited,
+    F_pipe_not,
+    F_block,
+    F_file_synchronize,
+  };
+
+  f_status_t status_closes[] = {
+    F_access_denied,
+    F_block,
+    F_file_descriptor,
+    F_file_overflow,
+    F_deadlock,
+    F_socket_not,
+    F_space_not,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_descriptor_max,
+    F_lock,
+    F_space_not,
+    F_file_type_not_directory,
+    F_prohibited,
+    F_pipe_not,
+    F_block,
+    F_file_close,
   };
 
-  for (int i = 0; i < 1; ++i) {
+  for (uint8_t flush = 0; flush < 2; ++flush) {
+
+    for (int i = 0; i < 19; ++i) {
+
+      f_file_t file = f_file_t_initialize;
+      file.id = 0;
+      file.stream = stdout;
+
+      if (flush) {
+        if (flush == 1) {
+          will_return(__wrap_fflush, true);
+          will_return(__wrap_fflush, errnos[i]);
+        }
+        else {
+          will_return(__wrap_fflush, false);
+          will_return(__wrap_fflush, 0);
+        }
 
-    //will_return(__wrap_open, true);
-    //will_return(__wrap_open, errnos[i]);
+        will_return(__wrap_fclose, true);
+        will_return(__wrap_fclose, errnos[i]);
+      }
+      else {
+        will_return(__wrap_fclose, true);
+        will_return(__wrap_fclose, errnos[i]);
+      }
 
-    //const f_status_t status = f_file_stream_close(path, F_false, &id);
+      const f_status_t status = f_file_stream_close(flush, &file);
 
-    //assert_int_equal(F_status_set_fine(status), statuss[i]);
+      assert_int_equal(F_status_set_fine(status), status_closes[i]);
+      assert_int_equal(file.id, -1);
+      assert_int_equal(file.stream, 0);
+    } // for
   } // for
 }
 
@@ -40,13 +196,73 @@ void test__f_file_stream_close__fails(void **state) {
 void test__f_file_stream_close__works(void **state) {
 
   {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
+    f_file_t file = f_file_t_initialize;
+
+    file.id = 0;
+    file.stream = stdout;
+
+    will_return(__wrap_fclose, false);
+    will_return(__wrap_fclose, 0);
+
+    const f_status_t status = f_file_stream_close(F_false, &file);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, -1);
+    assert_int_equal(file.stream, 0);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+
+    file.id = 0;
+    file.stream = 0;
+
+    will_return(__wrap_close, false);
+    will_return(__wrap_close, 0);
+
+    const f_status_t status = f_file_stream_close(F_false, &file);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, -1);
+    assert_int_equal(file.stream, 0);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+
+    file.id = 0;
+    file.stream = stdout;
+
+    will_return(__wrap_fflush, false);
+    will_return(__wrap_fflush, 0);
+
+    will_return(__wrap_fclose, false);
+    will_return(__wrap_fclose, 0);
+
+    const f_status_t status = f_file_stream_close(F_true, &file);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, -1);
+    assert_int_equal(file.stream, 0);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+
+    file.id = 0;
+    file.stream = 0;
+
+    will_return(__wrap_fsync, false);
+    will_return(__wrap_fsync, 0);
+
+    will_return(__wrap_close, false);
+    will_return(__wrap_close, 0);
 
-    //const f_status_t status = f_file_stream_close();
+    const f_status_t status = f_file_stream_close(F_true, &file);
 
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, -1);
+    assert_int_equal(file.stream, 0);
   }
 }
 
index 52baafe81e3a648b581cd78b98110fb20a77be5b..5eeffc0402d41090ae43e60353a9ae386c1f4fe7 100644 (file)
 #define _TEST__F_file_stream_close_h
 
 /**
- * Test that function fails.
+ * Test that function fails for a file using the file descriptor.
  *
  * @see f_file_stream_close()
  */
-extern void test__f_file_stream_close__fails(void **state);
+extern void test__f_file_stream_close__fails_for_file_descriptor(void **state);
+
+/**
+ * Test that function fails for a file stream.
+ *
+ * @see f_file_stream_close()
+ */
+extern void test__f_file_stream_close__fails_for_stream(void **state);
 
 /**
  * Test that parameter checking works as expected.
diff --git a/level_0/f_file/tests/unit/c/test-file-stream_descriptor.c b/level_0/f_file/tests/unit/c/test-file-stream_descriptor.c
deleted file mode 100644 (file)
index 303e6f4..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#include "test-file.h"
-#include "test-file-stream_descriptor.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void test__f_file_stream_descriptor__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_stream_descriptor(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_stream_descriptor__parameter_checking(void **state) {
-
-    {
-      const f_status_t status = f_file_stream_descriptor(f_string_empty_s, 0);
-
-      assert_int_equal(F_status_set_fine(status), F_parameter);
-    }
-  }
-#endif // _di_level_0_parameter_checking_
-
-void test__f_file_stream_descriptor__returns_data_not(void **state) {
-
-  {
-    f_file_t file = f_file_t_initialize;
-
-    const f_status_t status = f_file_stream_descriptor(f_string_empty_s, &file);
-
-    assert_int_equal(status, F_data_not);
-  }
-}
-
-void test__f_file_stream_descriptor__works(void **state) {
-
-  {
-    //will_return(__wrap_open, false);
-    //will_return(__wrap_open, 5);
-
-    //const f_status_t status = f_file_stream_descriptor();
-
-    //assert_int_equal(status, F_none);
-    //assert_int_equal(id, 5);
-  }
-}
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
diff --git a/level_0/f_file/tests/unit/c/test-file-stream_descriptor.h b/level_0/f_file/tests/unit/c/test-file-stream_descriptor.h
deleted file mode 100644 (file)
index 66b5058..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * FLL - Level 0
- *
- * Project: File
- * API Version: 0.5
- * Licenses: lgpl-2.1-or-later
- *
- * Test the file project.
- */
-#ifndef _TEST__F_file_stream_descriptor_h
-#define _TEST__F_file_stream_descriptor_h
-
-/**
- * Test that function fails.
- *
- * @see f_file_stream_descriptor()
- */
-extern void test__f_file_stream_descriptor__fails(void **state);
-
-/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_stream_descriptor()
- */
-#ifndef _di_level_0_parameter_checking_
-  extern void test__f_file_stream_descriptor__parameter_checking(void **state);
-#endif // _di_level_0_parameter_checking_
-
-/**
- * Test that function works but the path is empty.
- *
- * @see f_file_stream_descriptor()
- */
-extern void test__f_file_stream_descriptor__returns_data_not(void **state);
-
-/**
- * Test that function works.
- *
- * @see f_file_stream_descriptor()
- */
-extern void test__f_file_stream_descriptor__works(void **state);
-
-#endif // _TEST__F_file_stream_descriptor_h
diff --git a/level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.c b/level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.c
new file mode 100644 (file)
index 0000000..7d4d997
--- /dev/null
@@ -0,0 +1,126 @@
+#include "test-file.h"
+#include "test-file-stream_open_descriptor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_file_stream_open_descriptor__fails(void **state) {
+
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+  int errnos[] = {
+    EACCES,
+    EAGAIN,
+    EBADF,
+    EFBIG,
+    EDEADLK,
+    EDESTADDRREQ,
+    EDQUOT,
+    EFAULT,
+    EINTR,
+    EINVAL,
+    EIO,
+    EMFILE,
+    ENOLCK,
+    ENOMEM,
+    ENOSPC,
+    ENOTDIR,
+    EPERM,
+    EPIPE,
+    EWOULDBLOCK,
+    mock_errno_generic,
+  };
+
+  f_status_t statuss[] = {
+    F_access_denied,
+    F_block,
+    F_file_descriptor,
+    F_file_overflow,
+    F_deadlock,
+    F_socket_not,
+    F_space_not,
+    F_buffer,
+    F_interrupt,
+    F_parameter,
+    F_input_output,
+    F_file_descriptor_max,
+    F_lock,
+    F_memory_not,
+    F_space_not,
+    F_file_type_not_directory,
+    F_prohibited,
+    F_pipe_not,
+    F_block,
+    F_failure,
+  };
+
+  for (int i = 0; i < 20; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+
+    will_return(__wrap_fdopen, true);
+    will_return(__wrap_fdopen, errnos[i]);
+
+    const f_status_t status = f_file_stream_open_descriptor(path, &file);
+
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
+  } // for
+
+  for (int i = 0; i < 20; ++i) {
+
+    f_file_t file = f_file_t_initialize;
+
+    will_return(__wrap_fdopen, true);
+    will_return(__wrap_fdopen, errnos[i]);
+
+    const f_status_t status = f_file_stream_open_descriptor(f_string_empty_s, &file);
+
+    assert_int_equal(F_status_set_fine(status), statuss[i]);
+  } // for
+}
+
+#ifndef _di_level_0_parameter_checking_
+  void test__f_file_stream_open_descriptor__parameter_checking(void **state) {
+
+    {
+      const f_status_t status = f_file_stream_open_descriptor(f_string_empty_s, 0);
+
+      assert_int_equal(F_status_set_fine(status), F_parameter);
+    }
+  }
+#endif // _di_level_0_parameter_checking_
+
+void test__f_file_stream_open_descriptor__works(void **state) {
+
+  const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+  const int id = 1;
+
+  {
+    f_file_t file = f_file_t_initialize;
+
+    will_return(__wrap_fdopen, false);
+    will_return(__wrap_fdopen, id);
+
+    const f_status_t status = f_file_stream_open_descriptor(path, &file);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, id);
+  }
+
+  {
+    f_file_t file = f_file_t_initialize;
+
+    will_return(__wrap_fdopen, false);
+    will_return(__wrap_fdopen, id);
+
+    const f_status_t status = f_file_stream_open_descriptor(f_string_empty_s, &file);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(file.id, id);
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.h b/level_0/f_file/tests/unit/c/test-file-stream_open_descriptor.h
new file mode 100644 (file)
index 0000000..a2deb6d
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: File
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the file project.
+ */
+#ifndef _TEST__F_file_stream_open_descriptor_h
+#define _TEST__F_file_stream_open_descriptor_h
+
+/**
+ * Test that function fails.
+ *
+ * @see f_file_stream_open_descriptor()
+ */
+extern void test__f_file_stream_open_descriptor__fails(void **state);
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_file_stream_open_descriptor()
+ */
+#ifndef _di_level_0_parameter_checking_
+  extern void test__f_file_stream_open_descriptor__parameter_checking(void **state);
+#endif // _di_level_0_parameter_checking_
+
+/**
+ * Test that function works.
+ *
+ * @see f_file_stream_open_descriptor()
+ */
+extern void test__f_file_stream_open_descriptor__works(void **state);
+
+#endif // _TEST__F_file_stream_open_descriptor_h
index 1ef2b7ddfd1eea6011d743e70d5bd9cedfc2e015..6ef4f47c7a2897f9addafc149d76c2eeec2cdc37 100644 (file)
@@ -259,12 +259,15 @@ int main(void) {
     cmocka_unit_test(test__f_file_stat_by_id__returns_file_closed),
     cmocka_unit_test(test__f_file_stat_by_id__works),
 
-/*
-
-    // f_file_stream_close
+    cmocka_unit_test(test__f_file_stream_close__fails_for_file_descriptor),
+    cmocka_unit_test(test__f_file_stream_close__fails_for_stream),
+    cmocka_unit_test(test__f_file_stream_close__works),
 
-    // f_file_stream_descriptor
+    // __wrap_fdopen does not appear to be working.
+    //cmocka_unit_test(test__f_file_stream_open_descriptor__fails),
+    //cmocka_unit_test(test__f_file_stream_open_descriptor__works),
 
+/*
     // f_file_stream_open
 
     // f_file_stream_read
@@ -364,7 +367,7 @@ int main(void) {
       cmocka_unit_test(test__f_file_stat_at__parameter_checking),
       cmocka_unit_test(test__f_file_stat_by_id__parameter_checking),
       cmocka_unit_test(test__f_file_stream_close__parameter_checking),
-      cmocka_unit_test(test__f_file_stream_descriptor__parameter_checking),
+      cmocka_unit_test(test__f_file_stream_open_descriptor__parameter_checking),
       cmocka_unit_test(test__f_file_stream_open__parameter_checking),
       cmocka_unit_test(test__f_file_stream_read__parameter_checking),
       cmocka_unit_test(test__f_file_stream_read_block__parameter_checking),
index 1969b64145e3dd32eceb7a627d22bdc7a8ba593c..8741d5dc139b3c21091a29938b44345edd89f5e2 100644 (file)
@@ -82,7 +82,7 @@
 #include "test-file-stat_at.h"
 #include "test-file-stat_by_id.h"
 #include "test-file-stream_close.h"
-#include "test-file-stream_descriptor.h"
+#include "test-file-stream_open_descriptor.h"
 #include "test-file-stream_open.h"
 #include "test-file-stream_read.h"
 #include "test-file-stream_read_block.h"