While working on unit tests I noticed that passing struct stat seems inconsistent.
While there is likely a performance gain of not having to call the stat() functions, the inconsistency is undesirable.
Optimizations can be done under another API series.
Add missing path.used check.
if (macro_f_file_type_is_link(source_stat.st_mode)) {
f_string_dynamic_t target = f_string_dynamic_t_initialize;
- status = private_f_file_link_read(source, source_stat, &target);
+ status = private_f_file_link_read(source, source_stat.st_size, &target);
if (F_status_is_error(status)) {
f_string_dynamic_resize(0, &target);
#endif // _di_f_file_link_hard_at_
#ifndef _di_f_file_link_read_
- f_status_t f_file_link_read(const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) {
+ f_status_t f_file_link_read(const f_string_static_t path, const bool dereference, f_string_dynamic_t * const target) {
#ifndef _di_level_0_parameter_checking_
- if (!link_stat.st_size) return F_status_set_error(F_parameter);
if (!target) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
return F_data_not;
}
- return private_f_file_link_read(path, link_stat, target);
+ struct stat stat_file;
+
+ memset(&stat_file, 0, sizeof(struct stat));
+
+ {
+ const f_status_t status = private_f_file_stat(path, dereference, &stat_file);
+ if (F_status_is_error(status)) return status;
+ }
+
+ return private_f_file_link_read(path, stat_file.st_size, target);
}
#endif // _di_f_file_link_read_
#ifndef _di_f_file_link_read_at_
- f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) {
+ f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const int flag, f_string_dynamic_t * const target) {
#ifndef _di_level_0_parameter_checking_
- if (!link_stat.st_size) return F_status_set_error(F_parameter);
if (!target) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
return F_data_not;
}
- return private_f_file_link_read_at(at_id, path, link_stat, target);
+ struct stat stat_file;
+
+ memset(&stat_file, 0, sizeof(struct stat));
+
+ {
+ const f_status_t status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ if (F_status_is_error(status)) return status;
+ }
+
+ return private_f_file_link_read_at(at_id, path, stat_file.st_size, target);
}
#endif // _di_f_file_link_read_at_
#endif // _di_f_file_mode_read_
#ifndef _di_f_file_mode_read_at_
- f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, mode_t * const mode) {
+ f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, const int flag, mode_t * const mode) {
#ifndef _di_level_0_parameter_checking_
if (!mode) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (!path.used) {
+ return F_data_not;
+ }
+
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat(path, F_true, &stat_file);
+ const f_status_t status = private_f_file_stat_at(at_id, path, F_true, &stat_file);
if (F_status_is_error(status)) return status;
}
*
* @param path
* The path file name.
- * @param link_stat
- * The link file statistics.
+ * @param dereference
+ * Set to TRUE to dereference symlinks.
+ * Set to FALSE to operate on the symlink itself.
* @param target
* Will be replaced with the path in which the link points to.
* Will be NULL terminated with the NULL at target.string[target.used];
* Errors (with error bit) from: f_string_dynamic_increase_by()
* Errors (with error bit) from: f_string_dynamic_terminate_after()
*
+ * @see lstat()
* @see readlink()
+ * @see stat()
*
* @see f_string_dynamic_increase_by()
* @see f_string_dynamic_terminate_after()
*/
#ifndef _di_f_file_link_read_
- extern f_status_t f_file_link_read(const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target);
+ extern f_status_t f_file_link_read(const f_string_static_t path, const bool dereference, f_string_dynamic_t * const target);
#endif // _di_f_file_link_read_
/**
* The parent directory, as an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
- * @param link_stat
- * The link file statistics.
+ * @param flag
+ * Any valid flag, such as F_file_at_path_empty_d, F_file_at_automount_no_d, or F_file_at_symlink_follow_no_d.
* @param target
* Will be replaced with the path in which the link points to.
* Will be NULL terminated with the NULL at target.string[target.used];
* Errors (with error bit) from: f_string_dynamic_increase_by()
* Errors (with error bit) from: f_string_dynamic_terminate_after()
*
+ * @see fstatat()
* @see readlinkat()
*
* @see f_string_dynamic_increase_by()
* @see f_string_dynamic_terminate_after()
*/
#ifndef _di_f_file_link_read_at_
- extern f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target);
+ extern f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const int flag, f_string_dynamic_t * const target);
#endif // _di_f_file_link_read_at_
/**
* The parent directory, as an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
+ * @param flag
+ * Any valid flag, such as F_file_at_path_empty_d, F_file_at_automount_no_d, or F_file_at_symlink_follow_no_d.
* @param mode
* The read file mode.
*
* @see fstatat()
*/
#ifndef _di_f_file_mode_read_at_
- extern f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, mode_t * const mode);
+ extern f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, const int flag, mode_t * const mode);
#endif // _di_f_file_mode_read_at_
/**
#endif // !defined(_di_f_file_link_at_) || !defined(_di_f_file_copy_at_)
#if !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_)
- f_status_t private_f_file_link_read(const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) {
+ f_status_t private_f_file_link_read(const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) {
target->used = 0;
- f_status_t status = f_string_dynamic_increase_by(link_stat.st_size + 1, target);
+ f_status_t status = f_string_dynamic_increase_by(size + 1, target);
if (F_status_is_error(status)) return status;
- if (readlink(path.string, target->string, link_stat.st_size) < 0) {
- if (errno == EACCES) return F_status_set_error(F_access_denied);
- if (errno == EFAULT) return F_status_set_error(F_buffer);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
- if (errno == EIO) return F_status_set_error(F_input_output);
- if (errno == ELOOP) return F_status_set_error(F_loop);
- if (errno == ENAMETOOLONG) return F_status_set_error(F_name);
- if (errno == ENOENT) return F_status_set_error(F_file_found_not);
- if (errno == ENOMEM) return F_status_set_error(F_memory_not);
- if (errno == ENOTDIR) return F_status_set_error(F_directory_not);
+ if (size) {
+ if (readlink(path.string, target->string, size) < 0) {
+ if (errno == EACCES) return F_status_set_error(F_access_denied);
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == EIO) return F_status_set_error(F_input_output);
+ if (errno == ELOOP) return F_status_set_error(F_loop);
+ if (errno == ENAMETOOLONG) return F_status_set_error(F_name);
+ if (errno == ENOENT) return F_status_set_error(F_file_found_not);
+ if (errno == ENOMEM) return F_status_set_error(F_memory_not);
+ if (errno == ENOTDIR) return F_status_set_error(F_directory_not);
- return F_status_set_error(F_failure);
+ return F_status_set_error(F_failure);
+ }
}
- target->used = link_stat.st_size;
+ target->used = size;
status = f_string_dynamic_terminate_after(target);
if (F_status_is_error(status)) return status;
#endif // !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) {
+ f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) {
target->used = 0;
- f_status_t status = f_string_dynamic_increase_by(link_stat.st_size + 1, target);
+ f_status_t status = f_string_dynamic_increase_by(size + 1, target);
if (F_status_is_error(status)) return status;
- if (readlinkat(at_id, path.string, target->string, link_stat.st_size) < 0) {
- if (errno == EACCES) return F_status_set_error(F_access_denied);
- if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
- if (errno == EFAULT) return F_status_set_error(F_buffer);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
- if (errno == EIO) return F_status_set_error(F_input_output);
- if (errno == ELOOP) return F_status_set_error(F_loop);
- if (errno == ENAMETOOLONG) return F_status_set_error(F_name);
- if (errno == ENOENT) return F_status_set_error(F_file_found_not);
- if (errno == ENOMEM) return F_status_set_error(F_memory_not);
- if (errno == ENOTDIR) return F_status_set_error(F_directory_not);
+ if (size) {
+ if (readlinkat(at_id, path.string, target->string, size) < 0) {
+ if (errno == EACCES) return F_status_set_error(F_access_denied);
+ if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == EIO) return F_status_set_error(F_input_output);
+ if (errno == ELOOP) return F_status_set_error(F_loop);
+ if (errno == ENAMETOOLONG) return F_status_set_error(F_name);
+ if (errno == ENOENT) return F_status_set_error(F_file_found_not);
+ if (errno == ENOMEM) return F_status_set_error(F_memory_not);
+ if (errno == ENOTDIR) return F_status_set_error(F_directory_not);
- return F_status_set_error(F_failure);
+ return F_status_set_error(F_failure);
+ }
}
- target->used = link_stat.st_size;
+ target->used = size;
status = f_string_dynamic_terminate_after(target);
if (F_status_is_error(status)) return status;
*
* @param path
* The path file name.
- * @param link_stat
- * The link file statistics.
+ * @param size
+ * The file size in bytes, such as (struct stat).st_size.
* @param target
* Will be replaced with the path in which the link points to.
* Will be NULL terminated with the NULL at target.string[target.used];
* @see f_string_dynamic_terminate_after()
*/
#if !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_)
- extern f_status_t private_f_file_link_read(const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_link_read(const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_)
/**
* The parent directory, as an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
- * @param link_stat
- * The link file statistics.
+ * @param size
+ * The file size in bytes, such as (struct stat).st_size.
* @param target
* Will be replaced with the path in which the link points to.
* Will be NULL terminated with the NULL at target.string[target.used];
* @see f_string_dynamic_terminate_after()
*/
#if !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
/**
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_link_d;
+ statistics.st_size = 1;
for (int i = 0; i < 10; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_link_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 21; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 6; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 6; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 11; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 11; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
for (int i = 0; i < 11; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_socket_d;
+ statistics.st_size = 1;
for (int i = 0; i < 15; ++i) {
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_socket_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_block_d;
+ statistics.st_size = 1;
will_return(__wrap_stat, false);
will_return(__wrap_stat, &statistics);
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_character_d;
+ statistics.st_size = 1;
will_return(__wrap_stat, false);
will_return(__wrap_stat, &statistics);
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_directory_d;
+ statistics.st_size = 1;
will_return(__wrap_stat, false);
will_return(__wrap_stat, &statistics);
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_fifo_d;
+ statistics.st_size = 1;
will_return(__wrap_stat, false);
will_return(__wrap_stat, &statistics);
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_link_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_regular_d;
+ statistics.st_size = 1;
f_char_t buffer[1];
memset(&statistics, 0, sizeof(struct stat));
statistics.st_mode = 1 | F_file_type_socket_d;
+ statistics.st_size = 1;
will_return(__wrap_stat, false);
will_return(__wrap_stat, &statistics);
buffer.used = 0;
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
+
will_return(__wrap_readlink, true);
will_return(__wrap_readlink, errnos[i]);
- const f_status_t status = f_file_link_read(path, statistics, &buffer);
+ const f_status_t status = f_file_link_read(path, F_true, &buffer);
assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
{
- const f_status_t status = f_file_link_read(f_string_empty_s, statistics, 0);
+ const f_status_t status = f_file_link_read(f_string_empty_s, F_true, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
{
- const f_status_t status = f_file_link_read(f_string_empty_s, statistics, &buffer);
+ const f_status_t status = f_file_link_read(f_string_empty_s, F_true, &buffer);
assert_int_equal(status, F_data_not);
}
char source[2] = { 'x', 0 };
{
+ will_return(__wrap_stat, false);
+ will_return(__wrap_stat, &statistics);
+ will_return(__wrap_stat, 0);
+
will_return(__wrap_readlink, false);
will_return(__wrap_readlink, source);
will_return(__wrap_readlink, 0);
- const f_status_t status = f_file_link_read(path, statistics, &buffer);
+ const f_status_t status = f_file_link_read(path, F_true, &buffer);
assert_int_equal(status, F_none);
}
for (int i = 0; i < 11; ++i) {
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
+
will_return(__wrap_readlinkat, true);
will_return(__wrap_readlinkat, errnos[i]);
- const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer);
+ const f_status_t status = f_file_link_read_at(0, path, 0, &buffer);
assert_int_equal(F_status_set_fine(status), statuss[i]);
} // for
#ifndef _di_level_0_parameter_checking_
void test__f_file_link_read_at__parameter_checking(void **state) {
- struct stat statistics;
-
- memset(&statistics, 0, sizeof(struct stat));
-
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
{
- const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, 0);
+ const f_status_t status = f_file_link_read_at(0, f_string_empty_s, 0, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
- struct stat statistics;
-
- memset(&statistics, 0, sizeof(struct stat));
-
- statistics.st_size = 1;
-
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
{
- const f_status_t status = f_file_link_read_at(0, f_string_empty_s, statistics, &buffer);
+ const f_status_t status = f_file_link_read_at(0, f_string_empty_s, 0, &buffer);
assert_int_equal(status, F_data_not);
}
char source[2] = { 'x', 0 };
{
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
+
will_return(__wrap_readlinkat, false);
will_return(__wrap_readlinkat, source);
will_return(__wrap_readlinkat, 0);
- const f_status_t status = f_file_link_read_at(0, path, statistics, &buffer);
+ const f_status_t status = f_file_link_read_at(0, path, 0, &buffer);
assert_int_equal(status, F_none);
}
void test__f_file_mode_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) {
+
+ 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_mode_read(path, F_false, &id);
+ const f_status_t status = f_file_mode_read(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
}
void test__f_file_mode_read__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);
+ mode_t mode = 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_mode_read(path, F_false, &mode);
+
+ assert_int_equal(status, F_none);
+ assert_int_equal(mode, statistics.st_mode);
+ }
+
+ {
+ mode_t mode = 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_mode_read();
+ const f_status_t status = f_file_mode_read(path, F_true, &mode);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(mode, statistics.st_mode);
}
}
#include "test-file.h"
-#include "test-file-mode_read_at.h"
+#include "test-file-exists_at.h"
#ifdef __cplusplus
extern "C" {
void test__f_file_mode_read_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_mode_read_at(path, F_false, &id);
+ const f_status_t status = f_file_mode_read_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
}
void test__f_file_mode_read_at__parameter_checking(void **state) {
{
- const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, 0);
+ const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, 0, 0);
assert_int_equal(F_status_set_fine(status), F_parameter);
}
{
mode_t mode = 0;
- const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, &mode);
+ const f_status_t status = f_file_mode_read_at(0, f_string_empty_s, 0, &mode);
assert_int_equal(status, F_data_not);
}
void test__f_file_mode_read_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));
+
+ statistics.st_mode = 1 | F_file_type_regular_d;
+
{
- //will_return(__wrap_open, false);
- //will_return(__wrap_open, 5);
+ mode_t mode = 0;
+
+ will_return(__wrap_fstatat, false);
+ will_return(__wrap_fstatat, &statistics);
+ will_return(__wrap_fstatat, 0);
- //const f_status_t status = f_file_mode_read_at();
+ const f_status_t status = f_file_mode_read_at(0, path, 0, &mode);
- //assert_int_equal(status, F_none);
- //assert_int_equal(id, 5);
+ assert_int_equal(status, F_none);
+ assert_int_equal(mode, statistics.st_mode);
}
}
cmocka_unit_test(test__f_file_mode_from_string__works_basic_alphabet),
cmocka_unit_test(test__f_file_mode_from_string__works_basic_digit),
- // f_file_mode_read
+ cmocka_unit_test(test__f_file_mode_read__fails),
+ cmocka_unit_test(test__f_file_mode_read__returns_data_not),
+ cmocka_unit_test(test__f_file_mode_read__works),
- // f_file_mode_read_at
+ cmocka_unit_test(test__f_file_mode_read_at__fails),
+ cmocka_unit_test(test__f_file_mode_read_at__returns_data_not),
+ cmocka_unit_test(test__f_file_mode_read_at__works),
// f_file_mode_set