flags -Wl,--wrap=lchown
flags -Wl,--wrap=link
flags -Wl,--wrap=linkat
+flags -Wl,--wrap=lseek
flags -Wl,--wrap=lstat
flags -Wl,--wrap=makedev
flags -Wl,--wrap=mkdir
flags -Wl,--wrap=read
flags -Wl,--wrap=readlink
flags -Wl,--wrap=readlinkat
+flags -Wl,--wrap=rename
+flags -Wl,--wrap=renameat
+flags -Wl,--wrap=renameat2
flags -Wl,--wrap=remove
flags -Wl,--wrap=stat
flags -Wl,--wrap=symlink
return mock_type(int);
}
+off_t __wrap_lseek(int fd, off_t offset, int whence) {
+
+ const bool failure = mock_type(bool);
+
+ if (failure) {
+ errno = mock_type(int);
+
+ return -1;
+ }
+
+ return mock_type(int);
+}
+
int __wrap_lstat(const char *pathname, struct stat *statbuf) {
const bool failure = mock_type(bool);
return mock_type(int);
}
-int __wrap_remove(const char *pathname) {
+int __wrap_rename(const char *oldpath, const char *newpath) {
+
+ const bool failure = mock_type(bool);
+
+ if (failure) {
+ errno = mock_type(int);
+
+ return -1;
+ }
+
+ return mock_type(int);
+}
+
+int __wrap_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) {
+
+ const bool failure = mock_type(bool);
+
+ if (failure) {
+ errno = mock_type(int);
+
+ return -1;
+ }
+
+ return mock_type(int);
+}
+
+int __wrap_renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) {
const bool failure = mock_type(bool);
extern int __wrap_lchown(const char *pathname, uid_t owner, gid_t group);
extern int __wrap_link(const char *oldpath, const char *newpath);
extern int __wrap_linkat(const char *oldpath, const char *newpath);
+extern off_t __wrap_lseek(int fd, off_t offset, int whence);
extern int __wrap_lstat(const char *pathname, struct stat *statbuf);
extern int __wrap_mkdir(const char *pathname, mode_t mode);
extern int __wrap_mkdirat(int dirfd, const char *pathname, mode_t mode);
extern ssize_t __wrap_read(int fd, void *buf, size_t count);
extern ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz);
extern ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
-extern int __wrap_remove(const char *pathname);
+extern int __wrap_rename(const char *oldpath, const char *newpath);
+extern int __wrap_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
+extern int __wrap_renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags);
extern int __wrap_stat(const char *pathname, struct stat *statbuf);
extern int __wrap_symlink(const char *target, const char *linkpath);
extern int __wrap_symlinkat(const char *target, int newdirfd, const char *linkpath);
int errnos[] = {
EACCES,
EFAULT,
+ EINVAL,
ELOOP,
ENAMETOOLONG,
ENOENT,
f_status_t statuss[] = {
F_access_denied,
F_buffer,
+ F_parameter,
F_loop,
F_name,
F_false,
F_file_stat,
};
- for (int i = 0; i < 9; ++i) {
+ for (int i = 0; i < 10; ++i) {
will_return(__wrap_lstat, true);
will_return(__wrap_lstat, errnos[i]);
int errnos[] = {
EACCES,
EFAULT,
+ EINVAL,
ELOOP,
ENAMETOOLONG,
ENOENT,
f_status_t statuss[] = {
F_access_denied,
F_buffer,
+ F_parameter,
F_loop,
F_name,
F_file_found_not,
for (int j = 0; j < 8; ++j) {
- for (int i = 0; i < 9; ++i) {
+ for (int i = 0; i < 10; ++i) {
will_return(__wrap_lstat, true);
will_return(__wrap_lstat, errnos[i]);
int errnos[] = {
EACCES,
EFAULT,
+ EINVAL,
ELOOP,
ENAMETOOLONG,
ENOENT,
f_status_t statuss[] = {
F_access_denied,
F_buffer,
+ F_parameter,
F_loop,
F_name,
F_file_found_not,
F_file_stat,
};
- for (int i = 0; i < 9; ++i) {
+ for (int i = 0; i < 10; ++i) {
mode_t mode = 0;
#endif
void test__f_file_remove__fails(void **state) {
-/*
+
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
int errnos[] = {
EACCES,
EBUSY,
EFAULT,
- EINVAL,
EIO,
EISDIR,
ELOOP,
- EMFILE,
ENAMETOOLONG,
- ENFILE,
ENOENT,
ENOMEM,
ENOTDIR,
- ENOTEMPTY,
EPERM,
EROFS,
mock_errno_generic,
F_access_denied,
F_busy,
F_buffer,
- F_parameter,
F_input_output,
F_file_type_directory,
F_loop,
- F_file_descriptor_max,
F_name,
- F_file_open_max,
F_file_found_not,
F_memory_not,
- F_file_not,
- F_file_empty_not,
+ F_directory_not,
F_prohibited,
F_read_only,
F_failure,
};
{
- for (int i = 0; i < 17; ++i) {
+ for (int i = 0; i < 13; ++i) {
- will_return(__wrap_remove, true);
- will_return(__wrap_remove, errnos[i]);
+ will_return(__wrap_unlink, true);
+ will_return(__wrap_unlink, errnos[i]);
const f_status_t status = f_file_remove(path);
assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
- */
}
void test__f_file_remove__returns_data_not(void **state) {
}
void test__f_file_remove__works(void **state) {
-/*
+
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- will_return(__wrap_remove, false);
- will_return(__wrap_remove, 0);
+ will_return(__wrap_unlink, false);
+ will_return(__wrap_unlink, 0);
const f_status_t status = f_file_remove(path);
assert_int_equal(status, F_none);
}
- */
}
#ifdef __cplusplus
void test__f_file_remove_at__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EBUSY,
+ EFAULT,
+ EIO,
+ EISDIR,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EPERM,
+ EROFS,
mock_errno_generic,
};
f_status_t statuss[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_busy,
+ F_buffer,
+ F_input_output,
+ F_file_type_directory,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_prohibited,
+ F_read_only,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ {
+ for (int i = 0; i < 14; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_unlinkat, true);
+ will_return(__wrap_unlinkat, errnos[i]);
- //const f_status_t status = f_file_remove_at(path, F_false, &id);
+ const f_status_t status = f_file_remove_at(0, path, 0);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
+ } // for
+ }
}
void test__f_file_remove_at__returns_data_not(void **state) {
void test__f_file_remove_at__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_unlinkat, false);
+ will_return(__wrap_unlinkat, 0);
- //const f_status_t status = f_file_remove_at();
+ const f_status_t status = f_file_remove_at(0, path, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
void test__f_file_rename__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBUSY,
+ EDQUOT,
+ EFAULT,
+ EINVAL,
+ EISDIR,
+ ELOOP,
+ EMLINK,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOSPC,
+ ENOTDIR,
+ ENOTEMPTY,
+ EEXIST,
+ EPERM,
+ EROFS,
+ EXDEV,
mock_errno_generic,
};
f_status_t statuss[] = {
+ F_access_denied,
+ F_busy,
+ F_filesystem_quota_block,
+ F_buffer,
+ F_parameter,
+ F_file_type_directory,
+ F_loop,
+ F_link,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_space_not,
+ F_directory_not,
+ F_directory_empty_not,
+ F_directory_empty_not,
+ F_prohibited,
+ F_read_only,
+ F_mount,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ {
+ for (int i = 0; i < 19; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_rename, true);
+ will_return(__wrap_rename, errnos[i]);
- //const f_status_t status = f_file_rename(path, F_false, &id);
+ const f_status_t status = f_file_rename(path, path);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
+ } // for
+ }
}
void test__f_file_rename__returns_data_not(void **state) {
void test__f_file_rename__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_rename, false);
+ will_return(__wrap_rename, 0);
- //const f_status_t status = f_file_rename();
+ const f_status_t status = f_file_rename(path, path);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
void test__f_file_rename_at__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EBUSY,
+ EDQUOT,
+ EFAULT,
+ EINVAL,
+ EISDIR,
+ ELOOP,
+ EMLINK,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOSPC,
+ ENOTDIR,
+ ENOTEMPTY,
+ EEXIST,
+ EPERM,
+ EROFS,
+ EXDEV,
mock_errno_generic,
};
f_status_t statuss[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_busy,
+ F_filesystem_quota_block,
+ F_buffer,
+ F_parameter,
+ F_file_type_directory,
+ F_loop,
+ F_link,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_space_not,
+ F_directory_not,
+ F_directory_empty_not,
+ F_directory_empty_not,
+ F_prohibited,
+ F_read_only,
+ F_mount,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ {
+ for (int i = 0; i < 20; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ #ifdef _f_file_rename_use_renameat2_
+ will_return(__wrap_renameat2, true);
+ will_return(__wrap_renameat2, errnos[i]);
+ #else
+ will_return(__wrap_renameat, true);
+ will_return(__wrap_renameat, errnos[i]);
+ #endif // _f_file_rename_use_renameat2_
- //const f_status_t status = f_file_rename_at(path, F_false, &id);
+ const f_status_t status = f_file_rename_at(0, 0, path, path, 0);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
+ } // for
+ }
}
void test__f_file_rename_at__returns_data_not(void **state) {
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, f_string_empty_s);
+ const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, f_string_empty_s, 0);
assert_int_equal(status, F_data_not);
}
{
- const f_status_t status = f_file_rename_at(0, 0, path, f_string_empty_s);
+ const f_status_t status = f_file_rename_at(0, 0, path, f_string_empty_s, 0);
assert_int_equal(status, F_data_not);
}
{
- const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, path);
+ const f_status_t status = f_file_rename_at(0, 0, f_string_empty_s, path, 0);
assert_int_equal(status, F_data_not);
}
void test__f_file_rename_at__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ #ifdef _f_file_rename_use_renameat2_
+ will_return(__wrap_renameat2, false);
+ will_return(__wrap_renameat2, 0);
+ #else
+ will_return(__wrap_renameat, false);
+ will_return(__wrap_renameat, 0);
+ #endif // _f_file_rename_use_renameat2_
- //const f_status_t status = f_file_rename_at();
+ const f_status_t status = f_file_rename_at(0, 0, path, path, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
extern "C" {
#endif
-void test__f_file_role_change__fails(void **state) {
+void test__f_file_role_change__fails_for_dereference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
int errnos[] = {
+ EACCES,
+ EFAULT,
+ EIO,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EPERM,
+ EROFS,
mock_errno_generic,
};
- f_status_t statuss[] = {
+ f_status_t status_owners[] = {
+ F_access_denied,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_owner,
+ F_read_only,
+ F_failure,
+ };
+
+ f_status_t status_groups[] = {
+ F_access_denied,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_group,
+ F_read_only,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_chown, true);
+ will_return(__wrap_chown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_true);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_chown, false);
+ will_return(__wrap_chown, 0);
+
+ will_return(__wrap_chown, true);
+ will_return(__wrap_chown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_true);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_chown, true);
+ will_return(__wrap_chown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, -1, 0, F_true);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_chown, true);
+ will_return(__wrap_chown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, 0, -1, F_true);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+}
+
+void test__f_file_role_change__fails_for_reference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ int errnos[] = {
+ EACCES,
+ EFAULT,
+ EIO,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EPERM,
+ EROFS,
+ mock_errno_generic,
+ };
+
+ f_status_t status_owners[] = {
+ F_access_denied,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_owner,
+ F_read_only,
+ F_failure,
+ };
+
+ f_status_t status_groups[] = {
+ F_access_denied,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_group,
+ F_read_only,
+ F_failure,
+ };
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_lchown, true);
+ will_return(__wrap_lchown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_false);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_lchown, false);
+ will_return(__wrap_lchown, 0);
+
+ will_return(__wrap_lchown, true);
+ will_return(__wrap_lchown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_false);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 11; ++i) {
+
+ will_return(__wrap_lchown, true);
+ will_return(__wrap_lchown, errnos[i]);
+
+ const f_status_t status = f_file_role_change(path, -1, 0, F_false);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ for (int i = 0; i < 11; ++i) {
- //const f_status_t status = f_file_role_change(path, F_false, &id);
+ will_return(__wrap_lchown, true);
+ will_return(__wrap_lchown, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_role_change(path, 0, -1, F_false);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
} // for
}
void test__f_file_role_change__returns_data_not(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ const f_status_t status = f_file_role_change(f_string_empty_s, -1, -1, F_true);
+
+ assert_int_equal(status, F_data_not);
+ }
+
{
- //const f_status_t status = f_file_role_change(f_string_empty_s);
+ const f_status_t status = f_file_role_change(path, -1, -1, F_true);
- //assert_int_equal(status, F_data_not);
+ assert_int_equal(status, F_data_not);
+ }
+
+ {
+ const f_status_t status = f_file_role_change(f_string_empty_s, 0, 0, F_true);
+
+ assert_int_equal(status, F_data_not);
}
}
-void test__f_file_role_change__works(void **state) {
+void test__f_file_role_change__works_for_dereference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ will_return(__wrap_chown, false);
+ will_return(__wrap_chown, 0);
+
+ will_return(__wrap_chown, false);
+ will_return(__wrap_chown, 0);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_true);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_chown, false);
+ will_return(__wrap_chown, 0);
+
+ const f_status_t status = f_file_role_change(path, -1, 0, F_true);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_chown, false);
+ will_return(__wrap_chown, 0);
+
+ const f_status_t status = f_file_role_change(path, 0, -1, F_true);
+
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_file_role_change__works_for_reference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ will_return(__wrap_lchown, false);
+ will_return(__wrap_lchown, 0);
+
+ will_return(__wrap_lchown, false);
+ will_return(__wrap_lchown, 0);
+
+ const f_status_t status = f_file_role_change(path, 0, 0, F_false);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_lchown, false);
+ will_return(__wrap_lchown, 0);
+
+ const f_status_t status = f_file_role_change(path, -1, 0, F_false);
+
+ assert_int_equal(status, F_none);
+ }
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_lchown, false);
+ will_return(__wrap_lchown, 0);
- //const f_status_t status = f_file_role_change();
+ const f_status_t status = f_file_role_change(path, 0, -1, F_false);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
#define _TEST__F_file_role_change_h
/**
- * Test that function fails.
+ * Test that function fails for dereferenced files.
*
* @see f_file_role_change()
*/
-extern void test__f_file_role_change__fails(void **state);
+extern void test__f_file_role_change__fails_for_dereference(void **state);
+
+/**
+ * Test that function fails for referenced files.
+ *
+ * @see f_file_role_change()
+ */
+extern void test__f_file_role_change__fails_for_reference(void **state);
/**
* Test that function works but the path is empty.
extern void test__f_file_role_change__returns_data_not(void **state);
/**
- * Test that function works.
+ * Test that function works for dereferenced files.
+ *
+ * @see f_file_role_change()
+ */
+extern void test__f_file_role_change__works_for_dereference(void **state);
+
+/**
+ * Test that function works for referenced files.
*
* @see f_file_role_change()
*/
-extern void test__f_file_role_change__works(void **state);
+extern void test__f_file_role_change__works_for_reference(void **state);
#endif // _TEST__F_file_role_change_h
extern "C" {
#endif
-void test__f_file_role_change_at__fails(void **state) {
+void test__f_file_role_change_at__fails_for_dereference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EIO,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EPERM,
+ EROFS,
mock_errno_generic,
};
- f_status_t statuss[] = {
+ f_status_t status_owners[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_owner,
+ F_read_only,
+ F_failure,
+ };
+
+ f_status_t status_groups[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_group,
+ F_read_only,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, -1, 0, 0);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, -1, 0);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+}
+
+void test__f_file_role_change_at__fails_for_reference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EIO,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EPERM,
+ EROFS,
+ mock_errno_generic,
+ };
+
+ f_status_t status_owners[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_owner,
+ F_read_only,
+ F_failure,
+ };
+
+ f_status_t status_groups[] = {
+ F_access_denied,
+ F_directory_descriptor,
+ F_buffer,
+ F_input_output,
+ F_loop,
+ F_name,
+ F_file_found_not,
+ F_memory_not,
+ F_directory_not,
+ F_access_group,
+ F_read_only,
+ F_failure,
+ };
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
+ } // for
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
+
+ for (int i = 0; i < 12; ++i) {
+
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
+
+ const f_status_t status = f_file_role_change_at(0, path, -1, 0, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(F_status_set_fine(status), status_groups[i]);
+ } // for
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ for (int i = 0; i < 12; ++i) {
- //const f_status_t status = f_file_role_change_at(path, F_false, &id);
+ will_return(__wrap_fchownat, true);
+ will_return(__wrap_fchownat, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(F_status_set_fine(status), status_owners[i]);
} // for
}
void test__f_file_role_change_at__returns_data_not(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ const f_status_t status = f_file_role_change_at(0, f_string_empty_s, -1, -1, 0);
+
+ assert_int_equal(status, F_data_not);
+ }
+
{
- //const f_status_t status = f_file_role_change_at(f_string_empty_s);
+ const f_status_t status = f_file_role_change_at(0, path, -1, -1, 0);
- //assert_int_equal(status, F_data_not);
+ assert_int_equal(status, F_data_not);
+ }
+
+ {
+ const f_status_t status = f_file_role_change_at(0, f_string_empty_s, 0, 0, 0);
+
+ assert_int_equal(status, F_data_not);
}
}
-void test__f_file_role_change_at__works(void **state) {
+void test__f_file_role_change_at__works_for_dereference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, 0);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ const f_status_t status = f_file_role_change_at(0, path, -1, 0, 0);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, -1, 0);
+
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_file_role_change_at__works_for_reference(void **state) {
+
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ const f_status_t status = f_file_role_change_at(0, path, 0, 0, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(status, F_none);
+ }
+
+ {
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
+
+ const f_status_t status = f_file_role_change_at(0, path, -1, 0, F_file_at_symlink_follow_no_d);
+
+ assert_int_equal(status, F_none);
+ }
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_fchownat, false);
+ will_return(__wrap_fchownat, 0);
- //const f_status_t status = f_file_role_change_at();
+ const f_status_t status = f_file_role_change_at(0, path, 0, -1, F_file_at_symlink_follow_no_d);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
#define _TEST__F_file_role_change_at_h
/**
- * Test that function fails.
+ * Test that function fails for dereferenced files.
*
* @see f_file_role_change_at()
*/
-extern void test__f_file_role_change_at__fails(void **state);
+extern void test__f_file_role_change_at__fails_for_dereference(void **state);
+
+/**
+ * Test that function fails for referenced files.
+ *
+ * @see f_file_role_change_at()
+ */
+extern void test__f_file_role_change_at__fails_for_reference(void **state);
/**
* Test that function works but the path is empty.
extern void test__f_file_role_change_at__returns_data_not(void **state);
/**
- * Test that function works.
+ * Test that function works for dereferenced files.
+ *
+ * @see f_file_role_change_at()
+ */
+extern void test__f_file_role_change_at__works_for_dereference(void **state);
+
+/**
+ * Test that function works for referenced files.
*
* @see f_file_role_change_at()
*/
-extern void test__f_file_role_change_at__works(void **state);
+extern void test__f_file_role_change_at__works_for_reference(void **state);
#endif // _TEST__F_file_role_change_at_h
void test__f_file_seek__fails(void **state) {
int errnos[] = {
+ EBADF,
+ EINVAL,
+ ENXIO,
+ EOVERFLOW,
+ ESPIPE,
mock_errno_generic,
};
f_status_t statuss[] = {
+ F_file_descriptor,
+ F_parameter,
+ F_bound_not,
+ F_number_overflow,
+ F_file_type_pipe,
F_failure,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 6; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ off_t seeked = 0;
- //const f_status_t status = f_file_seek(path, F_false, &id);
+ will_return(__wrap_lseek, true);
+ will_return(__wrap_lseek, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_seek(0, 0, 0, &seeked);
+
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
#ifndef _di_level_0_parameter_checking_
void test__f_file_seek__parameter_checking(void **state) {
+ off_t seeked = 0;
+
+ {
+ const f_status_t status = f_file_seek(0, -1, 0, 0);
+
+ assert_int_equal(F_status_set_fine(status), F_parameter);
+ }
+
+ {
+ const f_status_t status = f_file_seek(0, -1, 0, &seeked);
+
+ assert_int_equal(F_status_set_fine(status), F_parameter);
+ }
+
{
const f_status_t status = f_file_seek(0, 0, 0, 0);
void test__f_file_seek__works(void **state) {
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ off_t seeked = 0;
+
+ will_return(__wrap_lseek, false);
+ will_return(__wrap_lseek, 0);
- //const f_status_t status = f_file_seek();
+ const f_status_t status = f_file_seek(0, 0, 0, &seeked);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
void test__f_file_size__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) {
+
+ off_t size = 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_size(path, F_false, &id);
+ const f_status_t status = f_file_size(path, F_false, &size);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_size__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));
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ off_t size = 0;
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
- //const f_status_t status = f_file_size();
+ const f_status_t status = f_file_size(path, F_true, &size);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(size, statistics.st_size);
}
}
void test__f_file_size_at__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EINVAL,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EOVERFLOW,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_access_denied,
+ F_directory_descriptor,
+ 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 < 11; ++i) {
+
+ off_t size = 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_size_at(path, F_false, &id);
+ const f_status_t status = f_file_size_at(0, path, F_false, &size);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_size_at__returns_data_not(void **state) {
{
- const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, 0);
+ off_t size = 0;
+
+ const f_status_t status = f_file_size_at(0, f_string_empty_s, F_false, &size);
assert_int_equal(status, F_data_not);
}
void test__f_file_size_at__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof(struct stat));
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ off_t size = 0;
+
+ statistics.st_mode = 1 | F_file_type_link_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
+
+ const f_status_t status = f_file_size_at(0, path, F_false, &size);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(size, statistics.st_size);
+ }
+
+ {
+ off_t size = 0;
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
- //const f_status_t status = f_file_size_at();
+ const f_status_t status = f_file_size_at(0, path, F_true, &size);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(size, statistics.st_size);
}
}
void test__f_file_size_by_id__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EINVAL,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EOVERFLOW,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_access_denied,
+ F_file_descriptor,
+ 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 < 11; ++i) {
+
+ off_t size = 0;
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ printf("\nDEBUG: i=%d\n", i);
- //const f_status_t status = f_file_size_by_id(path, F_false, &id);
+ will_return(__wrap_fstat, true);
+ will_return(__wrap_fstat, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_size_by_id(0, &size);
+
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
}
#endif // _di_level_0_parameter_checking_
+void test__f_file_size_by_id__returns_file_closed(void **state) {
+
+ {
+ off_t size = 0;
+
+ const f_status_t status = f_file_size_by_id(-1, &size);
+
+ assert_int_equal(F_status_set_fine(status), F_file_closed);
+ } // for
+}
+
void test__f_file_size_by_id__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));
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ off_t size = 0;
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstat, false);
+ will_return(__wrap_fstat, &statistics);
+ will_return(__wrap_fstat, 0);
- //const f_status_t status = f_file_size_by_id();
+ const f_status_t status = f_file_size_by_id(0, &size);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(size, statistics.st_size);
}
}
#endif // _di_level_0_parameter_checking_
/**
+ * Test that function works but the file is closed.
+ *
+ * @see f_file_size_by_id()
+ */
+extern void test__f_file_size_by_id__returns_file_closed(void **state);
+
+/**
* Test that function works.
*
* @see f_file_size_by_id()
#include "test-file.h"
-#include "test-file-stat.h"
+#include "test-file-size.h"
#ifdef __cplusplus
extern "C" {
void test__f_file_stat__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) {
+
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
- //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_stat(path, F_false, &id);
+ const f_status_t status = f_file_stat(path, F_false, &result);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_stat__returns_data_not(void **state) {
{
- struct stat statistics;
+ struct stat result;
- const f_status_t status = f_file_stat(f_string_empty_s, F_false, &statistics);
+ memset(&result, 0, sizeof(struct stat));
+
+ const f_status_t status = f_file_stat(f_string_empty_s, F_false, &result);
assert_int_equal(status, F_data_not);
}
void test__f_file_stat__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));
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
- //const f_status_t status = f_file_stat();
+ const f_status_t status = f_file_stat(path, F_true, &result);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(result.st_mode, statistics.st_mode);
+ assert_int_equal(result.st_size, statistics.st_size);
}
}
#include "test-file.h"
-#include "test-file-stat_at.h"
+#include "test-file-size_at.h"
#ifdef __cplusplus
extern "C" {
void test__f_file_stat_at__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EINVAL,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EOVERFLOW,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_access_denied,
+ F_directory_descriptor,
+ 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 < 11; ++i) {
+
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
- //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_stat_at(path, F_false, &id);
+ const f_status_t status = f_file_stat_at(0, path, F_false, &result);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_stat_at__parameter_checking(void **state) {
{
- const f_status_t status = f_file_stat_at(0, f_string_empty_s, 0, 0);
+ const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
void test__f_file_stat_at__returns_data_not(void **state) {
{
- struct stat statistics;
+ struct stat result;
- const f_status_t status = f_file_stat_at(0, f_string_empty_s, 0, &statistics);
+ memset(&result, 0, sizeof(struct stat));
+
+ const f_status_t status = f_file_stat_at(0, f_string_empty_s, F_false, &result);
assert_int_equal(status, F_data_not);
}
void test__f_file_stat_at__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof(struct stat));
+
+ {
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
+
+ statistics.st_mode = 1 | F_file_type_link_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
+
+ const f_status_t status = f_file_stat_at(0, path, F_false, &result);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(result.st_mode, statistics.st_mode);
+ assert_int_equal(result.st_size, statistics.st_size);
+ }
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
- //const f_status_t status = f_file_stat_at();
+ const f_status_t status = f_file_stat_at(0, path, F_true, &result);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(result.st_mode, statistics.st_mode);
+ assert_int_equal(result.st_size, statistics.st_size);
}
}
#include "test-file.h"
-#include "test-file-stat_by_id.h"
+#include "test-file-size_by_id.h"
#ifdef __cplusplus
extern "C" {
void test__f_file_stat_by_id__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EBADF,
+ EFAULT,
+ EINVAL,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EOVERFLOW,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_access_denied,
+ F_file_descriptor,
+ 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 < 11; ++i) {
+
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ printf("\nDEBUG: i=%d\n", i);
- //const f_status_t status = f_file_stat_by_id(path, F_false, &id);
+ will_return(__wrap_fstat, true);
+ will_return(__wrap_fstat, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_stat_by_id(0, &result);
+
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
}
#endif // _di_level_0_parameter_checking_
+void test__f_file_stat_by_id__returns_file_closed(void **state) {
+
+ {
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
+
+ const f_status_t status = f_file_stat_by_id(-1, &result);
+
+ assert_int_equal(F_status_set_fine(status), F_file_closed);
+ } // for
+}
+
void test__f_file_stat_by_id__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));
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ struct stat result;
+
+ memset(&result, 0, sizeof(struct stat));
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
+
+ will_return(__wrap_fstat, false);
+ will_return(__wrap_fstat, &statistics);
+ will_return(__wrap_fstat, 0);
- //const f_status_t status = f_file_stat_by_id();
+ const f_status_t status = f_file_stat_by_id(0, &result);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(result.st_mode, statistics.st_mode);
+ assert_int_equal(result.st_size, statistics.st_size);
}
}
#endif // _di_level_0_parameter_checking_
/**
+ * Test that function works but the file is closed.
+ *
+ * @see f_file_stat_by_id()
+ */
+extern void test__f_file_stat_by_id__returns_file_closed(void **state);
+
+/**
* Test that function works.
*
* @see f_file_stat_by_id()
cmocka_unit_test(test__f_file_read_until__returns_file_closed),
cmocka_unit_test(test__f_file_read_until__works),
-/*
cmocka_unit_test(test__f_file_remove__fails),
cmocka_unit_test(test__f_file_remove__returns_data_not),
cmocka_unit_test(test__f_file_remove__works),
cmocka_unit_test(test__f_file_remove_at__returns_data_not),
cmocka_unit_test(test__f_file_remove_at__works),
- // f_file_rename
+ cmocka_unit_test(test__f_file_rename__fails),
+ cmocka_unit_test(test__f_file_rename__returns_data_not),
+ cmocka_unit_test(test__f_file_rename__works),
+
+ cmocka_unit_test(test__f_file_rename_at__fails),
+ cmocka_unit_test(test__f_file_rename_at__returns_data_not),
+ cmocka_unit_test(test__f_file_rename_at__works),
- // f_file_rename_at
+ cmocka_unit_test(test__f_file_role_change__fails_for_dereference),
+ cmocka_unit_test(test__f_file_role_change__fails_for_reference),
+ cmocka_unit_test(test__f_file_role_change__returns_data_not),
+ cmocka_unit_test(test__f_file_role_change__works_for_dereference),
+ cmocka_unit_test(test__f_file_role_change__works_for_reference),
- // f_file_role_change
+ cmocka_unit_test(test__f_file_role_change_at__fails_for_dereference),
+ cmocka_unit_test(test__f_file_role_change_at__fails_for_reference),
+ cmocka_unit_test(test__f_file_role_change_at__returns_data_not),
+ cmocka_unit_test(test__f_file_role_change_at__works_for_dereference),
+ cmocka_unit_test(test__f_file_role_change_at__works_for_reference),
- // f_file_role_change_at
+ cmocka_unit_test(test__f_file_seek__fails),
+ cmocka_unit_test(test__f_file_seek__works),
- // f_file_seek
+ cmocka_unit_test(test__f_file_size__fails),
+ cmocka_unit_test(test__f_file_size__returns_data_not),
+ cmocka_unit_test(test__f_file_size__works),
- // f_file_size
+ cmocka_unit_test(test__f_file_size_at__fails),
+ cmocka_unit_test(test__f_file_size_at__returns_data_not),
+ cmocka_unit_test(test__f_file_size_at__works),
- // f_file_size_at
+ cmocka_unit_test(test__f_file_size_by_id__fails),
+ cmocka_unit_test(test__f_file_size_by_id__returns_file_closed),
+ cmocka_unit_test(test__f_file_size_by_id__works),
- // f_file_size_by_id
+ cmocka_unit_test(test__f_file_stat__fails),
+ cmocka_unit_test(test__f_file_stat__returns_data_not),
+ cmocka_unit_test(test__f_file_stat__works),
- // f_file_stat
+ cmocka_unit_test(test__f_file_stat_at__fails),
+ cmocka_unit_test(test__f_file_stat_at__returns_data_not),
+ cmocka_unit_test(test__f_file_stat_at__works),
- // f_file_stat_at
+ cmocka_unit_test(test__f_file_stat_by_id__fails),
+ cmocka_unit_test(test__f_file_stat_by_id__returns_file_closed),
+ cmocka_unit_test(test__f_file_stat_by_id__works),
- // f_file_stat_by_id
+/*
// f_file_stream_close