From c94811570270c7f87011069e74009ca4613d7d74 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 8 Feb 2024 21:24:54 -0600 Subject: [PATCH] Progress: Begin adding unit tests for fl_fss_payload_header_map(). I added the single digit unit tests for signed and unsigned. I started to add uint8_t with the test files but then I realized that I actually should implement uint8s_t. I am leaving those test files currently but I will change them at a later date. This adds a helper file for the payload header map private functions to simplify some of the code. --- build/level_1/settings | 2 +- build/monolithic/settings | 2 +- level_1/fl_fss/c/fss/payload.c | 13 +- level_1/fl_fss/c/fss/payload/define.h | 4 +- level_1/fl_fss/c/fss/private-payload-helper.c | 103 ++++++++ level_1/fl_fss/c/fss/private-payload-helper.h | 182 ++++++++++++++ level_1/fl_fss/c/fss/private-payload.c | 272 ++++----------------- level_1/fl_fss/c/fss/private-payload.h | 89 +------ level_1/fl_fss/data/build/settings | 2 +- level_1/fl_fss/data/build/settings-tests | 3 +- .../headers/payload-combined-abstruse_int16-0.txt | 9 + .../headers/payload-combined-abstruse_int16-1.txt | 7 + .../headers/payload-combined-abstruse_int16-2.txt | 7 + .../headers/payload-combined-abstruse_int32-0.txt | 9 + .../headers/payload-combined-abstruse_int32-1.txt | 7 + .../headers/payload-combined-abstruse_int32-2.txt | 7 + .../headers/payload-combined-abstruse_int64-0.txt | 9 + .../headers/payload-combined-abstruse_int64-1.txt | 7 + .../headers/payload-combined-abstruse_int64-2.txt | 9 + .../headers/payload-combined-abstruse_int8-0.txt | 9 + .../headers/payload-combined-abstruse_int8-1.txt | 7 + .../headers/payload-combined-abstruse_int8-2.txt | 7 + .../headers/payload-combined-abstruse_signed-0.txt | 9 + .../headers/payload-combined-abstruse_signed-1.txt | 7 + .../headers/payload-combined-abstruse_signed-2.txt | 7 + .../headers/payload-combined-abstruse_uint16-0.txt | 9 + .../headers/payload-combined-abstruse_uint16-1.txt | 7 + .../headers/payload-combined-abstruse_uint16-2.txt | 5 + .../headers/payload-combined-abstruse_uint32-0.txt | 9 + .../headers/payload-combined-abstruse_uint32-1.txt | 7 + .../headers/payload-combined-abstruse_uint32-2.txt | 5 + .../headers/payload-combined-abstruse_uint64-0.txt | 9 + .../headers/payload-combined-abstruse_uint64-1.txt | 7 + .../headers/payload-combined-abstruse_uint64-2.txt | 7 + .../headers/payload-combined-abstruse_uint8-0.txt | 9 + .../headers/payload-combined-abstruse_uint8-1.txt | 7 + .../headers/payload-combined-abstruse_uint8-2.txt | 5 + .../payload-combined-abstruse_unsigned-0.txt | 9 + .../payload-combined-abstruse_unsigned-1.txt | 7 + .../payload-combined-abstruse_unsigned-2.txt | 5 + .../variables/payload-combined-abstruse_int16.txt | 16 ++ .../variables/payload-combined-abstruse_int32.txt | 16 ++ .../variables/payload-combined-abstruse_int64.txt | 17 ++ .../variables/payload-combined-abstruse_int8.txt | 16 ++ .../variables/payload-combined-abstruse_signed.txt | 16 ++ .../variables/payload-combined-abstruse_uint16.txt | 15 ++ .../variables/payload-combined-abstruse_uint32.txt | 15 ++ .../variables/payload-combined-abstruse_uint64.txt | 16 ++ .../variables/payload-combined-abstruse_uint8.txt | 15 ++ .../payload-combined-abstruse_unsigned.txt | 15 ++ level_1/fl_fss/tests/unit/c/data-fss.c | 12 +- level_1/fl_fss/tests/unit/c/data-fss.h | 37 +-- level_1/fl_fss/tests/unit/c/help-fss.c | 133 ++++++++++ level_1/fl_fss/tests/unit/c/help-fss.h | 82 +++++++ .../tests/unit/c/test-fss-basic_content_read.c | 4 +- .../unit/c/test-fss-basic_list_content_read.c | 26 +- .../tests/unit/c/test-fss-basic_list_object_read.c | 4 +- .../tests/unit/c/test-fss-basic_object_read.c | 4 +- .../unit/c/test-fss-embedded_list_content_read.c | 26 +- .../unit/c/test-fss-embedded_list_object_read.c | 4 +- .../tests/unit/c/test-fss-extended_content_read.c | 18 +- .../unit/c/test-fss-extended_list_content_read.c | 26 +- .../unit/c/test-fss-extended_list_object_read.c | 4 +- .../tests/unit/c/test-fss-extended_object_read.c | 6 +- .../test-fss-payload_header_map-abstruse_signed.c | 141 +++++++++++ .../test-fss-payload_header_map-abstruse_signed.h | 20 ++ ...test-fss-payload_header_map-abstruse_unsigned.c | 141 +++++++++++ ...test-fss-payload_header_map-abstruse_unsigned.h | 20 ++ level_1/fl_fss/tests/unit/c/test-fss.c | 2 + level_1/fl_fss/tests/unit/c/test-fss.h | 4 + 70 files changed, 1355 insertions(+), 412 deletions(-) create mode 100644 level_1/fl_fss/c/fss/private-payload-helper.c create mode 100644 level_1/fl_fss/c/fss/private-payload-helper.h create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-2.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-0.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-1.txt create mode 100644 level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-2.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int16.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int32.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int64.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int8.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_signed.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint16.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint32.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint64.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint8.txt create mode 100644 level_1/fl_fss/data/tests/variables/payload-combined-abstruse_unsigned.txt create mode 100644 level_1/fl_fss/tests/unit/c/help-fss.c create mode 100644 level_1/fl_fss/tests/unit/c/help-fss.h create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.c create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.h create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.c create mode 100644 level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.h diff --git a/build/level_1/settings b/build/level_1/settings index 36c0d65..d898e8b 100644 --- a/build/level_1/settings +++ b/build/level_1/settings @@ -39,7 +39,7 @@ build_sources_library control_group.c build_sources_library conversion.c private-conversion.c conversion/common.c build_sources_library directory.c private-directory.c build_sources_library environment.c -build_sources_library private-fss.c fss/basic.c fss/basic_list.c fss/embedded_list.c fss/extended.c fss/extended_list.c fss/payload.c fss/private-payload.c +build_sources_library private-fss.c fss/basic.c fss/basic_list.c fss/embedded_list.c fss/extended.c fss/extended_list.c fss/payload.c fss/private-payload.c fss/private-payload-helper.c build_sources_library iki.c build_sources_library path.c build_sources_library print.c private-print.c print/common.c diff --git a/build/monolithic/settings b/build/monolithic/settings index 17f0d05..c8ea6ca 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -86,7 +86,7 @@ build_sources_library level_1/control_group.c build_sources_library level_1/conversion.c level_1/private-conversion.c level_1/conversion/common.c build_sources_library level_1/directory.c level_1/private-directory.c build_sources_library level_1/environment.c -build_sources_library level_1/private-fss.c level_1/fss/basic.c level_1/fss/basic_list.c level_1/fss/embedded_list.c level_1/fss/extended.c level_1/fss/extended_list.c level_1/fss/payload.c level_1/fss/private-payload.c +build_sources_library level_1/private-fss.c level_1/fss/basic.c level_1/fss/basic_list.c level_1/fss/embedded_list.c level_1/fss/extended.c level_1/fss/extended_list.c level_1/fss/payload.c level_1/fss/private-payload.c level_1/fss/private-payload-helper.c build_sources_library level_1/iki.c build_sources_library level_1/path.c build_sources_library level_1/print.c level_1/private-print.c level_1/print/common.c diff --git a/level_1/fl_fss/c/fss/payload.c b/level_1/fl_fss/c/fss/payload.c index 62076ed..eeec637 100644 --- a/level_1/fl_fss/c/fss/payload.c +++ b/level_1/fl_fss/c/fss/payload.c @@ -1,6 +1,7 @@ #include "payload.h" #include "../private-fss.h" #include "private-payload.h" +#include "private-payload-helper.h" #ifdef __cplusplus extern "C" { @@ -80,10 +81,8 @@ extern "C" { destinations->array[destinations->used].name.used = 0; destinations->array[destinations->used].value.used = 0; - if (!headers.array[internal.i].key.used) continue; - internal.range.start = 0; - internal.range.stop = headers.array[internal.i].key.used - 1; + internal.range.stop = headers.array[internal.i].key.used ? headers.array[internal.i].key.used - 1 : 0; private_fl_fss_basic_write(F_true, headers.array[internal.i].key, internal.quote, &internal.range, &destinations->array[destinations->used].name, state, (void * const) &internal); @@ -103,7 +102,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_signed(data, state, &internal, headers.array[internal.i].value.is.a_signed) == F_false) { - if (private_fl_payload_header_map_cache_write(data, state, &internal) == F_false) { + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, &internal, data->cache, destinations) == F_false) { ++destinations->used; } } @@ -114,7 +113,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_unsigned(data, state, &internal, headers.array[internal.i].value.is.a_unsigned) == F_false) { - if (private_fl_payload_header_map_cache_write(data, state, &internal) == F_false) { + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, &internal, data->cache, destinations) == F_false) { ++destinations->used; } } @@ -176,7 +175,7 @@ extern "C" { string_static.used = string_static.string ? strnlen(string_static.string, F_string_t_size_d) : 0; if (string_static.used || (data->flag & f_fss_payload_header_map_flag_null_string_e)) { - if (private_fl_payload_header_map_dynamic(data, state, &internal, &string_static, destinations) == F_false) { + if (private_fl_payload_helper_header_map_destination_write_buffer_or_empty(data, state, &internal, &string_static, destinations, f_fss_payload_header_map_flag_null_string_e) == F_false) { ++destinations->used; } } @@ -200,7 +199,7 @@ extern "C" { case f_abstruse_dynamic_e: if (headers.array[internal.i].value.is.a_dynamic.used || (data->flag & f_fss_payload_header_map_flag_null_dynamic_e)) { - if (private_fl_payload_header_map_dynamic(data, state, &internal, &headers.array[internal.i].value.is.a_dynamic, destinations) == F_false) { + if (private_fl_payload_helper_header_map_destination_write_buffer_or_empty(data, state, &internal, &headers.array[internal.i].value.is.a_dynamic, destinations, f_fss_payload_header_map_flag_null_dynamic_e) == F_false) { ++destinations->used; } } diff --git a/level_1/fl_fss/c/fss/payload/define.h b/level_1/fl_fss/c/fss/payload/define.h index 6dab431..35fadef 100644 --- a/level_1/fl_fss/c/fss/payload/define.h +++ b/level_1/fl_fss/c/fss/payload/define.h @@ -100,9 +100,7 @@ extern "C" { } /* for */ \ \ if (data->cache->used && (data->flag & f_fss_payload_header_map_flag_join_digits_e)) { \ - private_fl_payload_header_map_cache_write(data, state, &internal); \ - \ - if (F_status_is_error_not(state->status)) { \ + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, &internal, data->cache, destinations) == F_false) { \ ++destinations->used; \ } \ } diff --git a/level_1/fl_fss/c/fss/private-payload-helper.c b/level_1/fl_fss/c/fss/private-payload-helper.c new file mode 100644 index 0000000..88aae89 --- /dev/null +++ b/level_1/fl_fss/c/fss/private-payload-helper.c @@ -0,0 +1,103 @@ +#include "payload.h" +#include "../private-fss.h" +#include "private-payload-helper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_fl_fss_payload_header_map_) + uint8_t private_fl_payload_helper_header_map_destination_write_buffer(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations) { + + if (buffer->used) { + internal->range.start = 0; + internal->range.stop = buffer->used - 1; + + private_fl_fss_basic_write(F_false, *buffer, 0, &internal->range, &destinations->array[destinations->used].value, state, (void * const) internal); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_strip_null(&destinations->array[destinations->used].value); + if (F_status_is_error(state->status)) return F_true; + } + + state->status = F_okay; + + return F_false; + } +#endif // !defined(_di_fl_fss_payload_header_map_) + +#if !defined(_di_fl_fss_payload_header_map_) + uint8_t private_fl_payload_helper_header_map_destination_write_buffer_or_empty(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations, const uint64_t append_on_empty) { + + if (buffer->used) { + internal->range.start = 0; + internal->range.stop = buffer->used - 1; + + private_fl_fss_basic_write(F_false, *buffer, 0, &internal->range, &destinations->array[destinations->used].value, state, (void * const) internal); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_strip_null(&destinations->array[destinations->used].value); + if (F_status_is_error(state->status)) return F_true; + } + else if (data->flag & append_on_empty) { + state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); + if (F_status_is_error(state->status)) return F_true; + } + + state->status = F_okay; + + return F_false; + } +#endif // !defined(_di_fl_fss_payload_header_map_) + +#if !defined(_di_fl_fss_payload_header_map_) + uint8_t private_fl_payload_helper_header_map_destination_write_empty_three(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const destination, const f_string_static_t separator) { + + state->status = f_memory_array_increase_by(internal->quote_null.used * 3 + separator.used * 2, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append(internal->quote_null, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append_assure(separator, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append(internal->quote_null, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append_assure(separator, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append(internal->quote_null, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = F_okay; + + return F_false; + } +#endif // !defined(_di_fl_fss_payload_header_map_) + +#if !defined(_di_fl_fss_payload_header_map_) + uint8_t private_fl_payload_helper_header_map_destination_write_empty_two(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const destination, const f_string_static_t separator) { + + state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + separator.used, sizeof(f_char_t), (void **) &destination->string, &destination->used, &destination->size); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append(internal->quote_null, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append_assure(separator, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = f_string_dynamic_append(internal->quote_null, destination); + if (F_status_is_error(state->status)) return F_true; + + state->status = F_okay; + + return F_false; + } +#endif // !defined(_di_fl_fss_payload_header_map_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_fss/c/fss/private-payload-helper.h b/level_1/fl_fss/c/fss/private-payload-helper.h new file mode 100644 index 0000000..fed23ba --- /dev/null +++ b/level_1/fl_fss/c/fss/private-payload-helper.h @@ -0,0 +1,182 @@ +/** + * FLL - Level 1 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_FL_fss_payload_helper_h +#define _PRIVATE_FL_fss_payload_helper_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Write to the next destinations value, doing nothing on empty buffer. + * + * @param data + * The f_fss_payload_header_state_t pointer. + * Must not be NULL. + * @param state + * The state passed directly from the fl_fss_payload_header_map() parameters. + * + * This alters state.status: + * F_okay on success. + * + * Errors (with error bit) from: private_fl_fss_basic_write(). + * Errors (with error bit) from: f_string_dynamic_strip_null(). + * + * Must not be NULL. + * @param internal + * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). + * The internal.range is modified. + * Must not be NULL. + * @param buffer + * The buffer to write using the FLL Extended (FSS-0001) format. + * Must not be NULL. + * + * @return + * F_true if the caller should break or exit due to an error or something similar. + * F_false, otherwise. + * + * @see private_fl_fss_basic_write() + * @see f_string_dynamic_strip_null() + * + * @see fl_fss_payload_header_map() + */ +#if !defined(_di_fl_fss_payload_header_map_) + extern uint8_t private_fl_payload_helper_header_map_destination_write_buffer(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_fss_payload_header_map_) + +/** + * Write to the next destinations value, and if empty adding the quotes on NULL if needed. + * + * @param data + * The f_fss_payload_header_state_t pointer. + * Must not be NULL. + * @param state + * The state passed directly from the fl_fss_payload_header_map() parameters. + * + * This alters state.status: + * F_okay on success. + * + * Errors (with error bit) from: private_fl_fss_basic_write(). + * Errors (with error bit) from: f_string_dynamic_append(). + * Errors (with error bit) from: f_string_dynamic_strip_null(). + * + * Must not be NULL. + * @param internal + * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). + * The internal.range is modified. + * Must not be NULL. + * @param buffer + * The buffer to write using the FLL Extended (FSS-0001) format. + * Must not be NULL. + * @param append_on_empty + * Append the quoted empty string when the this flag is set. + * + * @return + * F_true if the caller should break or exit due to an error or something similar. + * F_false, otherwise. + * + * @see private_fl_fss_basic_write() + * @see f_string_dynamic_append() + * @see f_string_dynamic_strip_null() + * + * @see fl_fss_payload_header_map() + */ +#if !defined(_di_fl_fss_payload_header_map_) + extern uint8_t private_fl_payload_helper_header_map_destination_write_buffer_or_empty(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations, const uint64_t append_on_empty) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_fss_payload_header_map_) + +/** + * Write three quoted empty strings to the destination. + * + * @param data + * The f_fss_payload_header_state_t pointer. + * Must not be NULL. + * @param state + * The state passed directly from the fl_fss_payload_header_map() parameters. + * + * This alters state.status: + * F_okay on success. + * + * Errors (with error bit) from: private_fl_fss_basic_write(). + * Errors (with error bit) from: f_string_dynamic_append(). + * Errors (with error bit) from: f_string_dynamic_append_assure(). + * + * Must not be NULL. + * @param internal + * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). + * The internal.range is modified. + * Must not be NULL. + * @param destination + * The buffer to append to. + * Must not be NULL. + * @param separator + * The separate to use between each quoted empty string. + * + * @return + * F_true if the caller should break or exit due to an error or something similar. + * F_false, otherwise. + * + * @see private_fl_fss_basic_write() + * @see f_string_dynamic_append() + * @see f_string_dynamic_append_assure() + * + * @see fl_fss_payload_header_map() + */ +#if !defined(_di_fl_fss_payload_header_map_) + extern uint8_t private_fl_payload_helper_header_map_destination_write_empty_three(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const destination, const f_string_static_t separator) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_fss_payload_header_map_) + +/** + * Write two quoted empty strings to the destination. + * + * @param data + * The f_fss_payload_header_state_t pointer. + * Must not be NULL. + * @param state + * The state passed directly from the fl_fss_payload_header_map() parameters. + * + * This alters state.status: + * F_okay on success. + * + * Errors (with error bit) from: private_fl_fss_basic_write(). + * Errors (with error bit) from: f_string_dynamic_append(). + * Errors (with error bit) from: f_string_dynamic_append_assure(). + * + * Must not be NULL. + * @param internal + * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). + * The internal.range is modified. + * Must not be NULL. + * @param destination + * The buffer to append to. + * Must not be NULL. + * @param separator + * The separate to use between each quoted empty string. + * + * @return + * F_true if the caller should break or exit due to an error or something similar. + * F_false, otherwise. + * + * @see private_fl_fss_basic_write() + * @see f_string_dynamic_append() + * @see f_string_dynamic_append_assure() + * + * @see fl_fss_payload_header_map() + */ +#if !defined(_di_fl_fss_payload_header_map_) + extern uint8_t private_fl_payload_helper_header_map_destination_write_empty_two(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const destination, const f_string_static_t separator) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_fss_payload_header_map_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_FL_fss_payload_helper_h diff --git a/level_1/fl_fss/c/fss/private-payload.c b/level_1/fl_fss/c/fss/private-payload.c index b147bdb..08b11c9 100644 --- a/level_1/fl_fss/c/fss/private-payload.c +++ b/level_1/fl_fss/c/fss/private-payload.c @@ -1,56 +1,13 @@ #include "payload.h" #include "../private-fss.h" #include "private-payload.h" +#include "private-payload-helper.h" #ifdef __cplusplus extern "C" { #endif #if !defined(_di_fl_fss_payload_header_map_) - uint8_t private_fl_payload_header_map_cache_write(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal) { - - if (!data->cache->used) return F_false; - - internal->range.start = 0; - internal->range.stop = data->cache->used - 1; - - private_fl_fss_basic_write(F_false, *data->cache, internal->quote, &internal->range, &internal->destinations->array[internal->destinations->used].value, state, (void * const) internal); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_strip_null(&internal->destinations->array[internal->destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = F_okay; - - return F_false; - } -#endif // !defined(_di_fl_fss_payload_header_map_) - -#if !defined(_di_fl_fss_payload_header_map_) - uint8_t private_fl_payload_header_map_dynamic(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations) { - - if (buffer->used) { - internal->range.start = 0; - internal->range.stop = buffer->used - 1; - - private_fl_fss_basic_write(F_false, *buffer, 0, &internal->range, &destinations->array[destinations->used].value, state, (void * const) internal); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_strip_null(&destinations->array[destinations->used].value); - } - else { - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - } - - if (F_status_is_error(state->status)) return F_true; - - state->status = F_okay; - - return F_false; - } -#endif // !defined(_di_fl_fss_payload_header_map_) - -#if !defined(_di_fl_fss_payload_header_map_) uint8_t private_fl_payload_header_map_dynamics(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_statics_t * const buffers, f_string_maps_t * const destinations) { if (buffers->used) { @@ -637,7 +594,7 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; } - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { if ((data->flag & f_fss_payload_header_map_flag_null_map_multi_values_name_e) == f_fss_payload_header_map_flag_null_map_multi_values_name_e) { @@ -876,7 +833,7 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; } - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { if ((data->flag & f_fss_payload_header_map_flag_null_map_value_name_e) == f_fss_payload_header_map_flag_null_map_value_name_e) { @@ -954,10 +911,10 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_quantity_e) { if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantity.total) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); if (F_status_is_error(state->status)) return F_true; @@ -965,7 +922,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantity.total) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } } else { @@ -973,32 +930,11 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_quantity_e) { data->cache->used = 0; - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &data->cache->string, &data->cache->used, &data->cache->size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &destinations->array[destinations->used].value.string, &destinations->array[destinations->used].value.used, &destinations->array[destinations->used].value.size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, &destinations->array[destinations->used].value, f_fss_extended_next_s) == F_true) return F_true; } } } @@ -1059,18 +995,11 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; } - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; } } // for - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { data->cache->used = 0; @@ -1091,7 +1020,7 @@ extern "C" { if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantitys.array[internal->l].start) == F_true) return F_true; if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantitys.array[internal->l].total) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; continue; } @@ -1099,16 +1028,8 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_null_quantity_e) { data->cache->used = 0; - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } } // for } @@ -1127,7 +1048,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantitys.array[internal->l].start) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; data->cache->used = 0; @@ -1135,7 +1056,7 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; if (private_fl_payload_header_map_number_unsigned(data, state, internal, quantitys.array[internal->l].total) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); if (F_status_is_error(state->status)) return F_true; @@ -1164,32 +1085,11 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_quantitys_quantity_e) { data->cache->used = 0; - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_space_s.used, sizeof(f_char_t), (void **) &data->cache->string, &data->cache->used, &data->cache->size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &destinations->array[destinations->used].value.string, &destinations->array[destinations->used].value.used, &destinations->array[destinations->used].value.size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, &destinations->array[destinations->used].value, f_fss_extended_next_s) == F_true) return F_true; } } } @@ -1208,32 +1108,11 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_range_e) { data->cache->used = 0; - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &data->cache->string, &data->cache->used, &data->cache->size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &destinations->array[destinations->used].value.string, &destinations->array[destinations->used].value.used, &destinations->array[destinations->used].value.size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, &destinations->array[destinations->used].value, f_fss_extended_next_s) == F_true) return F_true; } } } @@ -1244,10 +1123,10 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_range_e) { if (private_fl_payload_header_map_number_unsigned(data, state, internal, range.stop) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); if (F_status_is_error(state->status)) return F_true; @@ -1255,7 +1134,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_unsigned(data, state, internal, range.stop) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } } @@ -1309,14 +1188,7 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; } - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; } continue; @@ -1326,7 +1198,7 @@ extern "C" { if (private_fl_payload_header_map_number_unsigned(data, state, internal, ranges.array[internal->l].stop) == F_true) return F_true; } // for - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { data->cache->used = 0; @@ -1346,16 +1218,8 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_null_range_e) { data->cache->used = 0; - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append_assure(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } continue; @@ -1365,7 +1229,7 @@ extern "C" { if (private_fl_payload_header_map_number_unsigned(data, state, internal, ranges.array[internal->l].start) == F_true) return F_true; if (private_fl_payload_header_map_number_unsigned(data, state, internal, ranges.array[internal->l].stop) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } // for } else { @@ -1394,7 +1258,7 @@ extern "C" { data->cache->used = 0; if (private_fl_payload_header_map_number_unsigned(data, state, internal, ranges.array[internal->l].start) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; data->cache->used = 0; @@ -1402,7 +1266,7 @@ extern "C" { if (F_status_is_error(state->status)) return F_true; if (private_fl_payload_header_map_number_unsigned(data, state, internal, ranges.array[internal->l].stop) == F_true) return F_true; - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; state->status = f_string_dynamic_append_assure(f_fss_extended_next_s, &destinations->array[destinations->used].value); if (F_status_is_error(state->status)) return F_true; @@ -1420,32 +1284,11 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_ranges_range_e) { data->cache->used = 0; - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_space_s.used, sizeof(f_char_t), (void **) &data->cache->string, &data->cache->used, &data->cache->size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - state->status = f_memory_array_increase_by(internal->quote_null.used * 2 + f_fss_extended_next_s.used, sizeof(f_char_t), (void **) &destinations->array[destinations->used].value.string, &destinations->array[destinations->used].value.used, &destinations->array[destinations->used].value.size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_two(data, state, internal, &destinations->array[destinations->used].value, f_fss_extended_next_s) == F_true) return F_true; } } } @@ -1622,7 +1465,7 @@ extern "C" { } if (data->flag & f_fss_payload_header_map_flag_join_triple_e) { - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { state->status = f_string_dynamic_strip_null(&destinations->array[destinations->used].value); @@ -1729,12 +1572,12 @@ extern "C" { } if (!(data->flag & f_fss_payload_header_map_flag_join_triples_e)) { - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } } // for if (data->flag & f_fss_payload_header_map_flag_join_triples_e) { - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } } else { @@ -1810,44 +1653,11 @@ extern "C" { if (data->flag & f_fss_payload_header_map_flag_join_triples_triple_e) { data->cache->used = 0; - state->status = f_memory_array_increase_by(internal->quote_null.used * 3 + f_fss_space_s.used * 2, sizeof(f_char_t), (void **) &data->cache->string, &data->cache->used, &data->cache->size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_space_s, data->cache); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, data->cache); - if (F_status_is_error(state->status)) return F_true; - - if (private_fl_payload_header_map_cache_write(data, state, internal) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_three(data, state, internal, data->cache, f_fss_space_s) == F_true) return F_true; + if (private_fl_payload_helper_header_map_destination_write_buffer(data, state, internal, data->cache, destinations) == F_true) return F_true; } else { - state->status = f_memory_array_increase_by(internal->quote_null.used * 3 + f_fss_extended_next_s.used * 2, sizeof(f_char_t), (void **) &destinations->array[destinations->used].value.string, &destinations->array[destinations->used].value.used, &destinations->array[destinations->used].value.size); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(f_fss_extended_next_s, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; - - state->status = f_string_dynamic_append(internal->quote_null, &destinations->array[destinations->used].value); - if (F_status_is_error(state->status)) return F_true; + if (private_fl_payload_helper_header_map_destination_write_empty_three(data, state, internal, &destinations->array[destinations->used].value, f_fss_extended_next_s) == F_true) return F_true; } } } diff --git a/level_1/fl_fss/c/fss/private-payload.h b/level_1/fl_fss/c/fss/private-payload.h index beba621..f45ba39 100644 --- a/level_1/fl_fss/c/fss/private-payload.h +++ b/level_1/fl_fss/c/fss/private-payload.h @@ -16,87 +16,6 @@ extern "C" { #endif /** - * Write the cache to the destination. - * - * @param data - * The f_fss_payload_header_state_t pointer. - * This caller must reset data.cache.used as needed. - * if data.cache.used is not 0, then this will append a space before adding the converted number. - * Must not be NULL. - * @param state - * The state passed directly from the fl_fss_payload_header_map() parameters. - * - * This alters state.status: - * F_okay on success. - * - * Errors (with error bit) from: private_fl_fss_basic_write(). - * Errors (with error bit) from: f_string_dynamic_strip_null(). - * - * Must not be NULL. - * @param internal - * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). - * The internal.range is modified. - * Must not be NULL. - * - * @return - * F_true if the caller should break or exit due to an error or something similar. - * F_false, otherwise. - * - * @see private_fl_fss_basic_write() - * @see f_string_dynamic_strip_null() - * - * @see fl_fss_payload_header_map() - */ -#if !defined(_di_fl_fss_payload_header_map_) - extern uint8_t private_fl_payload_header_map_cache_write(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_fss_payload_header_map_) - -/** - * Process the dynamic string, writing it into the packet with the appropriate escaping as necessary. - * - * This expects that the appropriate used and flag checks are performed prior to calling this. - * - * @param data - * The f_fss_payload_header_state_t pointer. - * Must not be NULL. - * @param state - * The state passed directly from the fl_fss_payload_header_map() parameters. - * - * This alters state.status: - * F_okay on success. - * - * Errors (with error bit) from: f_string_dynamic_strip_null(). - * Errors (with error bit) from: private_fl_fss_basic_write(). - * - * Must not be NULL. - * @param internal - * The internal state, f_fss_payload_header_internal_t, created inside of fl_fss_payload_header_map(). - * Must not be NULL. - * @param buffer - * The dynamic string to read from. - * Must not be NULL. - * @param destinations - * A map of strings representing the header names and values after being safely converted into the valid payload header format. - * This built header names and values are appended onto this. - * This is updated as appropriate. - * Must not be NULL. - * - * @return - * F_true if the caller should break or exit due to an error or something similar. - * F_false, otherwise. - * - * @see f_string_dynamic_append() - * @see f_string_dynamic_strip_null() - * - * @see private_fl_fss_basic_write() - * - * @see fl_fss_payload_header_map() - */ -#if !defined(_di_fl_fss_payload_header_map_) - extern uint8_t private_fl_payload_header_map_dynamic(f_fss_payload_header_state_t * const data, f_state_t * const state, f_fss_payload_header_internal_t * const internal, f_string_static_t * const buffer, f_string_maps_t * const destinations) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_fss_payload_header_map_) - -/** * Process the array of dynamic strings, writing it into the packet with the appropriate escaping as necessary. * * This expects that the appropriate used and flag checks are performed prior to calling this. @@ -340,6 +259,7 @@ extern "C" { /** * Process the signed number, converting it to a string and appending that string onto data->cache. + * * The resulting data->cache is then appended onto the destination value on success. * If the number is not appended to data->cache, then nothing is appended to the destination value. * @@ -380,6 +300,7 @@ extern "C" { /** * Process the unsigned number, converting it to a string and appending that string onto data->cache. + * * The resulting data->cache is then appended onto the destination value on success. * If the number is not appended to data->cache, then nothing is appended to the destination value. * @@ -491,8 +412,8 @@ extern "C" { * Errors (with error bit) from: f_string_dynamic_append(). * Errors (with error bit) from: f_string_dynamic_append_assure(). * Errors (with error bit) from: private_fl_fss_basic_write(). - * Errors (with error bit) from: private_fl_payload_header_map_cache_write(). * Errors (with error bit) from: private_fl_payload_header_map_number_unsigned(). + * Errors (with error bit) from: private_fl_payload_helper_header_map_destination_write_buffer(). * * Must not be NULL. * @param internal @@ -595,8 +516,8 @@ extern "C" { * Errors (with error bit) from: f_string_dynamic_append(). * Errors (with error bit) from: f_string_dynamic_append_assure(). * Errors (with error bit) from: private_fl_fss_basic_write(). - * Errors (with error bit) from: private_fl_payload_header_map_cache_write(). * Errors (with error bit) from: private_fl_payload_header_map_number_unsigned(). + * Errors (with error bit) from: private_fl_payload_helper_header_map_destination_write_buffer(). * * Must not be NULL. * @param internal @@ -752,8 +673,8 @@ extern "C" { * Errors (with error bit) from: f_string_dynamic_append(). * Errors (with error bit) from: f_string_dynamic_append_assure(). * Errors (with error bit) from: private_fl_fss_basic_write(). - * Errors (with error bit) from: private_fl_payload_header_map_cache_write(). * Errors (with error bit) from: private_fl_payload_header_map_number_unsigned(). + * Errors (with error bit) from: private_fl_payload_helper_header_map_destination_write_buffer(). * * Must not be NULL. * @param internal diff --git a/level_1/fl_fss/data/build/settings b/level_1/fl_fss/data/build/settings index f95ddf7..2de5d93 100644 --- a/level_1/fl_fss/data/build/settings +++ b/level_1/fl_fss/data/build/settings @@ -33,7 +33,7 @@ build_language c build_libraries -lc build_libraries-individual -lf_abstruse -lf_conversion -lf_file -lf_fss -lf_memory -lf_string -lf_type_array -lf_utf -build_sources_library private-fss.c fss/basic.c fss/basic_list.c fss/embedded_list.c fss/extended.c fss/extended_list.c fss/payload.c fss/private-payload.c +build_sources_library private-fss.c fss/basic.c fss/basic_list.c fss/embedded_list.c fss/extended.c fss/extended_list.c fss/payload.c fss/private-payload.c fss/private-payload-helper.c build_sources_headers fss.h fss/basic.h fss/basic_list.h fss/embedded_list.h fss/extended.h fss/extended_list.h fss/payload.h fss/payload/define.h fss/payload/type.h diff --git a/level_1/fl_fss/data/build/settings-tests b/level_1/fl_fss/data/build/settings-tests index 78b410a..e461429 100644 --- a/level_1/fl_fss/data/build/settings-tests +++ b/level_1/fl_fss/data/build/settings-tests @@ -31,8 +31,9 @@ build_sources_program test-fss-embedded_list_content_read.c test-fss-embedded_li build_sources_program test-fss-extended_content_read.c test-fss-extended_content_write.c test-fss-extended_object_read.c test-fss-extended_object_write.c build_sources_program test-fss-extended_list_content_read.c test-fss-extended_list_content_write.c test-fss-extended_list_object_read.c test-fss-extended_list_object_write.c build_sources_program test-fss-payload_header_map.c +build_sources_program test-fss-payload_header_map-abstruse_signed.c test-fss-payload_header_map-abstruse_unsigned.c -build_sources_program test-fss.c data-fss.c +build_sources_program test-fss.c data-fss.c help-fss.c build_script no build_shared yes diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-1.txt new file mode 100644 index 0000000..6e7b16d --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +555 +1 +7777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-2.txt new file mode 100644 index 0000000..eebcb15 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int16-2.txt @@ -0,0 +1,7 @@ +c +1 +012345 +1 +-32700 +1 +-1 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-2.txt new file mode 100644 index 0000000..0c8996c --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int32-2.txt @@ -0,0 +1,7 @@ +c +1 +123456789 +1 +-2147483600 +1 +-1 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-2.txt new file mode 100644 index 0000000..1190e0c --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int64-2.txt @@ -0,0 +1,9 @@ +c +1 +123456789 +1 +-9876543210 +1 +-1 +1 +-9223372036854775000 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-1.txt new file mode 100644 index 0000000..8b87989 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55 +1 +77 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-2.txt new file mode 100644 index 0000000..978a237 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_int8-2.txt @@ -0,0 +1,7 @@ +c +1 +12 +1 +-120 +1 +-1 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-2.txt new file mode 100644 index 0000000..42171ea --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_signed-2.txt @@ -0,0 +1,7 @@ +c +1 +123456789 +1 +-9876543210 +1 +-1 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-1.txt new file mode 100644 index 0000000..d4c115e --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +7777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-2.txt new file mode 100644 index 0000000..76998c8 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint16-2.txt @@ -0,0 +1,5 @@ +c +1 +1234 +1 +65500 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-2.txt new file mode 100644 index 0000000..2cc4b73 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint32-2.txt @@ -0,0 +1,5 @@ +c +1 +123456789 +1 +4294967200 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-2.txt new file mode 100644 index 0000000..cc5d23f --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint64-2.txt @@ -0,0 +1,7 @@ +c +1 +123456789 +1 +9876543210 +1 +18446744073709550000 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-1.txt new file mode 100644 index 0000000..8b87989 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55 +1 +77 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-2.txt new file mode 100644 index 0000000..4e63bf5 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_uint8-2.txt @@ -0,0 +1,5 @@ +c +1 +25 +1 +250 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-0.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-0.txt new file mode 100644 index 0000000..ea96fee --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-0.txt @@ -0,0 +1,9 @@ +a +1 +0 +1 +1 +1 +2 +1 +3 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-1.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-1.txt new file mode 100644 index 0000000..5cc4217 --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-1.txt @@ -0,0 +1,7 @@ +b +1 +44 +1 +55555 +1 +77777777 diff --git a/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-2.txt b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-2.txt new file mode 100644 index 0000000..deeff1b --- /dev/null +++ b/level_1/fl_fss/data/tests/headers/payload-combined-abstruse_unsigned-2.txt @@ -0,0 +1,5 @@ +c +1 +123456789 +1 +9876543210 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int16.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int16.txt new file mode 100644 index 0000000..7fedf92 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int16.txt @@ -0,0 +1,16 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +555 +7777 +c +3 +012345 +-32700 +-1 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int32.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int32.txt new file mode 100644 index 0000000..50445fa --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int32.txt @@ -0,0 +1,16 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +3 +0123456789 +-2147483600 +-1 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int64.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int64.txt new file mode 100644 index 0000000..8081765 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int64.txt @@ -0,0 +1,17 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +4 +0123456789 +-9876543210 +-1 +-9223372036854775000 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int8.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int8.txt new file mode 100644 index 0000000..cd76372 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_int8.txt @@ -0,0 +1,16 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55 +77 +c +3 +012 +-120 +-1 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_signed.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_signed.txt new file mode 100644 index 0000000..485a2ee --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_signed.txt @@ -0,0 +1,16 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +3 +0123456789 +-9876543210 +-1 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint16.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint16.txt new file mode 100644 index 0000000..34784a2 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint16.txt @@ -0,0 +1,15 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +7777 +c +2 +01234 +65500 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint32.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint32.txt new file mode 100644 index 0000000..312aafd --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint32.txt @@ -0,0 +1,15 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +2 +0123456789 +4294967200 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint64.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint64.txt new file mode 100644 index 0000000..59ee745 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint64.txt @@ -0,0 +1,16 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +3 +0123456789 +9876543210 +18446744073709550000 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint8.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint8.txt new file mode 100644 index 0000000..2873e85 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_uint8.txt @@ -0,0 +1,15 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55 +77 +c +2 +025 +250 diff --git a/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_unsigned.txt b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_unsigned.txt new file mode 100644 index 0000000..25a8316 --- /dev/null +++ b/level_1/fl_fss/data/tests/variables/payload-combined-abstruse_unsigned.txt @@ -0,0 +1,15 @@ +a +4 +0 +1 +2 +3 +b +3 +44 +55555 +77777777 +c +2 +0123456789 +9876543210 diff --git a/level_1/fl_fss/tests/unit/c/data-fss.c b/level_1/fl_fss/tests/unit/c/data-fss.c index 458e52b..ea4d35d 100644 --- a/level_1/fl_fss/tests/unit/c/data-fss.c +++ b/level_1/fl_fss/tests/unit/c/data-fss.c @@ -1,25 +1,27 @@ -#include "data-fss.h" +#include "test-fss.h" #ifdef __cplusplus extern "C" { #endif -FILE *data__file_open__named__all_read(const f_string_t set, const f_string_t name) { +FILE *data__file_open__named(const f_string_t set, const f_string_t name, const f_string_t context) { + char path[255]; memset(path, 0, 255); - snprintf(path, 254, "./data/tests/%s/%s-all_read.txt", set, name); + snprintf(path, 254, "./data/tests/%s/%s-%s.txt", set, name, context); return fopen(path, "r"); } -FILE *data__file_open__named_at__all_read(const f_string_t set, const f_string_t name, const uint8_t at) { +FILE *data__file_open__named_at(const f_string_t set, const f_string_t name, const f_string_t context, const uint16_t at) { + char path[255]; memset(path, 0, 255); - snprintf(path, 254, "./data/tests/%s/%s-all_read-%d.txt", set, name, at); + snprintf(path, 254, "./data/tests/%s/%s-%s-%d.txt", set, name, context, at); return fopen(path, "r"); } diff --git a/level_1/fl_fss/tests/unit/c/data-fss.h b/level_1/fl_fss/tests/unit/c/data-fss.h index e6e3fe9..965358a 100644 --- a/level_1/fl_fss/tests/unit/c/data-fss.h +++ b/level_1/fl_fss/tests/unit/c/data-fss.h @@ -15,17 +15,6 @@ #include #include -// FLL-0 includes. - -// FLL-1 includes. -#include -#include -#include -#include -#include -#include -#include - #ifdef __cplusplus extern "C" { #endif @@ -35,10 +24,17 @@ extern "C" { * * This requires the following: * - The file path is relative to the current working directory (tests are run from project root). - * - The file path is "data/tests/${set}/${name}-all_read.txt". + * - The file path is "data/tests/${set}/${name}-${context}.txt". * - Where "${set}" represents the directory set, like "contents", "objects", or "strings". * - Where "${name}" represents the standard name, such as "basic" or "extended". + * - Where "${context}" represents the test context, such as "all_read" or "header_map". * + * @param set + * The name of the test set, representing the directory the the files are stored within. + * @param context + * The test file directory set. + * @param name + * The test file standard name. * @param at * A number representing the specific content index position. * @@ -48,18 +44,25 @@ extern "C" { * * @see fopen() */ -extern FILE *data__file_open__named__all_read(const f_string_t set, const f_string_t name); +extern FILE *data__file_open__named(const f_string_t set, const f_string_t name, const f_string_t context); /** * Open the test data file for the given set with the given name and the given at index. * * This requires the following: * - The file path is relative to the current working directory (tests are run from project root). - * - The file path is "data/tests/${set}/${name}-all_read-${at}.txt". + * - The file path is "data/tests/${set}/${name}-${context}-${at}.txt". + * - Where "${set}" represents the directory set, like "contents", "headers", "objects", "strings", or "variables". + * - Where "${name}" represents the standard name, such as "basic", "extended", or "payload". + * - Where "${context}" represents the test context, such as "all_read" or "abstruse_signed". * - Where "${at}" represents the index. - * - Where "${set}" represents the directory set, like "contents", "objects", or "strings". - * - Where "${name}" represents the standard name, such as "basic" or "extended". * + * @param set + * The name of the test set, representing the directory the the files are stored within. + * @param context + * The test file directory set. + * @param name + * The test file standard name. * @param at * A number representing the specific content index position. * @@ -69,7 +72,7 @@ extern FILE *data__file_open__named__all_read(const f_string_t set, const f_stri * * @see fopen() */ -extern FILE *data__file_open__named_at__all_read(const f_string_t set, const f_string_t name, const uint8_t at); +extern FILE *data__file_open__named_at(const f_string_t set, const f_string_t name, const f_string_t context, const uint16_t at); #ifdef __cplusplus } // extern "C" diff --git a/level_1/fl_fss/tests/unit/c/help-fss.c b/level_1/fl_fss/tests/unit/c/help-fss.c new file mode 100644 index 0000000..f1b6186 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/help-fss.c @@ -0,0 +1,133 @@ +#include "test-fss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint8_t help__read_line_contents__single(FILE *file, f_string_dynamics_t * const contents) { + + size_t max = 255; + char *line_string = 0; + + ssize_t result = getline(&line_string, &max, file); + + if (result == -1) { + if (line_string) free(line_string); + + return F_true; + } + + assert_int_not_equal(result, 0); + assert_int_not_equal(line_string[0], 0); + + const f_number_unsigned_t count = (f_number_unsigned_t) atoi(line_string); + + if (!count) { + assert_int_equal(line_string[0], '0'); + } + + contents->used = 0; + + { + const f_status_t status = f_memory_array_increase_by(count, sizeof(f_string_dynamic_t), (void **) &contents->array, &contents->used, &contents->size); + assert_true(F_status_is_error_not(status)); + } + + for (; contents->used < count; ++contents->used) { + + max = 255; + contents->array[contents->used].used = 0; + + const f_status_t status = f_memory_array_increase_by(max, sizeof(f_string_t), (void **) &contents->array[contents->used].string, &contents->array[contents->used].used, &contents->array[contents->used].size); + assert_true(F_status_is_error_not(status)); + + result = getline(&contents->array[contents->used].string, &max, file); + assert_int_not_equal(result, -1); + assert_int_not_equal(result, 0); + + contents->array[contents->used].used = ((f_number_unsigned_t) result) - 1; + contents->array[contents->used].string[contents->array[contents->used].used] = 0; + } // for + + if (line_string) free(line_string); + + return F_false; +} + +uint8_t help__read_line_expects__single(FILE *file, const f_string_static_t object, f_string_maps_t * const expects) { + + size_t max = 255; + char *line_string = 0; + f_status_t status = F_okay; + + ssize_t result = getline(&line_string, &max, file); + + if (result == -1) { + if (line_string) free(line_string); + + return F_true; + } + + assert_int_not_equal(result, 0); + assert_int_not_equal(line_string[0], 0); + + const f_number_unsigned_t count = (f_number_unsigned_t) atoi(line_string); + + if (!count) { + assert_int_equal(line_string[0], '0'); + } + + status = f_memory_array_increase_by(count, sizeof(f_string_map_t), (void **) &expects->array, &expects->used, &expects->size); + assert_true(F_status_is_error_not(status)); + + for (f_number_unsigned_t i = 0; i < count; ++i, ++expects->used) { + + max = 255; + expects->array[expects->used].name.used = 0; + expects->array[expects->used].value.used = 0; + + status = f_string_dynamic_append(object, &expects->array[expects->used].name); + assert_true(F_status_is_error_not(status)); + + status = f_string_dynamic_terminate_after(&expects->array[expects->used].name); + assert_true(F_status_is_error_not(status)); + + status = f_memory_array_increase_by(max, sizeof(f_string_t), (void **) &expects->array[expects->used].value.string, &expects->array[expects->used].value.used, &expects->array[expects->used].value.size); + assert_true(F_status_is_error_not(status)); + + result = getline(&expects->array[expects->used].value.string, &max, file); + assert_int_not_equal(result, -1); + assert_int_not_equal(result, 0); + + expects->array[expects->used].value.used = ((f_number_unsigned_t) result) - 1; + expects->array[expects->used].value.string[expects->array[expects->used].value.used] = 0; + } // for + + if (line_string) free(line_string); + + return F_false; +} + +uint8_t help__read_line_object(FILE *file, f_string_dynamic_t * const object) { + + size_t max = 255; + + object->used = 0; + + const f_status_t status = f_memory_array_increase_by(max, sizeof(f_string_t), (void **) &object->string, &object->used, &object->size); + assert_true(F_status_is_error_not(status)); + + const ssize_t result = getline(&object->string, &max, file); + if (result == -1) return F_true; + + assert_int_not_equal(result, 0); + + object->used = ((f_number_unsigned_t) result) - 1; + object->string[object->used] = 0; + + return F_false; +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_fss/tests/unit/c/help-fss.h b/level_1/fl_fss/tests/unit/c/help-fss.h new file mode 100644 index 0000000..977bfb0 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/help-fss.h @@ -0,0 +1,82 @@ +/** + * 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_h +#define _HELP__FL_fss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Load the content lines from the given file. + * + * This first loads the content line total followed by each content line according to that total. + * + * The content read is treated each as a single, separate, map value. + * + * @param file + * The file to use. + * Must not be NULL. + * @param contents + * The array of contents to use. + * Must not be 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); + +/** + * Load the expect lines from the given file. + * + * This first loads the expect line total followed by each expect line according to that total. + * + * The expect read is treated each as a single, separate, map value. + * + * @param file + * The file to use. + * Must not be NULL. + * @param object + * The object name to associate with each expected content. + * @param expects + * The array of expects to use. + * Must not be NULL. + * + * @return + * F_true if there is no expect left to read in the file. + * F_false otherwise. + */ +uint8_t help__read_line_expects__single(FILE *file, const f_string_static_t object, f_string_maps_t * const expects); + +/** + * Load the object line from the given file. + * + * The object line is required to exist in the file. + * + * @param file + * The file to use. + * Must not be NULL. + * @param object + * The string to use. + * The used is set to the size of the string read, without the EOL. + * Must not be NULL. + * + * @return + * F_true if there is no object left to read in the file. + * F_false otherwise. + */ +uint8_t help__read_line_object(FILE *file, f_string_dynamic_t * const object); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _HELP__FL_fss_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c index b97d9aa..0983cab 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c @@ -89,8 +89,8 @@ void test__fl_fss_basic_content_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "basic"); - FILE *file_contents = data__file_open__named__all_read("contents", "basic"); + FILE *file_strings = data__file_open__named("strings", "basic", "all_read"); + FILE *file_contents = data__file_open__named("contents", "basic", "all_read"); assert_non_null(file_strings); assert_non_null(file_contents); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c index e0f6981..34210a3 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_content_read.c @@ -123,21 +123,21 @@ void test__fl_fss_basic_list_content_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "basic_list"); + FILE *file_strings = data__file_open__named("strings", "basic_list", "all_read"); FILE *file_contents[] = { - data__file_open__named_at__all_read("contents", "basic_list", 0), - data__file_open__named_at__all_read("contents", "basic_list", 1), - data__file_open__named_at__all_read("contents", "basic_list", 2), - data__file_open__named_at__all_read("contents", "basic_list", 3), - data__file_open__named_at__all_read("contents", "basic_list", 4), - data__file_open__named_at__all_read("contents", "basic_list", 5), - data__file_open__named_at__all_read("contents", "basic_list", 6), - data__file_open__named_at__all_read("contents", "basic_list", 7), - data__file_open__named_at__all_read("contents", "basic_list", 8), - data__file_open__named_at__all_read("contents", "basic_list", 9), - data__file_open__named_at__all_read("contents", "basic_list", 10), - data__file_open__named_at__all_read("contents", "basic_list", 11), + data__file_open__named_at("contents", "basic_list", "all_read", 0), + data__file_open__named_at("contents", "basic_list", "all_read", 1), + data__file_open__named_at("contents", "basic_list", "all_read", 2), + data__file_open__named_at("contents", "basic_list", "all_read", 3), + data__file_open__named_at("contents", "basic_list", "all_read", 4), + data__file_open__named_at("contents", "basic_list", "all_read", 5), + data__file_open__named_at("contents", "basic_list", "all_read", 6), + data__file_open__named_at("contents", "basic_list", "all_read", 7), + data__file_open__named_at("contents", "basic_list", "all_read", 8), + data__file_open__named_at("contents", "basic_list", "all_read", 9), + data__file_open__named_at("contents", "basic_list", "all_read", 10), + data__file_open__named_at("contents", "basic_list", "all_read", 11), }; assert_non_null(file_strings); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c index a58b676..1d24725 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c @@ -88,8 +88,8 @@ void test__fl_fss_basic_list_object_read__returns_data_not(void **void_state) { void test__fl_fss_basic_list_object_read__works(void **void_state) { { - FILE *file_strings = data__file_open__named__all_read("strings", "basic_list"); - FILE *file_objects = data__file_open__named__all_read("objects", "basic_list"); + FILE *file_strings = data__file_open__named("strings", "basic_list", "all_read"); + FILE *file_objects = data__file_open__named("objects", "basic_list", "all_read"); assert_non_null(file_strings); assert_non_null(file_objects); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c index 51b86ab..87ddb23 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c @@ -139,8 +139,8 @@ void test__fl_fss_basic_object_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "basic"); - FILE *file_objects = data__file_open__named__all_read("objects", "basic"); + FILE *file_strings = data__file_open__named("strings", "basic", "all_read"); + FILE *file_objects = data__file_open__named("objects", "basic", "all_read"); assert_non_null(file_strings); assert_non_null(file_objects); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c index 9fedb88..c331a05 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_content_read.c @@ -139,21 +139,21 @@ void test__fl_fss_embedded_list_content_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "embedded_list"); + FILE *file_strings = data__file_open__named("strings", "embedded_list", "all_read"); FILE *file_contents[] = { - data__file_open__named_at__all_read("contents", "embedded_list", 0), - data__file_open__named_at__all_read("contents", "embedded_list", 1), - data__file_open__named_at__all_read("contents", "embedded_list", 2), - data__file_open__named_at__all_read("contents", "embedded_list", 3), - data__file_open__named_at__all_read("contents", "embedded_list", 4), - data__file_open__named_at__all_read("contents", "embedded_list", 5), - data__file_open__named_at__all_read("contents", "embedded_list", 6), - data__file_open__named_at__all_read("contents", "embedded_list", 7), - data__file_open__named_at__all_read("contents", "embedded_list", 8), - data__file_open__named_at__all_read("contents", "embedded_list", 9), - data__file_open__named_at__all_read("contents", "embedded_list", 10), - data__file_open__named_at__all_read("contents", "embedded_list", 11), + data__file_open__named_at("contents", "embedded_list", "all_read", 0), + data__file_open__named_at("contents", "embedded_list", "all_read", 1), + data__file_open__named_at("contents", "embedded_list", "all_read", 2), + data__file_open__named_at("contents", "embedded_list", "all_read", 3), + data__file_open__named_at("contents", "embedded_list", "all_read", 4), + data__file_open__named_at("contents", "embedded_list", "all_read", 5), + data__file_open__named_at("contents", "embedded_list", "all_read", 6), + data__file_open__named_at("contents", "embedded_list", "all_read", 7), + data__file_open__named_at("contents", "embedded_list", "all_read", 8), + data__file_open__named_at("contents", "embedded_list", "all_read", 9), + data__file_open__named_at("contents", "embedded_list", "all_read", 10), + data__file_open__named_at("contents", "embedded_list", "all_read", 11), }; assert_non_null(file_strings); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c index d1068dc..4e27e97 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-embedded_list_object_read.c @@ -88,8 +88,8 @@ void test__fl_fss_embedded_list_object_read__returns_data_not(void **void_state) void test__fl_fss_embedded_list_object_read__works(void **void_state) { { - FILE *file_strings = data__file_open__named__all_read("strings", "embedded_list"); - FILE *file_objects = data__file_open__named__all_read("objects", "embedded_list"); + FILE *file_strings = data__file_open__named("strings", "embedded_list", "all_read"); + FILE *file_objects = data__file_open__named("objects", "embedded_list", "all_read"); assert_non_null(file_strings); assert_non_null(file_objects); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c index c6637c1..d8e905d 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c @@ -139,17 +139,17 @@ void test__fl_fss_extended_content_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "extended"); + FILE *file_strings = data__file_open__named("strings", "extended", "all_read"); FILE *file_contents[] = { - data__file_open__named_at__all_read("contents", "extended", 0), - data__file_open__named_at__all_read("contents", "extended", 1), - data__file_open__named_at__all_read("contents", "extended", 2), - data__file_open__named_at__all_read("contents", "extended", 3), - data__file_open__named_at__all_read("contents", "extended", 4), - data__file_open__named_at__all_read("contents", "extended", 5), - data__file_open__named_at__all_read("contents", "extended", 6), - data__file_open__named_at__all_read("contents", "extended", 7), + data__file_open__named_at("contents", "extended", "all_read", 0), + data__file_open__named_at("contents", "extended", "all_read", 1), + data__file_open__named_at("contents", "extended", "all_read", 2), + data__file_open__named_at("contents", "extended", "all_read", 3), + data__file_open__named_at("contents", "extended", "all_read", 4), + data__file_open__named_at("contents", "extended", "all_read", 5), + data__file_open__named_at("contents", "extended", "all_read", 6), + data__file_open__named_at("contents", "extended", "all_read", 7), }; assert_non_null(file_strings); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c index 40e3c44..140d8fb 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_content_read.c @@ -155,21 +155,21 @@ void test__fl_fss_extended_list_content_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "extended_list"); + FILE *file_strings = data__file_open__named("strings", "extended_list", "all_read"); FILE *file_contents[] = { - data__file_open__named_at__all_read("contents", "extended_list", 0), - data__file_open__named_at__all_read("contents", "extended_list", 1), - data__file_open__named_at__all_read("contents", "extended_list", 2), - data__file_open__named_at__all_read("contents", "extended_list", 3), - data__file_open__named_at__all_read("contents", "extended_list", 4), - data__file_open__named_at__all_read("contents", "extended_list", 5), - data__file_open__named_at__all_read("contents", "extended_list", 6), - data__file_open__named_at__all_read("contents", "extended_list", 7), - data__file_open__named_at__all_read("contents", "extended_list", 8), - data__file_open__named_at__all_read("contents", "extended_list", 9), - data__file_open__named_at__all_read("contents", "extended_list", 10), - data__file_open__named_at__all_read("contents", "extended_list", 11), + data__file_open__named_at("contents", "extended_list", "all_read", 0), + data__file_open__named_at("contents", "extended_list", "all_read", 1), + data__file_open__named_at("contents", "extended_list", "all_read", 2), + data__file_open__named_at("contents", "extended_list", "all_read", 3), + data__file_open__named_at("contents", "extended_list", "all_read", 4), + data__file_open__named_at("contents", "extended_list", "all_read", 5), + data__file_open__named_at("contents", "extended_list", "all_read", 6), + data__file_open__named_at("contents", "extended_list", "all_read", 7), + data__file_open__named_at("contents", "extended_list", "all_read", 8), + data__file_open__named_at("contents", "extended_list", "all_read", 9), + data__file_open__named_at("contents", "extended_list", "all_read", 10), + data__file_open__named_at("contents", "extended_list", "all_read", 11), }; assert_non_null(file_strings); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c index 687ebf6..acacff6 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_list_object_read.c @@ -88,8 +88,8 @@ void test__fl_fss_extended_list_object_read__returns_data_not(void **void_state) void test__fl_fss_extended_list_object_read__works(void **void_state) { { - FILE *file_strings = data__file_open__named__all_read("strings", "extended_list"); - FILE *file_objects = data__file_open__named__all_read("objects", "extended_list"); + FILE *file_strings = data__file_open__named("strings", "extended_list", "all_read"); + FILE *file_objects = data__file_open__named("objects", "extended_list", "all_read"); assert_non_null(file_strings); assert_non_null(file_objects); diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c index 50b86c8..6154b4b 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c @@ -155,8 +155,8 @@ void test__fl_fss_extended_object_read__works(void **void_state) { { // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters. - FILE *file_strings = data__file_open__named__all_read("strings", "extended"); - FILE *file_objects = data__file_open__named__all_read("objects", "extended"); + FILE *file_strings = data__file_open__named("strings", "extended", "all_read"); + FILE *file_objects = data__file_open__named("objects", "extended", "all_read"); assert_non_null(file_strings); assert_non_null(file_objects); @@ -176,7 +176,7 @@ void test__fl_fss_extended_object_read__works(void **void_state) { f_string_dynamic_t result_string = f_string_dynamic_t_initialize; f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize; - for (int line = 0; ; ++line) { + for (;;) { max = 255; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.c new file mode 100644 index 0000000..6127de9 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.c @@ -0,0 +1,141 @@ +#include "test-fss.h" +#include "test-fss-payload_header_map-abstruse_signed.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_fss_payload_header_map__abstruse_signed__works_combined(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", "combined-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", "combined-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].name.used, expects.array[i].name.used); + assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); + + assert_string_equal(destinations.array[i].name.string, expects.array[i].name.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_signed.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.h new file mode 100644 index 0000000..ea3fc38 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_signed.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_signed_h +#define _TEST__FL_fss_payload_header_map__abstruse_signed_h + +/** + * Test that the function works for abstruse_signed type. + * + * @see fl_fss_payload_header_map() + */ +extern void test__fl_fss_payload_header_map__abstruse_signed__works_combined(void **state); + +#endif // _TEST__FL_fss_payload_header_map__abstruse_signed_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.c b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.c new file mode 100644 index 0000000..fce3590 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.c @@ -0,0 +1,141 @@ +#include "test-fss.h" +#include "test-fss-payload_header_map-abstruse_unsigned.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_fss_payload_header_map__abstruse_unsigned__works_combined(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", "combined-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", "combined-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].name.used, expects.array[i].name.used); + assert_int_equal(destinations.array[i].value.used, expects.array[i].value.used); + + assert_string_equal(destinations.array[i].name.string, expects.array[i].name.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_unsigned.h b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.h new file mode 100644 index 0000000..d723318 --- /dev/null +++ b/level_1/fl_fss/tests/unit/c/test-fss-payload_header_map-abstruse_unsigned.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_unsigned_h +#define _TEST__FL_fss_payload_header_map__abstruse_unsigned_h + +/** + * Test that the function works for abstruse_unsigned type. + * + * @see fl_fss_payload_header_map() + */ +extern void test__fl_fss_payload_header_map__abstruse_unsigned__works_combined(void **state); + +#endif // _TEST__FL_fss_payload_header_map__abstruse_unsigned_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 ac4f2d6..a4b5b04 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -60,6 +60,8 @@ int main(void) { cmocka_unit_test(test__fl_fss_extended_list_object_read__works), cmocka_unit_test(test__fl_fss_payload_header_map__returns_data_not), + cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_signed__works_combined), + cmocka_unit_test(test__fl_fss_payload_header_map__abstruse_unsigned__works_combined), #ifndef _di_level_0_parameter_checking_ cmocka_unit_test(test__fl_fss_basic_content_read__parameter_checking), 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 17c1941..2e101a3 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.h +++ b/level_1/fl_fss/tests/unit/c/test-fss.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,7 @@ // Data includes. #include "data-fss.h" +#include "help-fss.h" // Test includes. #include "test-fss-basic_content_read.h" @@ -59,6 +61,8 @@ #include "test-fss-extended_list_object_read.h" #include "test-fss-extended_list_object_write.h" #include "test-fss-payload_header_map.h" +#include "test-fss-payload_header_map-abstruse_signed.h" +#include "test-fss-payload_header_map-abstruse_unsigned.h" #ifdef __cplusplus extern "C" { -- 1.8.3.1