// 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);
line_content[i] = 0;
} // for
+ line_matches = 0;
line_string = 0;
result_string.string = 0;
result_string.used = 0;
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);
}
}
+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