Add missing mocks.
flags_library -fPIC
# Inject mocks.
+flags -Wl,--wrap=ferror_unlocked
flags -Wl,--wrap=fwrite_unlocked
#define CMOCKA_XML_FILE ./out.xml
main:
- # Disable mocks until mocking can be fixed for this project.
- #build settings-mocks
- build settings individual test
+ build settings-mocks individual test
build settings-tests individual test
operate ld_library_path
extern "C" {
#endif
-size_t __wrap_fwrite_unlocked(const void * const ptr, size_t size, size_t n, FILE *stream) {
+int __wrap_ferror_unlocked(FILE *stream) {
+
+ return mock_type(int);
+}
+
+size_t __wrap_fwrite_unlocked(const void * const ptr, size_t size, size_t nmemb, FILE *stream) {
const bool failure = mock_type(bool);
return mock_type(int);
}
- check_expected(ptr);
+ const bool check_ptr = mock_type(bool);
+
+ if (check_ptr) {
+ check_expected(ptr);
+ }
- return n;
+ return nmemb;
}
#ifdef __cplusplus
const static int mock_errno_generic = 32767;
-extern size_t __wrap_fwrite_unlocked(const void * const ptr, size_t size, size_t n, FILE *stream);
+extern int __wrap_ferror_unlocked(FILE *stream);
+extern size_t __wrap_fwrite_unlocked(const void * const ptr, size_t size, size_t nmemb, FILE *stream);
#ifdef __cplusplus
} // extern "C"
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
void test__f_conversion_number_signed_print__fails_for_zero(void **state) {
{
- const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
void test__f_conversion_number_signed_print__works(void **state) {
{
- const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
+
+ will_return(__wrap_fwrite_unlocked, false);
+ will_return(__wrap_fwrite_unlocked, sizeof(f_char_t));
+ will_return(__wrap_ferror_unlocked, 0);
+
+ expect_string(__wrap_fwrite_unlocked, ptr, "1");
const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d);
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_conversion_number_signed_print__works_for_zero(void **state) {
+
+ {
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
+
will_return(__wrap_fwrite_unlocked, false);
+ will_return(__wrap_fwrite_unlocked, true);
+ will_return(__wrap_ferror_unlocked, false);
- expect_string(__wrap_fwrite_unlocked, ptr, "1");
+ expect_string(__wrap_fwrite_unlocked, ptr, "0");
+
+ const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d);
+
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_conversion_number_signed_print__works_for_zero_with_width_zero(void **state) {
+
+ {
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+
+ const f_status_t status = f_conversion_number_signed_print(0, data, F_type_output_d);
assert_int_equal(status, F_none);
}
*/
extern void test__f_conversion_number_signed_print__works(void **state);
+/**
+ * Test that function works for 0.
+ *
+ * @see f_conversion_number_signed_print()
+ */
+extern void test__f_conversion_number_signed_print__works_for_zero(void **state);
+
+/**
+ * Test that function works for 0 when width is 0.
+ *
+ * @see f_conversion_number_signed_print()
+ */
+extern void test__f_conversion_number_signed_print__works_for_zero_with_width_zero(void **state);
+
#endif // _TEST__F_conversion_number_signed_print_h
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) {
{
- const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
will_return(__wrap_fwrite_unlocked, true);
will_return(__wrap_fwrite_unlocked, 0);
+ will_return(__wrap_ferror_unlocked, true);
const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d);
- assert_int_equal(F_status_set_fine(status), F_output);
+ assert_int_equal(status, F_status_set_error(F_output));
}
}
void test__f_conversion_number_unsigned_print__works(void **state) {
{
- const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
+
+ will_return(__wrap_fwrite_unlocked, false);
+ will_return(__wrap_fwrite_unlocked, true);
+ will_return(__wrap_ferror_unlocked, false);
+
+ expect_string(__wrap_fwrite_unlocked, ptr, "1");
const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d);
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_conversion_number_unsigned_print__works_for_zero(void **state) {
+
+ {
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 1);
+
will_return(__wrap_fwrite_unlocked, false);
+ will_return(__wrap_fwrite_unlocked, true);
+ will_return(__wrap_ferror_unlocked, false);
- expect_string(__wrap_fwrite_unlocked, ptr, "1");
+ expect_string(__wrap_fwrite_unlocked, ptr, "0");
+
+ const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d);
+
+ assert_int_equal(status, F_none);
+ }
+}
+
+void test__f_conversion_number_unsigned_print__works_for_zero_with_width_zero(void **state) {
+
+ {
+ const f_conversion_data_t data = macro_f_conversion_data_t_initialize(10, 0, 0);
+
+ const f_status_t status = f_conversion_number_unsigned_print(0, data, F_type_output_d);
assert_int_equal(status, F_none);
}
*/
extern void test__f_conversion_number_unsigned_print__works(void **state);
+/**
+ * Test that function works for 0.
+ *
+ * @see f_conversion_number_unsigned_print()
+ */
+extern void test__f_conversion_number_unsigned_print__works_for_zero(void **state);
+
+/**
+ * Test that function works for 0 when width is 0.
+ *
+ * @see f_conversion_number_unsigned_print()
+ */
+extern void test__f_conversion_number_unsigned_print__works_for_zero_with_width_zero(void **state);
+
#endif // _TEST__F_conversion_number_unsigned_print_h
cmocka_unit_test(test__f_conversion_character_to_octal__fails),
cmocka_unit_test(test__f_conversion_character_to_octal__works),
- // Currently failing for uknown reasons, it appears __wrap_fwrite_unlocked() is somehow not being wrapped properly.
- //cmocka_unit_test(test__f_conversion_number_signed_print__fails),
- //cmocka_unit_test(test__f_conversion_number_signed_print__fails_for_prepend),
- //cmocka_unit_test(test__f_conversion_number_signed_print__fails_for_zero),
- //cmocka_unit_test(test__f_conversion_number_signed_print__works),
+ cmocka_unit_test(test__f_conversion_number_signed_print__fails),
+ cmocka_unit_test(test__f_conversion_number_signed_print__fails_for_prepend),
+ cmocka_unit_test(test__f_conversion_number_signed_print__fails_for_zero),
+
+ cmocka_unit_test(test__f_conversion_number_signed_print__works),
+ cmocka_unit_test(test__f_conversion_number_signed_print__works_for_zero),
+ cmocka_unit_test(test__f_conversion_number_signed_print__works_for_zero_with_width_zero),
cmocka_unit_test(test__f_conversion_number_signed_to_string__works),
cmocka_unit_test(test__f_conversion_number_signed_to_string__works_for_prepend),
cmocka_unit_test(test__f_conversion_number_signed_to_string__works_for_zero),
- // // Currently failing for uknown reasons, it appears __wrap_fwrite_unlocked() is somehow not being wrapped properly.
- //cmocka_unit_test(test__f_conversion_number_unsigned_print__fails),
- //cmocka_unit_test(test__f_conversion_number_unsigned_print__fails_for_prepend),
- //cmocka_unit_test(test__f_conversion_number_unsigned_print__fails_for_zero),
- //cmocka_unit_test(test__f_conversion_number_unsigned_print__works),
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__fails),
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__fails_for_prepend),
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__fails_for_zero),
+
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__works),
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__works_for_zero),
+ cmocka_unit_test(test__f_conversion_number_unsigned_print__works_for_zero_with_width_zero),
cmocka_unit_test(test__f_conversion_number_unsigned_to_string__works),
cmocka_unit_test(test__f_conversion_number_unsigned_to_string__works_for_prepend),