From: Kevin Day Date: Tue, 27 Jun 2023 02:41:15 +0000 (-0500) Subject: Update: Add unit tests for f_files_t and f_filess_t. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=81c6c306910ea4e47c9e08addffc2d1cd8e7bb97;p=fll Update: Add unit tests for f_files_t and f_filess_t. I forgot to add the unit tests with the commit fc1d33e993e99e8ff34d82be7fabadf7608d9c6d. This also addresses a define name design problem where I have two cases that _F_type_array_file_h would be defined. For now, just rename the _F_type_array_file_h to _F_type_array__file_h for the top-level file. --- diff --git a/level_0/f_type_array/c/type_array_file.h b/level_0/f_type_array/c/type_array_file.h index c7829b8..df38550 100644 --- a/level_0/f_type_array/c/type_array_file.h +++ b/level_0/f_type_array/c/type_array_file.h @@ -4,14 +4,9 @@ * Project: Type * API Version: 0.7 * Licenses: lgpl-2.1-or-later - * - * Provides an extension to the Type project (f_type) that depends on f_memory (linking to the f_memory library). - * - * As an exceptional case, this is an extension to f_type to avoid circular dependency issues with f_memory. - * The functions and macros in this project therefore are prefixed with 'f_type_' instead of 'f_type_array_'. */ -#ifndef _F_type_array_file_h -#define _F_type_array_file_h +#ifndef _F_type_array__file_h +#define _F_type_array__file_h // FLL-0 includes. #include @@ -30,4 +25,4 @@ extern "C" { } // extern "C" #endif -#endif // _F_type_array_file_h +#endif // _F_type_array__file_h diff --git a/level_0/f_type_array/data/build/settings-mocks b/level_0/f_type_array/data/build/settings-mocks index 1f0f920..be983b8 100644 --- a/level_0/f_type_array/data/build/settings-mocks +++ b/level_0/f_type_array/data/build/settings-mocks @@ -30,11 +30,11 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -build_sources_library type_array/cell.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c -build_sources_library type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c +build_sources_library type_array/cell.c type_array/file.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c +build_sources_library type_array/private-cell.c type_array/private-file.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c build_sources_library ../../tests/unit/c/mock-type_array.c -build_sources_headers type_array.h type_array_file.h type_array/common.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h +build_sources_headers type_array.h type_array_file.h type_array/common.h type_array/cell.h type_array/file.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h build_script yes build_shared yes diff --git a/level_0/f_type_array/data/build/settings-tests b/level_0/f_type_array/data/build/settings-tests index 32bf164..bb0f84e 100644 --- a/level_0/f_type_array/data/build/settings-tests +++ b/level_0/f_type_array/data/build/settings-tests @@ -23,6 +23,8 @@ build_language c build_libraries -lc -lcmocka build_libraries-individual -lf_memory -lf_type_array +build_sources_program test-type_array-files_adjust.c test-type_array-files_append.c test-type_array-files_append_all.c test-type_array-files_decimate_by.c test-type_array-files_decrease_by.c test-type_array-files_increase.c test-type_array-files_increase_by.c test-type_array-files_resize.c +build_sources_program test-type_array-filess_adjust.c test-type_array-filess_append.c test-type_array-filess_append_all.c test-type_array-filess_decimate_by.c test-type_array-filess_decrease_by.c test-type_array-filess_increase.c test-type_array-filess_increase_by.c test-type_array-filess_resize.c build_sources_program test-type_array-fll_ids_adjust.c test-type_array-fll_ids_append.c test-type_array-fll_ids_append_all.c test-type_array-fll_ids_decimate_by.c test-type_array-fll_ids_decrease_by.c test-type_array-fll_ids_increase.c test-type_array-fll_ids_increase_by.c test-type_array-fll_ids_resize.c build_sources_program test-type_array-fll_idss_adjust.c test-type_array-fll_idss_append.c test-type_array-fll_idss_append_all.c test-type_array-fll_idss_decimate_by.c test-type_array-fll_idss_decrease_by.c test-type_array-fll_idss_increase.c test-type_array-fll_idss_increase_by.c test-type_array-fll_idss_resize.c build_sources_program test-type_array-cells_adjust.c test-type_array-cells_append.c test-type_array-cells_append_all.c test-type_array-cells_decimate_by.c test-type_array-cells_decrease_by.c test-type_array-cells_increase.c test-type_array-cells_increase_by.c test-type_array-cells_resize.c diff --git a/level_0/f_type_array/tests/unit/c/mock-type_array.h b/level_0/f_type_array/tests/unit/c/mock-type_array.h index 534130c..061feda 100644 --- a/level_0/f_type_array/tests/unit/c/mock-type_array.h +++ b/level_0/f_type_array/tests/unit/c/mock-type_array.h @@ -22,6 +22,7 @@ // FLL-0 includes. #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_adjust.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_adjust.c new file mode 100644 index 0000000..2898b85 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_adjust.c @@ -0,0 +1,42 @@ +#include "test-type_array.h" +#include "test-type_array-files_adjust.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_adjust__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_adjust__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array/tests/unit/c/test-type_array-files_adjust.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_adjust.h new file mode 100644 index 0000000..29d4b64 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_adjust.h @@ -0,0 +1,27 @@ +/** + * 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_type_array__files_adjust +#define _TEST__F_type_array__files_adjust + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_adjust() + */ +extern void test__f_type_array_files_adjust__parameter_checking(void **state); + +/** + * Test that the function works. + * + * @see f_files_adjust() + */ +extern void test__f_type_array_files_adjust__works(void **state); + +#endif // _TEST__F_type_array__files_adjust diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_append.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_append.c new file mode 100644 index 0000000..60e088c --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_append.c @@ -0,0 +1,37 @@ +#include "test-type_array.h" +#include "test-type_array-files_append.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_append__parameter_checking(void **state) { + + const f_file_t data = f_file_t_initialize; + + { + const f_status_t status = f_files_append(data, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_type_array_files_append__works(void **state) { + + const f_file_t source = macro_f_file_t_initialize_id(3); + f_files_t destination = f_files_t_initialize; + + { + const f_status_t status = f_files_append(source, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, 1); + assert_int_equal(destination.array[0].id, source.id); + } + + free((void *) destination.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_append.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_append.h new file mode 100644 index 0000000..7df88b9 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_append.h @@ -0,0 +1,27 @@ +/** + * 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_type_array__files_append +#define _TEST__F_type_array__files_append + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_append() + */ +extern void test__f_type_array_files_append__parameter_checking(void **state); + +/** + * Test that the function works. + * + * @see f_files_append() + */ +extern void test__f_type_array_files_append__works(void **state); + +#endif // _TEST__F_type_array__files_append diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.c new file mode 100644 index 0000000..24a87b1 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.c @@ -0,0 +1,82 @@ +#include "test-type_array.h" +#include "test-type_array-files_append_all.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_append_all__parameter_checking(void **state) { + + const f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_append_all(data, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_type_array_files_append_all__returns_data_not(void **state) { + + const int length = 5; + f_files_t source = f_files_t_initialize; + f_files_t destination = f_files_t_initialize; + + { + const f_status_t status = f_files_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + { + const f_status_t status = f_files_append_all(source, &destination); + + assert_int_equal(status, F_data_not); + assert_int_equal(destination.used, 0); + assert_int_equal(destination.size, 0); + assert_null(destination.array); + } + + free((void *) source.array); +} + +void test__f_type_array_files_append_all__works(void **state) { + + const int length = 5; + const int length_used = 2; + f_files_t source = f_files_t_initialize; + f_files_t destination = f_files_t_initialize; + + { + const f_status_t status = f_files_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + for (; source.used < length_used; ++source.used) { + source.array[source.used].id = source.used + 1; + } // for + + { + const f_status_t status = f_files_append_all(source, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, source.used); + assert_int_equal(destination.size, source.used); + + for (f_number_unsigned_t i = 0; i < source.used; ++i) { + assert_int_equal(destination.array[i].id, i + 1); + } // for + } + + free((void *) source.array); + free((void *) destination.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.h new file mode 100644 index 0000000..fa8e3e2 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_append_all.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__files_append_all +#define _TEST__F_type_array__files_append_all + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_append_all() + */ +extern void test__f_type_array_files_append_all__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_files_append_all() + */ +extern void test__f_type_array_files_append_all__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_files_append_all() + */ +extern void test__f_type_array_files_append_all__works(void **state); + +#endif // _TEST__F_type_array__files_append_all diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_decimate_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_decimate_by.c new file mode 100644 index 0000000..52b8819 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_decimate_by.c @@ -0,0 +1,74 @@ +#include "test-type_array.h" +#include "test-type_array-files_decimate_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_decimate_by__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_decimate_by__returns_data_not(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array_files_decimate_by__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array/tests/unit/c/test-type_array-files_decimate_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_decimate_by.h new file mode 100644 index 0000000..82bee2a --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_decimate_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__files_decimate_by +#define _TEST__F_type_array__files_decimate_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_decimate_by() + */ +extern void test__f_type_array_files_decimate_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_files_decimate_by() + */ +extern void test__f_type_array_files_decimate_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_files_decimate_by() + */ +extern void test__f_type_array_files_decimate_by__works(void **state); + +#endif // _TEST__F_type_array__files_decimate_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_decrease_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_decrease_by.c new file mode 100644 index 0000000..7ecbe8b --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_decrease_by.c @@ -0,0 +1,74 @@ +#include "test-type_array.h" +#include "test-type_array-files_decrease_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_decrease_by__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_decrease_by__returns_data_not(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array_files_decrease_by__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array/tests/unit/c/test-type_array-files_decrease_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_decrease_by.h new file mode 100644 index 0000000..7fe8db3 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_decrease_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__files_decrease_by +#define _TEST__F_type_array__files_decrease_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_decrease_by() + */ +extern void test__f_type_array_files_decrease_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_files_decrease_by() + */ +extern void test__f_type_array_files_decrease_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_files_decrease_by() + */ +extern void test__f_type_array_files_decrease_by__works(void **state); + +#endif // _TEST__F_type_array__files_decrease_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_increase.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase.c new file mode 100644 index 0000000..8801f67 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase.c @@ -0,0 +1,76 @@ +#include "test-type_array.h" +#include "test-type_array-files_increase.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_increase__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_increase__returns_data_not(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array_files_increase__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array/tests/unit/c/test-type_array-files_increase.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase.h new file mode 100644 index 0000000..7c3adca --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__files_increase +#define _TEST__F_type_array__files_increase + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_increase() + */ +extern void test__f_type_array_files_increase__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_files_increase() + */ +extern void test__f_type_array_files_increase__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_files_increase() + */ +extern void test__f_type_array_files_increase__works(void **state); + +#endif // _TEST__F_type_array__files_increase diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_increase_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase_by.c new file mode 100644 index 0000000..8efbf25 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase_by.c @@ -0,0 +1,76 @@ +#include "test-type_array.h" +#include "test-type_array-files_increase_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_increase_by__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_increase_by__returns_data_not(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array_files_increase_by__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_files_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_type_array/tests/unit/c/test-type_array-files_increase_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase_by.h new file mode 100644 index 0000000..e7a6dbc --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_increase_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__files_increase_by +#define _TEST__F_type_array__files_increase_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_increase_by() + */ +extern void test__f_type_array_files_increase_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_files_increase_by() + */ +extern void test__f_type_array_files_increase_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_files_increase_by() + */ +extern void test__f_type_array_files_increase_by__works(void **state); + +#endif // _TEST__F_type_array__files_increase_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-files_resize.c b/level_0/f_type_array/tests/unit/c/test-type_array-files_resize.c new file mode 100644 index 0000000..8777148 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_resize.c @@ -0,0 +1,42 @@ +#include "test-type_array.h" +#include "test-type_array-files_resize.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_files_resize__parameter_checking(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array_files_resize__works(void **state) { + + const int length = 5; + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_files_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_type_array/tests/unit/c/test-type_array-files_resize.h b/level_0/f_type_array/tests/unit/c/test-type_array-files_resize.h new file mode 100644 index 0000000..f62e6e1 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-files_resize.h @@ -0,0 +1,27 @@ +/** + * 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_type_array__files_resize +#define _TEST__F_type_array__files_resize + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_files_resize() + */ +extern void test__f_type_array_files_resize__parameter_checking(void **state); + +/** + * Test that the function works. + * + * @see f_files_resize() + */ +extern void test__f_type_array_files_resize__works(void **state); + +#endif // _TEST__F_type_array__files_resize diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_adjust.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_adjust.c new file mode 100644 index 0000000..ea5b088 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_adjust.c @@ -0,0 +1,42 @@ +#include "test-type_array.h" +#include "test-type_array-filess_adjust.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_adjust__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_adjust__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array/tests/unit/c/test-type_array-filess_adjust.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_adjust.h new file mode 100644 index 0000000..e281823 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_adjust.h @@ -0,0 +1,27 @@ +/** + * 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_type_array__filess_adjust +#define _TEST__F_type_array__filess_adjust + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_adjust() + */ +extern void test__f_type_array_filess_adjust__parameter_checking(void **state); + +/** + * Test that the function works. + * + * @see f_filess_adjust() + */ +extern void test__f_type_array_filess_adjust__works(void **state); + +#endif // _TEST__F_type_array__filess_adjust diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.c new file mode 100644 index 0000000..09b483d --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.c @@ -0,0 +1,86 @@ +#include "test-type_array.h" +#include "test-type_array-filess_append.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_append__parameter_checking(void **state) { + + f_files_t data = f_files_t_initialize; + + { + const f_status_t status = f_filess_append(data, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_type_array_filess_append__returns_data_not(void **state) { + + const int length = 5; + f_files_t source = f_files_t_initialize; + f_filess_t destination = f_filess_t_initialize; + + { + const f_status_t status = f_files_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + { + const f_status_t status = f_filess_append(source, &destination); + + assert_int_equal(status, F_data_not); + assert_int_equal(destination.used, 0); + assert_int_equal(destination.size, 0); + assert_null(destination.array); + } + + free((void *) source.array); +} + +void test__f_type_array_filess_append__works(void **state) { + + const int length = 5; + f_files_t source = f_files_t_initialize; + f_filess_t destination = f_filess_t_initialize; + + { + const f_status_t status = f_files_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + for (; source.used < length; ++source.used) { + source.array[source.used].id = source.used + 1; + } // for + + { + const f_status_t status = f_filess_append(source, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, 1); + assert_int_equal(destination.array[0].used, source.used); + assert_int_equal(destination.array[0].size, source.used); + + for (f_number_unsigned_t i = 0; i < destination.array[0].used; ++i) { + assert_int_equal(destination.array[0].array[i].id, i + 1); + } // for + } + + for (f_number_unsigned_t i = 0; i < destination.used; ++i) { + free((void *) destination.array[i].array); + } // for + + free((void *) source.array); + free((void *) destination.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.h new file mode 100644 index 0000000..45b7e7c --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_append +#define _TEST__F_type_array__filess_append + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_append() + */ +extern void test__f_type_array_filess_append__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_filess_append() + */ +extern void test__f_type_array_filess_append__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_append() + */ +extern void test__f_type_array_filess_append__works(void **state); + +#endif // _TEST__F_type_array__filess_append diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.c new file mode 100644 index 0000000..13a23b6 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.c @@ -0,0 +1,105 @@ +#include "test-type_array.h" +#include "test-type_array-filess_append_all.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_append_all__parameter_checking(void **state) { + + const f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_append_all(data, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_type_array_filess_append_all__returns_data_not(void **state) { + + const int length = 5; + f_filess_t source = f_filess_t_initialize; + f_filess_t destination = f_filess_t_initialize; + + { + const f_status_t status = f_filess_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + { + const f_status_t status = f_filess_append_all(source, &destination); + + assert_int_equal(status, F_data_not); + assert_int_equal(destination.used, 0); + assert_int_equal(destination.size, 0); + assert_null(destination.array); + } + + free((void *) source.array); +} + +void test__f_type_array_filess_append_all__works(void **state) { + + const int length = 5; + const int length_inner = 2; + f_filess_t source = f_filess_t_initialize; + f_filess_t destination = f_filess_t_initialize; + + { + const f_status_t status = f_filess_resize(length, &source); + + assert_int_equal(status, F_none); + assert_int_equal(source.used, 0); + assert_int_equal(source.size, length); + } + + { + for (; source.used < length; ++source.used) { + + const f_status_t status = f_files_resize(length_inner, &source.array[source.used]); + + assert_int_equal(status, F_none); + + for (f_number_unsigned_t i = 0; i < length_inner; ++i) { + source.array[source.used].array[source.array[source.used].used++].id = i + 1; + } // for + } // for + } + + { + const f_status_t status = f_filess_append_all(source, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, source.used); + assert_int_equal(destination.size, source.used); + + for (f_number_unsigned_t i = 0; i < destination.used; ++i) { + + assert_int_equal(destination.array[i].used, length_inner); + assert_int_equal(destination.array[i].size, length_inner); + + for (f_number_unsigned_t j = 0; j < length_inner; ++j) { + assert_int_equal(destination.array[i].array[j].id, j + 1); + } // for + } // for + } + + for (f_number_unsigned_t i = 0; i < source.used; ++i) { + free((void *) source.array[i].array); + } // for + + for (f_number_unsigned_t i = 0; i < destination.used; ++i) { + free((void *) destination.array[i].array); + } // for + + free((void *) source.array); + free((void *) destination.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.h new file mode 100644 index 0000000..c4a9815 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_append_all.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_append_all +#define _TEST__F_type_array__filess_append_all + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_append_all() + */ +extern void test__f_type_array_filess_append_all__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_filess_append_all() + */ +extern void test__f_type_array_filess_append_all__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_append_all() + */ +extern void test__f_type_array_filess_append_all__works(void **state); + +#endif // _TEST__F_type_array__filess_append_all diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_decimate_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decimate_by.c new file mode 100644 index 0000000..b980a1a --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decimate_by.c @@ -0,0 +1,74 @@ +#include "test-type_array.h" +#include "test-type_array-filess_decimate_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_decimate_by__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_decimate_by__returns_data_not(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array_filess_decimate_by__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array/tests/unit/c/test-type_array-filess_decimate_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decimate_by.h new file mode 100644 index 0000000..e2ff0f0 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decimate_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_decimate_by +#define _TEST__F_type_array__filess_decimate_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_decimate_by() + */ +extern void test__f_type_array_filess_decimate_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_type_array_filess_decimate_by() + */ +extern void test__f_type_array_filess_decimate_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_decimate_by() + */ +extern void test__f_type_array_filess_decimate_by__works(void **state); + +#endif // _TEST__F_type_array__filess_decimate_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_decrease_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decrease_by.c new file mode 100644 index 0000000..a656bd6 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decrease_by.c @@ -0,0 +1,74 @@ +#include "test-type_array.h" +#include "test-type_array-filess_decrease_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_decrease_by__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_decrease_by__returns_data_not(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array_filess_decrease_by__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array/tests/unit/c/test-type_array-filess_decrease_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decrease_by.h new file mode 100644 index 0000000..816a091 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_decrease_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_decrease_by +#define _TEST__F_type_array__filess_decrease_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_decrease_by() + */ +extern void test__f_type_array_filess_decrease_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_filess_decrease_by() + */ +extern void test__f_type_array_filess_decrease_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_decrease_by() + */ +extern void test__f_type_array_filess_decrease_by__works(void **state); + +#endif // _TEST__F_type_array__filess_decrease_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase.c new file mode 100644 index 0000000..5a12a45 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase.c @@ -0,0 +1,76 @@ +#include "test-type_array.h" +#include "test-type_array-filess_increase.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_increase__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_files_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_increase__returns_data_not(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array_filess_increase__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array/tests/unit/c/test-type_array-filess_increase.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase.h new file mode 100644 index 0000000..0901222 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_increase +#define _TEST__F_type_array__filess_increase + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_increase() + */ +extern void test__f_type_array_filess_increase__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_filess_increase() + */ +extern void test__f_type_array_filess_increase__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_increase() + */ +extern void test__f_type_array_filess_increase__works(void **state); + +#endif // _TEST__F_type_array__filess_increase diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase_by.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase_by.c new file mode 100644 index 0000000..65b56e5 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase_by.c @@ -0,0 +1,84 @@ +#include "test-type_array.h" +#include "test-type_array-filess_increase_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_increase_by__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_increase_by__returns_data_not(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_filess_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_type_array_filess_increase_by__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_filess_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_type_array/tests/unit/c/test-type_array-filess_increase_by.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase_by.h new file mode 100644 index 0000000..e549585 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_increase_by.h @@ -0,0 +1,34 @@ +/** + * 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_type_array__filess_increase_by +#define _TEST__F_type_array__filess_increase_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_increase_by() + */ +extern void test__f_type_array_filess_increase_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_filess_increase_by() + */ +extern void test__f_type_array_filess_increase_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_filess_increase_by() + */ +extern void test__f_type_array_filess_increase_by__works(void **state); + +#endif // _TEST__F_type_array__filess_increase_by diff --git a/level_0/f_type_array/tests/unit/c/test-type_array-filess_resize.c b/level_0/f_type_array/tests/unit/c/test-type_array-filess_resize.c new file mode 100644 index 0000000..2323ae6 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_resize.c @@ -0,0 +1,42 @@ +#include "test-type_array.h" +#include "test-type_array-filess_resize.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_type_array_filess_resize__parameter_checking(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array_filess_resize__works(void **state) { + + const int length = 5; + f_filess_t data = f_filess_t_initialize; + + { + const f_status_t status = f_filess_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_type_array/tests/unit/c/test-type_array-filess_resize.h b/level_0/f_type_array/tests/unit/c/test-type_array-filess_resize.h new file mode 100644 index 0000000..e2e0472 --- /dev/null +++ b/level_0/f_type_array/tests/unit/c/test-type_array-filess_resize.h @@ -0,0 +1,27 @@ +/** + * 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_type_array__filess_resize +#define _TEST__F_type_array__filess_resize + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_filess_resize() + */ +extern void test__f_type_array_filess_resize__parameter_checking(void **state); + +/** + * Test that the function works. + * + * @see f_filess_resize() + */ +extern void test__f_type_array_filess_resize__works(void **state); + +#endif // _TEST__F_type_array__filess_resize diff --git a/level_0/f_type_array/tests/unit/c/test-type_array.c b/level_0/f_type_array/tests/unit/c/test-type_array.c index 85f92ea..d87b729 100644 --- a/level_0/f_type_array/tests/unit/c/test-type_array.c +++ b/level_0/f_type_array/tests/unit/c/test-type_array.c @@ -48,6 +48,37 @@ int main(void) { cmocka_unit_test(test__f_type_array_cellss_increase_by__works), cmocka_unit_test(test__f_type_array_cellss_resize__works), + cmocka_unit_test(test__f_type_array_files_append_all__returns_data_not), + cmocka_unit_test(test__f_type_array_files_decimate_by__returns_data_not), + cmocka_unit_test(test__f_type_array_files_decrease_by__returns_data_not), + cmocka_unit_test(test__f_type_array_files_increase__returns_data_not), + cmocka_unit_test(test__f_type_array_files_increase_by__returns_data_not), + + cmocka_unit_test(test__f_type_array_files_adjust__works), + cmocka_unit_test(test__f_type_array_files_append__works), + cmocka_unit_test(test__f_type_array_files_append_all__works), + cmocka_unit_test(test__f_type_array_files_decimate_by__works), + cmocka_unit_test(test__f_type_array_files_decrease_by__works), + cmocka_unit_test(test__f_type_array_files_increase__works), + cmocka_unit_test(test__f_type_array_files_increase_by__works), + cmocka_unit_test(test__f_type_array_files_resize__works), + + cmocka_unit_test(test__f_type_array_filess_append__returns_data_not), + cmocka_unit_test(test__f_type_array_filess_append_all__returns_data_not), + cmocka_unit_test(test__f_type_array_filess_decimate_by__returns_data_not), + cmocka_unit_test(test__f_type_array_filess_decrease_by__returns_data_not), + cmocka_unit_test(test__f_type_array_filess_increase__returns_data_not), + cmocka_unit_test(test__f_type_array_filess_increase_by__returns_data_not), + + cmocka_unit_test(test__f_type_array_filess_adjust__works), + cmocka_unit_test(test__f_type_array_filess_append__works), + cmocka_unit_test(test__f_type_array_filess_append_all__works), + cmocka_unit_test(test__f_type_array_filess_decimate_by__works), + cmocka_unit_test(test__f_type_array_filess_decrease_by__works), + cmocka_unit_test(test__f_type_array_filess_increase__works), + cmocka_unit_test(test__f_type_array_filess_increase_by__works), + cmocka_unit_test(test__f_type_array_filess_resize__works), + cmocka_unit_test(test__f_type_array_fll_ids_append_all__returns_data_not), cmocka_unit_test(test__f_type_array_fll_ids_decimate_by__returns_data_not), cmocka_unit_test(test__f_type_array_fll_ids_decrease_by__returns_data_not), @@ -549,6 +580,24 @@ int main(void) { cmocka_unit_test(test__f_type_array_cellss_increase_by__parameter_checking), cmocka_unit_test(test__f_type_array_cellss_resize__parameter_checking), + cmocka_unit_test(test__f_type_array_files_adjust__parameter_checking), + cmocka_unit_test(test__f_type_array_files_append__parameter_checking), + cmocka_unit_test(test__f_type_array_files_append_all__parameter_checking), + cmocka_unit_test(test__f_type_array_files_decimate_by__parameter_checking), + cmocka_unit_test(test__f_type_array_files_decrease_by__parameter_checking), + cmocka_unit_test(test__f_type_array_files_increase__parameter_checking), + cmocka_unit_test(test__f_type_array_files_increase_by__parameter_checking), + cmocka_unit_test(test__f_type_array_files_resize__parameter_checking), + + cmocka_unit_test(test__f_type_array_filess_adjust__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_append__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_append_all__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_decimate_by__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_decrease_by__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_increase__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_increase_by__parameter_checking), + cmocka_unit_test(test__f_type_array_filess_resize__parameter_checking), + cmocka_unit_test(test__f_type_array_fll_ids_adjust__parameter_checking), cmocka_unit_test(test__f_type_array_fll_ids_append__parameter_checking), cmocka_unit_test(test__f_type_array_fll_ids_append_all__parameter_checking), diff --git a/level_0/f_type_array/tests/unit/c/test-type_array.h b/level_0/f_type_array/tests/unit/c/test-type_array.h index e7f228a..2018c6c 100644 --- a/level_0/f_type_array/tests/unit/c/test-type_array.h +++ b/level_0/f_type_array/tests/unit/c/test-type_array.h @@ -43,6 +43,22 @@ #include "test-type_array-cellss_increase.h" #include "test-type_array-cellss_increase_by.h" #include "test-type_array-cellss_resize.h" +#include "test-type_array-files_adjust.h" +#include "test-type_array-files_append.h" +#include "test-type_array-files_append_all.h" +#include "test-type_array-files_decimate_by.h" +#include "test-type_array-files_decrease_by.h" +#include "test-type_array-files_increase.h" +#include "test-type_array-files_increase_by.h" +#include "test-type_array-files_resize.h" +#include "test-type_array-filess_adjust.h" +#include "test-type_array-filess_append.h" +#include "test-type_array-filess_append_all.h" +#include "test-type_array-filess_decimate_by.h" +#include "test-type_array-filess_decrease_by.h" +#include "test-type_array-filess_increase.h" +#include "test-type_array-filess_increase_by.h" +#include "test-type_array-filess_resize.h" #include "test-type_array-fll_ids_adjust.h" #include "test-type_array-fll_ids_append.h" #include "test-type_array-fll_ids_append_all.h"