Properly handle mock return types.
Make sure to return F_file_descriptor_not instead of F_stream_not in cases where the file descriptor is checked instead of the file stream.
const bool failure = mock_type(bool);
if (failure) {
- return mock_type(int);
+ return mock_type(size_t);
}
const bool check_ptr = mock_type(bool);
#ifndef _di_f_file_touch_at_
f_status_t f_file_touch_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const int flag) {
- if (directory.id == -1) return F_stream_not;
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
if (!type) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (directory.id == -1) return F_stream_not;
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
if (file.id == -1 || !buffer.used || !file.size_write) {
if (written) *written = 0;
- return file.id == -1 ? F_stream_not : F_data_not;
+ return file.id == -1 ? F_file_descriptor_not : F_data_not;
}
if (written) {
if (file.id == -1 || !buffer.used || !file.size_write) {
if (written) *written = 0;
- return file.id == -1 ? F_stream_not : F_data_not;
+ return file.id == -1 ? F_file_descriptor_not : F_data_not;
}
const f_array_length_t write_max = file.size_write > buffer.used ? buffer.used : file.size_write;
if (file.id == -1 || !buffer.used || !total || !file.size_write) {
if (written) *written = 0;
- return file.id == -1 ? F_stream_not : F_data_not;
+ return file.id == -1 ? F_file_descriptor_not : F_data_not;
}
const f_array_length_t write_max = total > buffer.used ? buffer.used : total;
*written = 0;
}
- return file.id == -1 ? F_stream_not : F_data_not;
+ return file.id == -1 ? F_file_descriptor_not : F_data_not;
}
const f_array_length_t write_max = (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1;
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
+ *
* F_access_denied (with error bit) on access denied.
* F_buffer (with error bit) if the buffer is invalid.
- * F_stream_not if file.stream is NULL.
- *
* F_busy (with error bit) if file system is too busy to perform write.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* F_directory_not (with error bit) if a supposed directory in path is not actually a directory.
*
* @return
* F_none if path was found and and the type was loaded in the type parameter.
+ * F_file_descriptor_not if file.id is -1.
* F_file_found_not if the path was not found.
- * F_stream_not if file.stream is NULL.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* F_none on success.
* F_none_eos on success and wrote up to buffer.used.
* F_data_not if buffer.used is 0 or range.start > range.stop.
- * F_stream_not if file.id is -1.
+ * F_file_descriptor_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
* F_none_stop on success and wrote up to stop point.
* F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
* F_data_not if buffer.used is 0 or range.start > range.stop.
- * F_stream_not if file.id is -1.
+ * F_file_descriptor_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
* F_none_stop on success and wrote up to stop point.
* F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
* F_data_not if buffer.used is 0 or range.start > range.stop.
- * F_stream_not if file.id is -1.
+ * F_file_descriptor_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
* F_none_stop on success and wrote up to stop point.
* F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
* F_data_not if buffer.used is 0 or range.start > range.stop.
- * F_stream_not if file.id is -1.
+ * F_file_descriptor_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
return file.stream ? F_data_not : F_stream_not;
}
+ f_status_t status = F_none;
+
if (written) {
- const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, written);
+ status = private_f_file_stream_write_until(file, buffer, buffer.used, written);
if (status == F_none && *written == buffer.used) return F_none_eos;
}
else {
f_array_length_t written_local = 0;
- const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
+ status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
if (status == F_none && written_local == buffer.used) return F_none_eos;
}
+ if (F_status_is_error(status)) return status;
+
return F_none;
}
#endif // _di_f_file_stream_write_
const f_array_length_t write_max = file.size_write > buffer.used ? buffer.used : file.size_write;
+ f_status_t status = F_none;
+
if (written) {
- const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, written);
+ status = private_f_file_stream_write_until(file, buffer, write_max, written);
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, &written_local);
+ status = private_f_file_stream_write_until(file, buffer, write_max, &written_local);
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
+ if (F_status_is_error(status)) return status;
+
return F_none;
}
#endif // _di_f_file_stream_write_block_
const f_array_length_t write_max = total > buffer.used ? buffer.used : total;
+ f_status_t status = F_none;
+
if (written) {
- const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, written);
+ status = private_f_file_stream_write_until(file, buffer, write_max, written);
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
+ status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
+ if (F_status_is_error(status)) return status;
+
return F_none;
}
#endif // _di_f_file_stream_write_until_
}
const f_array_length_t write_max = (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1;
+ const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize_1(buffer.string + range.start, 0, buffer.used - range.start);
- if (written) {
- const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize_1(buffer.string + range.start, 0, buffer.used - range.start);
+ f_status_t status = F_none;
- const f_status_t status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, written);
+ if (written) {
+ status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, written);
if (status == F_none) {
if (range.start + *written == buffer.used) return F_none_eos;
}
}
else {
- const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize_1(buffer.string + range.start, 0, buffer.used - range.start);
f_array_length_t written_local = 0;
- const f_status_t status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, &written_local);
+ status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, &written_local);
if (status == F_none) {
if (range.start + written_local == buffer.used) return F_none_eos;
}
}
+ if (F_status_is_error(status)) return status;
+
return F_none;
}
#endif // _di_f_file_stream_write_range_
const bool failure = mock_type(bool);
if (failure) {
- return mock_type(int);
+ return mock_type(size_t);
}
return mock_type(size_t);
file.size_read = 1;
file.size_write = 1;
- will_return(__wrap_write, 0);
+ will_return(__wrap_fwrite_unlocked, true);
+ will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_file_stream_write(file, test, 0);
}
}
-void test__f_file_stream_write__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_stream_write(file, f_string_empty_s, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_stream_write__returns_stream_not(void **state) {
const f_file_t file = f_file_t_initialize;
extern void test__f_file_stream_write__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_stream_write()
- */
-extern void test__f_file_stream_write__parameter_checking(void **state);
-
-/**
* Test that function works but the stream is not valid.
*
* @see f_file_stream_write()
}
}
-void test__f_file_stream_write_block__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_stream_write_block(file, f_string_empty_s, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_stream_write_block__returns_stream_not(void **state) {
const f_file_t file = f_file_t_initialize;
extern void test__f_file_stream_write_block__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_stream_write_block()
- */
-extern void test__f_file_stream_write_block__parameter_checking(void **state);
-
-/**
* Test that function works but the stream is not valid.
*
* @see f_file_stream_write_block()
}
}
-void test__f_file_stream_write_range__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- const f_string_range_t range = f_string_range_t_initialize;
-
- {
- const f_status_t status = f_file_stream_write_range(file, f_string_empty_s, range, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_stream_write_range__returns_stream_not(void **state) {
const f_file_t file = f_file_t_initialize;
extern void test__f_file_stream_write_range__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_stream_write_range()
- */
-extern void test__f_file_stream_write_range__parameter_checking(void **state);
-
-/**
* Test that function works but the stream is not valid.
*
* @see f_file_stream_write_range()
}
}
-void test__f_file_stream_write_until__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_stream_write_until(file, f_string_empty_s, 0, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_stream_write_until__returns_stream_not(void **state) {
f_file_t file = f_file_t_initialize;
extern void test__f_file_stream_write_until__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_stream_write_until()
- */
-extern void test__f_file_stream_write_until__parameter_checking(void **state);
-
-/**
* Test that function works but the stream is not valid.
*
* @see f_file_stream_write_until()
} // for
}
-void test__f_file_write__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_write(file, f_string_empty_s, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_write__returns_file_descriptor_not(void **state) {
const f_file_t file = f_file_t_initialize;
extern void test__f_file_write__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_write()
- */
-extern void test__f_file_write__parameter_checking(void **state);
-
-/**
* Test that function works but the descriptor is not valid.
*
* @see f_file_write()
} // for
}
-void test__f_file_write_block__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_write_block(file, f_string_empty_s, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_write_block__returns_file_descriptor_not(void **state) {
f_file_t file = f_file_t_initialize;
extern void test__f_file_write_block__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_write_block()
- */
-extern void test__f_file_write_block__parameter_checking(void **state);
-
-/**
* Test that function works but the descriptor is not valid.
*
* @see f_file_write_block()
} // for
}
-void test__f_file_write_range__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- const f_string_range_t range = f_string_range_t_initialize;
-
- {
- const f_status_t status = f_file_write_range(file, f_string_empty_s, range, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_write_range__returns_file_descriptor_not(void **state) {
f_file_t file = f_file_t_initialize;
extern void test__f_file_write_range__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_write_range()
- */
-extern void test__f_file_write_range__parameter_checking(void **state);
-
-/**
* Test that function works but the descriptor is not valid.
*
* @see f_file_write_range()
} // for
}
-void test__f_file_write_until__parameter_checking(void **state) {
-
- f_file_t file = macro_f_file_t_initialize_2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d);
- file.size_write = 0;
-
- {
- const f_status_t status = f_file_write_until(file, f_string_empty_s, 0, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
-}
-
void test__f_file_write_until__returns_file_descriptor_not(void **state) {
f_file_t file = f_file_t_initialize;
extern void test__f_file_write_until__fails(void **state);
/**
- * Test that parameter checking works as expected.
- *
- * @see f_file_write_until()
- */
-extern void test__f_file_write_until__parameter_checking(void **state);
-
-/**
* Test that function works but the descriptor is not valid.
*
* @see f_file_write_until()
cmocka_unit_test(test__f_file_stream_read_block__parameter_checking),
cmocka_unit_test(test__f_file_stream_read_until__parameter_checking),
cmocka_unit_test(test__f_file_stream_reopen__parameter_checking),
- cmocka_unit_test(test__f_file_stream_write__parameter_checking),
- cmocka_unit_test(test__f_file_stream_write_block__parameter_checking),
- cmocka_unit_test(test__f_file_stream_write_until__parameter_checking),
- cmocka_unit_test(test__f_file_stream_write_range__parameter_checking),
+ // f_file_stream_write() doesn't use parameter checking.
+ // f_file_stream_write_block() doesn't use parameter checking.
+ // f_file_stream_write_until() doesn't use parameter checking.
+ // f_file_stream_write_range() doesn't use parameter checking.
// f_file_touch() 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),
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),
- cmocka_unit_test(test__f_file_write_until__parameter_checking),
- cmocka_unit_test(test__f_file_write_range__parameter_checking),
+ // f_file_write() doesn't use parameter checking.
+ // f_file_write_block() doesn't use parameter checking.
+ // f_file_write_until() doesn't use parameter checking.
+ // f_file_write_range() doesn't use parameter checking.
#endif // _di_level_0_parameter_checking_
};
const bool failure = mock_type(bool);
if (failure) {
- return mock_type(int);
+ return mock_type(size_t);
}
return mock_type(size_t);
const bool failure = mock_type(bool);
if (failure) {
- errno = mock_type(int);
+ errno = mock_type(ssize_t);
return -1;
}