From 592e72c69acf009c59a03b67195863bf1b97e704 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 2 Mar 2024 11:36:45 -0600 Subject: [PATCH] Progress: Add string unit tests for fl_fss_payload_header_map(), and reduce redundancy in numbers. This adds unit tests for the string abstruse type. The numbers tests are all almost identical. Abstract their design out into a helper function and a callback. The string tests will likely need similar helper functions as the number tests. --- level_1/fl_fss/data/build/settings-tests | 3 +- .../headers/payload-join-abstruse_string-0.txt | 6 + .../headers/payload-join-abstruse_string-1.txt | 5 + .../headers/payload-join-abstruse_string-2.txt | 4 + .../tests/variables/payload-abstruse_string.txt | 15 +++ level_1/fl_fss/tests/unit/c/help-fss-number.c | 128 ++++++++++++++++++ level_1/fl_fss/tests/unit/c/help-fss-number.h | 35 +++++ level_1/fl_fss/tests/unit/c/help-fss.c | 4 +- level_1/fl_fss/tests/unit/c/help-fss.h | 4 +- ...t-fss-payload_header_map-abstruse_int16s-join.c | 145 +++----------------- ...t-fss-payload_header_map-abstruse_int16s-join.h | 14 ++ ...-fss-payload_header_map-abstruse_int16s-split.c | 144 +++----------------- ...-fss-payload_header_map-abstruse_int16s-split.h | 14 ++ ...t-fss-payload_header_map-abstruse_int32s-join.c | 145 +++----------------- ...t-fss-payload_header_map-abstruse_int32s-join.h | 14 ++ ...-fss-payload_header_map-abstruse_int32s-split.c | 144 +++----------------- ...-fss-payload_header_map-abstruse_int32s-split.h | 14 ++ ...t-fss-payload_header_map-abstruse_int64s-join.c | 145 +++----------------- ...t-fss-payload_header_map-abstruse_int64s-join.h | 14 ++ ...-fss-payload_header_map-abstruse_int64s-split.c | 144 +++----------------- ...-fss-payload_header_map-abstruse_int64s-split.h | 14 ++ ...st-fss-payload_header_map-abstruse_int8s-join.c | 145 +++----------------- ...st-fss-payload_header_map-abstruse_int8s-join.h | 14 ++ ...t-fss-payload_header_map-abstruse_int8s-split.c | 144 +++----------------- ...t-fss-payload_header_map-abstruse_int8s-split.h | 14 ++ ...t-fss-payload_header_map-abstruse_signed-join.c | 134 ++----------------- ...t-fss-payload_header_map-abstruse_signed-join.h | 14 ++ ...-fss-payload_header_map-abstruse_signeds-join.c | 145 +++----------------- ...-fss-payload_header_map-abstruse_signeds-join.h | 14 ++ ...fss-payload_header_map-abstruse_signeds-split.c | 144 +++----------------- ...fss-payload_header_map-abstruse_signeds-split.h | 14 ++ ...t-fss-payload_header_map-abstruse_string-join.c | 134 +++++++++++++++++++ ...t-fss-payload_header_map-abstruse_string-join.h | 20 +++ ...-fss-payload_header_map-abstruse_uint16s-join.c | 145 +++----------------- ...-fss-payload_header_map-abstruse_uint16s-join.h | 14 ++ ...fss-payload_header_map-abstruse_uint16s-split.c | 144 +++----------------- ...fss-payload_header_map-abstruse_uint16s-split.h | 14 ++ ...-fss-payload_header_map-abstruse_uint32s-join.c | 145 +++----------------- ...-fss-payload_header_map-abstruse_uint32s-join.h | 14 ++ ...fss-payload_header_map-abstruse_uint32s-split.c | 144 +++----------------- ...fss-payload_header_map-abstruse_uint32s-split.h | 14 ++ ...-fss-payload_header_map-abstruse_uint64s-join.c | 147 +++------------------ ...-fss-payload_header_map-abstruse_uint64s-join.h | 14 ++ ...fss-payload_header_map-abstruse_uint64s-split.c | 146 +++----------------- ...fss-payload_header_map-abstruse_uint64s-split.h | 14 ++ ...t-fss-payload_header_map-abstruse_uint8s-join.c | 145 +++----------------- ...t-fss-payload_header_map-abstruse_uint8s-join.h | 14 ++ ...-fss-payload_header_map-abstruse_uint8s-split.c | 144 +++----------------- ...-fss-payload_header_map-abstruse_uint8s-split.h | 14 ++ ...fss-payload_header_map-abstruse_unsigned-join.c | 134 ++----------------- ...fss-payload_header_map-abstruse_unsigned-join.h | 14 ++ ...ss-payload_header_map-abstruse_unsigneds-join.c | 145 +++----------------- ...ss-payload_header_map-abstruse_unsigneds-join.h | 14 ++ ...s-payload_header_map-abstruse_unsigneds-split.c | 144 +++----------------- ...s-payload_header_map-abstruse_unsigneds-split.h | 14 ++ level_1/fl_fss/tests/unit/c/test-fss.c | 2 + level_1/fl_fss/tests/unit/c/test-fss.h | 2 + 57 files changed, 1056 insertions(+), 2776 deletions(-) create mode 100644 level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-2.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-abstruse_string.txt create mode 100644 level_1/fl_fss/tests/unit/c/help-fss-number.c create mode 100644 level_1/fl_fss/tests/unit/c/help-fss-number.h create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.c create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.h diff --git a/level_1/fl_fss/data/build/settings-tests b/level_1/fl_fss/data/build/settings-tests index 8accf6c..7adf134 100644 --- a/level_1/fl_fss/data/build/settings-tests +++ b/level_1/fl_fss/data/build/settings-tests @@ -42,8 +42,9 @@ build_sources_program test-fss-payload_header_map-abstruse_int64s-split.c test-f build_sources_program test-fss-payload_header_map-abstruse_signed-join.c test-fss-payload_header_map-abstruse_unsigned-join.c build_sources_program test-fss-payload_header_map-abstruse_signeds-join.c test-fss-payload_header_map-abstruse_unsigneds-join.c build_sources_program test-fss-payload_header_map-abstruse_signeds-split.c test-fss-payload_header_map-abstruse_unsigneds-split.c +build_sources_program test-fss-payload_header_map-abstruse_string-join.c -build_sources_program test-fss.c data-fss.c help-fss.c +build_sources_program test-fss.c data-fss.c help-fss.c help-fss-number.c build_script no build_shared yes diff --git a/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-0.txt b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-0.txt new file mode 100644 index 0000000..7b06942 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-0.txt @@ -0,0 +1,6 @@ +a +4 +0 +hello +"some thing" +3全#$⸙ diff --git a/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-1.txt b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-1.txt new file mode 100644 index 0000000..50e859f --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-1.txt @@ -0,0 +1,5 @@ +b +3 +全 +⸙ +"␀ ␀ ␀ ␀ ␀ ␀" diff --git a/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-2.txt b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-2.txt new file mode 100644 index 0000000..41f6980 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-join-abstruse_string-2.txt @@ -0,0 +1,4 @@ +c +2 +� +""a b \" c" diff --git a/level_1/fl_fss/data/tests/variables/payload-abstruse_string.txt b/level_1/fl_fss/data/tests/variables/payload-abstruse_string.txt new file mode 100644 index 0000000..d64b7e9 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-abstruse_string.txt @@ -0,0 +1,15 @@ +a +4 +0 +hello +some thing +3全#$⸙ +b +3 +全 +⸙ +␀ ␀ ␀ ␀ ␀ ␀ +c +2 +� +"a b " c diff --git a/level_1/fl_fss/tests/unit/c/help-fss-number.c b/level_1/fl_fss/tests/unit/c/help-fss-number.c new file mode 100644 index 0000000..4f6adaa --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/help-fss-number.c @@ -0,0 +1,128 @@ +#include "test-fss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void help_number__test_payload(const f_string_t context_variables, const f_string_t context_headers, const uint64_t flag, void (*load_contents_at)(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state)) { + + // Note: Each line should probably be at max 255 characters. + // The payload begins with a digit on the first line representing the number of Content lines following the Object line. + // Following the digit is a single Object line. + // Following the Object line is a line for each Content designated by the first line (can be 0). + // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. + FILE *file_variables = data__file_open__named("variables", "payload", context_variables); + FILE *file_headers = 0; + + assert_non_null(file_variables); + + f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; + f_state_t state = f_state_t_initialize; + f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; + f_string_dynamic_t object = f_string_dynamic_t_initialize; + f_string_dynamics_t contents = f_string_dynamics_t_initialize; + f_string_dynamic_t cache = f_string_dynamic_t_initialize; + f_string_maps_t destinations = f_string_maps_t_initialize; + f_string_maps_t expects = f_string_maps_t_initialize; + + { + state.status = F_none; + state.data = &data; + data.cache = &cache; + data.flag = flag; + + for (uint16_t at = 0; ; ++at) { + + if (help__read_line_object(file_variables, &object)) break; + if (help__read_line_contents__single(file_variables, &contents, F_true)) break; + + state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); + assert_true(F_status_is_error_not(state.status)); + + load_contents_at(object, contents, &headers, &state); + + if (object.string) free(object.string); + + object.string = 0; + object.used = 0; + object.size = 0; + + ++headers.used; + + file_headers = data__file_open__named_at("headers", "payload", context_headers, at); + assert_non_null(file_headers); + + help__read_line_object(file_headers, &object); + + for (;;) { + state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); + assert_true(F_status_is_error_not(state.status)); + + if (help__read_line_expects__single(file_headers, object, &expects)) break; + } // for + + fl_fss_payload_header_map(headers, &destinations, &state); + assert_int_equal(state.status, F_okay); + assert_int_equal(destinations.used, expects.used); + + for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { + + assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); + assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); + + assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); + assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); + } // for + + if (object.string) free(object.string); + if (cache.string) free(cache.string); + if (file_headers) fclose(file_headers); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + + file_headers = 0; + + object.string = 0; + object.used = 0; + object.size = 0; + + cache.string = 0; + cache.used = 0; + cache.size = 0; + + contents.array = 0; + contents.used = 0; + contents.size = 0; + + headers.array = 0; + headers.used = 0; + headers.size = 0; + + destinations.array = 0; + destinations.used = 0; + destinations.size = 0; + + expects.array = 0; + expects.used = 0; + expects.size = 0; + } // for + } + + if (file_variables) fclose(file_variables); + if (file_headers) fclose(file_headers); + + if (object.string) free(object.string); + if (cache.string) free(cache.string); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_fss/tests/unit/c/help-fss-number.h b/level_1/fl_fss/tests/unit/c/help-fss-number.h new file mode 100644 index 0000000..da90da0 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/help-fss-number.h @@ -0,0 +1,35 @@ +/** + * FLL - Level 1 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Helper for the fss project tests. + */ +#ifndef _HELP__FL_fss_number_h +#define _HELP__FL_fss_number_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the unit test for a number. + * + * @param context_variables + * The context name of the variables file for data__file_open__named(). + * @param context_headers + * The context name of the headers file for data__file_open__named_at(). + * @param flag + * The payload header state data flag. + * @param load_contents_at + * A callback to perform the type-specific content loading translation of the number. + */ +void help_number__test_payload(const f_string_t context_variables, const f_string_t context_headers, const uint64_t flag, void (*load_contents_at)(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state)); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _HELP__FL_fss_number_h diff --git a/level_1/fl_fss/tests/unit/c/help-fss.c b/level_1/fl_fss/tests/unit/c/help-fss.c index 447e7eb..090121c 100644 --- a/level_1/fl_fss/tests/unit/c/help-fss.c +++ b/level_1/fl_fss/tests/unit/c/help-fss.c @@ -4,7 +4,7 @@ extern "C" { #endif -uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const contents) { +uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const contents, const uint8_t as_number) { size_t max = 255; char *line_string = 0; @@ -22,7 +22,7 @@ uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const const f_number_unsigned_t count = (f_number_unsigned_t) atoi(line_string); - if (!count) { + if (!count && as_number) { assert_int_equal(line_string[0], '0'); } diff --git a/level_1/fl_fss/tests/unit/c/help-fss.h b/level_1/fl_fss/tests/unit/c/help-fss.h index 977bfb0..9d670e5 100644 --- a/level_1/fl_fss/tests/unit/c/help-fss.h +++ b/level_1/fl_fss/tests/unit/c/help-fss.h @@ -27,12 +27,14 @@ extern "C" { * @param contents * The array of contents to use. * Must not be NULL. + * @param as_number + * Operate as a number, performing a check if the first character is '0' (the character and not NULL). * * @return * F_true if there is no content left to read in the file. * F_false otherwise. */ -uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const contents); +uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const contents, const uint8_t as_number); /** * Load the expect lines from the given file. diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.c index c4697a4..279402d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int16s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int16s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int16s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i16s.used = 0; - headers.array[0].value.type = f_abstruse_int16s_e; - is_a = &headers.array[0].value.is.a_i16s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_int16s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int16s", "join-abstruse_int16s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_int16s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int16s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int16s_t * const is_a = &headers->array[0].value.is.a_i16s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i16s.used = 0; + headers->array[0].value.type = f_abstruse_int16s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.h index 8b73f45..cac38e8 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int16s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int16s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int16s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.c index f8626fe..344fa49 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int16s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int16s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int16s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i16s.used = 0; - headers.array[0].value.type = f_abstruse_int16s_e; - is_a = &headers.array[0].value.is.a_i16s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_int16s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int16s", "split-abstruse_int16s", 0, test__fl_fss_payload_header_map__abstruse_int16s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int16s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int16s_t * const is_a = &headers->array[0].value.is.a_i16s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i16s.used = 0; + headers->array[0].value.type = f_abstruse_int16s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.h index 0f8482d..9558b21 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int16s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int16s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int16s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int16s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.c index 794aa38..b15d338 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int32s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int32s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int32s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i32s.used = 0; - headers.array[0].value.type = f_abstruse_int32s_e; - is_a = &headers.array[0].value.is.a_i32s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_int32s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int32s", "join-abstruse_int32s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_int32s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int32s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int32s_t * const is_a = &headers->array[0].value.is.a_i32s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i32s.used = 0; + headers->array[0].value.type = f_abstruse_int32s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.h index feb4dd8..7c15758 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int32s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int32s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int32s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.c index 7b85179..675b381 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int32s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int32s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int32s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i32s.used = 0; - headers.array[0].value.type = f_abstruse_int32s_e; - is_a = &headers.array[0].value.is.a_i32s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_int32s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int32s", "split-abstruse_int32s", 0, test__fl_fss_payload_header_map__abstruse_int32s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int32s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int32s_t * const is_a = &headers->array[0].value.is.a_i32s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i32s.used = 0; + headers->array[0].value.type = f_abstruse_int32s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.h index edbfc10..828dbd7 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int32s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int32s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int32s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int32s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.c index 5af5ed0..2620647 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int64s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int64s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int64s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i64s.used = 0; - headers.array[0].value.type = f_abstruse_int64s_e; - is_a = &headers.array[0].value.is.a_i64s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_int64s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int64s", "join-abstruse_int64s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_int64s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int64s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int64s_t * const is_a = &headers->array[0].value.is.a_i64s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i64s.used = 0; + headers->array[0].value.type = f_abstruse_int64s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.h index cc74c04..9a50ac9 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int64s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int64s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int64s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.c index bd4d9c1..41b1416 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int64s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int64s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int64s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i64s.used = 0; - headers.array[0].value.type = f_abstruse_int64s_e; - is_a = &headers.array[0].value.is.a_i64s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_int64s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int64s", "split-abstruse_int64s", 0, test__fl_fss_payload_header_map__abstruse_int64s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int64s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int64s_t * const is_a = &headers->array[0].value.is.a_i64s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i64s.used = 0; + headers->array[0].value.type = f_abstruse_int64s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.h index 7ebabf1..ec51131 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int64s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int64s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int64s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int64s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.c index f304a2a..ff45ab5 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int8s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int8s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int8s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i8s.used = 0; - headers.array[0].value.type = f_abstruse_int8s_e; - is_a = &headers.array[0].value.is.a_i8s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_int8s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int8s", "join-abstruse_int8s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_int8s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int8s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int8s_t * const is_a = &headers->array[0].value.is.a_i8s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i8s.used = 0; + headers->array[0].value.type = f_abstruse_int8s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.h index eb0cf4d..a610d1a 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int8s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int8s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int8s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.c index 8d4be14..bfca9a3 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_int8s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_int8s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_int8s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_i8s.used = 0; - headers.array[0].value.type = f_abstruse_int8s_e; - is_a = &headers.array[0].value.is.a_i8s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_int8s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_int8s", "split-abstruse_int8s", 0, test__fl_fss_payload_header_map__abstruse_int8s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_int8s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_int8s_t * const is_a = &headers->array[0].value.is.a_i8s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i8s.used = 0; + headers->array[0].value.type = f_abstruse_int8s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.h index ee11e60..7172c7f 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_int8s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_int8s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_int8s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_int8s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.c index 73cd677..876687b 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.c @@ -6,133 +6,27 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_signed__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_signed"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - for (f_number_unsigned_t i = 0; i < contents.used; ++i, ++headers.used) { - - const f_number_signed_t number = atoll(contents.array[i].string); - - if (!number) { - assert_int_equal(contents.array[i].string[0], '0'); - } - - headers.array[headers.used].key.used = 0; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - headers.array[headers.used].value.type = f_abstruse_signed_e; - headers.array[headers.used].value.is.a_signed = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_signed", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; - - object.string = 0; - object.used = 0; - object.size = 0; - - cache.string = 0; - cache.used = 0; - cache.size = 0; + help_number__test_payload("abstruse_signed", "join-abstruse_signed", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_signed__join_load_contents_at); +} - contents.array = 0; - contents.used = 0; - contents.size = 0; +void test__fl_fss_payload_header_map__abstruse_signed__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - headers.array = 0; - headers.used = 0; - headers.size = 0; + for (f_number_unsigned_t i = 0; i < contents.used; ++i, ++headers->used) { - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + const f_number_signed_t number = atoll(contents.array[i].string); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + if (!number) { + assert_int_equal(contents.array[i].string[0], '0'); + } - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + headers->array[headers->used].key.used = 0; - if (object.string) free(object.string); - if (cache.string) free(cache.string); + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + headers->array[headers->used].value.type = f_abstruse_signed_e; + headers->array[headers->used].value.is.a_signed = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.h index 25cbf10..617cbe5 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_signed__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_signed__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_signed_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.c index 278f7cc..728a0a6 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_signeds__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_signeds"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_number_signeds_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_signeds.used = 0; - headers.array[0].value.type = f_abstruse_signeds_e; - is_a = &headers.array[0].value.is.a_signeds; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_signeds", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_signeds", "join-abstruse_signeds", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_signeds__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_signeds__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_number_signeds_t * const is_a = &headers->array[0].value.is.a_signeds; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_signeds.used = 0; + headers->array[0].value.type = f_abstruse_signeds_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.h index 3f5469e..53cb59f 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_signeds__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_signeds__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_signeds_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.c index f680d9c..50bbd82 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_signeds__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_signeds"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_number_signeds_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_signeds.used = 0; - headers.array[0].value.type = f_abstruse_signeds_e; - is_a = &headers.array[0].value.is.a_signeds; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_signeds", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_signeds", "split-abstruse_signeds", 0, test__fl_fss_payload_header_map__abstruse_signeds__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_signeds__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_number_signeds_t * const is_a = &headers->array[0].value.is.a_signeds; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_signeds.used = 0; + headers->array[0].value.type = f_abstruse_signeds_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.h index fff05e1..7171f7b 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signeds-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_signeds__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_signeds__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_signeds_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.c new file mode 100644 index 0000000..c1e7429 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.c @@ -0,0 +1,134 @@ +#include "test-fss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_fss_payload_header_map__abstruse_string__works_join(void **void_state) { + + // Note: Each line should probably be at max 255 characters. + // The payload begins with a digit on the first line representing the number of Content lines following the Object line. + // Following the digit is a single Object line. + // Following the Object line is a line for each Content designated by the first line (can be 0). + // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. + FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_string"); + FILE *file_headers = 0; + + assert_non_null(file_variables); + + f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; + f_state_t state = f_state_t_initialize; + f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; + f_string_dynamic_t object = f_string_dynamic_t_initialize; + f_string_dynamics_t contents = f_string_dynamics_t_initialize; + f_string_dynamic_t cache = f_string_dynamic_t_initialize; + f_string_maps_t destinations = f_string_maps_t_initialize; + f_string_maps_t expects = f_string_maps_t_initialize; + + { + state.status = F_none; + state.data = &data; + data.cache = &cache; + + for (uint16_t at = 0; ; ++at) { + + if (help__read_line_object(file_variables, &object)) break; + if (help__read_line_contents__single(file_variables, &contents, F_false)) break; + + state.status = f_memory_array_increase_by(contents.used, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); + assert_true(F_status_is_error_not(state.status)); + + for (f_number_unsigned_t i = 0; i < contents.used; ++i, ++headers.used) { + + headers.array[headers.used].key.used = 0; + + state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); + assert_int_equal(state.status, F_okay); + + headers.array[headers.used].value.type = f_abstruse_string_e; + headers.array[headers.used].value.is.a_string = contents.array[i].string; + } // for + + if (object.string) free(object.string); + + object.string = 0; + object.used = 0; + object.size = 0; + + file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_string", at); + assert_non_null(file_headers); + + help__read_line_object(file_headers, &object); + + for (;;) { + state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); + assert_true(F_status_is_error_not(state.status)); + + if (help__read_line_expects__single(file_headers, object, &expects)) break; + } // for + + fl_fss_payload_header_map(headers, &destinations, &state); + assert_int_equal(state.status, F_okay); + assert_int_equal(destinations.used, expects.used); + + for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { + + assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); + assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); + + assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); + assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); + } // for + + if (object.string) free(object.string); + if (cache.string) free(cache.string); + if (file_headers) fclose(file_headers); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + + file_headers = 0; + + object.string = 0; + object.used = 0; + object.size = 0; + + cache.string = 0; + cache.used = 0; + cache.size = 0; + + contents.array = 0; + contents.used = 0; + contents.size = 0; + + headers.array = 0; + headers.used = 0; + headers.size = 0; + + destinations.array = 0; + destinations.used = 0; + destinations.size = 0; + + expects.array = 0; + expects.used = 0; + expects.size = 0; + } // for + } + + if (file_variables) fclose(file_variables); + if (file_headers) fclose(file_headers); + + if (object.string) free(object.string); + if (cache.string) free(cache.string); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.h new file mode 100644 index 0000000..cc19eba --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_string-join.h @@ -0,0 +1,20 @@ +/** + * FLL - Level 2 + * + * Project: FSS + * API Version: 0.6 + * Licenses: lgpl-2.1-or-later + * + * Test the fl_fss project. + */ +#ifndef _TEST__FL_fss_payload_header_map__abstruse_string_join_h +#define _TEST__FL_fss_payload_header_map__abstruse_string_join_h + +/** + * Test that the function works for abstruse_string type. + * + * @see fl_fss_payload_header_map() + */ +extern void test__fl_fss_payload_header_map__abstruse_string__works_join(void **state); + +#endif // _TEST__FL_fss_payload_header_map__abstruse_string_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.c index bc2fc4e..820b062 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint16s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint16s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint16s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u16s.used = 0; - headers.array[0].value.type = f_abstruse_uint16s_e; - is_a = &headers.array[0].value.is.a_u16s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_uint16s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint16s", "join-abstruse_uint16s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_uint16s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint16s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint16s_t * const is_a = &headers->array[0].value.is.a_u16s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i16s.used = 0; + headers->array[0].value.type = f_abstruse_uint16s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.h index 1b2b7ab..68209af 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint16s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint16s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint16s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.c index 25a98c7..f1c084a 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint16s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint16s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint16s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u16s.used = 0; - headers.array[0].value.type = f_abstruse_uint16s_e; - is_a = &headers.array[0].value.is.a_u16s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_uint16s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint16s", "split-abstruse_uint16s", 0, test__fl_fss_payload_header_map__abstruse_uint16s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint16s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint16s_t * const is_a = &headers->array[0].value.is.a_u16s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_u16s.used = 0; + headers->array[0].value.type = f_abstruse_uint16s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.h index 7d70090..7cfeeeb 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint16s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint16s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint16s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint16s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.c index 876256e..6ba4048 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint32s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint32s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint32s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u32s.used = 0; - headers.array[0].value.type = f_abstruse_uint32s_e; - is_a = &headers.array[0].value.is.a_u32s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_uint32s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint32s", "join-abstruse_uint32s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_uint32s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint32s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint32s_t * const is_a = &headers->array[0].value.is.a_u32s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i32s.used = 0; + headers->array[0].value.type = f_abstruse_uint32s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.h index 781a09c..87f8f8d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint32s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint32s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint32s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.c index 1d65e31..2316bbc 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint32s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint32s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint32s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u32s.used = 0; - headers.array[0].value.type = f_abstruse_uint32s_e; - is_a = &headers.array[0].value.is.a_u32s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_uint32s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint32s", "split-abstruse_uint32s", 0, test__fl_fss_payload_header_map__abstruse_uint32s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint32s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint32s_t * const is_a = &headers->array[0].value.is.a_u32s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_u32s.used = 0; + headers->array[0].value.type = f_abstruse_uint32s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.h index d34f5ff..958de22 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint32s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint32s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint32s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint32s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.c index 38622b4..628cc3e 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.c @@ -6,143 +6,34 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint64s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint64s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint64s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u64s.used = 0; - headers.array[0].value.type = f_abstruse_uint64s_e; - is_a = &headers.array[0].value.is.a_u64s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - // atoll() cannot be used here due to needing an unsigned 64-bit and atoll() returns a signed 64-bit. - const f_number_signed_t number = strtoull(contents.array[is_a->used].string, 0, 10); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_uint64s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint64s", "join-abstruse_uint64s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_uint64s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint64s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint64s_t * const is_a = &headers->array[0].value.is.a_u64s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i64s.used = 0; + headers->array[0].value.type = f_abstruse_uint64s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + // atoll() cannot be used here due to needing an unsigned 64-bit and atoll() returns a signed 64-bit. + const f_number_signed_t number = strtoull(contents.array[is_a->used].string, 0, 10); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.h index ba2e935..8bef639 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint64s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint64s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint64s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.c index 3a739df..655434c 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.c @@ -6,142 +6,34 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint64s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint64s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint64s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u64s.used = 0; - headers.array[0].value.type = f_abstruse_uint64s_e; - is_a = &headers.array[0].value.is.a_u64s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - // atoll() cannot be used here due to needing an unsigned 64-bit and atoll() returns a signed 64-bit. - const f_number_signed_t number = strtoull(contents.array[is_a->used].string, 0, 10); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_uint64s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint64s", "split-abstruse_uint64s", 0, test__fl_fss_payload_header_map__abstruse_uint64s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint64s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint64s_t * const is_a = &headers->array[0].value.is.a_u64s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i64s.used = 0; + headers->array[0].value.type = f_abstruse_uint64s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + // atoll() cannot be used here due to needing an unsigned 64-bit and atoll() returns a signed 64-bit. + const f_number_signed_t number = strtoull(contents.array[is_a->used].string, 0, 10); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.h index f1fdec9..dc063f7 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint64s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint64s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint64s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint64s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.c index 081e883..ff04243 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint8s__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint8s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint8s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u8s.used = 0; - headers.array[0].value.type = f_abstruse_uint8s_e; - is_a = &headers.array[0].value.is.a_u8s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_uint8s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint8s", "join-abstruse_uint8s", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_uint8s__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint8s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint8s_t * const is_a = &headers->array[0].value.is.a_u8s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_i8s.used = 0; + headers->array[0].value.type = f_abstruse_uint8s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.h index 0001a84..8339589 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint8s__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint8s__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint8s_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.c index bf46673..9a0b796 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_uint8s__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_uint8s"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_uint8s_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_u8s.used = 0; - headers.array[0].value.type = f_abstruse_uint8s_e; - is_a = &headers.array[0].value.is.a_u8s; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_uint8s", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_uint8s", "split-abstruse_uint8s", 0, test__fl_fss_payload_header_map__abstruse_uint8s__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_uint8s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_uint8s_t * const is_a = &headers->array[0].value.is.a_u8s; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_u8s.used = 0; + headers->array[0].value.type = f_abstruse_uint8s_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.h index 47b8826..7fe85cd 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_uint8s-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_uint8s__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_uint8s__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_uint8s_split_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.c index fe54e69..dae916f 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.c @@ -6,133 +6,27 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_unsigned__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_unsigned"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - for (f_number_unsigned_t i = 0; i < contents.used; ++i, ++headers.used) { - - const f_number_unsigned_t number = atoll(contents.array[i].string); - - if (!number) { - assert_int_equal(contents.array[i].string[0], '0'); - } - - headers.array[headers.used].key.used = 0; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - headers.array[headers.used].value.type = f_abstruse_unsigned_e; - headers.array[headers.used].value.is.a_unsigned = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_unsigned", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; - - object.string = 0; - object.used = 0; - object.size = 0; - - cache.string = 0; - cache.used = 0; - cache.size = 0; + help_number__test_payload("abstruse_unsigned", "join-abstruse_unsigned", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_unsigned__join_load_contents_at); +} - contents.array = 0; - contents.used = 0; - contents.size = 0; +void test__fl_fss_payload_header_map__abstruse_unsigned__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - headers.array = 0; - headers.used = 0; - headers.size = 0; + for (f_number_unsigned_t i = 0; i < contents.used; ++i, ++headers->used) { - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + const f_number_unsigned_t number = atoll(contents.array[i].string); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + if (!number) { + assert_int_equal(contents.array[i].string[0], '0'); + } - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + headers->array[headers->used].key.used = 0; - if (object.string) free(object.string); - if (cache.string) free(cache.string); + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + headers->array[headers->used].value.type = f_abstruse_unsigned_e; + headers->array[headers->used].value.is.a_unsigned = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.h index 533756a..cf0c5ef 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_unsigned__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_unsigned__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_unsigned_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.c index 3e09ee4..13ddc81 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.c @@ -6,142 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_unsigneds__works_join(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_unsigneds"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_number_unsigneds_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - data.flag |= f_fss_payload_header_map_flag_join_digits_e; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_unsigneds.used = 0; - headers.array[0].value.type = f_abstruse_unsigneds_e; - is_a = &headers.array[0].value.is.a_unsigneds; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "join-abstruse_unsigneds", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_unsigneds", "join-abstruse_unsigneds", f_fss_payload_header_map_flag_join_digits_e, test__fl_fss_payload_header_map__abstruse_unsigneds__join_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_unsigneds__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_number_unsigneds_t * const is_a = &headers->array[0].value.is.a_unsigneds; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_unsigneds.used = 0; + headers->array[0].value.type = f_abstruse_unsigneds_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.h index e9b96be..580477d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-join.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_unsigneds__works_join(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_unsigneds__join_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_unsigneds_join_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.c index 7258e46..a8be2d1 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.c @@ -6,141 +6,33 @@ extern "C" { void test__fl_fss_payload_header_map__abstruse_unsigneds__works_split(void **void_state) { - // Note: Each line should probably be at max 255 characters. - // The payload begins with a digit on the first line representing the number of Content lines following the Object line. - // Following the digit is a single Object line. - // Following the Object line is a line for each Content designated by the first line (can be 0). - // Following this Content line (even if 0 lines) should be the end of the test file or the start of the next set for the next line in the headers file. - FILE *file_variables = data__file_open__named("variables", "payload", "abstruse_unsigneds"); - FILE *file_headers = 0; - - assert_non_null(file_variables); - - f_abstruse_maps_t headers = f_abstruse_maps_t_initialize; - f_state_t state = f_state_t_initialize; - f_fss_payload_header_state_t data = f_fss_payload_header_state_t_initialize; - f_string_dynamic_t object = f_string_dynamic_t_initialize; - f_string_dynamics_t contents = f_string_dynamics_t_initialize; - f_string_dynamic_t cache = f_string_dynamic_t_initialize; - f_string_maps_t destinations = f_string_maps_t_initialize; - f_string_maps_t expects = f_string_maps_t_initialize; - f_number_unsigneds_t *is_a = 0; - - { - state.status = F_none; - state.data = &data; - data.cache = &cache; - - for (uint16_t at = 0; ; ++at) { - - if (help__read_line_object(file_variables, &object)) break; - if (help__read_line_contents__single(file_variables, &contents)) break; - - state.status = f_memory_array_increase(state.step_small, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size); - assert_true(F_status_is_error_not(state.status)); - - headers.array[0].key.used = 0; - headers.array[0].value.is.a_unsigneds.used = 0; - headers.array[0].value.type = f_abstruse_unsigneds_e; - is_a = &headers.array[0].value.is.a_unsigneds; - - state.status = f_string_dynamic_append(object, &headers.array[headers.used].key); - assert_int_equal(state.status, F_okay); - - state.status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); - assert_true(F_status_is_error_not(state.status)); - - for (is_a->used = 0; is_a->used < contents.used; ) { - - const f_number_signed_t number = atoll(contents.array[is_a->used].string); - - if (!number) { - assert_int_equal(contents.array[is_a->used].string[0], '0'); - } - - is_a->array[is_a->used++] = number; - } // for - - if (object.string) free(object.string); - - object.string = 0; - object.used = 0; - object.size = 0; - - ++headers.used; - - file_headers = data__file_open__named_at("headers", "payload", "split-abstruse_unsigneds", at); - assert_non_null(file_headers); - - help__read_line_object(file_headers, &object); - - for (;;) { - state.status = f_memory_array_increase(state.step_small, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size); - assert_true(F_status_is_error_not(state.status)); - - if (help__read_line_expects__single(file_headers, object, &expects)) break; - } // for - - fl_fss_payload_header_map(headers, &destinations, &state); - assert_int_equal(state.status, F_okay); - assert_int_equal(destinations.used, expects.used); - - for (f_number_unsigned_t i = 0; i < destinations.used; ++i) { - - assert_int_equal(destinations.array[i].key.used, expects.array[i].key.used); - assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); - - assert_string_equal(destinations.array[i].key.string, expects.array[i].key.string); - assert_string_equal(destinations.array[i].value.string, expects.array[i].value.string); - } // for - - if (object.string) free(object.string); - if (cache.string) free(cache.string); - if (file_headers) fclose(file_headers); - - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); - - file_headers = 0; + help_number__test_payload("abstruse_unsigneds", "split-abstruse_unsigneds", 0, test__fl_fss_payload_header_map__abstruse_unsigneds__split_load_contents_at); +} - object.string = 0; - object.used = 0; - object.size = 0; +void test__fl_fss_payload_header_map__abstruse_unsigneds__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state) { - cache.string = 0; - cache.used = 0; - cache.size = 0; + f_number_unsigneds_t * const is_a = &headers->array[0].value.is.a_unsigneds; - contents.array = 0; - contents.used = 0; - contents.size = 0; + headers->array[0].key.used = 0; + headers->array[0].value.is.a_unsigneds.used = 0; + headers->array[0].value.type = f_abstruse_unsigneds_e; - headers.array = 0; - headers.used = 0; - headers.size = 0; + state->status = f_string_dynamic_append(object, &headers->array[headers->used].key); + assert_int_equal(state->status, F_okay); - destinations.array = 0; - destinations.used = 0; - destinations.size = 0; + state->status = f_memory_array_increase_by(contents.used, sizeof(f_number_signed_t), (void **) &is_a->array, &is_a->used, &is_a->size); + assert_true(F_status_is_error_not(state->status)); - expects.array = 0; - expects.used = 0; - expects.size = 0; - } // for - } + for (is_a->used = 0; is_a->used < contents.used; ) { - if (file_variables) fclose(file_variables); - if (file_headers) fclose(file_headers); + const f_number_signed_t number = atoll(contents.array[is_a->used].string); - if (object.string) free(object.string); - if (cache.string) free(cache.string); + if (!number) { + assert_int_equal(contents.array[is_a->used].string[0], '0'); + } - f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &contents.array, &contents.used, &contents.size, &f_string_dynamics_delete_callback); - f_memory_arrays_resize(0, sizeof(f_abstruse_map_t), (void **) &headers.array, &headers.used, &headers.size, &f_abstruse_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &destinations.array, &destinations.used, &destinations.size, &f_string_maps_delete_callback); - f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &expects.array, &expects.used, &expects.size, &f_string_maps_delete_callback); + is_a->array[is_a->used++] = number; + } // for } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.h index 0787c3e..bd431cf 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigneds-split.h @@ -17,4 +17,18 @@ */ extern void test__fl_fss_payload_header_map__abstruse_unsigneds__works_split(void **state); +/** + * Callback to load the contents for the test. + * + * @param object + * The object parameter. + * @param contents + * The contents parameter. + * @param headers + * The headers parameter. + * @param state + * The state parameter. + */ +void test__fl_fss_payload_header_map__abstruse_unsigneds__split_load_contents_at(const f_string_static_t object, const f_string_dynamics_t contents, f_abstruse_maps_t * const headers, f_state_t * const state); + #endif // _TEST__FL_fss_payload_header_map__abstruse_unsigneds_split_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 dccb40f..329815c 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -71,6 +71,8 @@ int main(void) { cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_signed__works_join), cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_signeds__works_join), cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_signeds__works_split), + cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_string__works_join), + //cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_strings__works_join), cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_uint8s__works_join), cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_uint8s__works_split), cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_uint16s__works_join), diff --git a/level_1/fl_fss/tests/unit/c/test-fss.h b/level_1/fl_fss/tests/unit/c/test-fss.h index be718e5..d0e0e5a 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.h +++ b/level_1/fl_fss/tests/unit/c/test-fss.h @@ -38,6 +38,7 @@ // Data includes. #include "data-fss.h" #include "help-fss.h" +#include "help-fss-number.h" // Test includes. #include "test-fss-basic_content_read.h" @@ -72,6 +73,7 @@ #include "test-fss-payload_header_map-abstruse_signed-join.h" #include "test-fss-payload_header_map-abstruse_signeds-join.h" #include "test-fss-payload_header_map-abstruse_signeds-split.h" +#include "test-fss-payload_header_map-abstruse_string-join.h" #include "test-fss-payload_header_map-abstruse_uint8s-join.h" #include "test-fss-payload_header_map-abstruse_uint8s-split.h" #include "test-fss-payload_header_map-abstruse_uint16s-join.h" -- 1.8.3.1