From: Kevin Day Date: Sun, 27 Mar 2022 22:29:33 +0000 (-0500) Subject: Update: Add remaining tests for f_string project. X-Git-Tag: 0.5.9~57 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=bd4c3a69ccb727ad61bca93ee212428478d41816;p=fll Update: Add remaining tests for f_string project. --- diff --git a/level_0/f_string/data/build/settings-tests b/level_0/f_string/data/build/settings-tests index 5187f8d..937b288 100644 --- a/level_0/f_string/data/build/settings-tests +++ b/level_0/f_string/data/build/settings-tests @@ -21,11 +21,18 @@ build_libraries-individual -lf_memory -lf_string build_libraries-level -lfll_0 build_libraries-monolithic -lfll build_sources_program test-string-append.c test-string-append_assure.c test-string-append_assure_nulless.c test-string-append_nulless.c -build_sources_program test-string-dynamic_append.c test-string-dynamic_append_assure.c test-string-dynamic_append_assure_nulless.c test-string-dynamic_append_nulless.c +build_sources_program test-string-dynamic_adjust.c test-string-dynamic_append.c test-string-dynamic_append_assure.c test-string-dynamic_append_assure_nulless.c test-string-dynamic_append_nulless.c +build_sources_program test-string-dynamic_decimate_by.c test-string-dynamic_decrease_by.c test-string-dynamic_increase.c test-string-dynamic_increase_by.c build_sources_program test-string-dynamic_mash.c test-string-dynamic_mash_nulless.c build_sources_program test-string-dynamic_mish.c test-string-dynamic_mish_nulless.c +build_sources_program test-string-dynamic_partial_append.c test-string-dynamic_partial_append_assure.c test-string-dynamic_partial_append_assure_nulless.c test-string-dynamic_partial_append_nulless.c +build_sources_program test-string-dynamic_partial_mash.c test-string-dynamic_partial_mash_nulless.c +build_sources_program test-string-dynamic_partial_mish.c test-string-dynamic_partial_mish_nulless.c +build_sources_program test-string-dynamic_partial_prepend.c test-string-dynamic_partial_prepend_assure.c test-string-dynamic_partial_prepend_assure_nulless.c test-string-dynamic_partial_prepend_nulless.c build_sources_program test-string-dynamic_prepend.c test-string-dynamic_prepend_assure.c test-string-dynamic_prepend_assure_nulless.c test-string-dynamic_prepend_nulless.c +build_sources_program test-string-dynamic_resize.c build_sources_program test-string-dynamic_seek_line.c test-string-dynamic_seek_line_to.c test-string-dynamic_seek_to.c +build_sources_program test-string-dynamic_terminate.c test-string-dynamic_terminate_after.c build_sources_program test-string-dynamics_adjust.c test-string-dynamics_append.c test-string-dynamics_append_all.c test-string-dynamics_decimate_by.c test-string-dynamics_decrease_by.c test-string-dynamics_increase.c test-string-dynamics_increase_by.c test-string-dynamics_resize.c test-string-dynamicss_adjust.c test-string-dynamicss_append.c test-string-dynamicss_append_all.c test-string-dynamicss_decimate_by.c test-string-dynamicss_decrease_by.c test-string-dynamicss_increase.c test-string-dynamicss_increase_by.c test-string-dynamicss_resize.c build_sources_program test-string-map_multis_adjust.c test-string-map_multis_append.c test-string-map_multis_append_all.c test-string-map_multis_decimate_by.c test-string-map_multis_decrease_by.c test-string-map_multis_increase.c test-string-map_multis_increase_by.c test-string-map_multis_resize.c test-string-map_multiss_adjust.c test-string-map_multiss_append.c test-string-map_multiss_append_all.c test-string-map_multiss_decimate_by.c test-string-map_multiss_decrease_by.c test-string-map_multiss_increase.c test-string-map_multiss_increase_by.c test-string-map_multiss_resize.c build_sources_program test-string-maps_adjust.c test-string-maps_append.c test-string-maps_append_all.c test-string-maps_decimate_by.c test-string-maps_decrease_by.c test-string-maps_increase.c test-string-maps_increase_by.c test-string-maps_resize.c test-string-mapss_adjust.c test-string-mapss_append.c test-string-mapss_append_all.c test-string-mapss_decimate_by.c test-string-mapss_decrease_by.c test-string-mapss_increase.c test-string-mapss_increase_by.c test-string-mapss_resize.c diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.c b/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.c new file mode 100644 index 0000000..e1f5afe --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.c @@ -0,0 +1,42 @@ +#include "test-string.h" +#include "test-string-dynamic_adjust.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_adjust__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_adjust(length, &data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_adjust__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.h b/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.h new file mode 100644 index 0000000..f11c5bb --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_adjust.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string__string_dynamic_adjust +#define _TEST__F_string__string_dynamic_adjust + +/** + * Test that the function works. + * + * @see f_string_dynamic_adjust() + */ +extern void test__f_string_dynamic_adjust__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_adjust() + */ +extern void test__f_string_dynamic_adjust__parameter_checking(void **state); + +#endif // _TEST__F_string__string_dynamic_adjust diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.c b/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.c new file mode 100644 index 0000000..8f54726 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.c @@ -0,0 +1,50 @@ +#include "test-string.h" +#include "test-string-dynamic_decimate_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_decimate_by__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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_string_dynamic_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.string); +} + +void test__f_string_dynamic_decimate_by__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.h b/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.h new file mode 100644 index 0000000..3a3f31d --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_decimate_by.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_dynamic_decimate_by_h +#define _TEST__F_dynamic_decimate_by_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_decimate_by() + */ +extern void test__f_string_dynamic_decimate_by__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_decimate_by() + */ +extern void test__f_string_dynamic_decimate_by__parameter_checking(void **state); + +#endif // _TEST__F_dynamic_decimate_by_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.c b/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.c new file mode 100644 index 0000000..510db9c --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.c @@ -0,0 +1,50 @@ +#include "test-string.h" +#include "test-string-dynamic_decrease_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_decrease_by__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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_string_dynamic_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.string); +} + +void test__f_string_dynamic_decrease_by__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.h b/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.h new file mode 100644 index 0000000..3bcc961 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_decrease_by.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_decrease_by_h +#define _TEST__F_string_dynamic_decrease_by_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_decrease_by() + */ +extern void test__f_string_dynamic_decrease_by__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_decrease_by() + */ +extern void test__f_string_dynamic_decrease_by__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_decrease_by_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_increase.c b/level_0/f_string/tests/unit/c/test-string-dynamic_increase.c new file mode 100644 index 0000000..b6503da --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_increase.c @@ -0,0 +1,76 @@ +#include "test-string.h" +#include "test-string-dynamic_increase.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_increase__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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_string_dynamic_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.string); +} + +void test__f_string_dynamic_increase__returns_data_not(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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_string_dynamic_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.string); +} + +void test__f_string_dynamic_increase__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_increase.h b/level_0/f_string/tests/unit/c/test-string-dynamic_increase.h new file mode 100644 index 0000000..8708cae --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_increase.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_increase_h +#define _TEST__F_string_dynamic_increase_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_increase() + */ +extern void test__f_string_dynamic_increase__works(void **state); + +/** + * Test that the function returns F_data_not when asked to copy an empty structure. + * + * @see f_string_dynamic_increase() + */ +extern void test__f_string_dynamic_increase__returns_data_not(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_increase() + */ +extern void test__f_string_dynamic_increase__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_increase_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.c b/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.c new file mode 100644 index 0000000..a94e8fe --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.c @@ -0,0 +1,52 @@ +#include "test-string.h" +#include "test-string-dynamic_increase_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_increase_by__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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_string_dynamic_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.string); +} + +void test__f_string_dynamic_increase_by__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.h b/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.h new file mode 100644 index 0000000..94dcbdf --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_increase_by.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_increase_by_h +#define _TEST__F_string_dynamic_increase_by_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_increase_by() + */ +extern void test__f_string_dynamic_increase_by__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_increase_by() + */ +extern void test__f_string_dynamic_increase_by__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_increase_by_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.c new file mode 100644 index 0000000..3e3000f --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.c @@ -0,0 +1,42 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_append.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_append__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_append__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.h new file mode 100644 index 0000000..49965ba --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_append_h +#define _TEST__F_string_dynamic_partial_append_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_append() + */ +extern void test__f_string_dynamic_partial_append__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_append() + */ +extern void test__f_string_dynamic_partial_append__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_append_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.c new file mode 100644 index 0000000..9ef06cc --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.c @@ -0,0 +1,55 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_append_assure.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_append_assure__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_append(expected, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + // The string already exists, so destination should be unchanged. + { + const f_status_t status = f_string_dynamic_partial_append_assure(source, partial, &destination); + + printf("\nDEBUG: [%d]='%s %s'\n", destination.used, destination.string, destination.string + 3); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_append_assure__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append_assure(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.h new file mode 100644 index 0000000..6fd2df6 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_append_assure_h +#define _TEST__F_string_dynamic_partial_append_assure_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_append_assure() + */ +extern void test__f_string_dynamic_partial_append_assure__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_append_assure() + */ +extern void test__f_string_dynamic_partial_append_assure__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_append_assure_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.c new file mode 100644 index 0000000..2b79212 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.c @@ -0,0 +1,51 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_append_assure_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_append_assure_nulless__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_append(expected, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + // The string already exists, so destination should be unchanged. + { + const f_status_t status = f_string_dynamic_partial_append_assure_nulless(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_append_assure_nulless__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append_assure_nulless(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.h new file mode 100644 index 0000000..44e382b --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_assure_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_append_assure_nulless_h +#define _TEST__F_string_dynamic_partial_append_assure_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_append_assure_nulless() + */ +extern void test__f_string_dynamic_partial_append_assure_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_append_assure_nulless() + */ +extern void test__f_string_dynamic_partial_append_assure_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_append_assure_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.c new file mode 100644 index 0000000..329af06 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.c @@ -0,0 +1,41 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_append_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_append_nulless__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_append_nulless__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.h new file mode 100644 index 0000000..8b7ecc7 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_append_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_append_nulless_h +#define _TEST__F_string_dynamic_partial_append_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_append_nulless() + */ +extern void test__f_string_dynamic_partial_append_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_append_nulless() + */ +extern void test__f_string_dynamic_partial_append_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_append_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.c new file mode 100644 index 0000000..566cb30 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.c @@ -0,0 +1,57 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_mash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_mash__works(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected1 = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_static_t expected2 = macro_f_string_static_t_initialize("te\0st:te\0st", 0, 11); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mash(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected1.used); + + assert_string_equal(destination.string, expected1.string); + assert_string_equal(destination.string + 3, expected1.string + 3); + } + + // Check that the glue is added. + { + const f_status_t status = f_string_dynamic_partial_mash(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected2.used); + + assert_string_equal(destination.string, expected2.string); + assert_string_equal(destination.string + 3, expected2.string + 3); + assert_string_equal(destination.string + 9, expected2.string + 9); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_mash__parameter_checking(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mash(glue, source, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.h new file mode 100644 index 0000000..a5f3d75 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_mash_h +#define _TEST__F_string_dynamic_partial_mash_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_mash() + */ +extern void test__f_string_dynamic_partial_mash__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_mash() + */ +extern void test__f_string_dynamic_partial_mash__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_mash_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.c new file mode 100644 index 0000000..e4aaf21 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.c @@ -0,0 +1,54 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_mash_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_mash_nulless__works(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected1 = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_static_t expected2 = macro_f_string_static_t_initialize("test:test", 0, 9); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mash_nulless(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected1.used); + + assert_string_equal(destination.string, expected1.string); + } + + // Check that the glue is added. + { + const f_status_t status = f_string_dynamic_partial_mash_nulless(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected2.used); + + assert_string_equal(destination.string, expected2.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_mash_nulless__parameter_checking(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mash_nulless(glue, source, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.h new file mode 100644 index 0000000..0cda6b3 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mash_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_mash_nulless_h +#define _TEST__F_string_dynamic_partial_mash_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_mash_nulless() + */ +extern void test__f_string_dynamic_partial_mash_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_mash_nulless() + */ +extern void test__f_string_dynamic_partial_mash_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_mash_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.c new file mode 100644 index 0000000..1f41027 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.c @@ -0,0 +1,57 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_mish.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_mish__works(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected1 = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_static_t expected2 = macro_f_string_static_t_initialize("te\0st:te\0st", 0, 11); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mish(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected1.used); + + assert_string_equal(destination.string, expected1.string); + assert_string_equal(destination.string + 3, expected1.string + 3); + } + + // Check that the glue is added. + { + const f_status_t status = f_string_dynamic_partial_mish(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected2.used); + + assert_string_equal(destination.string, expected2.string); + assert_string_equal(destination.string + 3, expected2.string + 3); + assert_string_equal(destination.string + 9, expected2.string + 9); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_mish__parameter_checking(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mish(glue, source, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.h new file mode 100644 index 0000000..34acaa0 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish.h @@ -0,0 +1,26 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_mish_h +#define _TEST__F_string_dynamic_partial_mish_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_mish() + */ +extern void test__f_string_dynamic_partial_mish__works(void **state); +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_mish() + */ +extern void test__f_string_dynamic_partial_mish__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_mish_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.c new file mode 100644 index 0000000..b7ff292 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.c @@ -0,0 +1,54 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_mish_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_mish_nulless__works(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected1 = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_static_t expected2 = macro_f_string_static_t_initialize("test:test", 0, 9); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mish_nulless(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected1.used); + + assert_string_equal(destination.string, expected1.string); + } + + // Check that the glue is added. + { + const f_status_t status = f_string_dynamic_partial_mish_nulless(glue, source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected2.used); + + assert_string_equal(destination.string, expected2.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_mish_nulless__parameter_checking(void **state) { + + const f_string_static_t glue = macro_f_string_static_t_initialize(":", 0, 1); + const f_string_static_t source = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_mish_nulless(glue, source, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.h new file mode 100644 index 0000000..e738cd9 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_mish_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_mish_nulless_h +#define _TEST__F_string_dynamic_partial_mish_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_mish_nulless() + */ +extern void test__f_string_dynamic_partial_mish_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_mish_nulless() + */ +extern void test__f_string_dynamic_partial_mish_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_mish_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.c new file mode 100644 index 0000000..885b758 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.c @@ -0,0 +1,42 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_prepend.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_prepend__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_prepend__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.h new file mode 100644 index 0000000..0ec9fd1 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_prepend_h +#define _TEST__F_string_dynamic_partial_prepend_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_prepend() + */ +extern void test__f_string_dynamic_partial_prepend__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_prepend() + */ +extern void test__f_string_dynamic_partial_prepend__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_prepend_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.c new file mode 100644 index 0000000..12f0d91 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.c @@ -0,0 +1,53 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_prepend_assure.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_prepend_assure__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("te\0st", 0, 5); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_assure(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + // The string already exists, so destination should be unchanged. + { + const f_status_t status = f_string_dynamic_partial_prepend_assure(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + assert_string_equal(destination.string + 3, expected.string + 3); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_prepend_assure__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_assure(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.h new file mode 100644 index 0000000..b6330d7 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_prepend_assure_h +#define _TEST__F_string_dynamic_partial_prepend_assure_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_prepend_assure() + */ +extern void test__f_string_dynamic_partial_prepend_assure__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_prepend_assure() + */ +extern void test__f_string_dynamic_partial_prepend_assure__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_prepend_assure_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.c new file mode 100644 index 0000000..5f340c1 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.c @@ -0,0 +1,51 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_prepend_assure_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_prepend_assure_nulless__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_assure_nulless(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + // The string already exists, so destination should be unchanged. + { + const f_status_t status = f_string_dynamic_partial_prepend_assure_nulless(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_prepend_assure_nulless__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_assure_nulless(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.h new file mode 100644 index 0000000..b117fe1 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_assure_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_prepend_assure_nulless_h +#define _TEST__F_string_dynamic_partial_prepend_assure_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_prepend_assure_nulless() + */ +extern void test__f_string_dynamic_partial_prepend_assure_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_prepend_assure_nulless() + */ +extern void test__f_string_dynamic_partial_prepend_assure_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_prepend_assure_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.c b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.c new file mode 100644 index 0000000..dbef9f8 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.c @@ -0,0 +1,41 @@ +#include "test-string.h" +#include "test-string-dynamic_partial_prepend_nulless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_partial_prepend_nulless__works(void **state) { + + const f_string_static_t source = macro_f_string_static_t_initialize("_te\0st_", 0, 7); + const f_string_static_t expected = macro_f_string_static_t_initialize("test", 0, 4); + const f_string_range_t partial = macro_f_string_range_t_initialize(1, 5); + f_string_dynamic_t destination = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_nulless(source, partial, &destination); + + assert_int_equal(status, F_none); + assert_int_equal(destination.used, expected.used); + + assert_string_equal(destination.string, expected.string); + } + + free((void *) destination.string); +} + +void test__f_string_dynamic_partial_prepend_nulless__parameter_checking(void **state) { + + const f_string_dynamic_t data = f_string_dynamic_t_initialize; + const f_string_range_t partial = f_string_range_t_initialize; + + { + const f_status_t status = f_string_dynamic_partial_prepend_nulless(data, partial, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.h b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.h new file mode 100644 index 0000000..a53fd22 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_partial_prepend_nulless.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_partial_prepend_nulless_h +#define _TEST__F_string_dynamic_partial_prepend_nulless_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_partial_prepend_nulless() + */ +extern void test__f_string_dynamic_partial_prepend_nulless__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_partial_prepend_nulless() + */ +extern void test__f_string_dynamic_partial_prepend_nulless__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_partial_prepend_nulless_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_resize.c b/level_0/f_string/tests/unit/c/test-string-dynamic_resize.c new file mode 100644 index 0000000..4c763f6 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_resize.c @@ -0,0 +1,42 @@ +#include "test-string.h" +#include "test-string-dynamic_resize.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_resize__works(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_resize(length, &data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_resize__parameter_checking(void **state) { + + const int length = 5; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + { + const f_status_t status = f_string_dynamic_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.string); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_resize.h b/level_0/f_string/tests/unit/c/test-string-dynamic_resize.h new file mode 100644 index 0000000..c919684 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_resize.h @@ -0,0 +1,27 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_resize_h +#define _TEST__F_string_dynamic_resize_h + +/** + * Test that the function works. + * + * @see f_string_dynamic_resize() + */ +extern void test__f_string_dynamic_resize__works(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_resize() + */ +extern void test__f_string_dynamic_resize__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_resize_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.c b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.c new file mode 100644 index 0000000..f81cb82 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.c @@ -0,0 +1,69 @@ +#include "test-string.h" +#include "test-string-dynamic_terminate.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_string_dynamic_terminate__appends_null(void **state) { + + const f_array_length_t length = 2; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + // Put some value in the unused section at the end so that it gets overridden. + { + const f_status_t status = f_string_dynamic_resize(length, &data); + + assert_int_equal(status, F_none); + + data.string[0] = 'X'; + } + + { + const f_status_t status = f_string_dynamic_terminate(&data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 1); + assert_int_equal(data.string[0], 0); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_terminate__doesnt_append_null(void **state) { + + const f_array_length_t length = 2; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + // Ensure a NULL already exists so that the test can confirm that another NULL is not appended. + { + const f_status_t status = f_string_dynamic_resize(length, &data); + + assert_int_equal(status, F_none); + + data.string[0] = 0; + } + + { + const f_status_t status = f_string_dynamic_terminate(&data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 1); + assert_int_equal(data.string[0], 0); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_terminate__parameter_checking(void **state) { + + { + const f_status_t status = f_string_dynamic_terminate(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.h b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.h new file mode 100644 index 0000000..e63cd19 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_terminate_h +#define _TEST__F_string_dynamic_terminate_h + +/** + * Test that the function appends a NULL. + * + * @see f_string_dynamic_terminate() + */ +extern void test__f_string_dynamic_terminate__appends_null(void **state); + +/** + * Test that the function does not append a NULL. + * + * @see f_string_dynamic_terminate() + */ +extern void test__f_string_dynamic_terminate__doesnt_append_null(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_terminate() + */ +extern void test__f_string_dynamic_terminate__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_terminate_h diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.c b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.c new file mode 100644 index 0000000..0f2e318 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.c @@ -0,0 +1,73 @@ +#include "test-string.h" +#include "test-string-dynamic_terminate_after.h" + +#ifdef __cplusplus +extern "C" { +#endif +void test__f_string_dynamic_terminate_after__appends_null(void **state) { + + const f_array_length_t length = 2; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + // Put some value in the unused section at the end so that it gets overridden. + { + const f_status_t status = f_string_dynamic_resize(length, &data); + + assert_int_equal(status, F_none); + + data.string[0] = 'X'; + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_in_range(data.size, 1, 1 + F_memory_default_allocation_small_d); + + assert_int_equal(data.string[data.used], 0); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_terminate_after__doesnt_append_null(void **state) { + + const f_array_length_t length = 2; + f_string_dynamic_t data = f_string_dynamic_t_initialize; + + // Ensure a NULL already exists so that the test can confirm that another NULL is not appended. + { + const f_status_t status = f_string_dynamic_resize(length, &data); + + assert_int_equal(status, F_none); + assert_in_range(data.size, length, length + F_memory_default_allocation_small_d); + + data.string[0] = 0; + } + + { + const f_status_t status = f_string_dynamic_terminate_after(&data); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_in_range(data.size, length, length + F_memory_default_allocation_small_d); + + assert_int_equal(data.string[data.used], 0); + } + + free((void *) data.string); +} + +void test__f_string_dynamic_terminate_after__parameter_checking(void **state) { + + { + const f_status_t status = f_string_dynamic_terminate_after(0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.h b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.h new file mode 100644 index 0000000..444f776 --- /dev/null +++ b/level_0/f_string/tests/unit/c/test-string-dynamic_terminate_after.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the type project. + */ +#ifndef _TEST__F_string_dynamic_terminate_after_h +#define _TEST__F_string_dynamic_terminate_after_h + +/** + * Test that the function appends a new line. + * + * @see f_string_dynamic_terminate_after() + */ +extern void test__f_string_dynamic_terminate_after__appends_null(void **state); + +/** + * Test that the function does not append a new line. + * + * @see f_string_dynamic_terminate_after() + */ +extern void test__f_string_dynamic_terminate_after__doesnt_append_null(void **state); + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_string_dynamic_terminate_after() + */ +extern void test__f_string_dynamic_terminate_after__parameter_checking(void **state); + +#endif // _TEST__F_string_dynamic_terminate_after_h diff --git a/level_0/f_string/tests/unit/c/test-string.c b/level_0/f_string/tests/unit/c/test-string.c index 0b5e220..1369d1b 100644 --- a/level_0/f_string/tests/unit/c/test-string.c +++ b/level_0/f_string/tests/unit/c/test-string.c @@ -24,22 +24,48 @@ int main(void) { cmocka_unit_test(test__f_string_append_assure_nulless__works), cmocka_unit_test(test__f_string_append_nulless__works), + cmocka_unit_test(test__f_string_dynamic_adjust__works), + cmocka_unit_test(test__f_string_dynamic_append__works), cmocka_unit_test(test__f_string_dynamic_append_assure__works), cmocka_unit_test(test__f_string_dynamic_append_assure_nulless__works), cmocka_unit_test(test__f_string_dynamic_append_nulless__works), + cmocka_unit_test(test__f_string_dynamic_decimate_by__works), + cmocka_unit_test(test__f_string_dynamic_decrease_by__works), + cmocka_unit_test(test__f_string_dynamic_increase__works), + cmocka_unit_test(test__f_string_dynamic_increase__returns_data_not), + cmocka_unit_test(test__f_string_dynamic_increase_by__works), + cmocka_unit_test(test__f_string_dynamic_mash__works), cmocka_unit_test(test__f_string_dynamic_mash_nulless__works), cmocka_unit_test(test__f_string_dynamic_mish__works), cmocka_unit_test(test__f_string_dynamic_mish_nulless__works), + cmocka_unit_test(test__f_string_dynamic_partial_append__works), + cmocka_unit_test(test__f_string_dynamic_partial_append_assure__works), + cmocka_unit_test(test__f_string_dynamic_partial_append_assure_nulless__works), + cmocka_unit_test(test__f_string_dynamic_partial_append_nulless__works), + + cmocka_unit_test(test__f_string_dynamic_partial_mash__works), + cmocka_unit_test(test__f_string_dynamic_partial_mash_nulless__works), + + cmocka_unit_test(test__f_string_dynamic_partial_mish__works), + cmocka_unit_test(test__f_string_dynamic_partial_mish_nulless__works), + + cmocka_unit_test(test__f_string_dynamic_partial_prepend__works), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_assure__works), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_assure_nulless__works), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_nulless__works), + cmocka_unit_test(test__f_string_dynamic_prepend__works), cmocka_unit_test(test__f_string_dynamic_prepend_assure__works), cmocka_unit_test(test__f_string_dynamic_prepend_assure_nulless__works), cmocka_unit_test(test__f_string_dynamic_prepend_nulless__works), + cmocka_unit_test(test__f_string_dynamic_resize__works), + cmocka_unit_test(test__f_string_dynamic_seek_line__returns_data_not_stop), cmocka_unit_test(test__f_string_dynamic_seek_line__returns_none_eos), cmocka_unit_test(test__f_string_dynamic_seek_line__returns_none_stop), @@ -56,6 +82,12 @@ int main(void) { cmocka_unit_test(test__f_string_dynamic_seek_to__returns_none_stop), cmocka_unit_test(test__f_string_dynamic_seek_to__works), + cmocka_unit_test(test__f_string_dynamic_terminate__appends_null), + cmocka_unit_test(test__f_string_dynamic_terminate__doesnt_append_null), + + cmocka_unit_test(test__f_string_dynamic_terminate_after__appends_null), + cmocka_unit_test(test__f_string_dynamic_terminate_after__doesnt_append_null), + cmocka_unit_test(test__f_string_dynamics_adjust__works), cmocka_unit_test(test__f_string_dynamics_append__works), cmocka_unit_test(test__f_string_dynamics_append_all__works), @@ -224,6 +256,55 @@ int main(void) { cmocka_unit_test(test__f_string_append_assure_nulless__parameter_checking), cmocka_unit_test(test__f_string_append_nulless__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_adjust__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_append__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_append_assure__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_append_assure_nulless__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_append_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_decimate_by__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_decrease_by__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_increase__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_increase__returns_data_not), + cmocka_unit_test(test__f_string_dynamic_increase_by__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_mash__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_mash_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_mish__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_mish_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_partial_append__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_append_assure__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_append_assure_nulless__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_append_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_partial_mash__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_mash_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_partial_mish__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_mish_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_partial_prepend__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_assure__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_assure_nulless__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_partial_prepend_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_prepend__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_prepend_assure__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_prepend_assure_nulless__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_prepend_nulless__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_resize__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_seek_line__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_seek_line_to__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_seek_to__parameter_checking), + + cmocka_unit_test(test__f_string_dynamic_terminate__parameter_checking), + cmocka_unit_test(test__f_string_dynamic_terminate_after__parameter_checking), + cmocka_unit_test(test__f_string_dynamics_adjust__parameter_checking), cmocka_unit_test(test__f_string_dynamics_append__parameter_checking), cmocka_unit_test(test__f_string_dynamics_append_all__parameter_checking), diff --git a/level_0/f_string/tests/unit/c/test-string.h b/level_0/f_string/tests/unit/c/test-string.h index 5f6fb38..373dfbe 100644 --- a/level_0/f_string/tests/unit/c/test-string.h +++ b/level_0/f_string/tests/unit/c/test-string.h @@ -30,21 +30,41 @@ #include "test-string-append_assure.h" #include "test-string-append_assure_nulless.h" #include "test-string-append_nulless.h" +#include "test-string-dynamic_adjust.h" #include "test-string-dynamic_append.h" #include "test-string-dynamic_append_assure.h" #include "test-string-dynamic_append_assure_nulless.h" #include "test-string-dynamic_append_nulless.h" +#include "test-string-dynamic_decimate_by.h" +#include "test-string-dynamic_decrease_by.h" +#include "test-string-dynamic_increase.h" +#include "test-string-dynamic_increase_by.h" #include "test-string-dynamic_mash.h" #include "test-string-dynamic_mash_nulless.h" #include "test-string-dynamic_mish.h" #include "test-string-dynamic_mish_nulless.h" +#include "test-string-dynamic_partial_append.h" +#include "test-string-dynamic_partial_append_assure.h" +#include "test-string-dynamic_partial_append_assure_nulless.h" +#include "test-string-dynamic_partial_append_nulless.h" +#include "test-string-dynamic_partial_mash.h" +#include "test-string-dynamic_partial_mash_nulless.h" +#include "test-string-dynamic_partial_mish.h" +#include "test-string-dynamic_partial_mish_nulless.h" +#include "test-string-dynamic_partial_prepend.h" +#include "test-string-dynamic_partial_prepend_assure.h" +#include "test-string-dynamic_partial_prepend_assure_nulless.h" +#include "test-string-dynamic_partial_prepend_nulless.h" #include "test-string-dynamic_prepend.h" #include "test-string-dynamic_prepend_assure.h" #include "test-string-dynamic_prepend_assure_nulless.h" #include "test-string-dynamic_prepend_nulless.h" +#include "test-string-dynamic_resize.h" #include "test-string-dynamic_seek_line.h" #include "test-string-dynamic_seek_line_to.h" #include "test-string-dynamic_seek_to.h" +#include "test-string-dynamic_terminate.h" +#include "test-string-dynamic_terminate_after.h" #include "test-string-dynamics_adjust.h" #include "test-string-dynamics_append.h" #include "test-string-dynamics_append_all.h"