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;
- }
+ line_content[i][result > 0 ? result - 1 : 0] = 0;
} // or
state.status = F_none;
{
// Note: These files are required to have the same number of lines and each line should probably be at max 255 characters.
+ FILE *file_counts = data__file_open__named("counts", "extended_list", "combining_read");
+ FILE *file_matches = data__file_open__named("matches", "extended_list", "combining_read");
+ FILE *file_objects = data__file_open__named("objects", "extended_list", "combining_read");
FILE *file_strings = data__file_open__named("strings", "extended_list", "combining_read");
FILE *file_contents[] = {
data__file_open__named_at("contents", "extended_list", "combining_read", 2),
data__file_open__named_at("contents", "extended_list", "combining_read", 3),
data__file_open__named_at("contents", "extended_list", "combining_read", 4),
- data__file_open__named_at("contents", "extended_list", "combining_read", 5),
};
+ assert_non_null(file_counts);
+ assert_non_null(file_matches);
+ assert_non_null(file_objects);
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]);
+ const uint8_t sets_total = 5;
+
+ int counts = 0;
+ int matches = 0;
size_t max = 0;
- char *line_string = 0;
- char *line_content[] = {
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- };
ssize_t result = 0;
- const uint8_t total_content = 6;
- f_string_static_t buffer_string = f_string_static_t_initialize;
+ char *line_counts = 0;
+ char *line_matches = 0;
+ char *line_object = 0;
- f_state_t state = f_state_t_initialize;
f_range_t close = f_range_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 found_content = f_ranges_t_initialize;
f_ranges_t comments = f_ranges_t_initialize;
+
+ f_state_t state = f_state_t_initialize;
+ f_status_t status_object = F_okay;
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_string_dynamic_t set_delimit = f_string_dynamic_t_initialize;
+ f_string_dynamic_t set_result = f_string_dynamic_t_initialize;
+ f_string_dynamic_t set_strings = f_string_dynamic_t_initialize;
+
+ f_string_dynamic_t set_contents[] = {
+ macro_f_string_dynamic_t_initialize_2(0, 0),
+ macro_f_string_dynamic_t_initialize_2(0, 0),
+ macro_f_string_dynamic_t_initialize_2(0, 0),
+ macro_f_string_dynamic_t_initialize_2(0, 0),
+ macro_f_string_dynamic_t_initialize_2(0, 0),
+ };
+
+ {
+ const f_status_t status = data__file_load_buffer(file_strings, &set_strings);
+
+ if (F_status_is_error(status)) {
+ printf("[ -------> ] --- [00] Failure with data__file_load_buffer() for loading file strings, status=%u has error bit set.\n", status);
+ }
+
+ assert_true(F_status_is_error_not(status));
+ }
+
+ for (uint8_t i = 0; i < sets_total; ++i) {
+
+ const f_status_t status = data__file_load_buffer(file_contents[i], &set_contents[i]);
+
+ if (F_status_is_error(status)) {
+ printf("[ -------> ] --- [01] Failure with data__file_load_buffer() for loading file contents at %u, status=%u has error bit set.\n", i, status);
+ }
+
+ assert_true(F_status_is_error_not(state.status));
+ } // for
+
+ {
+ const f_status_t status = f_string_dynamic_append(set_strings, &set_delimit);
+
+ if (status != F_okay) {
+ printf("[ -------> ] --- [02] Failure with f_string_dynamic_append() for preparing delimit string, status=%u, expected=%u.\n", status, F_okay);
+ }
+
+ assert_int_equal(status, F_okay);
+ }
+
+ range.start = 0;
+ range.stop = set_strings.used - 1;
+
+ for (f_number_unsigned_t set = 0; set < sets_total; ++set) {
max = 255;
- result = getline(&line_string, &max, file_strings);
- if (result == -1) break;
+ result = getline(&line_object, &max, file_objects);
- buffer_string.string = line_string;
- buffer_string.used = (f_number_unsigned_t) result;
- buffer_string.size = buffer_string.used;
+ if (result < 0) {
+ printf("[ -------> ] --- [03] Failure with getline() for objects, with set %lu, result is negative.\n", set);
+ }
- for (uint8_t i = 0; i < total_content; ++i) {
+ assert_return_code(result, 0);
- max = 255;
+ // The newline is copied by getline(), and so remove that newline before comparing.
+ line_object[result ? result - 1 : 0] = 0;
- result = getline(&line_content[i], &max, file_contents[i]);
+ max = 255;
- // The newline is copied by getline(), and so remove that newline before comparing.
- if (result > 0) {
- line_content[i][result - 1] = 0;
- }
- } // or
+ result = getline(&line_matches, &max, file_matches);
+
+ if (result < 0) {
+ printf("[ -------> ] --- [04] Failure with getline() for matches, with set %lu, result is negative.\n", set);
+ }
+
+ assert_true(result >= 0);
+
+ matches = atoi(line_matches);
- state.status = F_none;
- range.start = 0;
- range.stop = buffer_string.used - 1;
found_object.start = 1;
found_object.stop = 0;
+ state.status = F_none;
- fl_fss_extended_list_object_read(buffer_string, &range, &found_object, &delimits, &state);
+ fl_fss_extended_list_object_read(set_strings, &range, &found_object, &delimits, &state);
- assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not);
+ if (matches) {
+
+ // When matches is 2, then this matches both object and content.
+ if (matches == 2) {
+ if (!(state.status == F_fss_found_object)) {
+ printf("[ -------> ] --- [05] Failure with fl_fss_extended_list_object_read(), with set %lu, matches=%d, status=%u, expected %u.\n", set, 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("[ -------> ] --- [06] Failure with fl_fss_extended_list_object_read(), with set %lu, matches=%d, status=%u, expected %u.\n", set, matches, state.status, F_fss_found_object_content_not);
+ }
+
+ assert_true(state.status == F_fss_found_object_content_not);
+ }
+ }
+ else {
+ if (!(state.status == F_fss_found_object_not)) {
+ printf("[ -------> ] --- [07] Failure with with fl_fss_extended_list_object_read(), set %lu, matches=%d, status=%u, expected %u.\n", set, matches, state.status, F_fss_found_object_not);
+ }
+
+ assert_true(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, &close, &delimits, &comments, &state);
+
+ // The Object had to be read before getting to the Content, so test it as well.
+ {
+ const f_status_t status = data__extract_from_source(set_strings, found_object, &set_result);
+
+ if (F_status_is_error(status)) {
+ printf("[ -------> ] --- [14] Failure with data__extract_from_source() for extract object, with set %lu, status=%u has error bit set.\n", set, status);
+ }
+
+ assert_true(F_status_is_error_not(status));
+ }
+
+ if (strcmp(set_result.string, line_object)) {
+ printf("[ -------> ] --- [09] Failure with set %lu, object strings do not match.\n", set);
+ }
+
+ assert_string_equal(set_result.string, line_object);
+
+ max = 255;
+
+ result = getline(&line_counts, &max, file_counts);
+
+ if (result < 0) {
+ printf("[ -------> ] --- [10] Failure with getline() for counts, with set %lu, result is negative.\n", set);
+ }
+
+ assert_true(result >= 0);
+
+ counts = atoi(line_counts);
+
+ fl_fss_extended_list_content_read(set_strings, &range, &found_content, &close, &delimits, &comments, &state);
+
+ if (!(state.status == F_fss_found_content || state.status == F_data_not)) {
+ printf("[ -------> ] --- [11] Failure with fl_fss_extended_list_content_read(), with set %lu, status=%u, expected %u, or %u.\n", set, state.status, F_fss_found_content, F_data_not);
+ }
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);
+ if (!found_content.used) {
+ printf("[ -------> ] --- [12] Failure with fl_fss_extended_list_content_read(), with set %lu, expected found_content.used (%lu) <> 0.\n", set, found_content.used);
}
- state.status = F_none;
+ assert_true(found_content.used);
- f_fss_apply_delimit(delimits, &delimit_string, &state);
- assert_int_equal(state.status, F_okay);
+ if (found_content.used != (f_number_unsigned_t) counts) {
+ printf("[ -------> ] --- [13] Failure with fl_fss_extended_list_content_read(), with set %lu, expected found_content.used (%lu) == %lu, found = '%s', expected = '%s'.\n", set, found_content.used, (f_number_unsigned_t) counts, set_result.string ? set_result.string : "", set_contents[set].string ? set_contents[set].string : "");
+ }
- {
- uint8_t i = 0;
+ assert_true(found_content.used == (f_number_unsigned_t) counts);
- for (; i < found.used; ++i) {
+ state.status = F_none;
- result_string.used = 0;
+ f_fss_apply_delimit(delimits, &set_delimit, &state);
- {
- 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);
- }
+ if (state.status != F_okay) {
+ printf("[ -------> ] --- [14] Failure with f_fss_apply_delimit(), with set %lu, status=%u, expected=%u.\n", set, state.status, F_okay);
+ }
- {
- const f_status_t status = f_string_dynamic_terminate_after(&result_string);
- assert_int_equal(status, F_okay);
- }
+ assert_int_equal(state.status, F_okay);
- assert_string_equal(result_string.string, line_content[i]);
- } // for
+ {
+ const f_status_t status = data__extract_from_source(set_delimit, found_content.array[0], &set_result);
- // 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);
+ if (F_status_is_error(status)) {
+ printf("[ -------> ] --- [15] Failure with data__extract_from_source() for extract set contents, with set %lu, status=%u has error bit set.\n", set, status);
}
+
+ assert_true(F_status_is_error_not(status));
+ }
+
+ if (strcmp(set_result.string, set_contents[set].string)) {
+ printf("[ -------> ] --- [16] Failure with set %lu, content strings do not match.\n", set);
}
+
+ assert_string_equal(set_result.string, set_contents[set].string);
}
else {
- assert_true(!found.used);
+ if (found_content.used) {
+ printf("[ -------> ] --- [17] Failure with set %lu, should not have any content, but match %lu.\n", set, found_content.used);
+ }
+
+ assert_true(!found_content.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 (delimits.array) free(delimits.array);
+ if (found_content.array) free(found_content.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
+ if (line_counts) free(line_counts);
+ if (line_matches) free(line_matches);
+ if (line_object) free(line_object);
+ if (set_result.string) free(set_result.string);
- 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;
+ delimits.array = 0;
+ delimits.used = 0;
+ delimits.size = 0;
+ found_content.array = 0;
+ found_content.used = 0;
+ found_content.size = 0;
+ line_counts = 0;
+ line_matches = 0;
+ line_object = 0;
quotes.array = 0;
quotes.used = 0;
quotes.size = 0;
+ set_result.string = 0;
+ set_result.used = 0;
+ set_result.size = 0;
} // for
- for (uint8_t i = 0; i < total_content; ++i) {
+ for (uint8_t i = 0; i < sets_total; ++i) {
if (file_contents[i]) fclose(file_contents[i]);
- if (line_content[i]) free(line_content[i]);
-
- line_content[i] = 0;
+ if (set_contents[i].string) free(set_contents[i].string);
} // for
+ if (line_counts) free(line_counts);
+ if (line_matches) free(line_matches);
+ if (line_object) free(line_object);
+ if (set_delimit.string) free(set_delimit.string);
+ if (set_result.string) free(set_result.string);
+ if (set_strings.string) free(set_strings.string);
+
+ if (file_counts) fclose(file_counts);
+ if (file_matches) fclose(file_matches);
+ if (file_objects) fclose(file_objects);
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 (delimits.array) free(delimits.array);
+ if (found_content.array) free(found_content.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);
}
}