From 931b29e35c2622ea3f2234eaf86eafbaed8ee955 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 30 Jan 2024 22:08:35 -0600 Subject: [PATCH] Progress: Add Basic List and Extended List unit tests for fl_fss. This adds the "works" unit tests for Basic List and Extended List. --- .../tests/contents/extended_list-all_read-0.txt | 1 + .../tests/contents/extended_list-all_read-1.txt | 0 .../tests/contents/extended_list-all_read-10.txt | 2 + .../tests/contents/extended_list-all_read-11.txt | 1 + .../tests/contents/extended_list-all_read-12.txt | 1 + .../tests/contents/extended_list-all_read-2.txt | 2 + .../tests/contents/extended_list-all_read-3.txt | 5 + .../tests/contents/extended_list-all_read-4.txt | 2 + .../tests/contents/extended_list-all_read-5.txt | 4 + .../tests/contents/extended_list-all_read-6.txt | 1 + .../tests/contents/extended_list-all_read-7.txt | 4 + .../tests/contents/extended_list-all_read-8.txt | 2 + .../tests/contents/extended_list-all_read-9.txt | 3 + .../data/tests/objects/extended_list-all_read.txt | 13 ++ .../data/tests/strings/extended_list-all_read.txt | 56 ++++++ .../unit/c/test-fss-basic_list_content_read.c | 212 +++++++++++++++++++++ .../unit/c/test-fss-basic_list_content_read.h | 7 + .../unit/c/test-fss-extended_list_content_read.c | 212 +++++++++++++++++++++ .../unit/c/test-fss-extended_list_content_read.h | 7 + .../unit/c/test-fss-extended_list_object_read.c | 111 +++++++++++ .../unit/c/test-fss-extended_list_object_read.h | 7 + level_1/fl_fss/tests/unit/c/test-fss.c | 5 +- 22 files changed, 657 insertions(+), 1 deletion(-) create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-0.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-1.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-10.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-11.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-12.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-2.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-3.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-4.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-5.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-6.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-7.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-8.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended_list-all_read-9.txt create mode 100644 level_1/fl_fss/data/tests/objects/extended_list-all_read.txt create mode 100644 level_1/fl_fss/data/tests/strings/extended_list-all_read.txt diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-0.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-0.txt new file mode 100644 index 0000000..51c850e --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-0.txt @@ -0,0 +1 @@ + content. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-1.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-1.txt new file mode 100644 index 0000000..e69de29 diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-10.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-10.txt new file mode 100644 index 0000000..8dbc0e5 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-10.txt @@ -0,0 +1,2 @@ + Has UTF-8 characters. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-11.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-11.txt new file mode 100644 index 0000000..5bbb0cc --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-11.txt @@ -0,0 +1 @@ + Has UTF-8: привет мир diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-12.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-12.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-12.txt @@ -0,0 +1 @@ + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-2.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-2.txt new file mode 100644 index 0000000..fd49844 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-2.txt @@ -0,0 +1,2 @@ + content as well. + With multiple lines. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-3.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-3.txt new file mode 100644 index 0000000..d7b62b5 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-3.txt @@ -0,0 +1,5 @@ +Not tabbed over. + + +Has empty lines before and after. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-4.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-4.txt new file mode 100644 index 0000000..91ad432 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-4.txt @@ -0,0 +1,2 @@ +This{ is not a list. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-5.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-5.txt new file mode 100644 index 0000000..d730a3b --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-5.txt @@ -0,0 +1,4 @@ + + just\{ + Add a slash. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-6.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-6.txt new file mode 100644 index 0000000..9976c8b --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-6.txt @@ -0,0 +1 @@ + a slash. diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-7.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-7.txt new file mode 100644 index 0000000..fc2f7ac --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-7.txt @@ -0,0 +1,4 @@ + slashes. +Has Slashes but is not a list\\\{ + This is part of the previous one. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-8.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-8.txt new file mode 100644 index 0000000..686da75 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-8.txt @@ -0,0 +1,2 @@ + The object name is an empty string. + diff --git a/level_1/fl_fss/data/tests/contents/extended_list-all_read-9.txt b/level_1/fl_fss/data/tests/contents/extended_list-all_read-9.txt new file mode 100644 index 0000000..233a300 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended_list-all_read-9.txt @@ -0,0 +1,3 @@ + Quotes aren't supported here, so this is not an empty object. +} + diff --git a/level_1/fl_fss/data/tests/objects/extended_list-all_read.txt b/level_1/fl_fss/data/tests/objects/extended_list-all_read.txt new file mode 100644 index 0000000..022a5a7 --- /dev/null +++ b/level_1/fl_fss/data/tests/objects/extended_list-all_read.txt @@ -0,0 +1,13 @@ +first +empty +third +fourth +spaces around +To "disable" +Has\ +Also Has\\ + +"" +привет +Content also' +Comments diff --git a/level_1/fl_fss/data/tests/strings/extended_list-all_read.txt b/level_1/fl_fss/data/tests/strings/extended_list-all_read.txt new file mode 100644 index 0000000..65fa1d7 --- /dev/null +++ b/level_1/fl_fss/data/tests/strings/extended_list-all_read.txt @@ -0,0 +1,56 @@ +first{ + content. +} +empty{ +} +third{ + content as well. + With multiple lines. +} +fourth{ +Not tabbed over. + + +Has empty lines before and after. + +} + spaces around { +This{ is not a list. + +} +To "disable"{ + + just\{ + Add a slash. + +} +Has\\{ + a slash. +} +Also Has\\\\{ + slashes. +Has Slashes but is not a list\\\{ + This is part of the previous one. + +} +{ + The object name is an empty string. + +} +""{ + Quotes aren't supported here, so this is not an empty object. +\} + +} +привет{ + Has UTF-8 characters. + +} +Content also'{ + Has UTF-8: привет мир +} +Comments{ +# Are + #### ignored. +} +# and after. diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c index 191e606..e0f6981 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c @@ -119,6 +119,218 @@ void test__fl_fss_basic_list_content_read__returns_data_not(void **void_state) { } } +void test__fl_fss_basic_list_content_read__works(void **void_state) { + + { + // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. + FILE *file_strings = data__file_open__named__all_read("strings", "basic_list"); + + FILE *file_contents[] = { + data__file_open__named_at__all_read("contents", "basic_list", 0), + data__file_open__named_at__all_read("contents", "basic_list", 1), + data__file_open__named_at__all_read("contents", "basic_list", 2), + data__file_open__named_at__all_read("contents", "basic_list", 3), + data__file_open__named_at__all_read("contents", "basic_list", 4), + data__file_open__named_at__all_read("contents", "basic_list", 5), + data__file_open__named_at__all_read("contents", "basic_list", 6), + data__file_open__named_at__all_read("contents", "basic_list", 7), + data__file_open__named_at__all_read("contents", "basic_list", 8), + data__file_open__named_at__all_read("contents", "basic_list", 9), + data__file_open__named_at__all_read("contents", "basic_list", 10), + data__file_open__named_at__all_read("contents", "basic_list", 11), + }; + + assert_non_null(file_strings); + assert_non_null(file_contents[0]); + assert_non_null(file_contents[1]); + assert_non_null(file_contents[2]); + assert_non_null(file_contents[3]); + assert_non_null(file_contents[4]); + assert_non_null(file_contents[5]); + assert_non_null(file_contents[6]); + assert_non_null(file_contents[7]); + assert_non_null(file_contents[8]); + assert_non_null(file_contents[9]); + assert_non_null(file_contents[10]); + assert_non_null(file_contents[11]); + + size_t max = 0; + char *line_string = 0; + char *line_content[] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + }; + ssize_t result = 0; + const uint8_t total_content = 12; + + f_string_static_t buffer_string = f_string_static_t_initialize; + + f_state_t state = f_state_t_initialize; + f_range_t range = f_range_t_initialize; + f_range_t found_object = f_range_t_initialize; + f_ranges_t found = f_ranges_t_initialize; + f_ranges_t comments = f_ranges_t_initialize; + f_uint8s_t quotes = f_uint8s_t_initialize; + f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize; + f_string_dynamic_t result_string = f_string_dynamic_t_initialize; + f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize; + f_status_t status_object = F_okay; + + for (;;) { + + max = 255; + + result = getline(&line_string, &max, file_strings); + if (result == -1) break; + + buffer_string.string = line_string; + buffer_string.used = (f_number_unsigned_t) result; + buffer_string.size = buffer_string.used; + + for (uint8_t i = 0; i < total_content; ++i) { + + max = 255; + + result = getline(&line_content[i], &max, file_contents[i]); + + // The newline is copied by getline(), and so remove that newline before comparing. + if (result > 0) { + line_content[i][result - 1] = 0; + } + else { + line_content[i][0] = 0; + } + } // or + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found_object.start = 1; + found_object.stop = 0; + + fl_fss_basic_list_object_read(buffer_string, &range, &found_object, &delimits, &state); + + assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not); + + status_object = state.status; + state.status = F_none; + + if (status_object == F_fss_found_object) { + fl_fss_basic_list_content_read(buffer_string, &range, &found, &delimits, &comments, &state); + + assert_true(state.status == F_fss_found_content || state.status == F_data_not); + + if (state.status == F_fss_found_content) { + assert_true(found.used); + assert_true(found.used <= (f_number_unsigned_t) total_content); + + { + const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); + assert_int_equal(status, F_okay); + } + + state.status = F_none; + + f_fss_apply_delimit(delimits, &delimit_string, &state); + assert_int_equal(state.status, F_okay); + + { + uint8_t i = 0; + + for (; i < found.used; ++i) { + + result_string.used = 0; + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found.array[i], &result_string); + assert_true(status == F_okay || status == F_data_not_eos); + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&result_string); + assert_int_equal(status, F_okay); + } + + assert_string_equal(result_string.string, line_content[i]); + } // for + + // All remaining positions in the file need to be a zero length string. + for (; i < total_content; ++i) { + assert_int_equal(line_content[i][0], 0); + } + } + } + else { + assert_true(!found.used); + } + } + + if (line_string) free(line_string); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + if (delimits.array) free(delimits.array); + if (found.array) free(found.array); + if (comments.array) free(comments.array); + if (quotes.array) free(quotes.array); + + for (uint8_t i = 0; i < total_content; ++i) { + + if (line_content[i]) free(line_content[i]); + + line_content[i] = 0; + } // for + + line_string = 0; + result_string.string = 0; + result_string.used = 0; + result_string.size = 0; + delimit_string.string = 0; + delimit_string.used = 0; + delimit_string.size = 0; + delimits.array = 0; + delimits.used = 0; + delimits.size = 0; + found.array = 0; + found.used = 0; + found.size = 0; + comments.array = 0; + comments.used = 0; + comments.size = 0; + quotes.array = 0; + quotes.used = 0; + quotes.size = 0; + } // for + + for (uint8_t i = 0; i < total_content; ++i) { + + if (file_contents[i]) fclose(file_contents[i]); + if (line_content[i]) free(line_content[i]); + + line_content[i] = 0; + } // for + + if (file_strings) fclose(file_strings); + + if (delimits.array) free(delimits.array); + if (found.array) free(found.array); + if (comments.array) free(comments.array); + if (quotes.array) free(quotes.array); + if (line_string) free(line_string); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.h b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.h index 2da85e6..4b4d99c 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_basic_list_content_read__parameter_checking(void **stat */ extern void test__fl_fss_basic_list_content_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_basic_list_content_read() + */ +extern void test__fl_fss_basic_list_content_read__works(void **state); + #endif // _TEST__FL_fss_basic_list_content_read_list_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c index 8665371..40e3c44 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c @@ -151,6 +151,218 @@ void test__fl_fss_extended_list_content_read__returns_data_not(void **void_state } } +void test__fl_fss_extended_list_content_read__works(void **void_state) { + + { + // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. + FILE *file_strings = data__file_open__named__all_read("strings", "extended_list"); + + FILE *file_contents[] = { + data__file_open__named_at__all_read("contents", "extended_list", 0), + data__file_open__named_at__all_read("contents", "extended_list", 1), + data__file_open__named_at__all_read("contents", "extended_list", 2), + data__file_open__named_at__all_read("contents", "extended_list", 3), + data__file_open__named_at__all_read("contents", "extended_list", 4), + data__file_open__named_at__all_read("contents", "extended_list", 5), + data__file_open__named_at__all_read("contents", "extended_list", 6), + data__file_open__named_at__all_read("contents", "extended_list", 7), + data__file_open__named_at__all_read("contents", "extended_list", 8), + data__file_open__named_at__all_read("contents", "extended_list", 9), + data__file_open__named_at__all_read("contents", "extended_list", 10), + data__file_open__named_at__all_read("contents", "extended_list", 11), + }; + + assert_non_null(file_strings); + assert_non_null(file_contents[0]); + assert_non_null(file_contents[1]); + assert_non_null(file_contents[2]); + assert_non_null(file_contents[3]); + assert_non_null(file_contents[4]); + assert_non_null(file_contents[5]); + assert_non_null(file_contents[6]); + assert_non_null(file_contents[7]); + assert_non_null(file_contents[8]); + assert_non_null(file_contents[9]); + assert_non_null(file_contents[10]); + assert_non_null(file_contents[11]); + + size_t max = 0; + char *line_string = 0; + char *line_content[] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + }; + ssize_t result = 0; + const uint8_t total_content = 12; + + f_string_static_t buffer_string = f_string_static_t_initialize; + + f_state_t state = f_state_t_initialize; + f_range_t range = f_range_t_initialize; + f_range_t found_object = f_range_t_initialize; + f_ranges_t found = f_ranges_t_initialize; + f_ranges_t comments = f_ranges_t_initialize; + f_uint8s_t quotes = f_uint8s_t_initialize; + f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize; + f_string_dynamic_t result_string = f_string_dynamic_t_initialize; + f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize; + f_status_t status_object = F_okay; + + for (;;) { + + max = 255; + + result = getline(&line_string, &max, file_strings); + if (result == -1) break; + + buffer_string.string = line_string; + buffer_string.used = (f_number_unsigned_t) result; + buffer_string.size = buffer_string.used; + + for (uint8_t i = 0; i < total_content; ++i) { + + max = 255; + + result = getline(&line_content[i], &max, file_contents[i]); + + // The newline is copied by getline(), and so remove that newline before comparing. + if (result > 0) { + line_content[i][result - 1] = 0; + } + else { + line_content[i][0] = 0; + } + } // or + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found_object.start = 1; + found_object.stop = 0; + + fl_fss_extended_list_object_read(buffer_string, &range, &found_object, &delimits, &state); + + assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not); + + status_object = state.status; + state.status = F_none; + + if (status_object == F_fss_found_object) { + fl_fss_extended_list_content_read(buffer_string, &range, &found, &delimits, &comments, &state); + + assert_true(state.status == F_fss_found_content || state.status == F_data_not); + + if (state.status == F_fss_found_content) { + assert_true(found.used); + assert_true(found.used <= (f_number_unsigned_t) total_content); + + { + const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); + assert_int_equal(status, F_okay); + } + + state.status = F_none; + + f_fss_apply_delimit(delimits, &delimit_string, &state); + assert_int_equal(state.status, F_okay); + + { + uint8_t i = 0; + + for (; i < found.used; ++i) { + + result_string.used = 0; + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found.array[i], &result_string); + assert_true(status == F_okay || status == F_data_not_eos); + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&result_string); + assert_int_equal(status, F_okay); + } + + assert_string_equal(result_string.string, line_content[i]); + } // for + + // All remaining positions in the file need to be a zero length string. + for (; i < total_content; ++i) { + assert_int_equal(line_content[i][0], 0); + } + } + } + else { + assert_true(!found.used); + } + } + + if (line_string) free(line_string); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + if (delimits.array) free(delimits.array); + if (found.array) free(found.array); + if (comments.array) free(comments.array); + if (quotes.array) free(quotes.array); + + for (uint8_t i = 0; i < total_content; ++i) { + + if (line_content[i]) free(line_content[i]); + + line_content[i] = 0; + } // for + + line_string = 0; + result_string.string = 0; + result_string.used = 0; + result_string.size = 0; + delimit_string.string = 0; + delimit_string.used = 0; + delimit_string.size = 0; + delimits.array = 0; + delimits.used = 0; + delimits.size = 0; + found.array = 0; + found.used = 0; + found.size = 0; + comments.array = 0; + comments.used = 0; + comments.size = 0; + quotes.array = 0; + quotes.used = 0; + quotes.size = 0; + } // for + + for (uint8_t i = 0; i < total_content; ++i) { + + if (file_contents[i]) fclose(file_contents[i]); + if (line_content[i]) free(line_content[i]); + + line_content[i] = 0; + } // for + + if (file_strings) fclose(file_strings); + + if (delimits.array) free(delimits.array); + if (found.array) free(found.array); + if (comments.array) free(comments.array); + if (quotes.array) free(quotes.array); + if (line_string) free(line_string); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.h index 8f348ab..7e689cc 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_extended_list_content_read__parameter_checking(void **s */ extern void test__fl_fss_extended_list_content_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_extended_list_content_read() + */ +extern void test__fl_fss_extended_list_content_read__works(void **state); + #endif // _TEST__FL_fss_extended_list_content_read_list_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c index 5dd75ca..687ebf6 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c @@ -85,6 +85,117 @@ void test__fl_fss_extended_list_object_read__returns_data_not(void **void_state) } } +void test__fl_fss_extended_list_object_read__works(void **void_state) { + + { + FILE *file_strings = data__file_open__named__all_read("strings", "extended_list"); + FILE *file_objects = data__file_open__named__all_read("objects", "extended_list"); + + assert_non_null(file_strings); + assert_non_null(file_objects); + + size_t max = 0; + char *line_string = 0; + char *line_object = 0; + ssize_t result = 0; + + f_string_static_t buffer_string = f_string_static_t_initialize; + + f_state_t state = f_state_t_initialize; + f_range_t range = f_range_t_initialize; + f_range_t found = f_range_t_initialize; + f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize; + f_string_dynamic_t result_string = f_string_dynamic_t_initialize; + f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize; + + for (int line = 1;; ++line) { + + max = 255; + + result = getline(&line_string, &max, file_strings); + if (result == -1) break; + + buffer_string.string = line_string; + buffer_string.used = (f_number_unsigned_t) result; + buffer_string.size = buffer_string.used; + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found.start = 1; + found.stop = 0; + + fl_fss_extended_list_object_read(buffer_string, &range, &found, &delimits, &state); + + assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not); + + if (state.status == F_fss_found_object) { + max = 255; + + result = getline(&line_object, &max, file_objects); + assert_return_code(result, 0); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_object[result - 1] = 0; + + if (found.start <= found.stop) { + { + const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); + assert_int_equal(status, F_okay); + } + + state.status = F_none; + + f_fss_apply_delimit(delimits, &delimit_string, &state); + assert_int_equal(state.status, F_okay); + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found, &result_string); + assert_true(status == F_okay || status == F_data_not_eos); + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&result_string); + assert_int_equal(status, F_okay); + } + + assert_string_equal(result_string.string, line_object); + } + else { + assert_int_equal(line_object[0], 0); + } + } + + if (line_string) free(line_string); + if (line_object) free(line_object); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + if (delimits.array) free(delimits.array); + + line_string = 0; + line_object = 0; + result_string.string = 0; + result_string.used = 0; + result_string.size = 0; + delimit_string.string = 0; + delimit_string.used = 0; + delimit_string.size = 0; + delimits.array = 0; + delimits.used = 0; + delimits.size = 0; + } // for + + if (file_strings) fclose(file_strings); + if (file_objects) fclose(file_objects); + + if (delimits.array) free(delimits.array); + if (line_string) free(line_string); + if (line_object) free(line_object); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.h index 6ca4410..bdd2561 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_extended_list_object_read__parameter_checking(void **st */ extern void test__fl_fss_extended_list_object_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_extended_list_object_read() + */ +extern void test__fl_fss_extended_list_object_read__works(void **state); + #endif // _TEST__FL_fss_extended_list_object_read_list_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss.c b/level_1/fl_fss/tests/unit/c/test-fss.c index a220c8e..f793a4d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -32,7 +32,7 @@ int main(void) { cmocka_unit_test(test__fl_fss_basic_list_object_read__returns_data_not), cmocka_unit_test(test__fl_fss_basic_list_object_write__returns_data_not), - //cmocka_unit_test(test__fl_fss_basic_list_content_read__works), + cmocka_unit_test(test__fl_fss_basic_list_content_read__works), cmocka_unit_test(test__fl_fss_basic_list_object_read__works), cmocka_unit_test(test__fl_fss_embedded_list_content_read__returns_data_not), @@ -53,6 +53,9 @@ int main(void) { cmocka_unit_test(test__fl_fss_extended_list_object_read__returns_data_not), cmocka_unit_test(test__fl_fss_extended_list_object_write__returns_data_not), + cmocka_unit_test(test__fl_fss_extended_list_content_read__works), + cmocka_unit_test(test__fl_fss_extended_list_object_read__works), + cmocka_unit_test(test__fl_fss_payload_header_map__returns_data_not), #ifndef _di_level_0_parameter_checking_ -- 1.8.3.1