flags -Wl,--wrap=unlink
flags -Wl,--wrap=unlinkat
flags -Wl,--wrap=utimensat
+flags -Wl,--wrap=umask
flags -Wl,--wrap=write
return mock_type(int);
}
+mode_t __wrap_umask(mode_t mask) {
+
+ return mock_type(mode_t);
+}
+
ssize_t __wrap_write(int fd, const void *buf, size_t count) {
const bool failure = mock_type(bool);
extern int __wrap_symlinkat(const char *target, int newdirfd, const char *linkpath);
extern int __wrap_unlink(const char *pathname);
extern int __wrap_unlinkat(int dirfd, const char *pathname, int flags);
+extern mode_t __wrap_umask(mode_t mask);
extern int __wrap_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
extern ssize_t __wrap_write(int fd, const void *buf, size_t count);
extern "C" {
#endif
-void test__f_file_umask_get__fails(void **state) {
+#ifndef _di_level_0_parameter_checking_
+ void test__f_file_umask_get__parameter_checking(void **state) {
- int errnos[] = {
- mock_errno_generic,
- };
+ {
+ const f_status_t status = f_file_umask_get(0);
- f_status_t statuss[] = {
- F_failure,
- };
-
- for (int i = 0; i < 1; ++i) {
-
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
-
- //const f_status_t status = f_file_umask_get(path, F_false, &id);
-
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
-}
-
-void test__f_file_umask_get__returns_data_not(void **state) {
-
- {
- //const f_status_t status = f_file_umask_get(f_string_empty_s);
-
- //assert_int_equal(status, F_data_not);
+ assert_int_equal(F_status_set_fine(status), F_parameter);
+ }
}
-}
+#endif // _di_level_0_parameter_checking_
void test__f_file_umask_get__works(void **state) {
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_umask, F_file_mode_all_rw_d);
+ will_return(__wrap_umask, 0);
+
+ mode_t mode = 0;
- //const f_status_t status = f_file_umask_get();
+ const mode_t status = f_file_umask_get(&mode);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(mode, F_file_mode_all_rw_d);
}
}
#define _TEST__F_file_umask_get_h
/**
- * Test that function fails.
+ * Test that parameter checking works as expected.
*
* @see f_file_umask_get()
*/
-extern void test__f_file_umask_get__fails(void **state);
-
-/**
- * Test that function works but the path is empty.
- *
- * @see f_file_umask_get()
- */
-extern void test__f_file_umask_get__returns_data_not(void **state);
+#ifndef _di_level_0_parameter_checking_
+ extern void test__f_file_umask_get__parameter_checking(void **state);
+#endif // _di_level_0_parameter_checking_
/**
* Test that function works.
extern "C" {
#endif
-void test__f_file_umask_set__fails(void **state) {
-
- int errnos[] = {
- mock_errno_generic,
- };
-
- f_status_t statuss[] = {
- F_failure,
- };
-
- for (int i = 0; i < 1; ++i) {
-
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
-
- //const f_status_t status = f_file_umask_set(path, F_false, &id);
-
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
-}
-
-void test__f_file_umask_set__returns_data_not(void **state) {
-
- {
- //const f_status_t status = f_file_umask_set(f_string_empty_s);
-
- //assert_int_equal(status, F_data_not);
- }
-}
-
void test__f_file_umask_set__works(void **state) {
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_umask, 0);
- //const f_status_t status = f_file_umask_set();
+ const mode_t status = f_file_umask_set(F_file_mode_all_rw_d);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
}
}
#define _TEST__F_file_umask_set_h
/**
- * Test that function fails.
- *
- * @see f_file_umask_set()
- */
-extern void test__f_file_umask_set__fails(void **state);
-
-/**
- * Test that function works but the path is empty.
- *
- * @see f_file_umask_set()
- */
-extern void test__f_file_umask_set__returns_data_not(void **state);
-
-/**
* Test that function works.
*
* @see f_file_umask_set()
void test__f_file_write__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EAGAIN,
+ EBADF,
+ EFAULT,
+ EINTR,
+ EINVAL,
+ EIO,
+ EISDIR,
+ EWOULDBLOCK,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_block,
+ F_file_descriptor,
+ F_buffer,
+ F_interrupt,
+ F_parameter,
+ F_input_output,
+ F_file_type_directory,
+ F_block,
+ F_file_write,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 9; ++i) {
+
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
+
+ will_return(__wrap_write, true);
+ will_return(__wrap_write, errnos[i]);
+
+ const f_status_t status = f_file_write(file, path, 0);
+
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
+ } // for
+
+ for (int i = 0; i < 9; ++i) {
+
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, 1);
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_write, true);
+ will_return(__wrap_write, errnos[i]);
- //const f_status_t status = f_file_write(path, F_false, &id);
+ const f_status_t status = f_file_write(file, path, 0);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_write__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_t file = f_file_t_initialize;
+ file.size_write = path.used;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ const f_status_t status = f_file_write(file, path, 0);
+
+ assert_int_equal(status, F_none_eos);
+ }
+
+ {
+ f_file_t file = f_file_t_initialize;
+ file.size_write = path.used / 2;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, path.used / 2);
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, path.used / 2);
- //const f_status_t status = f_file_write();
+ const f_status_t status = f_file_write(file, path, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none_eos);
}
}
void test__f_file_write_block__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EAGAIN,
+ EBADF,
+ EFAULT,
+ EINTR,
+ EINVAL,
+ EIO,
+ EISDIR,
+ EWOULDBLOCK,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_block,
+ F_file_descriptor,
+ F_buffer,
+ F_interrupt,
+ F_parameter,
+ F_input_output,
+ F_file_type_directory,
+ F_block,
+ F_file_write,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 9; ++i) {
+
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_write, true);
+ will_return(__wrap_write, errnos[i]);
- //const f_status_t status = f_file_write_block(path, F_false, &id);
+ const f_status_t status = f_file_write_block(file, path, 0);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_write_block__returns_file_closed(void **state) {
- const f_file_t file = f_file_t_initialize;
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
{
const f_status_t status = f_file_write_block(file, f_string_empty_s, 0);
void test__f_file_write_block__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
+ {
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, 1);
+
+ const f_status_t status = f_file_write_block(file, path, 0);
+
+ assert_int_equal(status, F_none_stop);
+ }
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_t file = f_file_t_initialize;
+ file.size_write = path.used;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
- //const f_status_t status = f_file_write_block();
+ const f_status_t status = f_file_write_block(file, path, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none_eos);
}
}
void test__f_file_write_range__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+ const f_string_range_t range = macro_f_string_range_t_initialize(0, 0);
+
int errnos[] = {
+ EAGAIN,
+ EBADF,
+ EFAULT,
+ EINTR,
+ EINVAL,
+ EIO,
+ EISDIR,
+ EWOULDBLOCK,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_block,
+ F_file_descriptor,
+ F_buffer,
+ F_interrupt,
+ F_parameter,
+ F_input_output,
+ F_file_type_directory,
+ F_block,
+ F_file_write,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 9; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
- //const f_status_t status = f_file_write_range(path, F_false, &id);
+ will_return(__wrap_write, true);
+ will_return(__wrap_write, errnos[i]);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ const f_status_t status = f_file_write_range(file, path, range, 0);
+
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_write_range__returns_file_closed(void **state) {
- const f_file_t file = f_file_t_initialize;
+ f_file_t file = f_file_t_initialize;
const f_string_range_t range = f_string_range_t_initialize;
+ file.size_write = 1;
+
{
const f_status_t status = f_file_write_range(file, f_string_empty_s, range, 0);
void test__f_file_write_range__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+ const f_string_range_t range = macro_f_string_range_t_initialize(0, 0);
+
+ {
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ const f_status_t status = f_file_write_range(file, path, range, 0);
+
+ assert_int_equal(status, F_none_stop);
+ }
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_t file = f_file_t_initialize;
+ file.size_write = path.used;
+ file.id = 0;
- //const f_status_t status = f_file_write_range();
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ const f_status_t status = f_file_write_range(file, path, range, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none_eos);
}
}
void test__f_file_write_until__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EAGAIN,
+ EBADF,
+ EFAULT,
+ EINTR,
+ EINVAL,
+ EIO,
+ EISDIR,
+ EWOULDBLOCK,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_block,
+ F_file_descriptor,
+ F_buffer,
+ F_interrupt,
+ F_parameter,
+ F_input_output,
+ F_file_type_directory,
+ F_block,
+ F_file_write,
};
- for (int i = 0; i < 1; ++i) {
+ for (int i = 0; i < 9; ++i) {
+
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_write, true);
+ will_return(__wrap_write, errnos[i]);
- //const f_status_t status = f_file_write_until(path, F_false, &id);
+ const f_status_t status = f_file_write_until(file, path, 1, 0);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
}
void test__f_file_write_until__returns_file_closed(void **state) {
- const f_file_t file = f_file_t_initialize;
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
{
- const f_status_t status = f_file_write_until(file, f_string_empty_s, 0, 0);
+ const f_status_t status = f_file_write_until(file, f_string_empty_s, 1, 0);
assert_int_equal(F_status_set_fine(status), F_file_closed);
}
void test__f_file_write_until__works(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_t file = f_file_t_initialize;
+ file.size_write = 1;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
+
+ const f_status_t status = f_file_write_until(file, path, path.used, 0);
+
+ assert_int_equal(status, F_none_eos);
+ }
+
+ {
+ f_file_t file = f_file_t_initialize;
+ file.size_write = path.used;
+ file.id = 0;
+
+ will_return(__wrap_write, false);
+ will_return(__wrap_write, file.size_write);
- //const f_status_t status = f_file_write_until();
+ const f_status_t status = f_file_write_until(file, path, path.used, 0);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none_eos);
}
}
cmocka_unit_test(test__f_file_type_at__returns_data_not),
cmocka_unit_test(test__f_file_type_at__works),
-/*
- // f_file_umask_get
+ cmocka_unit_test(test__f_file_umask_get__works),
- // f_file_umask_set
+ cmocka_unit_test(test__f_file_umask_set__works),
- // f_file_write
+ cmocka_unit_test(test__f_file_write__fails),
+ cmocka_unit_test(test__f_file_write__returns_file_closed),
+ cmocka_unit_test(test__f_file_write__returns_data_not),
+ cmocka_unit_test(test__f_file_write__works),
- // f_file_write_block
+ cmocka_unit_test(test__f_file_write_block__fails),
+ cmocka_unit_test(test__f_file_write_block__returns_file_closed),
+ cmocka_unit_test(test__f_file_write_block__returns_data_not),
+ cmocka_unit_test(test__f_file_write_block__works),
- // f_file_write_until
+ cmocka_unit_test(test__f_file_write_range__fails),
+ cmocka_unit_test(test__f_file_write_range__returns_file_closed),
+ cmocka_unit_test(test__f_file_write_range__returns_data_not),
+ cmocka_unit_test(test__f_file_write_range__works),
+
+ cmocka_unit_test(test__f_file_write_until__fails),
+ cmocka_unit_test(test__f_file_write_until__returns_file_closed),
+ cmocka_unit_test(test__f_file_write_until__returns_data_not),
+ cmocka_unit_test(test__f_file_write_until__works),
- // f_file_write_range
-*/
#ifndef _di_level_0_parameter_checking_
// f_file_access() doesn't use parameter checking.
// f_file_access_at() doesn't use parameter checking.
// f_file_touch_at() doesn't use parameter checking.
cmocka_unit_test(test__f_file_type__parameter_checking),
cmocka_unit_test(test__f_file_type_at__parameter_checking),
- // f_file_umask_get() doesn't use parameter checking.
+ cmocka_unit_test(test__f_file_umask_get__parameter_checking),
// f_file_umask_set() doesn't use parameter checking.
cmocka_unit_test(test__f_file_write__parameter_checking),
cmocka_unit_test(test__f_file_write_block__parameter_checking),