From 8a9248d98b54f39824a335da036b7671d05bae1f Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 12 Aug 2023 18:07:33 -0500 Subject: [PATCH] Progress: Continue re-designing of the memory logic. --- build/stand_alone/fake.config.h | 14 +- level_0/f_account/c/account/accounts.c | 306 +++++++------------ level_0/f_account/c/account/accounts.h | 338 +++------------------ level_0/f_account/c/account/common.h | 22 -- level_0/f_account/c/account/private-accounts.c | 209 +------------ level_0/f_account/c/account/private-accounts.h | 205 +------------ level_0/f_account/data/build/settings-mocks | 2 + level_0/f_account/data/build/settings-tests | 4 +- level_0/f_account/tests/unit/c/mock-account.c | 36 +++ level_0/f_account/tests/unit/c/mock-account.h | 8 + .../f_account/tests/unit/c/test-account-by_id.c | 6 + .../f_account/tests/unit/c/test-account-by_name.c | 2 + .../tests/unit/c/test-account-group_name_by_id.c | 2 + .../tests/unit/c/test-account-name_by_id.c | 2 + .../f_account/tests/unit/c/test-account-s_adjust.c | 42 --- .../f_account/tests/unit/c/test-account-s_adjust.h | 27 -- .../tests/unit/c/test-account-s_adjust_callback.c | 61 ++++ .../tests/unit/c/test-account-s_adjust_callback.h | 27 ++ .../f_account/tests/unit/c/test-account-s_append.c | 7 + .../f_account/tests/unit/c/test-account-s_append.h | 2 +- .../tests/unit/c/test-account-s_append_all.c | 17 +- .../tests/unit/c/test-account-s_append_all.h | 2 +- .../tests/unit/c/test-account-s_decimate_by.c | 74 ----- .../tests/unit/c/test-account-s_decimate_by.h | 34 --- .../tests/unit/c/test-account-s_decrease_by.c | 74 ----- .../tests/unit/c/test-account-s_decrease_by.h | 34 --- .../tests/unit/c/test-account-s_increase.c | 76 ----- .../tests/unit/c/test-account-s_increase.h | 34 --- .../tests/unit/c/test-account-s_increase_by.c | 76 ----- .../tests/unit/c/test-account-s_increase_by.h | 34 --- .../f_account/tests/unit/c/test-account-s_resize.c | 42 --- .../f_account/tests/unit/c/test-account-s_resize.h | 27 -- .../tests/unit/c/test-account-s_resize_callback.c | 127 ++++++++ .../tests/unit/c/test-account-s_resize_callback.h | 27 ++ .../tests/unit/c/test-account-ss_adjust.c | 42 --- .../tests/unit/c/test-account-ss_adjust.h | 27 -- .../tests/unit/c/test-account-ss_append.c | 16 +- .../tests/unit/c/test-account-ss_append.h | 2 +- .../tests/unit/c/test-account-ss_append_all.c | 18 +- .../tests/unit/c/test-account-ss_append_all.h | 2 +- .../tests/unit/c/test-account-ss_decimate_by.c | 74 ----- .../tests/unit/c/test-account-ss_decimate_by.h | 34 --- .../tests/unit/c/test-account-ss_decrease_by.c | 74 ----- .../tests/unit/c/test-account-ss_decrease_by.h | 34 --- .../tests/unit/c/test-account-ss_increase.c | 76 ----- .../tests/unit/c/test-account-ss_increase.h | 34 --- .../tests/unit/c/test-account-ss_increase_by.c | 108 ------- .../tests/unit/c/test-account-ss_increase_by.h | 34 --- .../tests/unit/c/test-account-ss_resize.c | 42 --- .../tests/unit/c/test-account-ss_resize.h | 27 -- level_0/f_account/tests/unit/c/test-account.c | 41 +-- level_0/f_account/tests/unit/c/test-account.h | 14 +- level_0/f_iki/c/iki/common.h | 22 -- level_0/f_iki/c/iki/data.c | 243 +++++---------- level_0/f_iki/c/iki/data.h | 328 ++------------------ level_0/f_iki/c/iki/private-data.c | 118 ------- level_0/f_iki/c/iki/private-data.h | 152 +-------- level_0/f_iki/c/private-iki.h | 134 -------- level_0/f_iki/data/build/settings-mocks | 71 +++++ level_0/f_iki/data/build/settings-tests | 2 +- level_0/f_iki/data/build/testfile | 2 +- level_0/f_iki/tests/unit/c/mock-iki.c | 79 +++++ level_0/f_iki/tests/unit/c/mock-iki.h | 48 +++ level_0/f_iki/tests/unit/c/test-iki-datas_adjust.c | 42 --- level_0/f_iki/tests/unit/c/test-iki-datas_adjust.h | 27 -- .../tests/unit/c/test-iki-datas_adjust_callback.c | 103 +++++++ .../tests/unit/c/test-iki-datas_adjust_callback.h | 27 ++ level_0/f_iki/tests/unit/c/test-iki-datas_append.h | 2 +- .../f_iki/tests/unit/c/test-iki-datas_append_all.c | 4 +- .../f_iki/tests/unit/c/test-iki-datas_append_all.h | 2 +- .../tests/unit/c/test-iki-datas_decimate_by.c | 50 --- .../tests/unit/c/test-iki-datas_decimate_by.h | 27 -- .../tests/unit/c/test-iki-datas_decrease_by.c | 50 --- .../tests/unit/c/test-iki-datas_decrease_by.h | 27 -- .../f_iki/tests/unit/c/test-iki-datas_increase.c | 76 ----- .../f_iki/tests/unit/c/test-iki-datas_increase.h | 34 --- .../tests/unit/c/test-iki-datas_increase_by.c | 52 ---- .../tests/unit/c/test-iki-datas_increase_by.h | 27 -- level_0/f_iki/tests/unit/c/test-iki-datas_resize.c | 42 --- level_0/f_iki/tests/unit/c/test-iki-datas_resize.h | 27 -- .../tests/unit/c/test-iki-datas_resize_callback.c | 103 +++++++ .../tests/unit/c/test-iki-datas_resize_callback.h | 27 ++ .../f_iki/tests/unit/c/test-iki-datass_adjust.c | 42 --- .../f_iki/tests/unit/c/test-iki-datass_adjust.h | 27 -- .../f_iki/tests/unit/c/test-iki-datass_append.c | 4 +- .../f_iki/tests/unit/c/test-iki-datass_append.h | 2 +- .../tests/unit/c/test-iki-datass_append_all.c | 6 +- .../tests/unit/c/test-iki-datass_append_all.h | 2 +- .../tests/unit/c/test-iki-datass_decimate_by.c | 50 --- .../tests/unit/c/test-iki-datass_decimate_by.h | 27 -- .../tests/unit/c/test-iki-datass_decrease_by.c | 50 --- .../tests/unit/c/test-iki-datass_decrease_by.h | 27 -- .../f_iki/tests/unit/c/test-iki-datass_increase.c | 76 ----- .../f_iki/tests/unit/c/test-iki-datass_increase.h | 34 --- .../tests/unit/c/test-iki-datass_increase_by.c | 52 ---- .../tests/unit/c/test-iki-datass_increase_by.h | 27 -- .../f_iki/tests/unit/c/test-iki-datass_resize.c | 42 --- .../f_iki/tests/unit/c/test-iki-datass_resize.h | 27 -- level_0/f_iki/tests/unit/c/test-iki-read.c | 2 + level_0/f_iki/tests/unit/c/test-iki.c | 37 +-- level_0/f_iki/tests/unit/c/test-iki.h | 16 +- level_3/controller/c/common/private-rule.c | 2 +- level_3/controller/c/rule/private-rule.c | 18 +- level_3/controller/c/rule/private-rule.h | 6 +- 104 files changed, 1129 insertions(+), 4094 deletions(-) delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_adjust.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_adjust.h create mode 100644 level_0/f_account/tests/unit/c/test-account-s_adjust_callback.c create mode 100644 level_0/f_account/tests/unit/c/test-account-s_adjust_callback.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_decimate_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_decimate_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_decrease_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_decrease_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_increase.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_increase.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_increase_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_increase_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_resize.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-s_resize.h create mode 100644 level_0/f_account/tests/unit/c/test-account-s_resize_callback.c create mode 100644 level_0/f_account/tests/unit/c/test-account-s_resize_callback.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_adjust.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_adjust.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_increase.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_increase.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_increase_by.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_increase_by.h delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_resize.c delete mode 100644 level_0/f_account/tests/unit/c/test-account-ss_resize.h create mode 100644 level_0/f_iki/data/build/settings-mocks create mode 100644 level_0/f_iki/tests/unit/c/mock-iki.c create mode 100644 level_0/f_iki/tests/unit/c/mock-iki.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_adjust.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_adjust.h create mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.c create mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_increase.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_increase.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_resize.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_resize.h create mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.c create mode 100644 level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_adjust.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_adjust.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_increase.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_increase.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.h delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_resize.c delete mode 100644 level_0/f_iki/tests/unit/c/test-iki-datass_resize.h diff --git a/build/stand_alone/fake.config.h b/build/stand_alone/fake.config.h index 80dfa1b..83922f3 100644 --- a/build/stand_alone/fake.config.h +++ b/build/stand_alone/fake.config.h @@ -668,22 +668,12 @@ #define _di_f_iki_content_partial_is_ //#define _di_f_iki_data_delete_ #define _di_f_iki_data_destroy_ -#define _di_f_iki_datas_adjust_ +#define _di_f_iki_datas_adjust_callback_ #define _di_f_iki_datas_append_ #define _di_f_iki_datas_append_all_ -#define _di_f_iki_datas_decimate_by_ -#define _di_f_iki_datas_decrease_by_ -#define _di_f_iki_datas_increase_ -#define _di_f_iki_datas_increase_by_ -#define _di_f_iki_datas_resize_ -#define _di_f_iki_datass_adjust_ +#define _di_f_iki_datas_resize_callack_ #define _di_f_iki_datass_append_ #define _di_f_iki_datass_append_all_ -#define _di_f_iki_datass_decimate_by_ -#define _di_f_iki_datass_decrease_by_ -#define _di_f_iki_datass_increase_ -#define _di_f_iki_datass_increase_by_ -#define _di_f_iki_datass_resize_ #define _di_f_iki_datass_t_ #define _di_f_iki_datas_t_ //#define _di_f_iki_data_t_ diff --git a/level_0/f_account/c/account/accounts.c b/level_0/f_account/c/account/accounts.c index fa325f1..6946d40 100644 --- a/level_0/f_account/c/account/accounts.c +++ b/level_0/f_account/c/account/accounts.c @@ -7,167 +7,173 @@ extern "C" { #endif #ifndef _di_f_account_delete_ - f_status_t f_account_delete(f_account_t *account) { + f_status_t f_account_delete(f_account_t * const account) { #ifndef _di_level_0_parameter_checking_ if (!account) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_account_delete(account); + f_status_t status = f_string_dynamic_resize(0, &account->home); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &account->label); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &account->name); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &account->password); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &account->shell); + if (F_status_is_error(status)) return status; + + return F_none; } #endif // _di_f_account_delete_ #ifndef _di_f_account_destroy_ - f_status_t f_account_destroy(f_account_t *account) { + f_status_t f_account_destroy(f_account_t * const account) { #ifndef _di_level_0_parameter_checking_ if (!account) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_account_destroy(account); - } -#endif // _di_f_account_destroy_ + f_status_t status = f_string_dynamic_adjust(0, &account->home); + if (F_status_is_error(status)) return status; -#ifndef _di_f_accounts_adjust_ - f_status_t f_accounts_adjust(const f_number_unsigned_t length, f_accounts_t *accounts) { - #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_dynamic_adjust(0, &account->label); + if (F_status_is_error(status)) return status; - return private_f_accounts_adjust(length, accounts); - } -#endif // _di_f_accounts_adjust_ + status = f_string_dynamic_adjust(0, &account->name); + if (F_status_is_error(status)) return status; -#ifndef _di_f_accounts_append_ - f_status_t f_accounts_append(const f_account_t source, f_accounts_t *destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_dynamic_adjust(0, &account->password); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_adjust(0, &account->shell); + if (F_status_is_error(status)) return status; - return private_f_accounts_append(source, destination); + return F_none; } -#endif // _di_f_accounts_append_ +#endif // _di_f_account_destroy_ -#ifndef _di_f_accounts_append_all_ - f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ +#ifndef _di_f_accounts_adjust_callback_ + f_status_t f_accounts_adjust_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { - if (!source.used) return F_data_not; + { + f_accounts_t * const array = (f_accounts_t *) void_array; + f_status_t status = F_none; - return private_f_accounts_append_all(source, destination); - } -#endif // _di_f_accounts_append_all_ + for (f_number_unsigned_t i = start; i < stop; ++i) { -#ifndef _di_f_accounts_decimate_by_ - f_status_t f_accounts_decimate_by(const f_number_unsigned_t amount, f_accounts_t *accounts) { - #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_dynamic_adjust(0, &array->array[i].home); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_adjust(0, &array->array[i].label); + if (F_status_is_error(status)) return status; - if (!amount) return F_data_not; + status = f_string_dynamic_adjust(0, &array->array[i].name); + if (F_status_is_error(status)) return status; - if (accounts->size > amount) { - return private_f_accounts_adjust(accounts->size - amount, accounts); + status = f_string_dynamic_adjust(0, &array->array[i].password); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_adjust(0, &array->array[i].shell); + if (F_status_is_error(status)) return status; + } // for } - return private_f_accounts_adjust(0, accounts); + return F_none; } -#endif // _di_f_accounts_decimate_by_ +#endif // _di_f_accounts_adjust_callback_ -#ifndef _di_f_accounts_decrease_by_ - f_status_t f_accounts_decrease_by(const f_number_unsigned_t amount, f_accounts_t *accounts) { +#ifndef _di_f_accounts_append_ + f_status_t f_accounts_append(const f_account_t source, f_accounts_t * const destination) { #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_account_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; - if (accounts->size > amount) { - return private_f_accounts_resize(accounts->size - amount, accounts); - } + destination->array[destination->used].home.used = 0; + destination->array[destination->used].label.used = 0; + destination->array[destination->used].name.used = 0; + destination->array[destination->used].password.used = 0; + destination->array[destination->used].shell.used = 0; - return private_f_accounts_resize(0, accounts); - } -#endif // _di_f_accounts_decrease_by_ + status = f_string_dynamic_append(source.home, &destination->array[destination->used].home); + if (F_status_is_error(status)) return status; -#ifndef _di_f_accounts_increase_ - f_status_t f_accounts_increase(const f_number_unsigned_t step, f_accounts_t *accounts) { - #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_dynamic_append(source.label, &destination->array[destination->used].label); + if (F_status_is_error(status)) return status; - if (step && accounts->used + 1 > accounts->size) { - f_number_unsigned_t size = accounts->used + step; + status = f_string_dynamic_append(source.name, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; - if (size > F_number_t_size_unsigned_d) { - if (accounts->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } + status = f_string_dynamic_append(source.password, &destination->array[destination->used].password); + if (F_status_is_error(status)) return status; - size = F_number_t_size_unsigned_d; - } + status = f_string_dynamic_append(source.shell, &destination->array[destination->used].shell); + if (F_status_is_error(status)) return status; - return private_f_accounts_resize(size, accounts); - } + ++destination->used; - return F_data_not; + return F_none; } -#endif // _di_f_accounts_increase_ +#endif // _di_f_accounts_append_ -#ifndef _di_f_accounts_increase_by_ - f_status_t f_accounts_increase_by(const f_number_unsigned_t amount, f_accounts_t *accounts) { +#ifndef _di_f_accounts_append_all_ + f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t * const destination) { #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; + if (!source.used) return F_data_not; - if (accounts->used + amount > accounts->size) { - if (accounts->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } + return private_f_accounts_append_all(source, destination); + } +#endif // _di_f_accounts_append_all_ - return private_f_accounts_resize(accounts->used + amount, accounts); - } +#ifndef _di_f_accounts_resize_callback_ + f_status_t f_accounts_resize_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { - return F_data_not; - } -#endif // _di_f_accounts_increase_by_ + { + f_accounts_t * const array = (f_accounts_t *) void_array; + f_status_t status = F_none; -#ifndef _di_f_accounts_resize_ - f_status_t f_accounts_resize(const f_number_unsigned_t length, f_accounts_t *accounts) { - #ifndef _di_level_0_parameter_checking_ - if (!accounts) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + for (f_number_unsigned_t i = start; i < stop; ++i) { - return private_f_accounts_resize(length, accounts); - } -#endif // _di_f_accounts_resize_ + status = f_string_dynamic_resize(0, &array->array[i].home); + if (F_status_is_error(status)) return status; -#ifndef _di_f_accountss_adjust_ - f_status_t f_accountss_adjust(const f_number_unsigned_t length, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_dynamic_resize(0, &array->array[i].label); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &array->array[i].name); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &array->array[i].password); + if (F_status_is_error(status)) return status; + + status = f_string_dynamic_resize(0, &array->array[i].shell); + if (F_status_is_error(status)) return status; + } // for + } - return private_f_accountss_adjust(length, accountss); + return F_none; } -#endif // _di_f_accountss_adjust_ +#endif // _di_f_accounts_resize_callback_ #ifndef _di_f_accountss_append_ - f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t *destination) { + f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_accountss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_accounts_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; status = private_f_accounts_append_all(source, &destination->array[destination->used]); if (F_status_is_error(status)) return status; @@ -179,19 +185,15 @@ extern "C" { #endif // _di_f_accountss_append_ #ifndef _di_f_accountss_append_all_ - f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t *destination) { + f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t * const destination) { #ifndef _di_level_0_parameter_checking_ if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_accountss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_accounts_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { @@ -207,92 +209,6 @@ extern "C" { } #endif // _di_f_accountss_append_all_ -#ifndef _di_f_accountss_decimate_by_ - f_status_t f_accountss_decimate_by(const f_number_unsigned_t amount, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (accountss->size > amount) { - return private_f_accountss_adjust(accountss->size - amount, accountss); - } - - return private_f_accountss_adjust(0, accountss); - } -#endif // _di_f_accountss_decimate_by_ - -#ifndef _di_f_accountss_decrease_by_ - f_status_t f_accountss_decrease_by(const f_number_unsigned_t amount, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (accountss->size > amount) { - return private_f_accountss_resize(accountss->size - amount, accountss); - } - - return private_f_accountss_resize(0, accountss); - } -#endif // _di_f_accountss_decrease_by_ - -#ifndef _di_f_accountss_increase_ - f_status_t f_accountss_increase(const f_number_unsigned_t step, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && accountss->used + 1 > accountss->size) { - f_number_unsigned_t size = accountss->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (accountss->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_accountss_resize(size, accountss); - } - - return F_data_not; - } -#endif // _di_f_accountss_increase_ - -#ifndef _di_f_accountss_increase_by_ - f_status_t f_accountss_increase_by(const f_number_unsigned_t amount, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (accountss->used + amount > accountss->size) { - if (accountss->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_accountss_resize(accountss->used + amount, accountss); - } - - return F_data_not; - } -#endif // _di_f_accountss_increase_by_ - -#ifndef _di_f_accountss_resize_ - f_status_t f_accountss_resize(const f_number_unsigned_t length, f_accountss_t *accountss) { - #ifndef _di_level_0_parameter_checking_ - if (!accountss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_accountss_resize(length, accountss); - } -#endif // _di_f_accountss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/c/account/accounts.h b/level_0/f_account/c/account/accounts.h index 0fd8049..b67e906 100644 --- a/level_0/f_account/c/account/accounts.h +++ b/level_0/f_account/c/account/accounts.h @@ -32,7 +32,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_f_account_delete_ - extern f_status_t f_account_delete(f_account_t *account); + extern f_status_t f_account_delete(f_account_t * const account); #endif // _di_f_account_delete_ /** @@ -51,31 +51,35 @@ extern "C" { * @see f_string_dynamic_adjust() */ #ifndef _di_f_account_destroy_ - extern f_status_t f_account_destroy(f_account_t *account); + extern f_status_t f_account_destroy(f_account_t * const account); #endif // _di_f_account_destroy_ /** - * Resize the accounts array. + * A callback intended to be passed to f_memory_arrays_adjust() for an f_accountss_t structure. * - * @param length - * The new size to use. - * @param accounts - * The accounts array to resize. + * This does not do parameter checking. + * + * @param start + * The inclusive start position in the array to start deleting. + * @param stop + * The exclusive stop position in the array to stop deleting. + * @param array + * The array structure to delete all values of. + * Must not be NULL. * * @return * F_none on success. * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). + * Errors (with error bit) from: f_memory_array_adjust(). * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() + * @see f_memory_array_adjust() + * @see f_memory_arrays_adjust() */ -#ifndef _di_f_accounts_adjust_ - extern f_status_t f_accounts_adjust(const f_number_unsigned_t length, f_accounts_t *accounts); -#endif // _di_f_accounts_adjust_ +#ifndef _di_f_accounts_adjust_callback_ + extern f_status_t f_accounts_adjust_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); +#endif // _di_f_accounts_adjust_callback_ /** * Append the single source account onto the destination. @@ -98,7 +102,7 @@ extern "C" { * @see f_string_dynamic_append() */ #ifndef _di_f_accounts_append_ - extern f_status_t f_accounts_append(const f_account_t source, f_accounts_t *destination); + extern f_status_t f_accounts_append(const f_account_t source, f_accounts_t * const destination); #endif // _di_f_accounts_append_ /** @@ -122,168 +126,35 @@ extern "C" { * @see f_string_dynamic_append() */ #ifndef _di_f_accounts_append_all_ - extern f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination); + extern f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t * const destination); #endif // _di_f_accounts_append_all_ /** - * Resize the accounts array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to les than 0. - * - * @param amount - * A positive number representing how much to decimate the size by. - * @param accounts - * The accounts array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() - */ -#ifndef _di_f_accounts_decimate_by_ - extern f_status_t f_accounts_decimate_by(const f_number_unsigned_t amount, f_accounts_t *accounts); -#endif // _di_f_accounts_decimate_by_ - -/** - * Resize the accounts array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to les than 0. - * - * @param amount - * A positive number representing how much to decrease the size by. - * @param accounts - * The accounts array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accounts_decrease_by_ - extern f_status_t f_accounts_decrease_by(const f_number_unsigned_t amount, f_accounts_t *accounts); -#endif // _di_f_accounts_decrease_by_ - -/** - * Increase the size of the accounts array, but only if necesary. - * - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param accounts - * The accounts array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. + * A callback intended to be passed to f_memory_arrays_resize() for an f_accountss_t structure. * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accounts_increase_ - extern f_status_t f_accounts_increase(const f_number_unsigned_t step, f_accounts_t *accounts); -#endif // _di_f_accounts_increase_ - -/** - * Resize the accounts array to a larger size. - * - * This will resize making the array larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param amount - * A positive number representing how much to increase the size by. - * @param accounts - * The accounts array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accounts_increase_by_ - extern f_status_t f_accounts_increase_by(const f_number_unsigned_t amount, f_accounts_t *accounts); -#endif // _di_f_accounts_increase_by_ - -/** - * Resize the accounts array. - * - * @param length - * The new size to use. - * @param accounts - * The accounts array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accounts_resize_ - extern f_status_t f_accounts_resize(const f_number_unsigned_t length, f_accounts_t *accounts); -#endif // _di_f_accounts_resize_ - -/** - * Resize the string accountss array. + * This does not do parameter checking. * - * @param length - * The new size to use. - * @param accountss - * The string accountss array to resize. + * @param start + * The inclusive start position in the array to start deleting. + * @param stop + * The exclusive stop position in the array to stop deleting. + * @param array + * The array structure to delete all values of. + * Must not be NULL. * * @return * F_none on success. * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). + * Errors (with error bit) from: f_memory_array_resize(). * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() + * @see f_memory_array_resize() + * @see f_memory_arrays_resize() */ -#ifndef _di_f_accountss_adjust_ - extern f_status_t f_accountss_adjust(const f_number_unsigned_t length, f_accountss_t *accountss); -#endif // _di_f_accountss_adjust_ +#ifndef _di_f_accounts_resize_callback_ + extern f_status_t f_accounts_resize_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); +#endif // _di_f_accounts_resize_callback_ /** * Append the single source accounts onto the destination. @@ -306,7 +177,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_f_accountss_append_ - extern f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t *destination); + extern f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t * const destination); #endif // _di_f_accountss_append_ /** @@ -330,144 +201,9 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_f_accountss_append_all_ - extern f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t *destination); + extern f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t * const destination); #endif // _di_f_accountss_append_all_ -/** - * Resize the string accountss array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. - * - * @param amount - * A positive number representing how much to decimate the size by. - * @param accountss - * The string accountss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() - */ -#ifndef _di_f_accountss_decimate_by_ - extern f_status_t f_accountss_decimate_by(const f_number_unsigned_t amount, f_accountss_t *accountss); -#endif // _di_f_accountss_decimate_by_ - -/** - * Resize the string accountss array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. - * - * @param amount - * A positive number representing how much to decrease the size by. - * @param accountss - * The string accountss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accountss_decrease_by_ - extern f_status_t f_accountss_decrease_by(const f_number_unsigned_t amount, f_accountss_t *accountss); -#endif // _di_f_accountss_decrease_by_ - -/** - * Increase the size of the string accountss array, but only if necessary. - * - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param accountss - * The string accountss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accountss_increase_ - extern f_status_t f_accountss_increase(const f_number_unsigned_t step, f_accountss_t *accountss); -#endif // _di_f_accountss_increase_ - -/** - * Resize the string accountss array to a larger size. - * - * This will resize making the array larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param amount - * A positive number representing how much to increase the size by. - * @param accountss - * The string accountss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accountss_increase_by_ - extern f_status_t f_accountss_increase_by(const f_number_unsigned_t amount, f_accountss_t *accountss); -#endif // _di_f_accountss_increase_by_ - -/** - * Resize the string accountss array. - * - * @param length - * The new size to use. - * @param accountss - * The accounts array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - */ -#ifndef _di_f_accountss_resize_ - extern f_status_t f_accountss_resize(const f_number_unsigned_t length, f_accountss_t *accountss); -#endif // _di_f_accountss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/c/account/common.h b/level_0/f_account/c/account/common.h index 7ee1e8b..bdad4ba 100644 --- a/level_0/f_account/c/account/common.h +++ b/level_0/f_account/c/account/common.h @@ -97,17 +97,6 @@ extern "C" { #define macro_f_accounts_t_initialize_2(array, length) { array, length, length } #define macro_f_accounts_t_clear(accounts) macro_f_memory_structures_clear(accounts) - - #define macro_f_accounts_t_resize(status, accounts, length) status = f_accounts_resize(length, &accounts); - #define macro_f_accounts_t_adjust(status, accounts, length) status = f_accounts_adjust(length, &accounts); - - #define macro_f_accounts_t_delete_simple(accounts) f_accounts_resize(0, &accounts); - #define macro_f_accounts_t_destroy_simple(accounts) f_accounts_adjust(0, &accounts); - - #define macro_f_accounts_t_increase(status, step, accounts) status = f_accounts_increase(step, &accounts); - #define macro_f_accounts_t_increase_by(status, accounts, amount) status = f_accounts_increase_by(amount, &accounts); - #define macro_f_accounts_t_decrease_by(status, accounts, amount) status = f_accounts_decrease_by(amount, &accounts); - #define macro_f_accounts_t_decimate_by(status, accounts, amount) status = f_accounts_decimate_by(amount, &accounts); #endif // _di_f_accounts_t_ /** @@ -132,17 +121,6 @@ extern "C" { #define macro_f_accountss_t_initialize_2(array, length) { array, length, length } #define macro_f_accountss_t_clear(accountss) macro_f_memory_structures_clear(accountss) - - #define macro_f_accountss_t_resize(status, accountss, length) status = f_accountss_resize(length, &accountss); - #define macro_f_accountss_t_adjust(status, accountss, length) status = f_accountss_adjust(length, &accountss); - - #define macro_f_accountss_t_delete_simple(accountss) f_accountss_resize(0, &accountss); - #define macro_f_accountss_t_destroy_simple(accountss) f_accountss_adjust(0, &accountss); - - #define macro_f_accountss_t_increase(status, step, accountss) status = f_accountss_increase(step, &accountss); - #define macro_f_accountss_t_increase_by(status, accountss, amount) status = f_accountss_increase_by(amount, &accountss); - #define macro_f_accountss_t_decrease_by(status, accountss, amount) status = f_accountss_decrease_by(amount, &accountss); - #define macro_f_accountss_t_decimate_by(status, accountss, amount) status = f_accountss_decimate_by(amount, &accountss); #endif // _di_f_accountss_t_ #ifdef __cplusplus diff --git a/level_0/f_account/c/account/private-accounts.c b/level_0/f_account/c/account/private-accounts.c index e3969d5..8f14e41 100644 --- a/level_0/f_account/c/account/private-accounts.c +++ b/level_0/f_account/c/account/private-accounts.c @@ -6,122 +6,11 @@ extern "C" { #endif -#if !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - f_status_t private_f_account_delete(f_account_t *account) { - - f_status_t status = f_string_dynamic_resize(0, &account->home); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &account->label); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &account->name); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &account->password); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &account->shell); - if (F_status_is_error(status)) return status; - - return F_none; - } -#endif // !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - -#if !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - f_status_t private_f_account_destroy(f_account_t *account) { - - f_status_t status = f_string_dynamic_adjust(0, &account->home); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_adjust(0, &account->label); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_adjust(0, &account->name); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_adjust(0, &account->password); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_adjust(0, &account->shell); - if (F_status_is_error(status)) return status; - - return F_none; - } -#endif // !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -#if !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - f_status_t private_f_accounts_adjust(const f_number_unsigned_t length, f_accounts_t *accounts) { - - f_status_t status = F_none; - - if (length < accounts->size) { - for (f_number_unsigned_t i = length; i < accounts->size; ++i) { - - status = private_f_account_destroy(&accounts->array[i]); - if (F_status_is_error(status)) return status; - } // for - } - - status = f_memory_adjust(accounts->size, length, sizeof(f_account_t), (void **) & accounts->array); - if (F_status_is_error(status)) return status; - - accounts->size = length; - - if (accounts->used > accounts->size) { - accounts->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -#if !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_) - extern f_status_t private_f_accounts_append(const f_account_t source, f_accounts_t *destination) { - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_accounts_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].home.used = 0; - destination->array[destination->used].label.used = 0; - destination->array[destination->used].name.used = 0; - destination->array[destination->used].password.used = 0; - destination->array[destination->used].shell.used = 0; - - status = f_string_dynamic_append(source.home, &destination->array[destination->used].home); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_append(source.label, &destination->array[destination->used].label); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_append(source.name, &destination->array[destination->used].name); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_append(source.password, &destination->array[destination->used].password); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_append(source.shell, &destination->array[destination->used].shell); - if (F_status_is_error(status)) return status; - - ++destination->used; - - return F_none; - } -#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_) - #if !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_) - extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) { - - f_status_t status = F_none; + extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t * const destination) { - if (destination->used + source.used > destination->size) { - status = private_f_accounts_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_account_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { @@ -151,98 +40,6 @@ extern "C" { } #endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_) -#if !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - f_status_t private_f_accounts_resize(const f_number_unsigned_t length, f_accounts_t *accounts) { - - f_status_t status = F_none; - - if (length < accounts->size) { - for (f_number_unsigned_t i = length; i < accounts->size; ++i) { - - status = f_string_dynamic_resize(0, &accounts->array[i].home); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &accounts->array[i].label); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &accounts->array[i].name); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &accounts->array[i].password); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_resize(0, &accounts->array[i].shell); - if (F_status_is_error(status)) return status; - } // for - } - - status = f_memory_resize(accounts->size, length, sizeof(f_account_t), (void **) & accounts->array); - if (F_status_is_error(status)) return status; - - accounts->size = length; - - if (accounts->used > accounts->size) { - accounts->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - -#if !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - f_status_t private_f_accountss_adjust(const f_number_unsigned_t length, f_accountss_t *accountss) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < accountss->size; ++i) { - - status = private_f_accounts_adjust(0, &accountss->array[i]); - if (F_status_is_error(status)) return status; - - accountss->array[i].size = 0; - accountss->array[i].used = 0; - } // for - - status = f_memory_adjust(accountss->size, length, sizeof(f_accounts_t), (void **) & accountss->array); - if (F_status_is_error(status)) return status; - - accountss->size = length; - - if (accountss->used > accountss->size) { - accountss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -#if !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - f_status_t private_f_accountss_resize(const f_number_unsigned_t length, f_accountss_t *accountss) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < accountss->size; ++i) { - - status = private_f_accounts_resize(0, &accountss->array[i]); - if (F_status_is_error(status)) return status; - - accountss->array[i].size = 0; - accountss->array[i].used = 0; - } // for - - status = f_memory_resize(accountss->size, length, sizeof(f_accounts_t), (void **) & accountss->array); - if (F_status_is_error(status)) return status; - - accountss->size = length; - - if (accountss->used > accountss->size) { - accountss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/c/account/private-accounts.h b/level_0/f_account/c/account/private-accounts.h index 6483ed4..deb26c5 100644 --- a/level_0/f_account/c/account/private-accounts.h +++ b/level_0/f_account/c/account/private-accounts.h @@ -16,115 +16,6 @@ extern "C" { #endif /** - * Private implementation for resizing the account. - * - * Intended to be shared to each of the different implementation variations. - * - * @param account - * The account to delete. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_string_dynamic_resize() - * - * @see f_account_delete() - * @see f_accounts_append() - * @see f_accounts_decimate_by() - * @see f_accounts_resize() - * @see f_accountss_append() - * @see f_accountss_decrease_by() - * @see f_accountss_increase() - * @see f_accountss_increase_by() - * @see f_accountss_resize() - */ -#if !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - extern f_status_t private_f_account_delete(f_account_t *account) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - -/** - * Private implementation for resizing the account. - * - * Intended to be shared to each of the different implementation variations. - * - * @param account - * The account to delete. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: f_string_dynamic_adjust(). - * - * @see f_string_dynamic_adjust() - * - * @see f_account_destroy() - * @see f_accounts_adjust() - * @see f_accounts_decimate_by() - * @see f_accountss_adjust() - * @see f_accountss_decimate_by() - */ -#if !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - extern f_status_t private_f_account_destroy(f_account_t *account) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -/** - * Private implementation for resizing the accounts array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param accounts - * The accounts array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() - * - * @see f_accounts_adjust() - * @see f_accounts_decimate_by() - * @see f_accountss_adjust() - * @see f_accountss_decimate_by() - */ -#if !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - extern f_status_t private_f_accounts_adjust(const f_number_unsigned_t length, f_accounts_t *accounts) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -/** - * Private implementation for appending the account array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source account to append. - * @param destination - * The destination lengths the source is appended onto. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_append(). - * - * @see f_memory_resize() - * @see f_string_dynamic_append() - * - * @see f_accounts_append() - * @see f_accountss_append() - */ -#if !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_) - extern f_status_t private_f_accounts_append(const f_account_t source, f_accounts_t *destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_) - -/** * Private implementation for appending the account array. * * Intended to be shared to each of the different implementation variations. @@ -148,103 +39,9 @@ extern "C" { * @see f_accountss_append_all() */ #if !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_) - extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) F_attribute_visibility_internal_d; + extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t * const destination) F_attribute_visibility_internal_d; #endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_) -/** - * Private implementation for resizing the accounts array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param accounts - * The accounts array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamic_resize() - * - * @see f_accounts_append() - * @see f_accounts_decimate_by() - * @see f_accounts_resize() - * @see f_accountss_append() - * @see f_accountss_decrease_by() - * @see f_accountss_increase() - * @see f_accountss_increase_by() - * @see f_accountss_resize() - */ -#if !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - extern f_status_t private_f_accounts_resize(const f_number_unsigned_t length, f_accounts_t *accounts) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - -/** - * Private implementation for resizing the accountss array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param accountss - * The accountss array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_string_dynamic_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamic_adjust() - * - * @see f_accountss_adjust() - * @see f_accountss_decimate_by() - */ -#if !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - extern f_status_t private_f_accountss_adjust(const f_number_unsigned_t length, f_accountss_t *accountss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_) - -/** - * Private implementation for resizing the accountss array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to resize to. - * @param accountss - * The accountss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_accountss_decrease_by() - * @see f_accountss_increase() - * @see f_accountss_increase_by() - * @see f_accountss_resize() - */ -#if !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - extern f_status_t private_f_accountss_resize(const f_number_unsigned_t length, f_accountss_t *accountss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/data/build/settings-mocks b/level_0/f_account/data/build/settings-mocks index 7212551..5f917a3 100644 --- a/level_0/f_account/data/build/settings-mocks +++ b/level_0/f_account/data/build/settings-mocks @@ -61,6 +61,8 @@ flags-coverage --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ flags_library -fPIC # Inject mocks. +flags -Wl,--wrap=f_string_dynamic_adjust +flags -Wl,--wrap=f_string_dynamic_resize flags -Wl,--wrap=getpwnam_r flags -Wl,--wrap=getpwuid_r flags -Wl,--wrap=getgrnam_r diff --git a/level_0/f_account/data/build/settings-tests b/level_0/f_account/data/build/settings-tests index 6597153..d752945 100644 --- a/level_0/f_account/data/build/settings-tests +++ b/level_0/f_account/data/build/settings-tests @@ -26,8 +26,8 @@ build_libraries -lc -lcmocka build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_account build_sources_program test-account-by_id.c test-account-by_name.c test-account-group_name_by_id.c test-account-group_id_by_name.c test-account-id_by_name.c test-account-name_by_id.c -build_sources_program test-account-s_adjust.c test-account-s_append.c test-account-s_append_all.c test-account-s_decimate_by.c test-account-s_decrease_by.c test-account-s_increase.c test-account-s_increase_by.c test-account-s_resize.c -build_sources_program test-account-ss_adjust.c test-account-ss_append.c test-account-ss_append_all.c test-account-ss_decimate_by.c test-account-ss_decrease_by.c test-account-ss_increase.c test-account-ss_increase_by.c test-account-ss_resize.c +build_sources_program test-account-s_adjust_callback.c test-account-s_append.c test-account-s_append_all.c test-account-s_resize_callback.c +build_sources_program test-account-ss_append.c test-account-ss_append_all.c build_sources_program test-account.c build_script no diff --git a/level_0/f_account/tests/unit/c/mock-account.c b/level_0/f_account/tests/unit/c/mock-account.c index caf13cc..00add2f 100644 --- a/level_0/f_account/tests/unit/c/mock-account.c +++ b/level_0/f_account/tests/unit/c/mock-account.c @@ -4,6 +4,42 @@ extern "C" { #endif +int mock_unwrap = 0; + +f_status_t __wrap_f_string_dynamic_adjust(const f_number_unsigned_t length, f_string_dynamic_t * const structure) { + + if (mock_unwrap) { + return __real_f_string_dynamic_adjust(length, structure); + } + + if (!structure) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + structure->size = length; + + return mock_type(f_status_t); +} + +f_status_t __wrap_f_string_dynamic_resize(const f_number_unsigned_t length, f_string_dynamic_t * const structure) { + + if (mock_unwrap) { + return __real_f_string_dynamic_resize(length, structure); + } + + if (!structure) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + structure->size = length; + + return mock_type(f_status_t); +} + int __wrap_getpwnam_r(const char * const name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) { const bool failure = mock_type(bool); diff --git a/level_0/f_account/tests/unit/c/mock-account.h b/level_0/f_account/tests/unit/c/mock-account.h index 81ccc16..76c0412 100644 --- a/level_0/f_account/tests/unit/c/mock-account.h +++ b/level_0/f_account/tests/unit/c/mock-account.h @@ -28,6 +28,14 @@ extern "C" { const static int mock_errno_generic = 32767; +extern int mock_unwrap; + +extern f_status_t __real_f_string_dynamic_adjust(const f_number_unsigned_t length, f_string_dynamic_t * const structure); +extern f_status_t __real_f_string_dynamic_resize(const f_number_unsigned_t length, f_string_dynamic_t * const structure); + +extern f_status_t __wrap_f_string_dynamic_adjust(const f_number_unsigned_t length, f_string_dynamic_t * const structure); +extern f_status_t __wrap_f_string_dynamic_resize(const f_number_unsigned_t length, f_string_dynamic_t * const structure); + extern int __wrap_getpwnam_r(const char * const name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result); extern int __wrap_getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result); extern int __wrap_getgrgid_r(uid_t uid, struct group *grp, char *buf, size_t buflen, struct group **result); diff --git a/level_0/f_account/tests/unit/c/test-account-by_id.c b/level_0/f_account/tests/unit/c/test-account-by_id.c index 317ba11..673d83d 100644 --- a/level_0/f_account/tests/unit/c/test-account-by_id.c +++ b/level_0/f_account/tests/unit/c/test-account-by_id.c @@ -7,6 +7,8 @@ extern "C" { void test__f_account_by_id__fails(void **state) { + mock_unwrap = 1; + const long size = 20; uid_t uid = 0; f_account_t account = f_account_t_initialize; @@ -47,6 +49,8 @@ void test__f_account_by_id__fails(void **state) { void test__f_account_by_id__not_found(void **state) { + mock_unwrap = 1; + const long size = 20; struct passwd password; uid_t uid = 0; @@ -77,6 +81,8 @@ void test__f_account_by_id__parameter_checking(void **state) { void test__f_account_by_id__works(void **state) { + mock_unwrap = 1; + const long size = 20; struct passwd password; struct passwd pointer; diff --git a/level_0/f_account/tests/unit/c/test-account-by_name.c b/level_0/f_account/tests/unit/c/test-account-by_name.c index b302eb8..07775c7 100644 --- a/level_0/f_account/tests/unit/c/test-account-by_name.c +++ b/level_0/f_account/tests/unit/c/test-account-by_name.c @@ -7,6 +7,8 @@ extern "C" { void test__f_account_by_name__fails(void **state) { + mock_unwrap = 1; + const long size = 20; f_account_t account = f_account_t_initialize; diff --git a/level_0/f_account/tests/unit/c/test-account-group_name_by_id.c b/level_0/f_account/tests/unit/c/test-account-group_name_by_id.c index 3009313..fb352e6 100644 --- a/level_0/f_account/tests/unit/c/test-account-group_name_by_id.c +++ b/level_0/f_account/tests/unit/c/test-account-group_name_by_id.c @@ -77,6 +77,8 @@ void test__f_account_group_name_by_id__parameter_checking(void **state) { void test__f_account_group_name_by_id__works(void **state) { + mock_unwrap = 0; + const long size = 20; struct group group_data; struct group pointer; diff --git a/level_0/f_account/tests/unit/c/test-account-name_by_id.c b/level_0/f_account/tests/unit/c/test-account-name_by_id.c index e8bf6d9..5bbc093 100644 --- a/level_0/f_account/tests/unit/c/test-account-name_by_id.c +++ b/level_0/f_account/tests/unit/c/test-account-name_by_id.c @@ -77,6 +77,8 @@ void test__f_account_name_by_id__parameter_checking(void **state) { void test__f_account_name_by_id__works(void **state) { + mock_unwrap = 0; + const long size = 20; struct passwd password; struct passwd pointer; diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust.c b/level_0/f_account/tests/unit/c/test-account-s_adjust.c deleted file mode 100644 index 52bbd86..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_adjust.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-account.h" -#include "test-account-s_adjust.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_adjust__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_adjust(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accounts_adjust__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_adjust(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust.h b/level_0/f_account/tests/unit/c/test-account-s_adjust.h deleted file mode 100644 index 0cf011e..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_adjust.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_adjust -#define _TEST__F_account_s_adjust - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_adjust() - */ -extern void test__f_accounts_adjust__parameter_checking(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_adjust() - */ -extern void test__f_accounts_adjust__works(void **state); - -#endif // _TEST__F_account_s_adjust diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.c b/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.c new file mode 100644 index 0000000..37bcc5a --- /dev/null +++ b/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.c @@ -0,0 +1,61 @@ +#include "test-account.h" +#include "test-account-s_adjust_callback.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_accounts_adjust_callback__fails(void **state) { + + mock_unwrap = 0; + + f_account_t data = f_account_t_initialize; + f_account_t data_array[] = { data }; + f_accounts_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_accounts_t datass_array[] = { datas }; + + { + will_return(__wrap_f_string_dynamic_adjust, true); + will_return(__wrap_f_string_dynamic_adjust, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_adjust_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } +} + +void test__f_accounts_adjust_callback__works(void **state) { + + mock_unwrap = 0; + + f_account_t data = f_account_t_initialize; + f_account_t data_array[] = { data }; + f_accounts_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_accounts_t datass_array[] = { datas }; + const f_number_unsigned_t length = 1; + + { + will_return(__wrap_f_string_dynamic_adjust, false); + will_return(__wrap_f_string_dynamic_adjust, F_none); + + will_return(__wrap_f_string_dynamic_adjust, false); + will_return(__wrap_f_string_dynamic_adjust, F_none); + + will_return(__wrap_f_string_dynamic_adjust, false); + will_return(__wrap_f_string_dynamic_adjust, F_none); + + will_return(__wrap_f_string_dynamic_adjust, false); + will_return(__wrap_f_string_dynamic_adjust, F_none); + + will_return(__wrap_f_string_dynamic_adjust, false); + will_return(__wrap_f_string_dynamic_adjust, F_none); + + const f_status_t status = f_accounts_adjust_callback(0, length, (void *) datass_array); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.h b/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.h new file mode 100644 index 0000000..98039dd --- /dev/null +++ b/level_0/f_account/tests/unit/c/test-account-s_adjust_callback.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Account + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_account__s_adjust_callback +#define _TEST__F_account__s_adjust_callback + +/** + * Test that the function fails. + * + * @see f_accounts_adjust_callback() + */ +extern void test__f_accounts_adjust_callback__fails(void **state); + +/** + * Test that the function works. + * + * @see f_accounts_adjust_callback() + */ +extern void test__f_accounts_adjust_callback__works(void **state); + +#endif // _TEST__F_account__s_adjust_callback diff --git a/level_0/f_account/tests/unit/c/test-account-s_append.c b/level_0/f_account/tests/unit/c/test-account-s_append.c index 4096618..bb5b43b 100644 --- a/level_0/f_account/tests/unit/c/test-account-s_append.c +++ b/level_0/f_account/tests/unit/c/test-account-s_append.c @@ -18,6 +18,8 @@ void test__f_accounts_append__parameter_checking(void **state) { void test__f_accounts_append__works(void **state) { + mock_unwrap = 1; + f_string_static_t home = macro_f_string_static_t_initialize_1("home", 0, 4); f_string_static_t label = macro_f_string_static_t_initialize_1("label", 0, 5); f_string_static_t name = macro_f_string_static_t_initialize_1("name", 0, 4); @@ -46,6 +48,11 @@ void test__f_accounts_append__works(void **state) { assert_int_equal(destination.array[0].shell.used, source.shell.used); } + free((void *) destination.array[0].home.string); + free((void *) destination.array[0].label.string); + free((void *) destination.array[0].name.string); + free((void *) destination.array[0].password.string); + free((void *) destination.array[0].shell.string); free((void *) destination.array); } diff --git a/level_0/f_account/tests/unit/c/test-account-s_append.h b/level_0/f_account/tests/unit/c/test-account-s_append.h index 87ad93e..1811817 100644 --- a/level_0/f_account/tests/unit/c/test-account-s_append.h +++ b/level_0/f_account/tests/unit/c/test-account-s_append.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: Account * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_account/tests/unit/c/test-account-s_append_all.c b/level_0/f_account/tests/unit/c/test-account-s_append_all.c index 4de5cf5..fa7e1f6 100644 --- a/level_0/f_account/tests/unit/c/test-account-s_append_all.c +++ b/level_0/f_account/tests/unit/c/test-account-s_append_all.c @@ -23,7 +23,7 @@ void test__f_accounts_append_all__returns_data_not(void **state) { f_accounts_t destination = f_accounts_t_initialize; { - const f_status_t status = f_accounts_resize(length, &source); + const f_status_t status = f_memory_array_resize(length, sizeof(f_account_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); @@ -44,6 +44,8 @@ void test__f_accounts_append_all__returns_data_not(void **state) { void test__f_accounts_append_all__works(void **state) { + mock_unwrap = 1; + const int length = 5; f_accounts_t source = f_accounts_t_initialize; f_accounts_t destination = f_accounts_t_initialize; @@ -64,7 +66,7 @@ void test__f_accounts_append_all__works(void **state) { const f_account_t account_1 = { .home = home_1, .label = label_1, .name = name_1, .password = password_1, .shell = shell_1 }; { - const f_status_t status = f_accounts_resize(length, &source); + const f_status_t status = f_memory_array_resize(length, sizeof(f_account_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); @@ -95,6 +97,17 @@ void test__f_accounts_append_all__works(void **state) { } free((void *) source.array); + + free((void *) destination.array[0].home.string); + free((void *) destination.array[0].label.string); + free((void *) destination.array[0].name.string); + free((void *) destination.array[0].password.string); + free((void *) destination.array[0].shell.string); + free((void *) destination.array[1].home.string); + free((void *) destination.array[1].label.string); + free((void *) destination.array[1].name.string); + free((void *) destination.array[1].password.string); + free((void *) destination.array[1].shell.string); free((void *) destination.array); } diff --git a/level_0/f_account/tests/unit/c/test-account-s_append_all.h b/level_0/f_account/tests/unit/c/test-account-s_append_all.h index 056fa31..43ef5fa 100644 --- a/level_0/f_account/tests/unit/c/test-account-s_append_all.h +++ b/level_0/f_account/tests/unit/c/test-account-s_append_all.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: Account * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.c b/level_0/f_account/tests/unit/c/test-account-s_decimate_by.c deleted file mode 100644 index 063d1f0..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "test-account.h" -#include "test-account-s_decimate_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_decimate_by__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_decimate_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accounts_decimate_by__returns_data_not(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_decimate_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accounts_decimate_by__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_decimate_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.h b/level_0/f_account/tests/unit/c/test-account-s_decimate_by.h deleted file mode 100644 index 2c13180..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_decimate_by -#define _TEST__F_account_s_decimate_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_decimate_by() - */ -extern void test__f_accounts_decimate_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accounts_decimate_by() - */ -extern void test__f_accounts_decimate_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_decimate_by() - */ -extern void test__f_accounts_decimate_by__works(void **state); - -#endif // _TEST__F_account_s_decimate_by diff --git a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.c b/level_0/f_account/tests/unit/c/test-account-s_decrease_by.c deleted file mode 100644 index 7ad19a4..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "test-account.h" -#include "test-account-s_decrease_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_decrease_by__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_decrease_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accounts_decrease_by__returns_data_not(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_decrease_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accounts_decrease_by__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_decrease_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.h b/level_0/f_account/tests/unit/c/test-account-s_decrease_by.h deleted file mode 100644 index bd6394c..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_decrease_by -#define _TEST__F_account_s_decrease_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_decrease_by() - */ -extern void test__f_accounts_decrease_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accounts_decrease_by() - */ -extern void test__f_accounts_decrease_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_decrease_by() - */ -extern void test__f_accounts_decrease_by__works(void **state); - -#endif // _TEST__F_account_s_decrease_by diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase.c b/level_0/f_account/tests/unit/c/test-account-s_increase.c deleted file mode 100644 index e528c88..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_increase.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "test-account.h" -#include "test-account-s_increase.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_increase__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_increase(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - free((void *) data.array); -} - -void test__f_accounts_increase__returns_data_not(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_increase(length, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accounts_increase__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_accounts_increase(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase.h b/level_0/f_account/tests/unit/c/test-account-s_increase.h deleted file mode 100644 index a953829..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_increase.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_increase -#define _TEST__F_account_s_increase - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_increase() - */ -extern void test__f_accounts_increase__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accounts_increase() - */ -extern void test__f_accounts_increase__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_increase() - */ -extern void test__f_accounts_increase__works(void **state); - -#endif // _TEST__F_account_s_increase diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase_by.c b/level_0/f_account/tests/unit/c/test-account-s_increase_by.c deleted file mode 100644 index c551006..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_increase_by.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "test-account.h" -#include "test-account-s_increase_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_increase_by__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_increase_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accounts_increase_by__returns_data_not(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accounts_increase_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accounts_increase_by__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_accounts_increase_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_int_equal(data.size, length * 2); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase_by.h b/level_0/f_account/tests/unit/c/test-account-s_increase_by.h deleted file mode 100644 index fc386c4..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_increase_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_increase_by -#define _TEST__F_account_s_increase_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_increase_by() - */ -extern void test__f_accounts_increase_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accounts_increase_by() - */ -extern void test__f_accounts_increase_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_increase_by() - */ -extern void test__f_accounts_increase_by__works(void **state); - -#endif // _TEST__F_account_s_increase_by diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize.c b/level_0/f_account/tests/unit/c/test-account-s_resize.c deleted file mode 100644 index b67cbab..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_resize.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-account.h" -#include "test-account-s_resize.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accounts_resize__parameter_checking(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accounts_resize__works(void **state) { - - const int length = 5; - f_accounts_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accounts_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize.h b/level_0/f_account/tests/unit/c/test-account-s_resize.h deleted file mode 100644 index 9cb047d..0000000 --- a/level_0/f_account/tests/unit/c/test-account-s_resize.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_s_resize -#define _TEST__F_account_s_resize - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accounts_resize() - */ -extern void test__f_accounts_resize__parameter_checking(void **state); - -/** - * Test that the function works. - * - * @see f_accounts_resize() - */ -extern void test__f_accounts_resize__works(void **state); - -#endif // _TEST__F_account_s_resize diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize_callback.c b/level_0/f_account/tests/unit/c/test-account-s_resize_callback.c new file mode 100644 index 0000000..abcd324 --- /dev/null +++ b/level_0/f_account/tests/unit/c/test-account-s_resize_callback.c @@ -0,0 +1,127 @@ +#include "test-account.h" +#include "test-account-s_resize_callback.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_accounts_resize_callback__fails(void **state) { + + mock_unwrap = 0; + + f_account_t data = f_account_t_initialize; + f_account_t data_array[] = { data }; + f_accounts_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_accounts_t datass_array[] = { datas }; + + { + will_return(__wrap_f_string_dynamic_resize, true); + will_return(__wrap_f_string_dynamic_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, true); + will_return(__wrap_f_string_dynamic_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, true); + will_return(__wrap_f_string_dynamic_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, true); + will_return(__wrap_f_string_dynamic_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, true); + will_return(__wrap_f_string_dynamic_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_accounts_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } +} + +void test__f_accounts_resize_callback__works(void **state) { + + mock_unwrap = 0; + + f_account_t data = f_account_t_initialize; + f_account_t data_array[] = { data }; + f_accounts_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_accounts_t datass_array[] = { datas }; + const f_number_unsigned_t length = 1; + + { + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + will_return(__wrap_f_string_dynamic_resize, false); + will_return(__wrap_f_string_dynamic_resize, F_none); + + const f_status_t status = f_accounts_resize_callback(0, length, (void *) datass_array); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize_callback.h b/level_0/f_account/tests/unit/c/test-account-s_resize_callback.h new file mode 100644 index 0000000..3fe68d0 --- /dev/null +++ b/level_0/f_account/tests/unit/c/test-account-s_resize_callback.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Account + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_account__s_resize_callback +#define _TEST__F_account__s_resize_callback + +/** + * Test that the function fails. + * + * @see f_accounts_resize_callback() + */ +extern void test__f_accounts_resize_callback__fails(void **state); + +/** + * Test that the function works. + * + * @see f_accounts_resize_callback() + */ +extern void test__f_accounts_resize_callback__works(void **state); + +#endif // _TEST__F_account__s_resize_callback diff --git a/level_0/f_account/tests/unit/c/test-account-ss_adjust.c b/level_0/f_account/tests/unit/c/test-account-ss_adjust.c deleted file mode 100644 index 66360a1..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_adjust.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_adjust.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_adjust__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_adjust(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accountss_adjust__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_adjust(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_adjust.h b/level_0/f_account/tests/unit/c/test-account-ss_adjust.h deleted file mode 100644 index ae4a766..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_adjust.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_adjust -#define _TEST__F_account_ss_adjust - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_adjust() - */ -extern void test__f_accountss_adjust__parameter_checking(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_adjust() - */ -extern void test__f_accountss_adjust__works(void **state); - -#endif // _TEST__F_account_ss_adjust diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append.c b/level_0/f_account/tests/unit/c/test-account-ss_append.c index 0815349..66a1e1d 100644 --- a/level_0/f_account/tests/unit/c/test-account-ss_append.c +++ b/level_0/f_account/tests/unit/c/test-account-ss_append.c @@ -23,7 +23,7 @@ void test__f_accountss_append__returns_data_not(void **state) { f_accountss_t destination = f_accountss_t_initialize; { - const f_status_t status = f_accounts_resize(length, &source); + const f_status_t status = f_memory_array_resize(length, sizeof(f_account_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); @@ -44,6 +44,8 @@ void test__f_accountss_append__returns_data_not(void **state) { void test__f_accountss_append__works(void **state) { + mock_unwrap = 1; + const int length = 5; f_accounts_t sources = f_accounts_t_initialize; f_accountss_t destination = f_accountss_t_initialize; @@ -57,7 +59,7 @@ void test__f_accountss_append__works(void **state) { const f_account_t source = { .home = home, .label = label, .name = name, .password = password, .shell = shell }; { - const f_status_t status = f_accounts_resize(length, &sources); + const f_status_t status = f_memory_array_resize(length, sizeof(f_account_t), (void **) &sources.array, &sources.used, &sources.size); assert_int_equal(status, F_none); assert_int_equal(sources.used, 0); @@ -93,6 +95,16 @@ void test__f_accountss_append__works(void **state) { } for (f_number_unsigned_t i = 0; i < destination.used; ++i) { + + for (f_number_unsigned_t j = 0; j < destination.array[i].used; ++j) { + + free((void *) destination.array[i].array[j].home.string); + free((void *) destination.array[i].array[j].label.string); + free((void *) destination.array[i].array[j].name.string); + free((void *) destination.array[i].array[j].password.string); + free((void *) destination.array[i].array[j].shell.string); + } + free((void *) destination.array[i].array); } // for diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append.h b/level_0/f_account/tests/unit/c/test-account-ss_append.h index a45dd70..ca626a4 100644 --- a/level_0/f_account/tests/unit/c/test-account-ss_append.h +++ b/level_0/f_account/tests/unit/c/test-account-ss_append.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: Account * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append_all.c b/level_0/f_account/tests/unit/c/test-account-ss_append_all.c index 09afa82..e4e1cca 100644 --- a/level_0/f_account/tests/unit/c/test-account-ss_append_all.c +++ b/level_0/f_account/tests/unit/c/test-account-ss_append_all.c @@ -23,7 +23,7 @@ void test__f_accountss_append_all__returns_data_not(void **state) { f_accountss_t destination = f_accountss_t_initialize; { - const f_status_t status = f_accountss_resize(length, &source); + const f_status_t status = f_memory_arrays_resize(length, sizeof(f_accounts_t), (void **) &source.array, &source.used, &source.size, &f_accounts_resize_callback); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); @@ -44,6 +44,8 @@ void test__f_accountss_append_all__returns_data_not(void **state) { void test__f_accountss_append_all__works(void **state) { + mock_unwrap = 1; + const int length = 5; const int length_inner = 2; f_accountss_t source = f_accountss_t_initialize; @@ -65,7 +67,7 @@ void test__f_accountss_append_all__works(void **state) { const f_account_t account_1 = { .home = home_1, .label = label_1, .name = name_1, .password = password_1, .shell = shell_1 }; { - const f_status_t status = f_accountss_resize(length, &source); + const f_status_t status = f_memory_arrays_resize(length, sizeof(f_accounts_t), (void **) &source.array, &source.used, &source.size, &f_accounts_resize_callback); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); @@ -75,7 +77,7 @@ void test__f_accountss_append_all__works(void **state) { { for (; source.used < length; ++source.used) { - const f_status_t status = f_accounts_resize(length_inner, &source.array[source.used]); + const f_status_t status = f_memory_array_resize(length_inner, sizeof(f_account_t), (void **) &source.array[source.used].array, &source.array[source.used].used, &source.array[source.used].size); assert_int_equal(status, F_none); @@ -115,6 +117,16 @@ void test__f_accountss_append_all__works(void **state) { } // for for (f_number_unsigned_t i = 0; i < destination.used; ++i) { + + for (f_number_unsigned_t j = 0; j < destination.array[i].used; ++j) { + + free((void *) destination.array[i].array[j].home.string); + free((void *) destination.array[i].array[j].label.string); + free((void *) destination.array[i].array[j].name.string); + free((void *) destination.array[i].array[j].password.string); + free((void *) destination.array[i].array[j].shell.string); + } + free((void *) destination.array[i].array); } // for diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append_all.h b/level_0/f_account/tests/unit/c/test-account-ss_append_all.h index a728832..4074adb 100644 --- a/level_0/f_account/tests/unit/c/test-account-ss_append_all.h +++ b/level_0/f_account/tests/unit/c/test-account-ss_append_all.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: Account * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c b/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c deleted file mode 100644 index e9af665..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_decimate_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_decimate_by__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_decimate_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accountss_decimate_by__returns_data_not(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_decimate_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accountss_decimate_by__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_decimate_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h b/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h deleted file mode 100644 index 4ac5cc2..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_decimate_by -#define _TEST__F_account_ss_decimate_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_decimate_by() - */ -extern void test__f_accountss_decimate_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accountss_decimate_by() - */ -extern void test__f_accountss_decimate_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_decimate_by() - */ -extern void test__f_accountss_decimate_by__works(void **state); - -#endif // _TEST__F_account_ss_decimate_by diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c b/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c deleted file mode 100644 index 34fc020..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_decrease_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_decrease_by__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_decrease_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accountss_decrease_by__returns_data_not(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_decrease_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accountss_decrease_by__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_decrease_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h b/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h deleted file mode 100644 index cdf0b2c..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_decrease_by -#define _TEST__F_account_ss_decrease_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_decrease_by() - */ -extern void test__f_accountss_decrease_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accountss_decrease_by() - */ -extern void test__f_accountss_decrease_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_decrease_by() - */ -extern void test__f_accountss_decrease_by__works(void **state); - -#endif // _TEST__F_account_ss_decrease_by diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase.c b/level_0/f_account/tests/unit/c/test-account-ss_increase.c deleted file mode 100644 index 710c2e2..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_increase.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_increase.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_increase__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_increase(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - free((void *) data.array); -} - -void test__f_accountss_increase__returns_data_not(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_increase(length, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accountss_increase__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_accountss_increase(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase.h b/level_0/f_account/tests/unit/c/test-account-ss_increase.h deleted file mode 100644 index 67326d0..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_increase.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_increase -#define _TEST__F_account_ss_increase - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_increase() - */ -extern void test__f_accountss_increase__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accountss_increase() - */ -extern void test__f_accountss_increase__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_increase() - */ -extern void test__f_accountss_increase__works(void **state); - -#endif // _TEST__F_account_ss_increase diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.c b/level_0/f_account/tests/unit/c/test-account-ss_increase_by.c deleted file mode 100644 index 0398ccf..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_increase_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_increase_by__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_increase_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accountss_increase_by__returns_data_not(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_increase_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_increase_by(length, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_account_decrease_by__returns_data_not(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_accountss_decrease_by(0, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_accountss_increase_by__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accounts_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_accountss_increase_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_int_equal(data.size, length * 2); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.h b/level_0/f_account/tests/unit/c/test-account-ss_increase_by.h deleted file mode 100644 index 20d99fa..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_increase_by -#define _TEST__F_account_ss_increase_by - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_increase_by() - */ -extern void test__f_accountss_increase_by__parameter_checking(void **state); - -/** - * Test that the function returns F_data_not. - * - * @see f_accountss_increase_by() - */ -extern void test__f_accountss_increase_by__returns_data_not(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_increase_by() - */ -extern void test__f_accountss_increase_by__works(void **state); - -#endif // _TEST__F_account_ss_increase_by diff --git a/level_0/f_account/tests/unit/c/test-account-ss_resize.c b/level_0/f_account/tests/unit/c/test-account-ss_resize.c deleted file mode 100644 index d37cd77..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_resize.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-account.h" -#include "test-account-ss_resize.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_accountss_resize__parameter_checking(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_accountss_resize__works(void **state) { - - const int length = 5; - f_accountss_t data = f_accountss_t_initialize; - - { - const f_status_t status = f_accountss_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_account/tests/unit/c/test-account-ss_resize.h b/level_0/f_account/tests/unit/c/test-account-ss_resize.h deleted file mode 100644 index 1df4e83..0000000 --- a/level_0/f_account/tests/unit/c/test-account-ss_resize.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_account_ss_resize -#define _TEST__F_account_ss_resize - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_accountss_resize() - */ -extern void test__f_accountss_resize__parameter_checking(void **state); - -/** - * Test that the function works. - * - * @see f_accountss_resize() - */ -extern void test__f_accountss_resize__works(void **state); - -#endif // _TEST__F_account_ss_resize diff --git a/level_0/f_account/tests/unit/c/test-account.c b/level_0/f_account/tests/unit/c/test-account.c index 3eef52c..a6c2512 100644 --- a/level_0/f_account/tests/unit/c/test-account.c +++ b/level_0/f_account/tests/unit/c/test-account.c @@ -43,36 +43,22 @@ int main(void) { cmocka_unit_test(test__f_account_name_by_id__not_found), cmocka_unit_test(test__f_account_name_by_id__works), + cmocka_unit_test(test__f_accounts_adjust_callback__fails), + cmocka_unit_test(test__f_accounts_resize_callback__fails), + + cmocka_unit_test(test__f_accounts_adjust_callback__works), + cmocka_unit_test(test__f_accounts_resize_callback__works), + cmocka_unit_test(test__f_accounts_append_all__returns_data_not), - cmocka_unit_test(test__f_accounts_decimate_by__returns_data_not), - cmocka_unit_test(test__f_accounts_decrease_by__returns_data_not), - cmocka_unit_test(test__f_accounts_increase__returns_data_not), - cmocka_unit_test(test__f_accounts_increase_by__returns_data_not), - cmocka_unit_test(test__f_accounts_adjust__works), cmocka_unit_test(test__f_accounts_append__works), cmocka_unit_test(test__f_accounts_append_all__works), - cmocka_unit_test(test__f_accounts_decimate_by__works), - cmocka_unit_test(test__f_accounts_decrease_by__works), - cmocka_unit_test(test__f_accounts_increase__works), - cmocka_unit_test(test__f_accounts_increase_by__works), - cmocka_unit_test(test__f_accounts_resize__works), cmocka_unit_test(test__f_accountss_append__returns_data_not), cmocka_unit_test(test__f_accountss_append_all__returns_data_not), - cmocka_unit_test(test__f_accountss_decimate_by__returns_data_not), - cmocka_unit_test(test__f_accountss_decrease_by__returns_data_not), - cmocka_unit_test(test__f_accountss_increase__returns_data_not), - cmocka_unit_test(test__f_accountss_increase_by__returns_data_not), - cmocka_unit_test(test__f_accountss_adjust__works), cmocka_unit_test(test__f_accountss_append__works), cmocka_unit_test(test__f_accountss_append_all__works), - cmocka_unit_test(test__f_accountss_decimate_by__works), - cmocka_unit_test(test__f_accountss_decrease_by__works), - cmocka_unit_test(test__f_accountss_increase__works), - cmocka_unit_test(test__f_accountss_increase_by__works), - cmocka_unit_test(test__f_accountss_resize__works), #ifndef _di_level_0_parameter_checking_ cmocka_unit_test(test__f_account_by_id__parameter_checking), @@ -82,23 +68,14 @@ int main(void) { cmocka_unit_test(test__f_account_id_by_name__parameter_checking), cmocka_unit_test(test__f_account_name_by_id__parameter_checking), - cmocka_unit_test(test__f_accounts_adjust__parameter_checking), + // f_accounts_adjust_callback() doesn't use parameter checking. + // f_accounts_resize_callback() doesn't use parameter checking. + cmocka_unit_test(test__f_accounts_append__parameter_checking), cmocka_unit_test(test__f_accounts_append_all__parameter_checking), - cmocka_unit_test(test__f_accounts_decimate_by__parameter_checking), - cmocka_unit_test(test__f_accounts_decrease_by__parameter_checking), - cmocka_unit_test(test__f_accounts_increase__parameter_checking), - cmocka_unit_test(test__f_accounts_increase_by__parameter_checking), - cmocka_unit_test(test__f_accounts_resize__parameter_checking), - cmocka_unit_test(test__f_accountss_adjust__parameter_checking), cmocka_unit_test(test__f_accountss_append__parameter_checking), cmocka_unit_test(test__f_accountss_append_all__parameter_checking), - cmocka_unit_test(test__f_accountss_decimate_by__parameter_checking), - cmocka_unit_test(test__f_accountss_decrease_by__parameter_checking), - cmocka_unit_test(test__f_accountss_increase__parameter_checking), - cmocka_unit_test(test__f_accountss_increase_by__parameter_checking), - cmocka_unit_test(test__f_accountss_resize__parameter_checking), #endif // _di_level_0_parameter_checking_ }; diff --git a/level_0/f_account/tests/unit/c/test-account.h b/level_0/f_account/tests/unit/c/test-account.h index 89f1b8c..d2689c0 100644 --- a/level_0/f_account/tests/unit/c/test-account.h +++ b/level_0/f_account/tests/unit/c/test-account.h @@ -32,22 +32,12 @@ #include "test-account-group_name_by_id.h" #include "test-account-id_by_name.h" #include "test-account-name_by_id.h" -#include "test-account-s_adjust.h" +#include "test-account-s_adjust_callback.h" #include "test-account-s_append.h" #include "test-account-s_append_all.h" -#include "test-account-s_decimate_by.h" -#include "test-account-s_decrease_by.h" -#include "test-account-s_increase.h" -#include "test-account-s_increase_by.h" -#include "test-account-s_resize.h" -#include "test-account-ss_adjust.h" +#include "test-account-s_resize_callback.h" #include "test-account-ss_append.h" #include "test-account-ss_append_all.h" -#include "test-account-ss_decimate_by.h" -#include "test-account-ss_decrease_by.h" -#include "test-account-ss_increase.h" -#include "test-account-ss_increase_by.h" -#include "test-account-ss_resize.h" #ifdef __cplusplus extern "C" { diff --git a/level_0/f_iki/c/iki/common.h b/level_0/f_iki/c/iki/common.h index 541ee4e..f2f5f33 100644 --- a/level_0/f_iki/c/iki/common.h +++ b/level_0/f_iki/c/iki/common.h @@ -244,17 +244,6 @@ extern "C" { #define macro_f_iki_datas_t_initialize_1(content, size, used) { array, size, used } #define macro_f_iki_datas_t_initialize_2(array, length) { array, length, length } - - #define macro_f_iki_datas_t_resize(status, datas, length) status = f_iki_datas_resize(length, &datas); - #define macro_f_iki_datas_t_adjust(status, datas, length) status = f_iki_datas_adjust(length, &datas); - - #define macro_f_iki_datas_t_delete_simple(datas) status = f_iki_datas_resize(0, &datas); - #define macro_f_iki_datas_t_destroy_simple(datas) status = f_iki_datas_adjust(0, &datas); - - #define macro_f_iki_datas_t_increase(status, step, datas) status = f_iki_datas_increase(step, &datas); - #define macro_f_iki_datas_t_increase_by(status, datas, amount) status = f_iki_datas_increase_by(amount, &datas); - #define macro_f_iki_datas_t_decrease_by(status, datas, amount) status = f_iki_datas_decrease_by(amount, &datas); - #define macro_f_iki_datas_t_decimate_by(status, datas, amount) status = f_iki_datas_decimate_by(amount, &datas); #endif // _di_f_iki_datas_t_ /** @@ -277,17 +266,6 @@ extern "C" { #define macro_f_iki_datass_t_initialize_1(content, size, used) { array, size, used } #define macro_f_iki_datass_t_initialize_2(array, length) { array, length, length } - - #define macro_f_iki_datass_t_resize(status, datas, length) status = f_iki_datass_resize(length, &datas); - #define macro_f_iki_datass_t_adjust(status, datas, length) status = f_iki_datass_adjust(length, &datas); - - #define macro_f_iki_datass_t_delete_simple(datas) status = f_iki_datass_resize(0, &datas); - #define macro_f_iki_datass_t_destroy_simple(datas) status = f_iki_datass_adjust(0, &datas); - - #define macro_f_iki_datass_t_increase(status, step, datas) status = f_iki_datass_increase(step, &datas); - #define macro_f_iki_datass_t_increase_by(status, datas, amount) status = f_iki_datass_increase_by(amount, &datas); - #define macro_f_iki_datass_t_decrease_by(status, datas, amount) status = f_iki_datass_decrease_by(amount, &datas); - #define macro_f_iki_datass_t_decimate_by(status, datas, amount) status = f_iki_datass_decimate_by(amount, &datas); #endif // _di_f_iki_datass_t_ #ifdef __cplusplus diff --git a/level_0/f_iki/c/iki/data.c b/level_0/f_iki/c/iki/data.c index f98df4d..ee8df0a 100644 --- a/level_0/f_iki/c/iki/data.c +++ b/level_0/f_iki/c/iki/data.c @@ -50,129 +50,114 @@ extern "C" { } #endif // _di_f_iki_data_destroy_ -#ifndef _di_f_iki_datas_adjust_ - f_status_t f_iki_datas_adjust(const f_number_unsigned_t length, f_iki_datas_t *datas) { - #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_iki_datas_adjust(length, datas); - } -#endif // _di_f_iki_datas_adjust_ +#ifndef _di_f_iki_datas_adjust_callback_ + f_status_t f_iki_datas_adjust_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { -#ifndef _di_f_iki_datas_append_ - f_status_t f_iki_datas_append(const f_iki_data_t source, f_iki_datas_t *destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + { + f_iki_datas_t * const array = (f_iki_datas_t *) void_array; + f_status_t status = F_none; - return private_f_iki_datas_append(source, destination); - } -#endif // _di_f_iki_datas_append_ + for (f_number_unsigned_t i = start; i < stop; ++i) { -#ifndef _di_f_iki_datas_append_all_ - f_status_t f_iki_datas_append_all(const f_iki_datas_t source, f_iki_datas_t *destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; + status = f_string_ranges_adjust(0, &array->array[i].content); + if (F_status_is_error(status)) return status; - return private_f_iki_datas_append_all(source, destination); - } -#endif // _di_f_iki_datas_append_all_ + status = f_memory_array_adjust(0, sizeof(f_number_unsigned_t), (void **) &array->array[i].delimits.array, &array->array[i].delimits.used, &array->array[i].delimits.size); + if (F_status_is_error(status)) return status; -#ifndef _di_f_iki_datas_decimate_by_ - f_status_t f_iki_datas_decimate_by(const f_number_unsigned_t amount, f_iki_datas_t *datas) { - #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_ranges_adjust(0, &array->array[i].variable); + if (F_status_is_error(status)) return status; - if (!amount) return F_data_not; - if (datas->size > amount) return private_f_iki_datas_adjust(datas->size - amount, datas); + status = f_string_ranges_adjust(0, &array->array[i].vocabulary); + if (F_status_is_error(status)) return status; + } // for + } - return private_f_iki_datas_adjust(0, datas); + return F_none; } -#endif // _di_f_iki_datas_decimate_by_ +#endif // _di_f_iki_datas_adjust_callback_ -#ifndef _di_f_iki_datas_decrease_by_ - f_status_t f_iki_datas_decrease_by(const f_number_unsigned_t amount, f_iki_datas_t *datas) { +#ifndef _di_f_iki_datas_append_ + f_status_t f_iki_datas_append(const f_iki_data_t source, f_iki_datas_t *destination) { #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - if (datas->size > amount) return private_f_iki_datas_resize(datas->size - amount, datas); - - return private_f_iki_datas_resize(0, datas); - } -#endif // _di_f_iki_datas_decrease_by_ + f_status_t status = f_memory_array_increase(F_iki_default_allocation_small_d, sizeof(f_iki_data_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; -#ifndef _di_f_iki_datas_increase_ - f_status_t f_iki_datas_increase(const f_number_unsigned_t step, f_iki_datas_t *datas) { - #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + destination->array[destination->used].content.used = 0; + destination->array[destination->used].delimits.used = 0; + destination->array[destination->used].variable.used = 0; + destination->array[destination->used].vocabulary.used = 0; - if (step && datas->used + 1 > datas->size) { - if (datas->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + if (source.content.used) { + status = f_string_ranges_append_all(source.content, &destination->array[destination->used].content); + if (F_status_is_error(status)) return status; + } - f_number_unsigned_t length = datas->used + step; + if (source.delimits.used) { + for (f_number_unsigned_t i = 0; i < source.delimits.used; ++i) { - if (length > F_number_t_size_unsigned_d) { - if (datas->used + 1 > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + status = f_memory_array_append(source.delimits.array + i, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); + if (F_status_is_error(status)) return status; + } // for + } - length = F_number_t_size_unsigned_d; - } + if (source.variable.used) { + status = f_string_ranges_append_all(source.variable, &destination->array[destination->used].variable); + if (F_status_is_error(status)) return status; + } - return private_f_iki_datas_resize(length, datas); + if (source.vocabulary.used) { + status = f_string_ranges_append_all(source.vocabulary, &destination->array[destination->used].vocabulary); + if (F_status_is_error(status)) return status; } - return F_data_not; + ++destination->used; + + return F_none; } -#endif // _di_f_iki_datas_increase_ +#endif // _di_f_iki_datas_append_ -#ifndef _di_f_iki_datas_increase_by_ - f_status_t f_iki_datas_increase_by(const f_number_unsigned_t amount, f_iki_datas_t *datas) { +#ifndef _di_f_iki_datas_append_all_ + f_status_t f_iki_datas_append_all(const f_iki_datas_t source, f_iki_datas_t *destination) { #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (amount) { - if (datas->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + if (!source.used) return F_data_not; - const f_number_unsigned_t length = datas->used + amount; + return private_f_iki_datas_append_all(source, destination); + } +#endif // _di_f_iki_datas_append_all_ - if (length > datas->size) { - if (length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); +#ifndef _di_f_iki_datas_resize_callback_ + f_status_t f_iki_datas_resize_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { - return private_f_iki_datas_resize(length, datas); - } - } + { + f_iki_datas_t * const array = (f_iki_datas_t *) void_array; + f_status_t status = F_none; - return F_data_not; - } -#endif // _di_f_iki_datas_increase_by_ + for (f_number_unsigned_t i = start; i < stop; ++i) { -#ifndef _di_f_iki_datas_resize_ - f_status_t f_iki_datas_resize(const f_number_unsigned_t length, f_iki_datas_t *datas) { - #ifndef _di_level_0_parameter_checking_ - if (!datas) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_ranges_resize(0, &array->array[i].content); + if (F_status_is_error(status)) return status; - return private_f_iki_datas_resize(length, datas); - } -#endif // _di_f_iki_datas_resize_ + status = f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array->array[i].delimits.array, &array->array[i].delimits.used, &array->array[i].delimits.size); + if (F_status_is_error(status)) return status; -#ifndef _di_f_iki_datass_adjust_ - f_status_t f_iki_datass_adjust(const f_number_unsigned_t length, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + status = f_string_ranges_resize(0, &array->array[i].variable); + if (F_status_is_error(status)) return status; - return private_f_iki_datass_adjust(length, datass); + status = f_string_ranges_resize(0, &array->array[i].vocabulary); + if (F_status_is_error(status)) return status; + } // for + } + + return F_none; } -#endif // _di_f_iki_datass_adjust_ +#endif // _di_f_iki_datas_resize_callback_ #ifndef _di_f_iki_datass_append_ f_status_t f_iki_datass_append(const f_iki_datas_t source, f_iki_datass_t *destination) { @@ -219,86 +204,6 @@ extern "C" { } #endif // _di_f_iki_datass_append_all_ -#ifndef _di_f_iki_datass_decimate_by_ - f_status_t f_iki_datass_decimate_by(const f_number_unsigned_t amount, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - return private_f_iki_datass_adjust((datass->size > amount) ? datass->size - amount : 0, datass); - } -#endif // _di_f_iki_datass_decimate_by_ - -#ifndef _di_f_iki_datass_decrease_by_ - f_status_t f_iki_datass_decrease_by(const f_number_unsigned_t amount, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - return private_f_iki_datass_resize((datass->size > amount) ? datass->size - amount : 0, datass); - } -#endif // _di_f_iki_datass_decrease_by_ - -#ifndef _di_f_iki_datass_increase_ - f_status_t f_iki_datass_increase(const f_number_unsigned_t step, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && datass->used + 1 > datass->size) { - if (datass->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - f_number_unsigned_t length = datass->used + step; - - if (length > F_number_t_size_unsigned_d) { - if (datass->used + 1 > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - length = F_number_t_size_unsigned_d; - } - - return private_f_iki_datass_resize(length, datass); - } - - return F_data_not; - } -#endif // _di_f_iki_datass_increase_ - -#ifndef _di_f_iki_datass_increase_by_ - f_status_t f_iki_datass_increase_by(const f_number_unsigned_t amount, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (amount) { - if (datass->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - const f_number_unsigned_t length = datass->used + amount; - - if (length > datass->size) { - if (length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - return private_f_iki_datass_resize(length, datass); - } - } - - return F_data_not; - } -#endif // _di_f_iki_datass_increase_by_ - -#ifndef _di_f_iki_datass_resize_ - f_status_t f_iki_datass_resize(const f_number_unsigned_t length, f_iki_datass_t *datass) { - #ifndef _di_level_0_parameter_checking_ - if (!datass) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_iki_datass_resize(length, datass); - } -#endif // _di_f_iki_datass_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_iki/c/iki/data.h b/level_0/f_iki/c/iki/data.h index 36388a6..d99891b 100644 --- a/level_0/f_iki/c/iki/data.h +++ b/level_0/f_iki/c/iki/data.h @@ -59,12 +59,17 @@ extern "C" { #endif // _di_f_iki_data_destroy_ /** - * Resize the iki_datas array. + * A callback intended to be passed to f_memory_arrays_adjust() for an f_iki_datass_t structure. * - * @param length - * The new size to use. - * @param iki_datas - * The iki_datas array to resize. + * This does not do parameter checking. + * + * @param start + * The inclusive start position in the array to start deleting. + * @param stop + * The exclusive stop position in the array to stop deleting. + * @param array + * The array structure to delete all values of. + * Must not be NULL. * * @return * F_none on success. @@ -72,14 +77,13 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. * * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). * * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() + * @see f_memory_arrays_adjust() */ -#ifndef _di_f_iki_datas_adjust_ - extern f_status_t f_iki_datas_adjust(const f_number_unsigned_t length, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_adjust_ +#ifndef _di_f_iki_datas_adjust_callback_ + extern f_status_t f_iki_datas_adjust_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); +#endif // _di_f_iki_datas_adjust_callback_ /** * Append the single source iki_data onto the destination. @@ -95,11 +99,11 @@ extern "C" { * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_array_append_all(). + * Errors (with error bit) from: f_memory_array_append(). * Errors (with error bit) from: f_memory_array_increase(). * Errors (with error bit) from: f_string_ranges_append_all(). * - * @see f_memory_array_append_all() + * @see f_memory_array_append() * @see f_memory_array_increase() * @see f_string_ranges_append_all() */ @@ -121,11 +125,11 @@ extern "C" { * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_array_append_all(). + * Errors (with error bit) from: f_memory_array_append(). * Errors (with error bit) from: f_memory_array_increase_by(). * Errors (with error bit) from: f_string_ranges_append_all(). * - * @see f_memory_array_append_all() + * @see f_memory_array_append() * @see f_memory_array_increase_by() * @see f_string_ranges_append_all() */ @@ -134,164 +138,31 @@ extern "C" { #endif // _di_f_iki_datas_append_all_ /** - * Resize the iki_datas array to a smaller size. + * A callback intended to be passed to f_memory_arrays_resize() for an f_iki_datass_t structure. * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to les than 0. + * This does not do parameter checking. * - * @param amount - * A positive number representing how much to decimate the size by. - * @param iki_datas - * The iki_datas array to resize. + * @param start + * The inclusive start position in the array to start deleting. + * @param stop + * The exclusive stop position in the array to stop deleting. + * @param array + * The array structure to delete all values of. + * Must not be NULL. * * @return * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() - */ -#ifndef _di_f_iki_datas_decimate_by_ - extern f_status_t f_iki_datas_decimate_by(const f_number_unsigned_t amount, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_decimate_by_ - -/** - * Resize the iki_datas array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to les than 0. - * - * @param amount - * A positive number representing how much to decrease the size by. - * @param iki_datas - * The iki_datas array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. * * F_parameter (with error bit) if a parameter is invalid. * * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). * * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datas_decrease_by_ - extern f_status_t f_iki_datas_decrease_by(const f_number_unsigned_t amount, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_decrease_by_ - -/** - * Increase the size of the iki_datas array, but only if necesary. - * - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param iki_datas - * The iki_datas array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datas_increase_ - extern f_status_t f_iki_datas_increase(const f_number_unsigned_t step, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_increase_ - -/** - * Resize the iki_datas array to a larger size. - * - * This will resize making the array larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param amount - * A positive number representing how much to increase the size by. - * @param iki_datas - * The iki_datas array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datas_increase_by_ - extern f_status_t f_iki_datas_increase_by(const f_number_unsigned_t amount, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_increase_by_ - -/** - * Resize the iki_datas array. - * - * @param length - * The new size to use. - * @param iki_datas - * The iki_datas array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datas_resize_ - extern f_status_t f_iki_datas_resize(const f_number_unsigned_t length, f_iki_datas_t *datas); -#endif // _di_f_iki_datas_resize_ - -/** - * Resize the iki_datass array. - * - * @param length - * The new size to use. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() + * @see f_memory_arrays_resize() */ -#ifndef _di_f_iki_datass_adjust_ - extern f_status_t f_iki_datass_adjust(const f_number_unsigned_t length, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_adjust_ +#ifndef _di_f_iki_datas_resize_callback_ + extern f_status_t f_iki_datas_resize_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); +#endif // _di_f_iki_datas_resize_callback_ /** * Append the single source iki_datas onto the destination. @@ -345,143 +216,6 @@ extern "C" { extern f_status_t f_iki_datass_append_all(const f_iki_datass_t source, f_iki_datass_t *destination); #endif // _di_f_iki_datass_append_all_ -/** - * Resize the iki_datass array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. - * - * @param amount - * A positive number representing how much to decimate the size by. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() - */ -#ifndef _di_f_iki_datass_decimate_by_ - extern f_status_t f_iki_datass_decimate_by(const f_number_unsigned_t amount, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_decimate_by_ - -/** - * Resize the iki_datass array to a smaller size. - * - * This will resize making the array smaller based on (size - given length). - * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. - * - * @param amount - * A positive number representing how much to decrease the size by. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datass_decrease_by_ - extern f_status_t f_iki_datass_decrease_by(const f_number_unsigned_t amount, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_decrease_by_ - -/** - * Increase the size of the iki_datass array, but only if necessary. - * - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datass_increase_ - extern f_status_t f_iki_datass_increase(const f_number_unsigned_t step, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_increase_ - -/** - * Resize the iki_datass array to a larger size. - * - * This will resize making the array larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param amount - * A positive number representing how much to increase the size by. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datass_increase_by_ - extern f_status_t f_iki_datass_increase_by(const f_number_unsigned_t amount, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_increase_by_ - -/** - * Resize the iki_datass array. - * - * @param length - * The new size to use. - * @param iki_datass - * The iki_datass array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - */ -#ifndef _di_f_iki_datass_resize_ - extern f_status_t f_iki_datass_resize(const f_number_unsigned_t length, f_iki_datass_t *datass); -#endif // _di_f_iki_datass_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_iki/c/iki/private-data.c b/level_0/f_iki/c/iki/private-data.c index b9ab34a..4549d73 100644 --- a/level_0/f_iki/c/iki/private-data.c +++ b/level_0/f_iki/c/iki/private-data.c @@ -5,70 +5,6 @@ extern "C" { #endif -#if !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - f_status_t private_f_iki_datas_adjust(const f_number_unsigned_t length, f_iki_datas_t *structure) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < structure->size; ++i) { - - status = f_string_ranges_adjust(0, &structure->array[i].content); - if (F_status_is_error(status)) return status; - - status = f_memory_array_adjust(0, sizeof(f_number_unsigned_t), (void **) &structure->array[i].delimits.array, &structure->array[i].delimits.used, &structure->array[i].delimits.size); - if (F_status_is_error(status)) return status; - - status = f_string_ranges_adjust(0, &structure->array[i].variable); - if (F_status_is_error(status)) return status; - - status = f_string_ranges_adjust(0, &structure->array[i].vocabulary); - if (F_status_is_error(status)) return status; - } // for - - return f_memory_array_adjust(length, sizeof(f_iki_data_t), (void **) &structure->array, &structure->used, &structure->size); - } -#endif // !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - -#if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datass_append_) - extern f_status_t private_f_iki_datas_append(const f_iki_data_t source, f_iki_datas_t *destination) { - - f_status_t status = f_memory_array_increase(F_iki_default_allocation_small_d, sizeof(f_iki_data_t), (void **) &destination->array, &destination->used, &destination->size); - if (F_status_is_error(status)) return status; - - destination->array[destination->used].content.used = 0; - destination->array[destination->used].delimits.used = 0; - destination->array[destination->used].variable.used = 0; - destination->array[destination->used].vocabulary.used = 0; - - if (source.content.used) { - status = f_string_ranges_append_all(source.content, &destination->array[destination->used].content); - if (F_status_is_error(status)) return status; - } - - if (source.delimits.used) { - for (f_number_unsigned_t i = 0; i < source.delimits.used; ++i) { - - status = f_memory_array_append(source.delimits.array + i, sizeof(f_number_unsigned_t), (void **) &destination->array[destination->used].delimits.array, &destination->array[destination->used].delimits.used, &destination->array[destination->used].delimits.size); - if (F_status_is_error(status)) return status; - } // for - } - - if (source.variable.used) { - status = f_string_ranges_append_all(source.variable, &destination->array[destination->used].variable); - if (F_status_is_error(status)) return status; - } - - if (source.vocabulary.used) { - status = f_string_ranges_append_all(source.vocabulary, &destination->array[destination->used].vocabulary); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datass_append_) - #if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_append_all_) || !defined(_di_f_iki_datass_append_all_) extern f_status_t private_f_iki_datas_append_all(const f_iki_datas_t source, f_iki_datas_t *destination) { @@ -112,60 +48,6 @@ extern "C" { } #endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_append_all_) || !defined(_di_f_iki_datass_append_all_) -#if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decrease_by_) || !defined(_di_f_iki_datas_increase_) || !defined(_di_f_iki_datas_increase_by_) || !defined(_di_f_iki_datas_resize_) - f_status_t private_f_iki_datas_resize(const f_number_unsigned_t length, f_iki_datas_t *structure) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < structure->size; ++i) { - - status = f_string_ranges_resize(0, &structure->array[i].content); - if (F_status_is_error(status)) return status; - - status = f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &structure->array[i].delimits.array, &structure->array[i].delimits.used, &structure->array[i].delimits.size); - if (F_status_is_error(status)) return status; - - status = f_string_ranges_resize(0, &structure->array[i].variable); - if (F_status_is_error(status)) return status; - - status = f_string_ranges_resize(0, &structure->array[i].vocabulary); - if (F_status_is_error(status)) return status; - } // for - - return f_memory_array_resize(length, sizeof(f_iki_data_t), (void **) &structure->array, &structure->used, &structure->size); - } -#endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decrease_by_) || !defined(_di_f_iki_datas_increase_) || !defined(_di_f_iki_datas_increase_by_) || !defined(_di_f_iki_datas_resize_) - -#if !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - f_status_t private_f_iki_datass_adjust(const f_number_unsigned_t length, f_iki_datass_t *structure) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < structure->size; ++i) { - - status = private_f_iki_datas_adjust(0, &structure->array[i]); - if (F_status_is_error(status)) return status; - } // for - - return f_memory_array_adjust(length, sizeof(f_iki_datas_t), (void **) &structure->array, &structure->used, &structure->size); - } -#endif // !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - -#if !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - f_status_t private_f_iki_datass_resize(const f_number_unsigned_t length, f_iki_datass_t *structure) { - - f_status_t status = F_none; - - for (f_number_unsigned_t i = length; i < structure->size; ++i) { - - status = private_f_iki_datas_resize(0, &structure->array[i]); - if (F_status_is_error(status)) return status; - } // for - - return f_memory_array_resize(length, sizeof(f_iki_datas_t), (void **) &structure->array, &structure->used, &structure->size); - } -#endif // !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_iki/c/iki/private-data.h b/level_0/f_iki/c/iki/private-data.h index 236518d..a149cf4 100644 --- a/level_0/f_iki/c/iki/private-data.h +++ b/level_0/f_iki/c/iki/private-data.h @@ -16,61 +16,6 @@ extern "C" { #endif /** - * Private implementation for resizing the iki_datas array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param structure - * The iki_datas array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() - * - * @see f_iki_datas_adjust() - * @see f_iki_datas_decimate_by() - */ -#if !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - extern f_status_t private_f_iki_datas_adjust(const f_number_unsigned_t length, f_iki_datas_t *structure) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - -/** - * Private implementation for appending the iki_data array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source iki_data to append. - * @param destination - * The iki_datas array the source is appended onto. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: f_memory_array_append_all(). - * Errors (with error bit) from: f_memory_array_increase(). - * Errors (with error bit) from: f_string_ranges_append_all(). - * - * @see f_memory_array_append_all() - * @see f_memory_array_increase() - * @see f_string_ranges_append_all() - * - * @see f_iki_datas_append() - * @see f_iki_datass_append() - */ -#if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datass_append_) - extern f_status_t private_f_iki_datas_append(const f_iki_data_t source, f_iki_datas_t *destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datass_append_) - -/** * Private implementation for appending the iki_data array. * * Intended to be shared to each of the different implementation variations. @@ -83,11 +28,11 @@ extern "C" { * @return * F_none on success. * - * Errors (with error bit) from: f_memory_array_append_all(). + * Errors (with error bit) from: f_memory_array_append(). * Errors (with error bit) from: f_memory_array_increase_by(). * Errors (with error bit) from: f_string_ranges_append_all(). * - * @see f_memory_array_append_all() + * @see f_memory_array_append() * @see f_memory_array_increase_by() * @see f_string_ranges_append_all() * @@ -98,99 +43,6 @@ extern "C" { extern f_status_t private_f_iki_datas_append_all(const f_iki_datas_t source, f_iki_datas_t *destination) F_attribute_visibility_internal_d; #endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_append_all_) || !defined(_di_f_iki_datass_append_all_) -/** - * Private implementation for resizing the iki_datas array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param structure - * The iki_datas array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - * - * @see f_iki_datas_resize() - * @see f_iki_datas_append() - * @see f_iki_datas_decimate_by() - * @see f_iki_datass_append() - */ -#if !defined(_di_f_iki_datas_resize_) || !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decimate_by_) || !defined(_di_f_iki_datass_append_) - extern f_status_t private_f_iki_datas_resize(const f_number_unsigned_t length, f_iki_datas_t *structure) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_resize_) || !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decimate_by_) || !defined(_di_f_iki_datass_append_) - -/** - * Private implementation for resizing the iki_datass array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param iki_datass - * The iki_datass array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_adjust(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_array_adjust() - * @see f_string_ranges_adjust() - * - * @see f_iki_datass_adjust() - * @see f_iki_datass_decimate_by() - */ -#if !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - extern f_status_t private_f_iki_datass_adjust(const f_number_unsigned_t length, f_iki_datass_t *datass) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - -/** - * Private implementation for resizing the iki_datass array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to resize to. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_string_ranges_resize() - * - * @see f_iki_datass_decrease_by() - * @see f_iki_datass_increase() - * @see f_iki_datass_increase_by() - * @see f_iki_datass_resize() - */ -#if !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - extern f_status_t private_f_iki_datass_resize(const f_number_unsigned_t length, f_iki_datass_t *datass) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_iki/c/private-iki.h b/level_0/f_iki/c/private-iki.h index 7db3acc..36d588f 100644 --- a/level_0/f_iki/c/private-iki.h +++ b/level_0/f_iki/c/private-iki.h @@ -44,140 +44,6 @@ extern "C" { #endif // !defined(_di_f_iki_content_is_) || !defined(_di_f_iki_content_partial_is_) /** - * Private implementation for resizing the iki_datas array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param datas - * The IKI datas array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_string_ranges_adjust(). - * - * @see f_memory_adjust() - * @see f_memory_array_resize() - * @see f_string_ranges_adjust() - */ -#if !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - extern f_status_t private_f_iki_datas_adjust(const f_number_unsigned_t length, f_iki_datas_t *datas) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_adjust_) || !defined(_di_f_iki_datas_decimate_by_) - -/** - * Private implementation for appending the iki_data array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source iki_datas to append. - * @param destination - * The destination lengths the source is appended onto. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_resize() - * @see f_iki_datas_append_all() - * @see f_iki_datass_append() - * @see f_iki_datass_append_all() - */ -#if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_append_all_) || !defined(_di_f_iki_datass_append_all_) - extern f_status_t private_f_iki_datas_append_all(const f_iki_datas_t source, f_iki_datas_t *destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_append_all_) || !defined(_di_f_iki_datass_append_all_) - -/** - * Private implementation for resizing the iki_datas array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param datas - * The IKI datas array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_array_resize(). - * Errors (with error bit) from: f_memory_resize(). - * Errors (with error bit) from: f_string_ranges_resize(). - * - * @see f_memory_array_resize() - * @see f_memory_resize() - * @see f_string_ranges_resize() - */ -#if !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decrease_by_) || !defined(_di_f_iki_datas_increase_) || !defined(_di_f_iki_datas_increase_by_) || !defined(_di_f_iki_datas_resize_) - extern f_status_t private_f_iki_datas_resize(const f_number_unsigned_t length, f_iki_datas_t *datas) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datas_append_) || !defined(_di_f_iki_datas_decrease_by_) || !defined(_di_f_iki_datas_increase_) || !defined(_di_f_iki_datas_increase_by_) || !defined(_di_f_iki_datas_resize_) - -/** - * Private implementation for resizing the iki_datass array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param iki_datass - * The iki_datass array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). - * - * @see f_iki_datass_adjust() - * @see f_iki_datass_decimate_by() - */ -#if !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - extern f_status_t private_f_iki_datass_adjust(const f_number_unsigned_t length, f_iki_datass_t *datass) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datass_adjust_) || !defined(_di_f_iki_datass_decimate_by_) - -/** - * Private implementation for resizing the iki_datass array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to resize to. - * @param iki_datass - * The iki_datass array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if new length is larger than max array length. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_iki_datass_decrease_by() - * @see f_iki_datass_increase() - * @see f_iki_datass_increase_by() - * @see f_iki_datass_resize() - */ -#if !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - extern f_status_t private_f_iki_datass_resize(const f_number_unsigned_t length, f_iki_datass_t *datass) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_iki_datass_decrease_by_) || !defined(_di_f_iki_datass_increase_) || !defined(_di_f_iki_datass_increase_by_) || !defined(_di_f_iki_datass_resize_) - -/** * Private implementation of f_iki_object_partial_is(). * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_iki/data/build/settings-mocks b/level_0/f_iki/data/build/settings-mocks new file mode 100644 index 0000000..c6241fb --- /dev/null +++ b/level_0/f_iki/data/build/settings-mocks @@ -0,0 +1,71 @@ +# fss-0001 +# +# Build the project with appropriate mocks linked in via the dynamic linker's "--wrap" functionality. +# +# The -Wl,--wrap does not work across shared files. +# Therefore, this file is a work-around to inject the mocks into the library for testing purposes. +# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file. +# +# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called). +# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled. +# + +build_name f_iki + +version_major 0 +version_minor 7 +version_micro 0 +version_file micro +version_target minor + +modes individual clang test coverage +modes_default individual test + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries -lc +build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_utf + +build_sources_library iki.c private-iki.c iki/common.c iki/private-data.c iki/data.c +build_sources_library ../../tests/unit/c/mock-iki.c + +build_sources_headers iki.h iki/common.h iki/data.h + +build_script yes +build_shared yes +build_static no + +path_headers fll/level_0 +path_library_script script +path_library_shared shared +path_library_static static + +has_path_standard yes +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +environment PATH LD_LIBRARY_PATH +environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH + +#defines -D_pthread_attr_unsupported_ -D_pthread_sigqueue_unsupported_ +defines -D_pthread_sigqueue_unsupported_ + +flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector -Wall +flags-coverage --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ + +flags_library -fPIC + +# Inject mocks. +flags -Wl,--wrap=f_memory_array_adjust +flags -Wl,--wrap=f_memory_array_resize +flags -Wl,--wrap=f_string_ranges_adjust +flags -Wl,--wrap=f_string_ranges_resize diff --git a/level_0/f_iki/data/build/settings-tests b/level_0/f_iki/data/build/settings-tests index 1680284..ad630d2 100644 --- a/level_0/f_iki/data/build/settings-tests +++ b/level_0/f_iki/data/build/settings-tests @@ -26,7 +26,7 @@ build_libraries -lc -lcmocka build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_utf -lf_iki build_sources_program test-iki-content_is.c test-iki-content_partial_is.c test-iki-object_is.c test-iki-object_partial_is.c test-iki-read.c -build_sources_program test-iki-datas_adjust.c test-iki-datas_append.c test-iki-datas_append_all.c test-iki-datas_decimate_by.c test-iki-datas_decrease_by.c test-iki-datas_increase.c test-iki-datas_increase_by.c test-iki-datas_resize.c test-iki-datass_adjust.c test-iki-datass_append.c test-iki-datass_append_all.c test-iki-datass_decimate_by.c test-iki-datass_decrease_by.c test-iki-datass_increase.c test-iki-datass_increase_by.c test-iki-datass_resize.c +build_sources_program test-iki-datas_adjust_callback.c test-iki-datas_append.c test-iki-datas_append_all.c test-iki-datas_resize_callback.c test-iki-datass_append.c test-iki-datass_append_all.c build_sources_program test-iki.c build_script no diff --git a/level_0/f_iki/data/build/testfile b/level_0/f_iki/data/build/testfile index 23f5824..5f76e64 100644 --- a/level_0/f_iki/data/build/testfile +++ b/level_0/f_iki/data/build/testfile @@ -18,7 +18,7 @@ settings: #define CMOCKA_XML_FILE ./out.xml main: - build settings individual test + build settings-mocks individual test build settings-tests individual test operate build_path diff --git a/level_0/f_iki/tests/unit/c/mock-iki.c b/level_0/f_iki/tests/unit/c/mock-iki.c new file mode 100644 index 0000000..0441520 --- /dev/null +++ b/level_0/f_iki/tests/unit/c/mock-iki.c @@ -0,0 +1,79 @@ +#include "mock-iki.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int mock_unwrap = 0; + +f_status_t __wrap_f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + + if (mock_unwrap) { + return __real_f_memory_array_adjust(length, width, array, used, size); + } + + if (!array || !used || !size) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + *size = length; + + return mock_type(f_status_t); +} + +f_status_t __wrap_f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + + if (mock_unwrap) { + return __real_f_memory_array_resize(length, width, array, used, size); + } + + if (!array || !used || !size) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + *size = length; + + return mock_type(f_status_t); +} + +f_status_t __wrap_f_string_ranges_adjust(const f_number_unsigned_t length, f_string_ranges_t * const structure) { + + if (mock_unwrap) { + return __real_f_string_ranges_adjust(length, structure); + } + + if (!structure) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + structure->size = length; + + return mock_type(f_status_t); +} + +f_status_t __wrap_f_string_ranges_resize(const f_number_unsigned_t length, f_string_ranges_t * const structure) { + + if (mock_unwrap) { + return __real_f_string_ranges_resize(length, structure); + } + + if (!structure) return F_status_set_error(F_parameter_not); + + const bool failure = mock_type(bool); + + if (failure) return mock_type(f_status_t); + + structure->size = length; + + return mock_type(f_status_t); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_iki/tests/unit/c/mock-iki.h b/level_0/f_iki/tests/unit/c/mock-iki.h new file mode 100644 index 0000000..a42bfc5 --- /dev/null +++ b/level_0/f_iki/tests/unit/c/mock-iki.h @@ -0,0 +1,48 @@ +/** + * FLL - Level 0 + * + * Project: IKI + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the iki project. + */ +#ifndef _MOCK__iki_h +#define _MOCK__iki_h + +// Libc includes. +#include +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-0 includes. +#include + +#ifdef __cplusplus +extern "C" { +#endif + +const static int mock_errno_generic = 32767; + +extern int mock_unwrap; + +extern f_status_t __real_f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +extern f_status_t __real_f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +extern f_status_t __real_f_string_ranges_adjust(const f_number_unsigned_t length, f_string_ranges_t * const structure); +extern f_status_t __real_f_string_ranges_resize(const f_number_unsigned_t length, f_string_ranges_t * const structure); + +extern f_status_t __wrap_f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +extern f_status_t __wrap_f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +extern f_status_t __wrap_f_string_ranges_adjust(const f_number_unsigned_t length, f_string_ranges_t * const structure); +extern f_status_t __wrap_f_string_ranges_resize(const f_number_unsigned_t length, f_string_ranges_t * const structure); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _MOCK__iki_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.c b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.c deleted file mode 100644 index e528630..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_adjust.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_adjust__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_adjust(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datas_adjust__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_adjust(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.h b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.h deleted file mode 100644 index 588e89e..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_adjust_h -#define _TEST__F_iki_datas_adjust_h - -/** - * Test that the function works. - * - * @see f_iki_datas_adjust() - */ -extern void test__f_iki_datas_adjust__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_adjust() - */ -extern void test__f_iki_datas_adjust__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_adjust_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.c b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.c new file mode 100644 index 0000000..69bce9b --- /dev/null +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.c @@ -0,0 +1,103 @@ +#include "test-iki.h" +#include "test-iki-datas_adjust_callback.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_iki_datas_adjust_callback__fails(void **state) { + + mock_unwrap = 0; + + f_iki_data_t data = f_iki_data_t_initialize; + f_iki_data_t data_array[] = { data }; + f_iki_datas_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_iki_datas_t datass_array[] = { datas }; + + { + will_return(__wrap_f_string_ranges_adjust, true); + will_return(__wrap_f_string_ranges_adjust, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_adjust_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_memory_array_adjust, true); + will_return(__wrap_f_memory_array_adjust, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_adjust_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_memory_array_adjust, false); + will_return(__wrap_f_memory_array_adjust, F_none); + + will_return(__wrap_f_string_ranges_adjust, true); + will_return(__wrap_f_string_ranges_adjust, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_adjust_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_memory_array_adjust, false); + will_return(__wrap_f_memory_array_adjust, F_none); + + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_string_ranges_adjust, true); + will_return(__wrap_f_string_ranges_adjust, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_adjust_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } +} + +void test__f_iki_datas_adjust_callback__works(void **state) { + + mock_unwrap = 0; + + f_iki_data_t data = f_iki_data_t_initialize; + f_iki_data_t data_array[] = { data }; + f_iki_datas_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_iki_datas_t datass_array[] = { datas }; + const f_number_unsigned_t length = 1; + + { + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_memory_array_adjust, false); + will_return(__wrap_f_memory_array_adjust, F_none); + + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + will_return(__wrap_f_string_ranges_adjust, false); + will_return(__wrap_f_string_ranges_adjust, F_none); + + const f_status_t status = f_iki_datas_adjust_callback(0, length, (void *) datass_array); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.h b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.h new file mode 100644 index 0000000..ac7c857 --- /dev/null +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_adjust_callback.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: IKI + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_iki__datas_adjust_callback +#define _TEST__F_iki__datas_adjust_callback + +/** + * Test that the function fails. + * + * @see f_iki_datas_adjust_callback() + */ +extern void test__f_iki_datas_adjust_callback__fails(void **state); + +/** + * Test that the function works. + * + * @see f_iki_datas_adjust_callback() + */ +extern void test__f_iki_datas_adjust_callback__works(void **state); + +#endif // _TEST__F_iki__datas_adjust_callback diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_append.h b/level_0/f_iki/tests/unit/c/test-iki-datas_append.h index 46a8512..6b6eb41 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_append.h +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_append.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: IKI * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.c b/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.c index 764be62..6f4bc1b 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.c +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.c @@ -12,7 +12,7 @@ void test__f_iki_datas_append_all__works(void **state) { f_iki_datas_t destination = f_iki_datas_t_initialize; { - f_status_t status = f_iki_datas_resize(2, &source); + f_status_t status = f_memory_array_resize(2, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.size, 2); @@ -126,7 +126,7 @@ void test__f_iki_datas_append_all__returns_data_not(void **state) { f_iki_datas_t destination = f_iki_datas_t_initialize; { - const f_status_t status = f_iki_datas_resize(length, &source); + const f_status_t status = f_memory_array_resize(length, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.h b/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.h index 42200a3..da422ee 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.h +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_append_all.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: IKI * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.c b/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.c deleted file mode 100644 index d0dbd0e..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_decimate_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_decimate_by__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datas_decimate_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_iki_datas_decimate_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_decimate_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.h b/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.h deleted file mode 100644 index a9875f5..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_decimate_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_decimate_by_h -#define _TEST__F_iki_datas_decimate_by_h - -/** - * Test that the function works. - * - * @see f_iki_datas_decimate_by() - */ -extern void test__f_iki_datas_decimate_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_decimate_by() - */ -extern void test__f_iki_datas_decimate_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_decimate_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.c b/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.c deleted file mode 100644 index 3bd1865..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_decrease_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_decrease_by__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datas_decrease_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_iki_datas_decrease_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_decrease_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.h b/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.h deleted file mode 100644 index d32f0f2..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_decrease_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_decrease_by_h -#define _TEST__F_iki_datas_decrease_by_h - -/** - * Test that the function works. - * - * @see f_iki_datas_decrease_by() - */ -extern void test__f_iki_datas_decrease_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_decrease_by() - */ -extern void test__f_iki_datas_decrease_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_decrease_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_increase.c b/level_0/f_iki/tests/unit/c/test-iki-datas_increase.c deleted file mode 100644 index 16fe997..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_increase.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_increase.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_increase__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_iki_datas_increase(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d); - } - - free((void *) data.array); -} - -void test__f_iki_datas_increase__returns_data_not(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datas_increase(length, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datas_increase__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_increase(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_increase.h b/level_0/f_iki/tests/unit/c/test-iki-datas_increase.h deleted file mode 100644 index 3c726cf..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_increase.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_increase_h -#define _TEST__F_iki_datas_increase_h - -/** - * Test that the function works. - * - * @see f_iki_datas_increase() - */ -extern void test__f_iki_datas_increase__works(void **state); - -/** - * Test that the function returns F_data_not when asked to copy an empty structure. - * - * @see f_iki_datas_increase() - */ -extern void test__f_iki_datas_increase__returns_data_not(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_increase() - */ -extern void test__f_iki_datas_increase__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_increase_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.c b/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.c deleted file mode 100644 index ba53394..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_increase_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_increase_by__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_iki_datas_increase_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_int_equal(data.size, length * 2); - } - - free((void *) data.array); -} - -void test__f_iki_datas_increase_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_increase_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.h b/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.h deleted file mode 100644 index e441469..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_increase_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_increase_by_h -#define _TEST__F_iki_datas_increase_by_h - -/** - * Test that the function works. - * - * @see f_iki_datas_increase_by() - */ -extern void test__f_iki_datas_increase_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_increase_by() - */ -extern void test__f_iki_datas_increase_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_increase_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_resize.c b/level_0/f_iki/tests/unit/c/test-iki-datas_resize.c deleted file mode 100644 index e647f00..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_resize.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datas_resize.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datas_resize__works(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datas_resize__parameter_checking(void **state) { - - const int length = 5; - f_iki_datas_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datas_resize(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_resize.h b/level_0/f_iki/tests/unit/c/test-iki-datas_resize.h deleted file mode 100644 index 125f31a..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datas_resize.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datas_resize_h -#define _TEST__F_iki_datas_resize_h - -/** - * Test that the function works. - * - * @see f_iki_datas_resize() - */ -extern void test__f_iki_datas_resize__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datas_resize() - */ -extern void test__f_iki_datas_resize__parameter_checking(void **state); - -#endif // _TEST__F_iki_datas_resize_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.c b/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.c new file mode 100644 index 0000000..5cf1459 --- /dev/null +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.c @@ -0,0 +1,103 @@ +#include "test-iki.h" +#include "test-iki-datas_resize_callback.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_iki_datas_resize_callback__fails(void **state) { + + mock_unwrap = 0; + + f_iki_data_t data = f_iki_data_t_initialize; + f_iki_data_t data_array[] = { data }; + f_iki_datas_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_iki_datas_t datass_array[] = { datas }; + + { + will_return(__wrap_f_string_ranges_resize, true); + will_return(__wrap_f_string_ranges_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_memory_array_resize, true); + will_return(__wrap_f_memory_array_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_memory_array_resize, false); + will_return(__wrap_f_memory_array_resize, F_none); + + will_return(__wrap_f_string_ranges_resize, true); + will_return(__wrap_f_string_ranges_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } + + { + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_memory_array_resize, false); + will_return(__wrap_f_memory_array_resize, F_none); + + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_string_ranges_resize, true); + will_return(__wrap_f_string_ranges_resize, F_status_set_error(F_failure)); + + const f_status_t status = f_iki_datas_resize_callback(0, 1, (void *) datass_array); + + assert_int_equal(status, F_status_set_error(F_failure)); + } +} + +void test__f_iki_datas_resize_callback__works(void **state) { + + mock_unwrap = 0; + + f_iki_data_t data = f_iki_data_t_initialize; + f_iki_data_t data_array[] = { data }; + f_iki_datas_t datas = { .array = data_array, .used = 1, .size = 1 }; + f_iki_datas_t datass_array[] = { datas }; + const f_number_unsigned_t length = 1; + + { + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_memory_array_resize, false); + will_return(__wrap_f_memory_array_resize, F_none); + + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + will_return(__wrap_f_string_ranges_resize, false); + will_return(__wrap_f_string_ranges_resize, F_none); + + const f_status_t status = f_iki_datas_resize_callback(0, length, (void *) datass_array); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.h b/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.h new file mode 100644 index 0000000..1d846bb --- /dev/null +++ b/level_0/f_iki/tests/unit/c/test-iki-datas_resize_callback.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: IKI + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_iki__datas_resize_callback +#define _TEST__F_iki__datas_resize_callback + +/** + * Test that the function fails. + * + * @see f_iki_datas_resize_callback() + */ +extern void test__f_iki_datas_resize_callback__fails(void **state); + +/** + * Test that the function works. + * + * @see f_iki_datas_resize_callback() + */ +extern void test__f_iki_datas_resize_callback__works(void **state); + +#endif // _TEST__F_iki__datas_resize_callback diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.c b/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.c deleted file mode 100644 index d6f562d..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_adjust.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_adjust__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datass_t_initialize; - - { - const f_status_t status = f_iki_datass_adjust(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datass_adjust__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datass_t_initialize; - - { - const f_status_t status = f_iki_datass_adjust(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.h b/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.h deleted file mode 100644 index 9bcb3e9..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_adjust.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_adjust_h -#define _TEST__F_iki_datass_adjust_h - -/** - * Test that the function works. - * - * @see f_iki_datass_adjust() - */ -extern void test__f_iki_datass_adjust__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_adjust() - */ -extern void test__f_iki_datass_adjust__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_adjust_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_append.c b/level_0/f_iki/tests/unit/c/test-iki-datass_append.c index 83def3e..66a20b3 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_append.c +++ b/level_0/f_iki/tests/unit/c/test-iki-datass_append.c @@ -13,7 +13,7 @@ void test__f_iki_datass_append__works(void **state) { f_iki_datass_t destination = f_iki_datass_t_initialize; { - f_status_t status = f_iki_datas_resize(length_outer, &source); + f_status_t status = f_memory_array_resize(length_outer, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.size, length_outer); @@ -131,7 +131,7 @@ void test__f_iki_datass_append__returns_data_not(void **state) { f_iki_datass_t destination = f_iki_datass_t_initialize; { - const f_status_t status = f_iki_datas_resize(length, &source); + f_status_t status = f_memory_array_resize(length, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_append.h b/level_0/f_iki/tests/unit/c/test-iki-datass_append.h index 8ba174b..fb5a644 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_append.h +++ b/level_0/f_iki/tests/unit/c/test-iki-datass_append.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: IKI * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.c b/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.c index 45f68aa..1dca0c5 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.c +++ b/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.c @@ -14,7 +14,7 @@ void test__f_iki_datass_append_all__works(void **state) { f_iki_datass_t destination = f_iki_datass_t_initialize; { - f_status_t status = f_iki_datass_resize(length_outer, &source); + f_status_t status = f_memory_arrays_resize(length_outer, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size, &f_iki_datas_resize_callback); assert_int_equal(status, F_none); assert_int_equal(source.size, length_outer); @@ -24,7 +24,7 @@ void test__f_iki_datass_append_all__works(void **state) { for (; source.used < length_outer; ++source.used) { - status = f_iki_datas_resize(length_inner, &source.array[source.used]); + status = f_memory_array_resize(length_inner, sizeof(f_iki_data_t), (void **) &source.array[source.used].array, &source.array[source.used].used, &source.array[source.used].size); assert_int_equal(status, F_none); assert_int_equal(source.array[source.used].size, length_inner); @@ -147,7 +147,7 @@ void test__f_iki_datass_append_all__returns_data_not(void **state) { f_iki_datass_t destination = f_iki_datass_t_initialize; { - const f_status_t status = f_iki_datass_resize(length, &source); + const f_status_t status = f_memory_arrays_resize(length, sizeof(f_iki_data_t), (void **) &source.array, &source.used, &source.size, &f_iki_datas_resize_callback); assert_int_equal(status, F_none); assert_int_equal(source.used, 0); diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.h b/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.h index 3692a75..680a418 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.h +++ b/level_0/f_iki/tests/unit/c/test-iki-datass_append_all.h @@ -1,7 +1,7 @@ /** * FLL - Level 0 * - * Project: Type + * Project: IKI * API Version: 0.7 * Licenses: lgpl-2.1-or-later * diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.c b/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.c deleted file mode 100644 index 8866b8a..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_decimate_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_decimate_by__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datass_decimate_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_iki_datass_decimate_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_decimate_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.h b/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.h deleted file mode 100644 index ce5155d..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_decimate_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_decimate_by_h -#define _TEST__F_iki_datass_decimate_by_h - -/** - * Test that the function works. - * - * @see f_iki_datass_decimate_by() - */ -extern void test__f_iki_datass_decimate_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_decimate_by() - */ -extern void test__f_iki_datass_decimate_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_decimate_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.c b/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.c deleted file mode 100644 index dea8c3f..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_decrease_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_decrease_by__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datass_decrease_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -void test__f_iki_datass_decrease_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_decrease_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.h b/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.h deleted file mode 100644 index 174ca8e..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_decrease_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_decrease_by_h -#define _TEST__F_iki_datass_decrease_by_h - -/** - * Test that the function works. - * - * @see f_iki_datass_decrease_by() - */ -extern void test__f_iki_datass_decrease_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_decrease_by() - */ -extern void test__f_iki_datass_decrease_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_decrease_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_increase.c b/level_0/f_iki/tests/unit/c/test-iki-datass_increase.c deleted file mode 100644 index a2e3912..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_increase.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_increase.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_increase__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_iki_datass_increase(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d); - } - - free((void *) data.array); -} - -void test__f_iki_datass_increase__returns_data_not(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - const f_status_t status = f_iki_datass_increase(length, &data); - - assert_int_equal(status, F_data_not); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datass_increase__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_increase(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - free((void *) data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_increase.h b/level_0/f_iki/tests/unit/c/test-iki-datass_increase.h deleted file mode 100644 index db08526..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_increase.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_increase_h -#define _TEST__F_iki_datass_increase_h - -/** - * Test that the function works. - * - * @see f_iki_datass_increase() - */ -extern void test__f_iki_datass_increase__works(void **state); - -/** - * Test that the function returns F_data_not when asked to copy an empty structure. - * - * @see f_iki_datass_increase() - */ -extern void test__f_iki_datass_increase__returns_data_not(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_increase() - */ -extern void test__f_iki_datass_increase__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_increase_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.c b/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.c deleted file mode 100644 index 24e07c4..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_increase_by.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_increase_by__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - { - data.used = length; - - const f_status_t status = f_iki_datass_increase_by(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, length); - assert_int_equal(data.size, length * 2); - } - - free((void *) data.array); -} - -void test__f_iki_datass_increase_by__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datas_t_initialize; - - { - const f_status_t status = f_iki_datass_increase_by(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.h b/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.h deleted file mode 100644 index c9c8909..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_increase_by.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_increase_by_h -#define _TEST__F_iki_datass_increase_by_h - -/** - * Test that the function works. - * - * @see f_iki_datass_increase_by() - */ -extern void test__f_iki_datass_increase_by__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_increase_by() - */ -extern void test__f_iki_datass_increase_by__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_increase_by_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_resize.c b/level_0/f_iki/tests/unit/c/test-iki-datass_resize.c deleted file mode 100644 index 852ef54..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_resize.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "test-iki.h" -#include "test-iki-datass_resize.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test__f_iki_datass_resize__works(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datass_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, &data); - - assert_int_equal(status, F_none); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, length); - } - - free((void *) data.array); -} - -void test__f_iki_datass_resize__parameter_checking(void **state) { - - const int length = 5; - f_iki_datass_t data = f_iki_datass_t_initialize; - - { - const f_status_t status = f_iki_datass_resize(length, 0); - - assert_int_equal(status, F_status_set_error(F_parameter)); - assert_int_equal(data.used, 0); - assert_int_equal(data.size, 0); - } - - assert_null(data.array); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_iki/tests/unit/c/test-iki-datass_resize.h b/level_0/f_iki/tests/unit/c/test-iki-datass_resize.h deleted file mode 100644 index 06610a5..0000000 --- a/level_0/f_iki/tests/unit/c/test-iki-datass_resize.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: Type - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Test the array types in the type project. - */ -#ifndef _TEST__F_iki_datass_resize_h -#define _TEST__F_iki_datass_resize_h - -/** - * Test that the function works. - * - * @see f_iki_datass_resize() - */ -extern void test__f_iki_datass_resize__works(void **state); - -/** - * Test that the function correctly fails on invalid parameter. - * - * @see f_iki_datass_resize() - */ -extern void test__f_iki_datass_resize__parameter_checking(void **state); - -#endif // _TEST__F_iki_datass_resize_h diff --git a/level_0/f_iki/tests/unit/c/test-iki-read.c b/level_0/f_iki/tests/unit/c/test-iki-read.c index 22d5d88..d1c686f 100644 --- a/level_0/f_iki/tests/unit/c/test-iki-read.c +++ b/level_0/f_iki/tests/unit/c/test-iki-read.c @@ -83,6 +83,8 @@ void test__f_iki_read__returns_data_not_stop(void **state) { void test__f_iki_read__works(void **state) { + mock_unwrap = 1; + f_state_t state_data = f_state_t_initialize; f_string_static_t empty = macro_f_string_static_t_initialize_1(f_string_empty_s.string, f_string_empty_s.size, f_string_empty_s.used); f_string_static_t ascii_a = macro_f_string_static_t_initialize_1(f_string_ascii_a_s.string, f_string_ascii_a_s.size, f_string_ascii_a_s.used); diff --git a/level_0/f_iki/tests/unit/c/test-iki.c b/level_0/f_iki/tests/unit/c/test-iki.c index 8e46be3..3c12026 100644 --- a/level_0/f_iki/tests/unit/c/test-iki.c +++ b/level_0/f_iki/tests/unit/c/test-iki.c @@ -29,28 +29,20 @@ int main(void) { cmocka_unit_test(test__f_iki_content_partial_is__returns_false), cmocka_unit_test(test__f_iki_content_partial_is__returns_true), - cmocka_unit_test(test__f_iki_datas_adjust__works), + cmocka_unit_test(test__f_iki_datas_adjust_callback__fails), + cmocka_unit_test(test__f_iki_datas_resize_callback__fails), + + cmocka_unit_test(test__f_iki_datas_adjust_callback__works), + cmocka_unit_test(test__f_iki_datas_resize_callback__works), + cmocka_unit_test(test__f_iki_datas_append__works), cmocka_unit_test(test__f_iki_datas_append_all__works), cmocka_unit_test(test__f_iki_datas_append_all__returns_data_not), - cmocka_unit_test(test__f_iki_datas_decimate_by__works), - cmocka_unit_test(test__f_iki_datas_decrease_by__works), - cmocka_unit_test(test__f_iki_datas_increase__works), - cmocka_unit_test(test__f_iki_datas_increase__returns_data_not), - cmocka_unit_test(test__f_iki_datas_increase_by__works), - cmocka_unit_test(test__f_iki_datas_resize__works), - - cmocka_unit_test(test__f_iki_datass_adjust__works), + cmocka_unit_test(test__f_iki_datass_append__works), cmocka_unit_test(test__f_iki_datass_append__returns_data_not), cmocka_unit_test(test__f_iki_datass_append_all__works), cmocka_unit_test(test__f_iki_datass_append_all__returns_data_not), - cmocka_unit_test(test__f_iki_datass_decimate_by__works), - cmocka_unit_test(test__f_iki_datass_decrease_by__works), - cmocka_unit_test(test__f_iki_datass_increase__works), - cmocka_unit_test(test__f_iki_datass_increase__returns_data_not), - cmocka_unit_test(test__f_iki_datass_increase_by__works), - cmocka_unit_test(test__f_iki_datass_resize__works), cmocka_unit_test(test__f_iki_object_is__returns_data_not), cmocka_unit_test(test__f_iki_object_is__returns_false), @@ -71,23 +63,14 @@ int main(void) { cmocka_unit_test(test__f_iki_content_is__parameter_checking), cmocka_unit_test(test__f_iki_content_partial_is__parameter_checking), - cmocka_unit_test(test__f_iki_datas_adjust__parameter_checking), + // f_iki_datas_adjust_callback() doesn't use parameter checking. + // f_iki_datas_resize_callback() doesn't use parameter checking. + cmocka_unit_test(test__f_iki_datas_append__parameter_checking), cmocka_unit_test(test__f_iki_datas_append_all__parameter_checking), - cmocka_unit_test(test__f_iki_datas_decimate_by__parameter_checking), - cmocka_unit_test(test__f_iki_datas_decrease_by__parameter_checking), - cmocka_unit_test(test__f_iki_datas_increase__parameter_checking), - cmocka_unit_test(test__f_iki_datas_increase_by__parameter_checking), - cmocka_unit_test(test__f_iki_datas_resize__parameter_checking), - cmocka_unit_test(test__f_iki_datass_adjust__parameter_checking), cmocka_unit_test(test__f_iki_datass_append__parameter_checking), cmocka_unit_test(test__f_iki_datass_append_all__parameter_checking), - cmocka_unit_test(test__f_iki_datass_decimate_by__parameter_checking), - cmocka_unit_test(test__f_iki_datass_decrease_by__parameter_checking), - cmocka_unit_test(test__f_iki_datass_increase__parameter_checking), - cmocka_unit_test(test__f_iki_datass_increase_by__parameter_checking), - cmocka_unit_test(test__f_iki_datass_resize__parameter_checking), // f_iki_object_is() doesn't use parameter checking. // f_iki_object_partial_is() doesn't use parameter checking. diff --git a/level_0/f_iki/tests/unit/c/test-iki.h b/level_0/f_iki/tests/unit/c/test-iki.h index b84b7ca..b1a7267 100644 --- a/level_0/f_iki/tests/unit/c/test-iki.h +++ b/level_0/f_iki/tests/unit/c/test-iki.h @@ -23,27 +23,17 @@ #include // Mock includes. -//#include "mock-iki.h" +#include "mock-iki.h" // Test includes. #include "test-iki-content_is.h" #include "test-iki-content_partial_is.h" -#include "test-iki-datas_adjust.h" +#include "test-iki-datas_adjust_callback.h" #include "test-iki-datas_append.h" #include "test-iki-datas_append_all.h" -#include "test-iki-datas_decimate_by.h" -#include "test-iki-datas_decrease_by.h" -#include "test-iki-datas_increase.h" -#include "test-iki-datas_increase_by.h" -#include "test-iki-datas_resize.h" -#include "test-iki-datass_adjust.h" +#include "test-iki-datas_resize_callback.h" #include "test-iki-datass_append.h" #include "test-iki-datass_append_all.h" -#include "test-iki-datass_decimate_by.h" -#include "test-iki-datass_decrease_by.h" -#include "test-iki-datass_increase.h" -#include "test-iki-datass_increase_by.h" -#include "test-iki-datass_resize.h" #include "test-iki-object_is.h" #include "test-iki-object_partial_is.h" #include "test-iki-read.h" diff --git a/level_3/controller/c/common/private-rule.c b/level_3/controller/c/common/private-rule.c index 6532bbb..83a9078 100644 --- a/level_3/controller/c/common/private-rule.c +++ b/level_3/controller/c/common/private-rule.c @@ -14,7 +14,7 @@ extern "C" { void controller_rule_action_delete_simple(controller_rule_action_t * const action) { f_string_dynamics_resize(0, &action->parameters); - f_iki_datas_resize(0, &action->ikis); + f_memory_array_resize(0, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); } #endif // _di_controller_rule_action_delete_simple_ diff --git a/level_3/controller/c/rule/private-rule.c b/level_3/controller/c/rule/private-rule.c index dd79b8a..7b74e51 100644 --- a/level_3/controller/c/rule/private-rule.c +++ b/level_3/controller/c/rule/private-rule.c @@ -82,14 +82,14 @@ extern "C" { } if (content) { - status = f_iki_datas_increase_by(content->used + 1, &action->ikis); + status = f_memory_array_increase_by(content->used + 1, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); } else { - status = f_iki_datas_increase(controller_common_allocation_small_d, &action->ikis); + status = f_memory_array_increase(controller_common_allocation_small_d, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); } if (F_status_is_error(status)) { - controller_print_error(global.thread, global.main->error, F_status_set_fine(status), content ? "f_iki_datas_increase_by" : "f_iki_datas_increase", F_true); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), content ? "f_memory_array_increase_by" : "f_memory_array_increase", F_true); return status; } @@ -121,10 +121,10 @@ extern "C" { return status; } - status = f_iki_datas_increase_by(content->used, &action->ikis); + status = f_memory_array_increase_by(content->used, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); if (F_status_is_error(status)) { - controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_iki_datas_increase_by", F_true); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_memory_array_increase_by", F_true); return status; } @@ -276,10 +276,10 @@ extern "C" { return status; } - status = f_iki_datas_increase(controller_common_allocation_small_d, &actions->array[actions->used].ikis); + status = f_memory_array_increase(controller_common_allocation_small_d, sizeof(f_iki_data_t), (void **) &actions->array[actions->used].ikis.array, &actions->array[actions->used].ikis.used, &actions->array[actions->used].ikis.size); if (F_status_is_error(status)) { - controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_iki_datas_increase", F_true); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_memory_array_increase", F_true); return status; } @@ -576,10 +576,10 @@ extern "C" { return status; } - status = f_iki_datas_increase(controller_common_allocation_small_d, &actions->array[actions->used].ikis); + status = f_memory_array_increase(controller_common_allocation_small_d, sizeof(f_iki_data_t), (void **) &actions->array[actions->used].ikis.array, &actions->array[actions->used].ikis.used, &actions->array[actions->used].ikis.size); if (F_status_is_error(status)) { - controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_iki_datas_increase", F_true); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_memory_array_increase", F_true); return status; } diff --git a/level_3/controller/c/rule/private-rule.h b/level_3/controller/c/rule/private-rule.h index eba8634..8e6b7e0 100644 --- a/level_3/controller/c/rule/private-rule.h +++ b/level_3/controller/c/rule/private-rule.h @@ -87,14 +87,16 @@ extern "C" { * F_none on success. * * Errors (with error bit) from: f_fss_count_lines(). - * Errors (with error bit) from: f_iki_datas_increase_by(). + * Errors (with error bit) from: f_memory_array_increase(). + * Errors (with error bit) from: f_memory_array_increase_by(). * Errors (with error bit) from: f_string_dynamic_partial_append_nulless(). * Errors (with error bit) from: f_string_dynamics_increase(). * Errors (with error bit) from: f_string_dynamics_increase_by(). * Errors (with error bit) from: fl_iki_read(). * * @see f_fss_count_lines() - * @see f_iki_datas_increase_by() + * @see f_memory_array_increase() + * @see f_memory_array_increase_by() * @see f_string_dynamic_partial_append_nulless() * @see f_string_dynamics_increase() * @see f_string_dynamics_increase_by() -- 1.8.3.1