From: Kevin Day Date: Thu, 21 Apr 2022 03:56:00 +0000 (-0500) Subject: Progress: Continue witing f_file unit tests. X-Git-Tag: 0.5.10~191 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=a20180931b14c256a4637233ef05ccb473d0dc0b;p=fll Progress: Continue witing f_file unit tests. Almost there. Just a few more functions to write tests for left. --- diff --git a/level_0/f_file/data/build/settings-mocks b/level_0/f_file/data/build/settings-mocks index c566667..59a86e7 100644 --- a/level_0/f_file/data/build/settings-mocks +++ b/level_0/f_file/data/build/settings-mocks @@ -67,8 +67,8 @@ 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=feof_unlocked +flags -Wl,--wrap=ferror_unlocked flags -Wl,--wrap=fflush flags -Wl,--wrap=fileno flags -Wl,--wrap=flockfile @@ -79,7 +79,7 @@ flags -Wl,--wrap=fstat flags -Wl,--wrap=fstatat flags -Wl,--wrap=fsync flags -Wl,--wrap=funlockfile -flags -Wl,--wrap=fwrite +flags -Wl,--wrap=fwrite_unlocked flags -Wl,--wrap=lchown flags -Wl,--wrap=link flags -Wl,--wrap=linkat @@ -106,4 +106,5 @@ flags -Wl,--wrap=symlink flags -Wl,--wrap=symlinkat flags -Wl,--wrap=unlink flags -Wl,--wrap=unlinkat +flags -Wl,--wrap=utimensat flags -Wl,--wrap=write diff --git a/level_0/f_file/tests/unit/c/mock-file.c b/level_0/f_file/tests/unit/c/mock-file.c index d976f42..992b19d 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -680,6 +680,19 @@ int __wrap_unlinkat(int dirfd, const char *pathname, int flags) { return mock_type(int); } +int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + ssize_t __wrap_write(int fd, const void *buf, size_t count) { const bool failure = mock_type(bool); diff --git a/level_0/f_file/tests/unit/c/mock-file.h b/level_0/f_file/tests/unit/c/mock-file.h index 6a0bd98..9559784 100644 --- a/level_0/f_file/tests/unit/c/mock-file.h +++ b/level_0/f_file/tests/unit/c/mock-file.h @@ -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 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); #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-stream_open.c b/level_0/f_file/tests/unit/c/test-file-stream_open.c index 67ba5ed..1c72251 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_open.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_open.c @@ -7,22 +7,78 @@ extern "C" { void test__f_file_stream_open__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EDQUOT, + EEXIST, + ENAMETOOLONG, + EFAULT, + EFBIG, + EINTR, + EINVAL, + ELOOP, + ENFILE, + ENOENT, + ENOTDIR, + ENOMEM, + ENOSPC, + EPERM, + EROFS, + ETXTBSY, + EISDIR, + EOPNOTSUPP, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { + F_access_denied, + F_filesystem_quota_block, + F_file_found, + F_name, + F_buffer, + F_number_overflow, + F_interrupt, + F_parameter, + F_loop, + F_file_open_max, + F_file_found_not, + F_file_type_not_directory, + F_memory_not, + F_space_not, + F_prohibited, + F_read_only, + F_busy, + F_directory, + F_supported_not, + F_number_overflow, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 21; ++i) { + + f_file_t file = f_file_t_initialize; + + will_return(__wrap_fopen, true); + will_return(__wrap_fopen, errnos[i]); + + const f_status_t status = f_file_stream_open(path, path, &file); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + for (int i = 0; i < 21; ++i) { + + f_file_t file = f_file_t_initialize; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fopen, true); + will_return(__wrap_fopen, errnos[i]); - //const f_status_t status = f_file_stream_open(path, F_false, &id); + const f_status_t status = f_file_stream_open(path, f_string_empty_s, &file); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -44,38 +100,44 @@ void test__f_file_stream_open__returns_data_not(void **state) { { f_file_t file = f_file_t_initialize; - const f_status_t status = f_file_stream_open(f_string_empty_s, f_string_empty_s, &file); + const f_status_t status = f_file_stream_open(f_string_empty_s, path, &file); assert_int_equal(status, F_data_not); } +} + +void test__f_file_stream_open__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const int id = 1; + FILE *file_pointer = stdout; { f_file_t file = f_file_t_initialize; - const f_status_t status = f_file_stream_open(path, f_string_empty_s, &file); + will_return(__wrap_fopen, false); + will_return(__wrap_fopen, file_pointer); - assert_int_equal(status, F_data_not); + will_return(__wrap_fileno, id); + + const f_status_t status = f_file_stream_open(path, path, &file); + + assert_int_equal(status, F_none); + assert_int_equal(file.stream, file_pointer); } { f_file_t file = f_file_t_initialize; - const f_status_t status = f_file_stream_open(f_string_empty_s, path, &file); + will_return(__wrap_fopen, false); + will_return(__wrap_fopen, file_pointer); - assert_int_equal(status, F_data_not); - } -} - -void test__f_file_stream_open__works(void **state) { + will_return(__wrap_fileno, id); - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); - - //const f_status_t status = f_file_stream_open(); + const f_status_t status = f_file_stream_open(path, f_string_empty_s, &file); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(file.stream, file_pointer); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read.c b/level_0/f_file/tests/unit/c/test-file-stream_read.c index 797d96f..556f9b2 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read.c @@ -7,23 +7,58 @@ extern "C" { void test__f_file_stream_read__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_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) { + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + for (int i = 0; i < 9; ++i) { + + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fread_unlocked, true); + will_return(__wrap_fread_unlocked, errnos[i]); - //const f_status_t status = f_file_stream_read(path, F_false, &id); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_stream_read(file, &buffer); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ @@ -57,28 +92,56 @@ void test__f_file_stream_read__fails(void **state) { void test__f_file_stream_read__returns_file_closed(void **state) { - const f_file_t file = f_file_t_initialize; + const 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_stream_read(file, &string); + const f_status_t status = f_file_stream_read(file, &buffer); assert_int_equal(F_status_set_fine(status), F_file_closed); } + + f_string_dynamic_resize(0, &buffer); } void test__f_file_stream_read__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_fread_unlocked, false); + will_return(__wrap_fread_unlocked, file.size_read); - //const f_status_t status = f_file_stream_read(); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_fread_unlocked, false); + will_return(__wrap_fread_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + const f_status_t status = f_file_stream_read(file, &buffer); + + assert_int_equal(status, F_none_eof); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c index c1e6a98..5a6a05e 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c @@ -7,23 +7,58 @@ extern "C" { void test__f_file_stream_read_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_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) { + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + for (int i = 0; i < 9; ++i) { + + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_read_block(path, F_false, &id); + will_return(__wrap_fread_unlocked, true); + will_return(__wrap_fread_unlocked, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); + + const f_status_t status = f_file_stream_read_block(file, &buffer); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ @@ -70,15 +105,36 @@ void test__f_file_stream_read_block__returns_file_closed(void **state) { void test__f_file_stream_read_block__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_read_block(); + will_return(__wrap_fread_unlocked, false); + will_return(__wrap_fread_unlocked, file.size_read); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + const f_status_t status = f_file_stream_read_block(file, &buffer); + + assert_int_equal(status, F_none); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c index 4a1f318..c316d6d 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c @@ -7,23 +7,58 @@ extern "C" { void test__f_file_stream_read_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_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) { + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + + for (int i = 0; i < 9; ++i) { + + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fread_unlocked, true); + will_return(__wrap_fread_unlocked, errnos[i]); - //const f_status_t status = f_file_stream_read_until(path, F_false, &id); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_stream_read_until(file, 1, &buffer); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for + + f_string_dynamic_resize(0, &buffer); } #ifndef _di_level_0_parameter_checking_ @@ -57,28 +92,52 @@ void test__f_file_stream_read_until__fails(void **state) { void test__f_file_stream_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; + file.size_read = 1; - const f_status_t status = f_file_stream_read_until(file, 0, &string); + { + const f_status_t status = f_file_stream_read_until(file, 0, &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_stream_read_until__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_read_until(); + will_return(__wrap_fread_unlocked, false); + will_return(__wrap_fread_unlocked, file.size_read); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_feof_unlocked, false); + will_return(__wrap_feof_unlocked, 0); + + const f_status_t status = f_file_stream_read_until(file, 1, &buffer); + + assert_int_equal(status, F_none_stop); } + + f_string_dynamic_resize(0, &buffer); } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c index cf55fe7..5cffff6 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c @@ -7,22 +7,74 @@ extern "C" { void test__f_file_stream_reopen__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, + 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_space_not, + F_file_type_not_directory, + F_prohibited, + F_pipe_not, + F_block, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 19; ++i) { + + f_file_t file = f_file_t_initialize; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_freopen, true); + will_return(__wrap_freopen, errnos[i]); - //const f_status_t status = f_file_stream_reopen(path, F_false, &id); + const f_status_t status = f_file_stream_reopen(path, path, &file); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + for (int i = 0; i < 19; ++i) { + + f_file_t file = f_file_t_initialize; + + will_return(__wrap_freopen, true); + will_return(__wrap_freopen, errnos[i]); + + const f_status_t status = f_file_stream_reopen(path, f_string_empty_s, &file); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -48,34 +100,41 @@ void test__f_file_stream_reopen__returns_data_not(void **state) { assert_int_equal(status, F_data_not); } +} + +void test__f_file_stream_reopen__works(void **state) { + + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const int id = 1; + FILE *file_pointer = stdout; { f_file_t file = f_file_t_initialize; + file.stream = file_pointer; - const f_status_t status = f_file_stream_reopen(path, f_string_empty_s, &file); + will_return(__wrap_freopen, false); + will_return(__wrap_freopen, file_pointer); - assert_int_equal(status, F_data_not); + will_return(__wrap_fileno, id); + + const f_status_t status = f_file_stream_reopen(path, path, &file); + + assert_int_equal(status, F_none); + assert_int_equal(file.stream, file_pointer); } { f_file_t file = f_file_t_initialize; - const f_status_t status = f_file_stream_reopen(f_string_empty_s, path, &file); - - assert_int_equal(status, F_data_not); - } -} + will_return(__wrap_freopen, false); + will_return(__wrap_freopen, file_pointer); -void test__f_file_stream_reopen__works(void **state) { + will_return(__wrap_fileno, id); - { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); - - //const f_status_t status = f_file_stream_reopen(); + const f_status_t status = f_file_stream_reopen(path, f_string_empty_s, &file); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(file.stream, file_pointer); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write.c b/level_0/f_file/tests/unit/c/test-file-stream_write.c index c2475bb..355b6aa 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write.c @@ -7,22 +7,47 @@ extern "C" { void test__f_file_stream_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_read = 1; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, true); + will_return(__wrap_fwrite_unlocked, errnos[i]); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); - //const f_status_t status = f_file_stream_write(path, F_false, &id); + const f_status_t status = f_file_stream_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 } @@ -75,14 +100,22 @@ void test__f_file_stream_write__returns_data_not(void **state) { void test__f_file_stream_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.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_write(); + const f_status_t status = f_file_stream_write(file, path, 0); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none_eos); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c index 7f1a142..7b39220 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c @@ -7,22 +7,47 @@ extern "C" { void test__f_file_stream_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_read = 1; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, true); + will_return(__wrap_fwrite_unlocked, errnos[i]); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); - //const f_status_t status = f_file_stream_write_block(path, F_false, &id); + const f_status_t status = f_file_stream_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 } @@ -75,14 +100,38 @@ void test__f_file_stream_write_block__returns_data_not(void **state) { void test__f_file_stream_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.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + const f_status_t status = f_file_stream_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.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_write_block(); + const f_status_t status = f_file_stream_write_block(file, path, 0); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none_eos); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c index 0307e24..2a6da07 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c @@ -7,22 +7,48 @@ extern "C" { void test__f_file_stream_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) { + + f_file_t file = f_file_t_initialize; + file.size_read = 1; + file.stream = stdout; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fwrite_unlocked, true); + will_return(__wrap_fwrite_unlocked, errnos[i]); - //const f_status_t status = f_file_stream_write_range(path, F_false, &id); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); + + const f_status_t status = f_file_stream_write_range(file, path, range, 0); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -122,14 +148,39 @@ void test__f_file_stream_write_range__returns_data_not(void **state) { void test__f_file_stream_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); + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + file.size_write = 1; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); - //const f_status_t status = f_file_stream_write_range(); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + const f_status_t status = f_file_stream_write_range(file, path, range, 0); + + assert_int_equal(status, F_none_stop); + } + + { + f_file_t file = f_file_t_initialize; + file.size_write = path.used; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + const f_status_t status = f_file_stream_write_range(file, path, range, 0); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none_eos); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c index 873ef8e..6112a84 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c @@ -7,22 +7,47 @@ extern "C" { void test__f_file_stream_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_read = 1; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, true); + will_return(__wrap_fwrite_unlocked, errnos[i]); - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 1); - //const f_status_t status = f_file_stream_write_until(path, F_false, &id); + const f_status_t status = f_file_stream_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 } @@ -108,14 +133,56 @@ void test__f_file_stream_write_until__returns_data_not(void **state) { void test__f_file_stream_write_until__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.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); + + const f_status_t status = f_file_stream_write_until(file, path, path.used, 0); + + assert_int_equal(status, F_none_eos); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + f_file_t file = f_file_t_initialize; + file.size_write = path.used; + file.stream = stdout; + + will_return(__wrap_fwrite_unlocked, false); + will_return(__wrap_fwrite_unlocked, file.size_write); + + will_return(__wrap_ferror_unlocked, false); + will_return(__wrap_ferror_unlocked, 0); - //const f_status_t status = f_file_stream_write_until(); + const f_status_t status = f_file_stream_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); } } diff --git a/level_0/f_file/tests/unit/c/test-file-touch.c b/level_0/f_file/tests/unit/c/test-file-touch.c index 673452e..90fbea6 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch.c +++ b/level_0/f_file/tests/unit/c/test-file-touch.c @@ -6,15 +6,18 @@ extern "C" { #endif void test__f_file_touch__fails(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const mode_t mode = 0; { int errnos[] = { EACCES, EFAULT, + EINVAL, ELOOP, ENAMETOOLONG, + ENOENT, ENOMEM, ENOTDIR, EOVERFLOW, @@ -24,74 +27,42 @@ void test__f_file_touch__fails(void **state) { f_status_t statuss[] = { F_access_denied, F_buffer, + F_parameter, F_loop, F_name, + F_file_found_not, F_memory_not, - F_file_not, + F_directory_not, F_number_overflow, F_file_stat, }; - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < 10; ++i) { will_return(__wrap_stat, true); will_return(__wrap_stat, errnos[i]); - const f_status_t status = f_file_touch(path, 0); + if (statuss[i] == F_file_found_not) { + will_return(__wrap_open, false); + will_return(__wrap_open, 0); - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - } + will_return(__wrap_fsync, false); + will_return(__wrap_fsync, 0); - { - int errnos[] = { - EACCES, - EDQUOT, - EEXIST, - EFAULT, - EINVAL, - ELOOP, - EMLINK, - ENAMETOOLONG, - ENOENT, - ENOMEM, - ENOSPC, - ENOTDIR, - EPERM, - EROFS, - mock_errno_generic, - }; + will_return(__wrap_close, false); + will_return(__wrap_close, 0); + } - f_status_t statuss[] = { - F_access_denied, - F_filesystem_quota_block, - F_file_found, - F_buffer, - F_parameter, - F_loop, - F_file_link_max, - F_name, - F_file_found_not, - F_memory_not, - F_space_not, - F_file_not, - F_prohibited, - F_read_only, - F_failure, - }; - - for (int i = 0; i < 15; ++i) { - - will_return(__wrap_stat, true); - will_return(__wrap_stat, ENOENT); - will_return(__wrap_mkdir, true); - will_return(__wrap_mkdir, errnos[i]); - - const f_status_t status = f_file_touch(path, 0); + const f_status_t status = f_file_touch(path, mode, F_true); - assert_int_equal(F_status_set_fine(status), statuss[i]); + if (statuss[i] == F_file_found_not) { + assert_int_equal(status, F_none); + } + else { + assert_int_equal(F_status_set_fine(status), statuss[i]); + } } // for - } // for + } { int errnos[] = { @@ -111,13 +82,13 @@ void test__f_file_touch__fails(void **state) { f_status_t statuss[] = { F_access_denied, - F_file_descriptor, + F_directory_descriptor, F_buffer, F_parameter, F_loop, F_name, F_file_found_not, - F_file_not, + F_directory_not, F_prohibited, F_read_only, F_search, @@ -135,30 +106,32 @@ void test__f_file_touch__fails(void **state) { will_return(__wrap_stat, false); will_return(__wrap_stat, &statistics); will_return(__wrap_stat, 0); + will_return(__wrap_utimensat, true); will_return(__wrap_utimensat, errnos[i]); - const f_status_t status = f_file_touch(path, 0); + const f_status_t status = f_file_touch(path, mode, F_true); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } - */ } void test__f_file_touch__returns_data_not(void **state) { -/* + + const mode_t mode = 0; + { - const f_status_t status = f_file_touch(f_string_empty_s, 0); + const f_status_t status = f_file_touch(f_string_empty_s, mode, F_true); assert_int_equal(status, F_data_not); } - */ } void test__f_file_touch__works(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const mode_t mode = 0; { struct stat statistics; @@ -170,25 +143,14 @@ void test__f_file_touch__works(void **state) { will_return(__wrap_stat, false); will_return(__wrap_stat, &statistics); will_return(__wrap_stat, 0); + will_return(__wrap_utimensat, false); will_return(__wrap_utimensat, 0); - const f_status_t status = f_file_touch(path, 0); - - assert_int_equal(status, F_none); - } - - { - will_return(__wrap_stat, true); - will_return(__wrap_stat, ENOENT); - will_return(__wrap_mkdir, false); - will_return(__wrap_mkdir, 0); - - const f_status_t status = f_file_touch(path, 0); + const f_status_t status = f_file_touch(path, mode, F_true); assert_int_equal(status, F_none); } - */ } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-touch_at.c b/level_0/f_file/tests/unit/c/test-file-touch_at.c index de78a2a..59fbe26 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch_at.c +++ b/level_0/f_file/tests/unit/c/test-file-touch_at.c @@ -6,15 +6,19 @@ extern "C" { #endif void test__f_file_touch_at__fails(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const mode_t mode = 0; { int errnos[] = { EACCES, + EBADF, EFAULT, + EINVAL, ELOOP, ENAMETOOLONG, + ENOENT, ENOMEM, ENOTDIR, EOVERFLOW, @@ -23,75 +27,44 @@ void test__f_file_touch_at__fails(void **state) { f_status_t statuss[] = { F_access_denied, + F_directory_descriptor, F_buffer, + F_parameter, F_loop, F_name, + F_file_found_not, F_memory_not, - F_file_not, + F_directory_not, F_number_overflow, F_file_stat, }; - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < 11; ++i) { will_return(__wrap_fstatat, true); will_return(__wrap_fstatat, errnos[i]); - const f_status_t status = f_file_touch_at(1, path, 0, 0); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - } - - { - int errnos[] = { - EACCES, - EDQUOT, - EEXIST, - EFAULT, - EINVAL, - ELOOP, - EMLINK, - ENAMETOOLONG, - ENOENT, - ENOMEM, - ENOSPC, - ENOTDIR, - EPERM, - EROFS, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_access_denied, - F_filesystem_quota_block, - F_file_found, - F_buffer, - F_parameter, - F_loop, - F_file_link_max, - F_name, - F_file_found_not, - F_memory_not, - F_space_not, - F_file_not, - F_prohibited, - F_read_only, - F_failure, - }; + if (statuss[i] == F_file_found_not) { + will_return(__wrap_openat, false); + will_return(__wrap_openat, 0); - for (int i = 0; i < 15; ++i) { + will_return(__wrap_fsync, false); + will_return(__wrap_fsync, 0); - will_return(__wrap_fstatat, true); - will_return(__wrap_fstatat, ENOENT); - will_return(__wrap_mkdirat, true); - will_return(__wrap_mkdirat, errnos[i]); + will_return(__wrap_close, false); + will_return(__wrap_close, 0); + } - const f_status_t status = f_file_touch_at(1, path, 0, 0); + const f_status_t status = f_file_touch_at(1, path, mode, 0); - assert_int_equal(F_status_set_fine(status), statuss[i]); + if (statuss[i] == F_file_found_not) { + assert_int_equal(status, F_none); + } + else { + assert_int_equal(F_status_set_fine(status), statuss[i]); + } } // for - } // for + } { int errnos[] = { @@ -111,13 +84,13 @@ void test__f_file_touch_at__fails(void **state) { f_status_t statuss[] = { F_access_denied, - F_file_descriptor, + F_directory_descriptor, F_buffer, F_parameter, F_loop, F_name, F_file_found_not, - F_file_not, + F_directory_not, F_prohibited, F_read_only, F_search, @@ -135,30 +108,32 @@ void test__f_file_touch_at__fails(void **state) { will_return(__wrap_fstatat, false); will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); + will_return(__wrap_utimensat, true); will_return(__wrap_utimensat, errnos[i]); - const f_status_t status = f_file_touch_at(1, path, 0, 0); + const f_status_t status = f_file_touch_at(1, path, mode, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } - */ } void test__f_file_touch_at__returns_data_not(void **state) { -/* + + const mode_t mode = 0; + { - const f_status_t status = f_file_touch_at(1, f_string_empty_s, 0, 0); + const f_status_t status = f_file_touch_at(1, f_string_empty_s, mode, 0); assert_int_equal(status, F_data_not); } - */ } void test__f_file_touch_at__works(void **state) { -/* + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + const mode_t mode = 0; { struct stat statistics; @@ -170,25 +145,14 @@ void test__f_file_touch_at__works(void **state) { will_return(__wrap_fstatat, false); will_return(__wrap_fstatat, &statistics); will_return(__wrap_fstatat, 0); + will_return(__wrap_utimensat, false); will_return(__wrap_utimensat, 0); - const f_status_t status = f_file_touch_at(1, path, 0, 0); - - assert_int_equal(status, F_none); - } - - { - will_return(__wrap_fstatat, true); - will_return(__wrap_fstatat, ENOENT); - will_return(__wrap_mkdirat, false); - will_return(__wrap_mkdirat, 0); - - const f_status_t status = f_file_touch_at(1, path, 0, 0); + const f_status_t status = f_file_touch_at(1, path, mode, 0); assert_int_equal(status, F_none); } - */ } #ifdef __cplusplus diff --git a/level_0/f_file/tests/unit/c/test-file-type.c b/level_0/f_file/tests/unit/c/test-file-type.c index 19dd554..cb57a60 100644 --- a/level_0/f_file/tests/unit/c/test-file-type.c +++ b/level_0/f_file/tests/unit/c/test-file-type.c @@ -7,22 +7,44 @@ extern "C" { void test__f_file_type__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EFAULT, + EINVAL, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_buffer, + F_parameter, + 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 < 10; ++i) { + + mode_t mode = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_lstat, true); + will_return(__wrap_lstat, errnos[i]); - //const f_status_t status = f_file_type(path, F_false, &id); + const f_status_t status = f_file_type(path, F_false, &mode); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -30,7 +52,7 @@ void test__f_file_type__fails(void **state) { void test__f_file_type__parameter_checking(void **state) { { - const f_status_t status = f_file_type(f_string_empty_s, 0); + const f_status_t status = f_file_type(f_string_empty_s, F_true, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -42,7 +64,7 @@ void test__f_file_type__returns_data_not(void **state) { { int type = 0; - const f_status_t status = f_file_type(f_string_empty_s, &type); + const f_status_t status = f_file_type(f_string_empty_s, F_true, &type); assert_int_equal(status, F_data_not); } @@ -50,14 +72,40 @@ void test__f_file_type__returns_data_not(void **state) { void test__f_file_type__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)); + + { + int type = 0; + + statistics.st_mode = 1 | F_file_type_link_d; + + will_return(__wrap_lstat, false); + will_return(__wrap_lstat, &statistics); + will_return(__wrap_lstat, 0); + + const f_status_t status = f_file_type(path, F_false, &type); + + assert_int_equal(status, F_none); + assert_int_equal(type, F_file_type_link_d); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + int type = 0; + + statistics.st_mode = 1 | F_file_type_regular_d; + + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - //const f_status_t status = f_file_type(); + const f_status_t status = f_file_type(path, F_true, &type); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(type, F_file_type_regular_d); } } diff --git a/level_0/f_file/tests/unit/c/test-file-type_at.c b/level_0/f_file/tests/unit/c/test-file-type_at.c index bf9d700..d4eab00 100644 --- a/level_0/f_file/tests/unit/c/test-file-type_at.c +++ b/level_0/f_file/tests/unit/c/test-file-type_at.c @@ -7,22 +7,44 @@ extern "C" { void test__f_file_type_at__fails(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + int errnos[] = { + EACCES, + EBADF, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_directory_descriptor, + 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 < 10; ++i) { + + mode_t mode = 0; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fstatat, true); + will_return(__wrap_fstatat, errnos[i]); - //const f_status_t status = f_file_type_at(path, F_false, &id); + const f_status_t status = f_file_type_at(0, path, 0, &mode); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -50,14 +72,44 @@ void test__f_file_type_at__returns_data_not(void **state) { void test__f_file_type_at__works(void **state) { + const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); + + { + int type = 0; + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_link_d; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); + + const f_status_t status = f_file_type_at(0, path, 0, &type); + + assert_int_equal(status, F_none); + assert_int_equal(type, F_file_type_link_d); + } + { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + int type = 0; + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_mode = 1 | F_file_type_regular_d; + + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); - //const f_status_t status = f_file_type_at(); + const f_status_t status = f_file_type_at(0, path, 0, &type); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(type, F_file_type_regular_d); } } diff --git a/level_0/f_file/tests/unit/c/test-file.c b/level_0/f_file/tests/unit/c/test-file.c index 6ef4f47..7740470 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -267,24 +267,45 @@ int main(void) { //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 - - // f_file_stream_read_block - - // f_file_stream_read_until - - // f_file_stream_reopen - - // f_file_stream_write - - // f_file_stream_write_block - - // f_file_stream_write_until - - // f_file_stream_write_range + cmocka_unit_test(test__f_file_stream_open__fails), + cmocka_unit_test(test__f_file_stream_open__returns_data_not), + cmocka_unit_test(test__f_file_stream_open__works), + + cmocka_unit_test(test__f_file_stream_read__fails), + cmocka_unit_test(test__f_file_stream_read__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read__works), + + cmocka_unit_test(test__f_file_stream_read_block__fails), + cmocka_unit_test(test__f_file_stream_read_block__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read_block__works), + + cmocka_unit_test(test__f_file_stream_read_until__fails), + cmocka_unit_test(test__f_file_stream_read_until__returns_file_closed), + cmocka_unit_test(test__f_file_stream_read_until__works), + + cmocka_unit_test(test__f_file_stream_reopen__fails), + cmocka_unit_test(test__f_file_stream_reopen__returns_data_not), + cmocka_unit_test(test__f_file_stream_reopen__works), + + cmocka_unit_test(test__f_file_stream_write__fails), + cmocka_unit_test(test__f_file_stream_write__returns_file_closed), + cmocka_unit_test(test__f_file_stream_write__returns_data_not), + cmocka_unit_test(test__f_file_stream_write__works), + + cmocka_unit_test(test__f_file_stream_write_block__fails), + cmocka_unit_test(test__f_file_stream_write_block__returns_file_closed), + cmocka_unit_test(test__f_file_stream_write_block__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_block__works), + + cmocka_unit_test(test__f_file_stream_write_range__fails), + cmocka_unit_test(test__f_file_stream_write_range__returns_file_closed), + cmocka_unit_test(test__f_file_stream_write_range__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_range__works), + + cmocka_unit_test(test__f_file_stream_write_until__fails), + cmocka_unit_test(test__f_file_stream_write_until__returns_file_closed), + cmocka_unit_test(test__f_file_stream_write_until__returns_data_not), + cmocka_unit_test(test__f_file_stream_write_until__works), cmocka_unit_test(test__f_file_touch__fails), cmocka_unit_test(test__f_file_touch__returns_data_not), @@ -294,10 +315,15 @@ int main(void) { cmocka_unit_test(test__f_file_touch_at__returns_data_not), cmocka_unit_test(test__f_file_touch_at__works), - // f_file_type + cmocka_unit_test(test__f_file_type__fails), + cmocka_unit_test(test__f_file_type__returns_data_not), + cmocka_unit_test(test__f_file_type__works), - // f_file_type_at + cmocka_unit_test(test__f_file_type_at__fails), + cmocka_unit_test(test__f_file_type_at__returns_data_not), + cmocka_unit_test(test__f_file_type_at__works), +/* // f_file_umask_get // f_file_umask_set