From 0222bafc032d8ab79935143144ddd9baec4f16d1 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 24 Apr 2022 19:52:48 -0500 Subject: [PATCH] Bugfix: The FILE type may not have a known storage size and use F_type_output_d. Instantiate it as a pointer instead given that it is possible in this case. Use F_type_output_d instead of "stdout". --- .../tests/unit/c/test-conversion-number_signed_print.c | 12 ++++++------ .../tests/unit/c/test-conversion-number_unsigned_print.c | 12 ++++++------ level_0/f_file/tests/unit/c/test-file-stream_close.c | 6 +++--- level_0/f_file/tests/unit/c/test-file-stream_open.c | 9 ++++----- level_0/f_file/tests/unit/c/test-file-stream_read.c | 4 ++-- level_0/f_file/tests/unit/c/test-file-stream_read_block.c | 4 ++-- level_0/f_file/tests/unit/c/test-file-stream_read_until.c | 4 ++-- level_0/f_file/tests/unit/c/test-file-stream_reopen.c | 11 +++++------ level_0/f_file/tests/unit/c/test-file-stream_write.c | 7 +++---- level_0/f_file/tests/unit/c/test-file-stream_write_block.c | 9 ++++----- level_0/f_file/tests/unit/c/test-file-stream_write_range.c | 9 ++++----- level_0/f_file/tests/unit/c/test-file-stream_write_until.c | 9 ++++----- level_3/fake/c/private-clean.c | 2 +- 13 files changed, 46 insertions(+), 52 deletions(-) diff --git a/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c b/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c index c2c79e6..a7530e5 100644 --- a/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c +++ b/level_0/f_conversion/tests/unit/c/test-conversion-number_signed_print.c @@ -13,7 +13,7 @@ void test__f_conversion_number_signed_print__fails(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_signed_print(1, data, stdout); + 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); } @@ -27,7 +27,7 @@ void test__f_conversion_number_signed_print__fails_for_prepend(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_signed_print(1, data, stdout); + 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); } @@ -41,7 +41,7 @@ void test__f_conversion_number_signed_print__fails_for_zero(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_signed_print(0, data, stdout); + 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); } @@ -59,10 +59,10 @@ void test__f_conversion_number_signed_print__fails_for_zero(void **state) { } { - FILE file; + FILE *file = 0; const f_conversion_data_t data = macro_f_conversion_data_t_initialize(1, 0, 0); - const f_status_t status = f_conversion_number_signed_print(0, data, &file); + const f_status_t status = f_conversion_number_signed_print(0, data, file); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -74,7 +74,7 @@ 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_status_t status = f_conversion_number_signed_print(1, data, stdout); + const f_status_t status = f_conversion_number_signed_print(1, data, F_type_output_d); will_return(__wrap_fwrite_unlocked, false); diff --git a/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c b/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c index 2beaf7b..e662223 100644 --- a/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c +++ b/level_0/f_conversion/tests/unit/c/test-conversion-number_unsigned_print.c @@ -13,7 +13,7 @@ void test__f_conversion_number_unsigned_print__fails(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_unsigned_print(1, data, stdout); + 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); } @@ -27,7 +27,7 @@ void test__f_conversion_number_unsigned_print__fails_for_prepend(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_unsigned_print(1, data, stdout); + 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); } @@ -41,7 +41,7 @@ void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) { will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, 0); - const f_status_t status = f_conversion_number_unsigned_print(0, data, stdout); + 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); } @@ -59,10 +59,10 @@ void test__f_conversion_number_unsigned_print__fails_for_zero(void **state) { } { - FILE file; + FILE *file = 0; const f_conversion_data_t data = macro_f_conversion_data_t_initialize(1, 0, 0); - const f_status_t status = f_conversion_number_unsigned_print(0, data, &file); + const f_status_t status = f_conversion_number_unsigned_print(0, data, file); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -74,7 +74,7 @@ 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_status_t status = f_conversion_number_unsigned_print(1, data, stdout); + const f_status_t status = f_conversion_number_unsigned_print(1, data, F_type_output_d); will_return(__wrap_fwrite_unlocked, false); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_close.c b/level_0/f_file/tests/unit/c/test-file-stream_close.c index a860c35..e455823 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_close.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_close.c @@ -153,7 +153,7 @@ void test__f_file_stream_close__fails_for_stream(void **state) { f_file_t file = f_file_t_initialize; file.id = 0; - file.stream = stdout; + file.stream = F_type_input_d; if (flush) { if (flush == 1) { @@ -199,7 +199,7 @@ void test__f_file_stream_close__works(void **state) { f_file_t file = f_file_t_initialize; file.id = 0; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fclose, false); will_return(__wrap_fclose, 0); @@ -231,7 +231,7 @@ void test__f_file_stream_close__works(void **state) { f_file_t file = f_file_t_initialize; file.id = 0; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fflush, false); will_return(__wrap_fflush, 0); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_open.c b/level_0/f_file/tests/unit/c/test-file-stream_open.c index 1c72251..d1ddfca 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_open.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_open.c @@ -110,34 +110,33 @@ void test__f_file_stream_open__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int id = 1; - FILE *file_pointer = stdout; { f_file_t file = f_file_t_initialize; will_return(__wrap_fopen, false); - will_return(__wrap_fopen, file_pointer); + will_return(__wrap_fopen, F_type_output_d); will_return(__wrap_fileno, id); const f_status_t status = f_file_stream_open(path, path, &file); assert_int_equal(status, F_none); - assert_int_equal(file.stream, file_pointer); + assert_int_equal(file.stream, F_type_output_d); } { f_file_t file = f_file_t_initialize; will_return(__wrap_fopen, false); - will_return(__wrap_fopen, file_pointer); + will_return(__wrap_fopen, F_type_output_d); will_return(__wrap_fileno, id); const f_status_t status = f_file_stream_open(path, f_string_empty_s, &file); assert_int_equal(status, F_none); - assert_int_equal(file.stream, file_pointer); + assert_int_equal(file.stream, F_type_output_d); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read.c b/level_0/f_file/tests/unit/c/test-file-stream_read.c index 556f9b2..5016d8b 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read.c @@ -39,7 +39,7 @@ void test__f_file_stream_read__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); @@ -113,7 +113,7 @@ void test__f_file_stream_read__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c index 5a6a05e..c5da1c0 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_block.c @@ -39,7 +39,7 @@ void test__f_file_stream_read_block__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); @@ -112,7 +112,7 @@ void test__f_file_stream_read_block__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c index c316d6d..9a3384f 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_read_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_read_until.c @@ -39,7 +39,7 @@ void test__f_file_stream_read_until__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); @@ -115,7 +115,7 @@ void test__f_file_stream_read_until__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_feof_unlocked, false); will_return(__wrap_feof_unlocked, 0); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c index 5cffff6..352da55 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_reopen.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_reopen.c @@ -106,35 +106,34 @@ void test__f_file_stream_reopen__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); const int id = 1; - FILE *file_pointer = stdout; { f_file_t file = f_file_t_initialize; - file.stream = file_pointer; + file.stream = F_type_input_d; will_return(__wrap_freopen, false); - will_return(__wrap_freopen, file_pointer); + will_return(__wrap_freopen, F_type_input_d); will_return(__wrap_fileno, id); const f_status_t status = f_file_stream_reopen(path, path, &file); assert_int_equal(status, F_none); - assert_int_equal(file.stream, file_pointer); + assert_int_equal(file.stream, F_type_input_d); } { f_file_t file = f_file_t_initialize; will_return(__wrap_freopen, false); - will_return(__wrap_freopen, file_pointer); + will_return(__wrap_freopen, F_type_input_d); will_return(__wrap_fileno, id); const f_status_t status = f_file_stream_reopen(path, f_string_empty_s, &file); assert_int_equal(status, F_none); - assert_int_equal(file.stream, file_pointer); + assert_int_equal(file.stream, F_type_input_d); } } diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write.c b/level_0/f_file/tests/unit/c/test-file-stream_write.c index 355b6aa..4b62b81 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write.c @@ -37,7 +37,7 @@ void test__f_file_stream_write__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, errnos[i]); @@ -79,8 +79,7 @@ void test__f_file_stream_write__returns_file_closed(void **state) { void test__f_file_stream_write__returns_data_not(void **state) { f_file_t file = f_file_t_initialize; - FILE file_stucture; - file.stream = &file_stucture; + file.stream = F_type_input_d; { const f_status_t status = f_file_stream_write(file, f_string_empty_s, 0); @@ -105,7 +104,7 @@ void test__f_file_stream_write__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = path.used; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c index 7b39220..6ad1ac7 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_block.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_block.c @@ -37,7 +37,7 @@ void test__f_file_stream_write_block__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, errnos[i]); @@ -79,8 +79,7 @@ void test__f_file_stream_write_block__returns_file_closed(void **state) { void test__f_file_stream_write_block__returns_data_not(void **state) { f_file_t file = f_file_t_initialize; - FILE file_stucture; - file.stream = &file_stucture; + file.stream = F_type_input_d; { const f_status_t status = f_file_stream_write_block(file, f_string_empty_s, 0); @@ -105,7 +104,7 @@ void test__f_file_stream_write_block__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); @@ -121,7 +120,7 @@ void test__f_file_stream_write_block__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = path.used; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c index 2a6da07..6d8e5b9 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_range.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_range.c @@ -38,7 +38,7 @@ void test__f_file_stream_write_range__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, errnos[i]); @@ -83,8 +83,7 @@ void test__f_file_stream_write_range__returns_file_closed(void **state) { void test__f_file_stream_write_range__returns_data_not(void **state) { f_file_t file = f_file_t_initialize; - FILE file_stucture; - file.stream = &file_stucture; + file.stream = F_type_input_d; { const f_string_range_t range = f_string_range_t_initialize; @@ -154,7 +153,7 @@ void test__f_file_stream_write_range__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); @@ -170,7 +169,7 @@ void test__f_file_stream_write_range__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = path.used; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); diff --git a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c index 6112a84..149d42c 100644 --- a/level_0/f_file/tests/unit/c/test-file-stream_write_until.c +++ b/level_0/f_file/tests/unit/c/test-file-stream_write_until.c @@ -37,7 +37,7 @@ void test__f_file_stream_write_until__fails(void **state) { f_file_t file = f_file_t_initialize; file.size_read = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, true); will_return(__wrap_fwrite_unlocked, errnos[i]); @@ -82,8 +82,7 @@ void test__f_file_stream_write_until__returns_data_not(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 file_stucture; - file.stream = &file_stucture; + file.stream = F_type_input_d; { const f_status_t status = f_file_stream_write_until(file, f_string_empty_s, 0, 0); @@ -138,7 +137,7 @@ void test__f_file_stream_write_until__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = 1; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); @@ -172,7 +171,7 @@ void test__f_file_stream_write_until__works(void **state) { { f_file_t file = f_file_t_initialize; file.size_write = path.used; - file.stream = stdout; + file.stream = F_type_input_d; will_return(__wrap_fwrite_unlocked, false); will_return(__wrap_fwrite_unlocked, file.size_write); diff --git a/level_3/fake/c/private-clean.c b/level_3/fake/c/private-clean.c index af99fd6..2681b01 100644 --- a/level_3/fake/c/private-clean.c +++ b/level_3/fake/c/private-clean.c @@ -60,7 +60,7 @@ extern "C" { if (!result) { // @todo in order to get this working, the recursive function that calls this needs to be rewritten with more flexibility or provide a higher-level equivalent function. - fll_print_format("Removed '%S'.%r", stdout, path, f_string_eol_s); + fll_print_format("Removed '%S'.%r", F_type_input_d, path, f_string_eol_s); } return result; -- 1.8.3.1