From: Kevin Day Date: Sat, 12 Sep 2026 22:00:42 +0000 (-0500) Subject: Progress: Add extended content and object combining tests. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c66b62d1b2c697085867c0037489c12eeff1bca4;p=fll Progress: Add extended content and object combining tests. --- diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-0.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-0.txt new file mode 100644 index 000000000..fd91deecc --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-0.txt @@ -0,0 +1,6 @@ +valid. +and + + +is +is diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-1.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-1.txt new file mode 100644 index 000000000..e989d7c42 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-1.txt @@ -0,0 +1,6 @@ + +does + + +valid. +valid diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-2.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-2.txt new file mode 100644 index 000000000..68f43c1c0 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-2.txt @@ -0,0 +1,6 @@ + +not + + + +with diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-3.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-3.txt new file mode 100644 index 000000000..551dabd95 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-3.txt @@ -0,0 +1,6 @@ + +have + + + +two diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-4.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-4.txt new file mode 100644 index 000000000..2af451a4b --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-4.txt @@ -0,0 +1,6 @@ + +embedded + + + +combiners. diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-5.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-5.txt new file mode 100644 index 000000000..a99c891eb --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-5.txt @@ -0,0 +1,6 @@ + +new + + + + diff --git a/level_1/fl_fss/data/tests/contents/extended-combining_read-6.txt b/level_1/fl_fss/data/tests/contents/extended-combining_read-6.txt new file mode 100644 index 000000000..74dddee11 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-combining_read-6.txt @@ -0,0 +1,6 @@ + +line. + + + + diff --git a/level_1/fl_fss/data/tests/matches/extended-combining_read.txt b/level_1/fl_fss/data/tests/matches/extended-combining_read.txt new file mode 100644 index 000000000..87000e719 --- /dev/null +++ b/level_1/fl_fss/data/tests/matches/extended-combining_read.txt @@ -0,0 +1,6 @@ +2 +2 +1 +1 +2 +2 diff --git a/level_1/fl_fss/data/tests/objects/extended-combining_read.txt b/level_1/fl_fss/data/tests/objects/extended-combining_read.txt new file mode 100644 index 000000000..7ed2a8697 --- /dev/null +++ b/level_1/fl_fss/data/tests/objects/extended-combining_read.txt @@ -0,0 +1,6 @@ +first +is_second + ́ +fourth ͜no_space +fifth +sixtẖ̚ diff --git a/level_1/fl_fss/data/tests/strings/extended-combining_read.txt b/level_1/fl_fss/data/tests/strings/extended-combining_read.txt new file mode 100644 index 000000000..d2132bf51 --- /dev/null +++ b/level_1/fl_fss/data/tests/strings/extended-combining_read.txt @@ -0,0 +1,6 @@ +first valid. +is_second and does not have embedded new line. + ́ +fourth ͜no_space +fifth is valid. +sixtẖ̚ is valid with two combiners. diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c index af0b52226..8cf931320 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c @@ -270,13 +270,291 @@ void test__fl_fss_extended_content_read__works(void **void_state) { // 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); + } // for + } + } + 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 (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; + 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 (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); + } +} + +void test__fl_fss_extended_content_read__works_using_combining(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_matches = data__file_open__named("matches", "extended", "combining_read"); + FILE *file_strings = data__file_open__named("strings", "extended", "combining_read"); + + FILE *file_contents[] = { + data__file_open__named_at("contents", "extended", "combining_read", 0), + data__file_open__named_at("contents", "extended", "combining_read", 1), + data__file_open__named_at("contents", "extended", "combining_read", 2), + data__file_open__named_at("contents", "extended", "combining_read", 3), + data__file_open__named_at("contents", "extended", "combining_read", 4), + data__file_open__named_at("contents", "extended", "combining_read", 5), + data__file_open__named_at("contents", "extended", "combining_read", 6), + }; + + assert_non_null(file_matches); + 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]); + + int matches = 0; + size_t max = 0; + char *line_string = 0; + char *line_content[] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + }; + char *line_matches = 0; + ssize_t result = 0; + const uint8_t total_content = 7; + + 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; + uint8_t quote = 0; + 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 (f_number_unsigned_t line = 0; ; ++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; + + max = 255; + + result = getline(&line_matches, &max, file_matches); + if (result == -1) break; + + matches = atoi(line_matches); + + for (uint8_t i = 0; i < total_content; ++i) { + + max = 255; + + result = getline(&line_content[i], &max, file_contents[i]); + + if (result == -1) { + printf("[ -------> ] --- [00] Failure loading line line %lu for file './data/tests/strings/extended-combining_read-%d.txt' at %d, result = %lu.\n", line, i, i, result); + } + + assert_return_code(result, 0); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_content[i][result - 1] = 0; + } // for + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found_object.start = 1; + found_object.stop = 0; + + fl_fss_extended_object_read(buffer_string, &range, &found_object, "e, &delimits, &state); + + if (matches) { + // When matches is 2, then this matches both object and content. + if (matches == 2) { + if (!(state.status == F_fss_found_object)) { + printf("[ -------> ] --- [01] Failure with line %lu, matches=%d, status=%u, expected %u.\n", line, matches, state.status, F_fss_found_object); + } + + assert_true(state.status == F_fss_found_object); + } + + // When matches is 1, then this matches only object. + else { + if (!(state.status == F_fss_found_object_content_not)) { + printf("[ -------> ] --- [02] Failure with line %lu, matches=%d, status=%u, expected %u.\n", line, matches, state.status, F_fss_found_object_content_not); } + + assert_true(state.status == F_fss_found_object_content_not); + } + } + else { + + // This is currently not supported. + printf("[ -------> ] --- [03] Failure line %lu matches of 0 is not supported.\n", line); + assert_true(F_false); + } + + status_object = state.status; + state.status = F_none; + + fl_fss_extended_content_read(buffer_string, &range, &found, "es, &delimits, &state); + + if (status_object == F_fss_found_object) { + if (state.status != F_fss_found_content) { + printf("[ -------> ] --- [04] Failure with fl_fss_extended_content_read() line %lu status=%u, expected %u.\n", line, state.status, F_fss_found_content); + } + + assert_int_equal(state.status, F_fss_found_content); + } + else { + if (state.status != F_data_not) { + printf("[ -------> ] --- [05] Failure with fl_fss_extended_content_read() line %lu status=%u, expected %u.\n", line, state.status, F_data_not); + } + + assert_int_equal(state.status, F_data_not); + } + + if (state.status == F_fss_found_content) { + if (!found.used) { + printf("[ -------> ] --- [06] Failure with fl_fss_extended_content_read() line %lu got F_fss_found_content status=%u, expected found.used to be > 0.\n", line, state.status); + } + + assert_true(found.used); + + if (!(found.used <= (f_number_unsigned_t) total_content)) { + printf("[ -------> ] --- [07] Failure with fl_fss_extended_content_read() line %lu got F_fss_found_content status=%u, expected found.used (%lu) should be <= total_content (%lu).\n", line, state.status, found.used, (f_number_unsigned_t) total_content); + } + + assert_true(found.used <= (f_number_unsigned_t) total_content); + + { + const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); + + if (status != F_okay) { + printf("[ -------> ] --- [08] Failure with f_string_dynamic_append() line %lu, got status=%u, expected %u.\n", line, status, F_okay); + } + + assert_int_equal(status, F_okay); + } + + state.status = F_none; + + f_fss_apply_delimit(delimits, &delimit_string, &state); + + if (state.status != F_okay) { + printf("[ -------> ] --- [09] Failure with f_fss_apply_delimit() line %lu, got status=%u, expected %u.\n", line, state.status, F_okay); + } + + 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); + + if (!(status == F_okay || status == F_data_not_eos)) { + printf("[ -------> ] --- [10] Failure with f_string_dynamic_partial_append_nulless() line %lu and found[%u], got status=%u, expected either %u or %u.\n", line, i, status, F_okay, F_data_not_eos); + } + + assert_true(status == F_okay || status == F_data_not_eos); + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&result_string); + + if (status != F_okay) { + printf("[ -------> ] --- [11] Failure with f_string_dynamic_terminate_after() line %lu and found[%u], got status=%u, expected %u.\n", line, i, status, F_okay); + } + + assert_int_equal(status, F_okay); + } + + if (strcmp(result_string.string, line_content[i])) { + printf("[ -------> ] --- [12] Failure with f_string_dynamic_terminate_after() line %lu and found[%u], strings do not match.\n", line, i); + } + + 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) { + + if (line_content[i][0]) { + printf("[ -------> ] --- [13] Failure line %lu line_content[%u][0] should be 0 but got %u.\n", line, i, line_content[i][0]); + } + + assert_int_equal(line_content[i][0], 0); + } // for } } else { assert_true(!found.used); } + if (line_matches) free(line_matches); if (line_string) free(line_string); if (result_string.string) free(result_string.string); if (delimit_string.string) free(delimit_string.string); @@ -291,6 +569,7 @@ void test__fl_fss_extended_content_read__works(void **void_state) { line_content[i] = 0; } // for + line_matches = 0; line_string = 0; result_string.string = 0; result_string.used = 0; @@ -317,11 +596,13 @@ void test__fl_fss_extended_content_read__works(void **void_state) { line_content[i] = 0; } // for + if (file_matches) fclose(file_matches); if (file_strings) fclose(file_strings); if (delimits.array) free(delimits.array); if (found.array) free(found.array); if (quotes.array) free(quotes.array); + if (line_matches) free(line_matches); if (line_string) free(line_string); if (result_string.string) free(result_string.string); if (delimit_string.string) free(delimit_string.string); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h index 7b545bc21..54db05d31 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h @@ -31,4 +31,11 @@ extern void test__fl_fss_extended_content_read__returns_data_not(void **state); */ extern void test__fl_fss_extended_content_read__works(void **state); +/** + * Test that the function works when using combining characters. + * + * @see fl_fss_extended_content_read() + */ +extern void test__fl_fss_extended_content_read__works_using_combining(void **state); + #endif // _TEST__FL_fss_extended_content_read_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c index b91286a34..7f0519207 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c @@ -257,6 +257,186 @@ void test__fl_fss_extended_object_read__works(void **void_state) { } } +void test__fl_fss_extended_object_read__works_using_combining(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_matches = data__file_open__named("matches", "extended", "combining_read"); + FILE *file_strings = data__file_open__named("strings", "extended", "combining_read"); + FILE *file_objects = data__file_open__named("objects", "extended", "combining_read"); + + assert_non_null(file_matches); + assert_non_null(file_strings); + assert_non_null(file_objects); + + int matches = 0; + size_t max = 0; + char *line_matches = 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; + uint8_t quote = 0; + 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 (f_number_unsigned_t line = 0; ; ++line) { + + max = 255; + + result = getline(&line_matches, &max, file_matches); + if (result == -1) break; + + matches = atoi(line_matches); + + 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; + + max = 255; + + result = getline(&line_object, &max, file_objects); + + if (result == -1) { + printf("[ -------> ] --- [00] Failure loading line line %lu for file './data/tests/strings/extended-combining_read.txt', result = %lu.\n", line, result); + } + + assert_return_code(result, 0); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_object[result - 1] = 0; + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found.start = 1; + found.stop = 0; + + fl_fss_extended_object_read(buffer_string, &range, &found, "e, &delimits, &state); + + if (matches) { + // When matches is 2, then this matches both object and content. + if (matches == 2) { + if (!(state.status == F_fss_found_object)) { + printf("[ -------> ] --- [01] Failure with line %lu '%s', matches=%d, status=%u.\n", line, line_object, matches, state.status); + } + + assert_true(state.status == F_fss_found_object); + + if (!(found.start <= found.stop)) { + printf("[ -------> ] --- [02] Failure with line %lu '%s', matches=%d, found=(%lu, %lu).\n", line, line_object, matches, found.start, found.stop); + } + + assert_true(found.start <= found.stop); + } + + // When matches is 1, then this matches only object. + else { + if (!(state.status == F_fss_found_object_content_not)) { + printf("[ -------> ] --- [03] Failure with line %lu '%s', matches=%d, status=%u.\n", line, line_object, matches, state.status); + } + + assert_true(state.status == F_fss_found_object_content_not); + } + } + else { + + // This is currently not supported. + printf("[ -------> ] --- [04] Failure line %lu matches of 0 is not supported.\n", line); + assert_true(F_false); + } + + { + const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string); + + if (!(status == F_okay || status == F_data_not_eos)) { + printf("[ -------> ] --- [05] Failure with fl_fss_extended_object_read() line %lu, got status=%u, expected either %u or %u.\n", line, status, F_okay, F_data_not_eos); + } + + assert_int_equal(status, F_okay); + } + + state.status = F_none; + + f_fss_apply_delimit(delimits, &delimit_string, &state); + + if (state.status != F_okay) { + printf("[ -------> ] --- [06] Failure with f_fss_apply_delimit() line %lu, got status=%u, expected %u.\n", line, state.status, F_okay); + } + + assert_int_equal(state.status, F_okay); + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found, &result_string); + + if (!(status == F_okay || status == F_data_not_eos)) { + printf("[ -------> ] --- [07] Failure with f_string_dynamic_partial_append_nulless() line %lu, got status=%u, expected either %u or %u.\n", line, status, F_okay, F_data_not_eos); + } + + assert_true(status == F_okay || status == F_data_not_eos); + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&result_string); + + if (status != F_okay) { + printf("[ -------> ] --- [08] Failure with f_string_dynamic_terminate_after() line %lu, got status=%u, expected %u.\n", line, status, F_okay); + } + + assert_int_equal(status, F_okay); + } + + if (strcmp(result_string.string, line_object)) { + printf("[ -------> ] --- [09] Failure with f_string_dynamic_terminate_after() line %lu, strings do not match.\n", line); + } + + assert_string_equal(result_string.string, line_object); + + if (line_matches) free(line_matches); + 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_matches = 0; + 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_matches) fclose(file_matches); + if (file_strings) fclose(file_strings); + if (file_objects) fclose(file_objects); + + if (delimits.array) free(delimits.array); + if (line_matches) free(line_matches);\ + 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_object_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h index e5b08836b..b99676e37 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h @@ -31,4 +31,11 @@ extern void test__fl_fss_extended_object_read__returns_data_not(void **state); */ extern void test__fl_fss_extended_object_read__works(void **state); +/** + * Test that the function works when using combining characters. + * + * @see fl_fss_extended_object_read() + */ +extern void test__fl_fss_extended_object_read__works_using_combining(void **state); + #endif // _TEST__FL_fss_extended_object_read_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 c48cf3059..fffdb5c71 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -51,7 +51,9 @@ int main(void) { cmocka_unit_test(test__fl_fss_extended_object_write__returns_data_not), cmocka_unit_test(test__fl_fss_extended_content_read__works), + cmocka_unit_test(test__fl_fss_extended_content_read__works_using_combining), cmocka_unit_test(test__fl_fss_extended_object_read__works), + cmocka_unit_test(test__fl_fss_extended_object_read__works_using_combining), cmocka_unit_test(test__fl_fss_extended_list_content_read__returns_data_not), cmocka_unit_test(test__fl_fss_extended_list_content_write__returns_data_not),