The __wrap_read() needed to be updated.
return -1;
}
- buf = mock_type(void *);
+ char *buffer = mock_type(char *);
+ size_t size = mock_type(size_t);
+
+ if (size) {
+ memcpy(buf, buffer, size);
+ }
return mock_type(int);
}
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, false);
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, true);
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, false);
will_return(__wrap_write, 1);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 0);
will_return(__wrap_read, 0);
will_return(__wrap_fsync, false);
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, false);
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, true);
will_return(__wrap_open, 0);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 1);
will_return(__wrap_read, 1);
will_return(__wrap_write, false);
will_return(__wrap_write, 1);
will_return(__wrap_read, false);
- will_return(__wrap_read, (void *) buffer);
+ will_return(__wrap_read, buffer);
+ will_return(__wrap_read, 0);
will_return(__wrap_read, 0);
will_return(__wrap_fsync, false);
extern "C" {
#endif
-void test__f_file_mode_to_mode__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_mode_to_mode(path, F_false, &id);
-
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
-}
-
#ifndef _di_level_0_parameter_checking_
void test__f_file_mode_to_mode__parameter_checking(void **state) {
void test__f_file_mode_to_mode__works(void **state) {
- {
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_mode_t file_modes[] = {
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_read_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_write_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & F_file_mode_t_mask_bit_execute_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_owner_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_read_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_write_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & F_file_mode_t_mask_bit_execute_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_group_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_read_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_write_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & F_file_mode_t_mask_bit_execute_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_world_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_read_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_write_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & F_file_mode_t_mask_bit_execute_d,
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_write_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_read_d | F_file_mode_t_mask_bit_execute_d),
+ F_file_mode_t_mask_how_add_d & F_file_mode_t_block_all_d & (F_file_mode_t_mask_bit_write_d | F_file_mode_t_mask_bit_execute_d),
+ };
- //const f_status_t status = f_file_mode_to_mode();
+ f_file_mode_t modes[] = {
+ F_file_mode_owner_rwx_d,
+ F_file_mode_owner_r_d,
+ F_file_mode_owner_w_d,
+ F_file_mode_owner_x_d,
+ F_file_mode_owner_rw_d,
+ F_file_mode_owner_rx_d,
+ F_file_mode_owner_wx_d,
+ F_file_mode_group_rwx_d,
+ F_file_mode_group_r_d,
+ F_file_mode_group_w_d,
+ F_file_mode_group_x_d,
+ F_file_mode_group_rw_d,
+ F_file_mode_group_rx_d,
+ F_file_mode_group_wx_d,
+ F_file_mode_world_rwx_d,
+ F_file_mode_world_r_d,
+ F_file_mode_world_w_d,
+ F_file_mode_world_x_d,
+ F_file_mode_world_rw_d,
+ F_file_mode_world_rx_d,
+ F_file_mode_world_wx_d,
+ F_file_mode_all_rwx_d,
+ F_file_mode_all_r_d,
+ F_file_mode_all_w_d,
+ F_file_mode_all_x_d,
+ F_file_mode_all_rw_d,
+ F_file_mode_all_rx_d,
+ F_file_mode_all_wx_d,
+ };
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
- }
+ for (f_array_length_t i = 0; i < 28; ++i) {
+
+ mode_t mode = 0;
+
+ const f_status_t status = f_file_mode_to_mode(file_modes[i], &mode);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(mode, modes[i]);
+ } // for
}
#ifdef __cplusplus
#define _TEST__F_file_mode_to_mode_h
/**
- * Test that function fails.
- *
- * @see f_file_mode_to_mode()
- */
-extern void test__f_file_mode_to_mode__fails(void **state);
-
-/**
* Test that parameter checking works as expected.
*
* @see f_file_mode_to_mode()
extern "C" {
#endif
-void test__f_file_name_base__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_name_base(path, F_false, &id);
-
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
-}
-
#ifndef _di_level_0_parameter_checking_
void test__f_file_name_base__parameter_checking(void **state) {
void test__f_file_name_base__returns_data_not(void **state) {
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
{
- //const f_status_t status = f_file_name_base(f_string_empty_s);
+ const f_status_t status = f_file_name_base(f_string_empty_s, &buffer);
- //assert_int_equal(status, F_data_not);
+ assert_int_equal(status, F_data_not);
}
+
+ f_string_dynamic_resize(0, &buffer);
}
void test__f_file_name_base__works(void **state) {
- {
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ f_string_static_t paths[] = {
+ macro_f_string_static_t_initialize("/a", 0, 2),
+ macro_f_string_static_t_initialize("/a/b", 0, 4),
+ macro_f_string_static_t_initialize("/a/b/c", 0, 6),
+ macro_f_string_static_t_initialize("/a/", 0, 3),
+ macro_f_string_static_t_initialize("/a/b/", 0, 5),
+ macro_f_string_static_t_initialize("/a/b/c/", 0, 7),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("a/b", 0, 3),
+ macro_f_string_static_t_initialize("a/b/c", 0, 5),
+ macro_f_string_static_t_initialize("a/", 0, 2),
+ macro_f_string_static_t_initialize("a/b/", 0, 4),
+ macro_f_string_static_t_initialize("a/b/c/", 0, 6),
+ };
- //const f_status_t status = f_file_name_base();
+ f_string_static_t bases[] = {
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("b", 0, 1),
+ macro_f_string_static_t_initialize("c", 0, 1),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("b", 0, 1),
+ macro_f_string_static_t_initialize("c", 0, 1),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("b", 0, 1),
+ macro_f_string_static_t_initialize("c", 0, 1),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("b", 0, 1),
+ macro_f_string_static_t_initialize("c", 0, 1),
+ };
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
- }
+ for (uint8_t i = 0; i < 12; ++i) {
+
+ buffer.used = 0;
+
+ const f_status_t status = f_file_name_base(paths[i], &buffer);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(buffer.used, bases[i].used);
+ assert_string_equal(buffer.string, bases[i].string);
+ } // for
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifdef __cplusplus
#define _TEST__F_file_name_base_h
/**
- * Test that function fails.
- *
- * @see f_file_name_base()
- */
-extern void test__f_file_name_base__fails(void **state);
-
-/**
* Test that parameter checking works as expected.
*
* @see f_file_name_base()
extern "C" {
#endif
-void test__f_file_name_directory__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_name_directory(path, F_false, &id);
-
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
- } // for
-}
-
#ifndef _di_level_0_parameter_checking_
void test__f_file_name_directory__parameter_checking(void **state) {
void test__f_file_name_directory__returns_data_not(void **state) {
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
{
- //const f_status_t status = f_file_name_directory(f_string_empty_s);
+ const f_status_t status = f_file_name_directory(f_string_empty_s, &buffer);
- //assert_int_equal(status, F_data_not);
+ assert_int_equal(status, F_data_not);
}
+
+ f_string_dynamic_resize(0, &buffer);
}
void test__f_file_name_directory__works(void **state) {
- {
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ f_string_static_t paths[] = {
+ macro_f_string_static_t_initialize("/a", 0, 2),
+ macro_f_string_static_t_initialize("/a/b", 0, 4),
+ macro_f_string_static_t_initialize("/a/b/c", 0, 6),
+ macro_f_string_static_t_initialize("/a/", 0, 3),
+ macro_f_string_static_t_initialize("/a/b/", 0, 5),
+ macro_f_string_static_t_initialize("/a/b/c/", 0, 7),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("a/b", 0, 3),
+ macro_f_string_static_t_initialize("a/b/c", 0, 5),
+ macro_f_string_static_t_initialize("a/", 0, 2),
+ macro_f_string_static_t_initialize("a/b/", 0, 4),
+ macro_f_string_static_t_initialize("a/b/c/", 0, 6),
+ };
- //const f_status_t status = f_file_name_directory();
+ f_string_static_t bases[] = {
+ macro_f_string_static_t_initialize("/", 0, 1),
+ macro_f_string_static_t_initialize("/a", 0, 2),
+ macro_f_string_static_t_initialize("/a/b", 0, 4),
+ macro_f_string_static_t_initialize("/", 0, 1),
+ macro_f_string_static_t_initialize("/a", 0, 2),
+ macro_f_string_static_t_initialize("/a/b", 0, 4),
+ macro_f_string_static_t_initialize("", 0, 0),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("a/b", 0, 3),
+ macro_f_string_static_t_initialize("", 0, 0),
+ macro_f_string_static_t_initialize("a", 0, 1),
+ macro_f_string_static_t_initialize("a/b", 0, 3),
+ };
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
- }
+ for (uint8_t i = 0; i < 12; ++i) {
+
+ buffer.used = 0;
+
+ const f_status_t status = f_file_name_directory(paths[i], &buffer);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(buffer.used, bases[i].used);
+ assert_string_equal(buffer.string, bases[i].string);
+ } // for
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifdef __cplusplus
#define _TEST__F_file_name_directory_h
/**
- * Test that function fails.
- *
- * @see f_file_name_directory()
- */
-extern void test__f_file_name_directory__fails(void **state);
-
-/**
* Test that parameter checking works as expected.
*
* @see f_file_name_directory()
int errnos[] = {
EACCES,
+ EDQUOT,
EEXIST,
EFAULT,
EFBIG,
- EDQUOT,
EINTR,
EINVAL,
EISDIR,
f_status_t statuss[] = {
F_access_denied,
+ F_filesystem_quota_block,
F_file_found,
F_buffer,
F_number_overflow,
- F_filesystem_quota_block,
F_interrupt,
F_parameter,
F_directory,
}
void test__f_file_open__works(void **state) {
-/*
+
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
const f_status_t status = f_file_open(path, 0, &file);
assert_int_equal(status, F_none);
- assert_int_equal(id, 5);
+ assert_int_equal(file.id, 5);
}
- */
}
#ifdef __cplusplus
#endif
void test__f_file_open_at__fails(void **state) {
-/*
- const int at = 1;
+
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
int errnos[] = {
EACCES,
+ EBADF,
+ EDQUOT,
EEXIST,
EFAULT,
EFBIG,
- EDQUOT,
EINTR,
EINVAL,
EISDIR,
f_status_t statuss[] = {
F_access_denied,
+ F_directory_descriptor,
+ F_filesystem_quota_block,
F_file_found,
F_buffer,
F_number_overflow,
- F_filesystem_quota_block,
F_interrupt,
F_parameter,
F_directory,
F_failure,
};
- for (int i = 0; i < 17; ++i) {
+ for (int i = 0; i < 22; ++i) {
- int id = 0;
+ f_file_t file = f_file_t_initialize;
will_return(__wrap_openat, true);
will_return(__wrap_openat, errnos[i]);
- const f_status_t status = f_file_open_at(at, path, F_false, &id);
+ const f_status_t status = f_file_open_at(0, path, 0, &file);
assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
- */
}
#ifndef _di_level_0_parameter_checking_
void test__f_file_open_at__returns_data_not(void **state) {
- const int at = 1;
-
{
f_file_t file = f_file_t_initialize;
- const f_status_t status = f_file_open_at(at, f_string_empty_s, 0, &file);
+ const f_status_t status = f_file_open_at(0, f_string_empty_s, 0, &file);
assert_int_equal(status, F_data_not);
}
}
void test__f_file_open_at__works(void **state) {
-/*
- const int at = 1;
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- int id = 0;
+ f_file_t file = f_file_t_initialize;
will_return(__wrap_openat, false);
will_return(__wrap_openat, 5);
- const f_status_t status = f_file_open_at(at, path, F_false, &id);
+ const f_status_t status = f_file_open_at(0, path, F_false, &file);
assert_int_equal(status, F_none);
- assert_int_equal(id, 5);
+ assert_int_equal(file.id, 5);
}
- */
}
#ifdef __cplusplus
void test__f_file_owner_read__fails(void **state) {
+ const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
+
int errnos[] = {
+ EACCES,
+ EFAULT,
+ ELOOP,
+ ENAMETOOLONG,
+ ENOENT,
+ ENOMEM,
+ ENOTDIR,
+ EOVERFLOW,
mock_errno_generic,
};
f_status_t statuss[] = {
- F_failure,
+ F_access_denied,
+ 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 < 9; ++i) {
+
+ gid_t id = 0;
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_stat, true);
+ will_return(__wrap_stat, errnos[i]);
- //const f_status_t status = f_file_owner_read(path, F_false, &id);
+ const f_status_t status = f_file_owner_read(path, F_true, &id);
- //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_owner_read__returns_data_not(void **state) {
{
- uid_t id = 0;
+ gid_t id = 0;
const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, &id);
void test__f_file_owner_read__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);
+ gid_t id = 0;
+
+ struct stat statistics;
+
+ memset(&statistics, 0, sizeof(struct stat));
+
+ statistics.st_uid = 5;
+
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
- //const f_status_t status = f_file_owner_read();
+ const f_status_t status = f_file_owner_read(path, F_true, &id);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(id, 5);
}
}
void test__f_file_read__fails(void **state) {
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
+
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) {
+ for (int i = 0; i < 9; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_read, true);
+ will_return(__wrap_read, errnos[i]);
- //const f_status_t status = f_file_read(path, F_false, &id);
+ const f_status_t status = f_file_read(file, &buffer);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifndef _di_level_0_parameter_checking_
void test__f_file_read__parameter_checking(void **state) {
f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
{
const f_status_t status = f_file_read(file, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#endif // _di_level_0_parameter_checking_
void test__f_file_read__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;
+ const f_status_t status = f_file_read(file, &buffer);
- const f_status_t status = f_file_read(file, &string);
-
- 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_read__works(void **state) {
- {
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
- //const f_status_t status = f_file_read();
+ file.id = 1;
+ file.size_read = 4;
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ {
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "abcd");
+ will_return(__wrap_read, 4);
+ will_return(__wrap_read, 4);
+
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "ef");
+ will_return(__wrap_read, 2);
+ will_return(__wrap_read, 2);
+
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "");
+ will_return(__wrap_read, 0);
+ will_return(__wrap_read, 0);
+
+ const f_status_t status = f_file_read(file, &buffer);
+
+ // Ensure string ends in NULL so that assert_string_equal() can be used.
+ f_string_dynamic_increase_by(1, &buffer);
+ buffer.string[buffer.used] = 0;
+
+ assert_int_equal(status, F_none_eof);
+ assert_int_equal(buffer.used, 6);
+ assert_string_equal(buffer.string, "abcdef");
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifdef __cplusplus
void test__f_file_read_block__fails(void **state) {
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
+
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) {
+ for (int i = 0; i < 9; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_read, true);
+ will_return(__wrap_read, errnos[i]);
- //const f_status_t status = f_file_read_block(path, F_false, &id);
+ const f_status_t status = f_file_read_block(file, &buffer);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifndef _di_level_0_parameter_checking_
void test__f_file_read_block__parameter_checking(void **state) {
f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
{
const f_status_t status = f_file_read_block(file, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#endif // _di_level_0_parameter_checking_
void test__f_file_read_block__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;
-
- const f_status_t status = f_file_read_block(file, &string);
+ const f_status_t status = f_file_read_block(file, &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_read_block__works(void **state) {
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
+ file.size_read = 4;
+
+ {
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "abcd");
+ will_return(__wrap_read, 4);
+ will_return(__wrap_read, 4);
+
+ const f_status_t status = f_file_read_block(file, &buffer);
+
+ // Ensure string ends in NULL so that assert_string_equal() can be used.
+ f_string_dynamic_increase_by(1, &buffer);
+ buffer.string[buffer.used] = 0;
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(buffer.used, 4);
+ assert_string_equal(buffer.string, "abcd");
+ }
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "");
+ will_return(__wrap_read, 0);
+ will_return(__wrap_read, 0);
- //const f_status_t status = f_file_read_block();
+ const f_status_t status = f_file_read_block(file, &buffer);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none_eof);
+ assert_int_equal(buffer.used, 4);
+ assert_string_equal(buffer.string, "abcd");
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifdef __cplusplus
void test__f_file_read_until__fails(void **state) {
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
+
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) {
+ for (int i = 0; i < 9; ++i) {
- //will_return(__wrap_open, true);
- //will_return(__wrap_open, errnos[i]);
+ will_return(__wrap_read, true);
+ will_return(__wrap_read, errnos[i]);
- //const f_status_t status = f_file_read_until(path, F_false, &id);
+ const f_status_t status = f_file_read_until(file, 1, &buffer);
- //assert_int_equal(F_status_set_fine(status), statuss[i]);
+ assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifndef _di_level_0_parameter_checking_
void test__f_file_read_until__parameter_checking(void **state) {
f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
{
- const f_status_t status = f_file_read_until(file, 0, 0);
+ const f_status_t status = f_file_read_until(file, 1, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
file.size_read = 0;
{
- const f_status_t status = f_file_read_until(file, 0, 0);
+ const f_status_t status = f_file_read_until(file, 1, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
{
f_string_dynamic_t string = f_string_dynamic_t_initialize;
- const f_status_t status = f_file_read_until(file, 0, &string);
+ const f_status_t status = f_file_read_until(file, 1, &string);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#endif // _di_level_0_parameter_checking_
void test__f_file_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;
+ const f_status_t status = f_file_read_until(file, 1, &buffer);
- const f_status_t status = f_file_read_until(file, 0, &string);
-
- 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_read_until__works(void **state) {
+ f_file_t file = f_file_t_initialize;
+ f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
+
+ file.id = 1;
+ file.size_read = 4;
+
+ {
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "abcd");
+ will_return(__wrap_read, 4);
+ will_return(__wrap_read, 4);
+
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "ef");
+ will_return(__wrap_read, 2);
+ will_return(__wrap_read, 2);
+
+ const f_status_t status = f_file_read_until(file, 6, &buffer);
+
+ // Ensure string ends in NULL so that assert_string_equal() can be used.
+ f_string_dynamic_increase_by(1, &buffer);
+ buffer.string[buffer.used] = 0;
+
+ assert_int_equal(status, F_none_stop);
+ assert_int_equal(buffer.used, 6);
+ assert_string_equal(buffer.string, "abcdef");
+ }
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ buffer.used = 0;
+
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "abcd");
+ will_return(__wrap_read, 4);
+ will_return(__wrap_read, 4);
+
+ will_return(__wrap_read, false);
+ will_return(__wrap_read, "");
+ will_return(__wrap_read, 0);
+ will_return(__wrap_read, 0);
- //const f_status_t status = f_file_read_until();
+ const f_status_t status = f_file_read_until(file, 6, &buffer);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ // Ensure string ends in NULL so that assert_string_equal() can be used.
+ f_string_dynamic_increase_by(1, &buffer);
+ buffer.string[buffer.used] = 0;
+
+ assert_int_equal(status, F_none_eof);
+ assert_int_equal(buffer.used, 4);
+ assert_string_equal(buffer.string, "abcd");
}
+
+ f_string_dynamic_resize(0, &buffer);
}
#ifdef __cplusplus
cmocka_unit_test(test__f_file_mode_set_at__returns_data_not),
cmocka_unit_test(test__f_file_mode_set_at__works),
- // f_file_mode_to_mode
+ cmocka_unit_test(test__f_file_mode_to_mode__works),
- // f_file_name_base
+ cmocka_unit_test(test__f_file_name_base__returns_data_not),
+ cmocka_unit_test(test__f_file_name_base__works),
- // f_file_name_directory
+ cmocka_unit_test(test__f_file_name_directory__returns_data_not),
+ cmocka_unit_test(test__f_file_name_directory__works),
-/*
cmocka_unit_test(test__f_file_open__fails),
cmocka_unit_test(test__f_file_open__returns_data_not),
cmocka_unit_test(test__f_file_open__works),
cmocka_unit_test(test__f_file_open_at__returns_data_not),
cmocka_unit_test(test__f_file_open_at__works),
- // f_file_owner_read
+ cmocka_unit_test(test__f_file_owner_read__fails),
+ cmocka_unit_test(test__f_file_owner_read__returns_data_not),
+ cmocka_unit_test(test__f_file_owner_read__works),
- // f_file_read
+ cmocka_unit_test(test__f_file_read__fails),
+ cmocka_unit_test(test__f_file_read__returns_file_closed),
+ cmocka_unit_test(test__f_file_read__works),
- // f_file_read_block
+ cmocka_unit_test(test__f_file_read_block__fails),
+ cmocka_unit_test(test__f_file_read_block__returns_file_closed),
+ cmocka_unit_test(test__f_file_read_block__works),
- // f_file_read_until
+ cmocka_unit_test(test__f_file_read_until__fails),
+ 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),