From 10319113aaf632fa96e02d826dbd277fe0f7b8fb Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 29 Mar 2023 19:15:28 -0500 Subject: [PATCH] Update: Back port unit tests from 0.7.x development. The f_compare unit tests are back ported to fl_string. --- level_1/fl_string/data/build/dependencies-tests | 3 + level_1/fl_string/data/build/settings-tests | 61 ++++ level_1/fl_string/data/build/testfile | 55 +++ .../fl_string/tests/unit/c/test-string-compare.c | 269 +++++++++++++++ .../fl_string/tests/unit/c/test-string-compare.h | 22 ++ .../tests/unit/c/test-string-compare_dynamic.c | 269 +++++++++++++++ .../tests/unit/c/test-string-compare_dynamic.h | 22 ++ .../unit/c/test-string-compare_dynamic_except.c | 283 ++++++++++++++++ .../unit/c/test-string-compare_dynamic_except.h | 22 ++ .../c/test-string-compare_dynamic_except_string.c | 283 ++++++++++++++++ .../c/test-string-compare_dynamic_except_string.h | 22 ++ .../c/test-string-compare_dynamic_except_trim.c | 296 ++++++++++++++++ .../c/test-string-compare_dynamic_except_trim.h | 22 ++ ...est-string-compare_dynamic_except_trim_string.c | 296 ++++++++++++++++ ...est-string-compare_dynamic_except_trim_string.h | 22 ++ .../unit/c/test-string-compare_dynamic_partial.c | 299 +++++++++++++++++ .../unit/c/test-string-compare_dynamic_partial.h | 22 ++ .../test-string-compare_dynamic_partial_dynamic.c | 296 ++++++++++++++++ .../test-string-compare_dynamic_partial_dynamic.h | 22 ++ .../c/test-string-compare_dynamic_partial_except.c | 304 +++++++++++++++++ .../c/test-string-compare_dynamic_partial_except.h | 22 ++ ...string-compare_dynamic_partial_except_dynamic.c | 301 +++++++++++++++++ ...string-compare_dynamic_partial_except_dynamic.h | 22 ++ ...-string-compare_dynamic_partial_except_string.c | 304 +++++++++++++++++ ...-string-compare_dynamic_partial_except_string.h | 22 ++ ...st-string-compare_dynamic_partial_except_trim.c | 317 +++++++++++++++++ ...st-string-compare_dynamic_partial_except_trim.h | 22 ++ ...g-compare_dynamic_partial_except_trim_dynamic.c | 314 +++++++++++++++++ ...g-compare_dynamic_partial_except_trim_dynamic.h | 22 ++ ...ng-compare_dynamic_partial_except_trim_string.c | 317 +++++++++++++++++ ...ng-compare_dynamic_partial_except_trim_string.h | 22 ++ .../c/test-string-compare_dynamic_partial_string.c | 299 +++++++++++++++++ .../c/test-string-compare_dynamic_partial_string.h | 22 ++ .../c/test-string-compare_dynamic_partial_trim.c | 312 +++++++++++++++++ .../c/test-string-compare_dynamic_partial_trim.h | 22 ++ ...t-string-compare_dynamic_partial_trim_dynamic.c | 309 +++++++++++++++++ ...t-string-compare_dynamic_partial_trim_dynamic.h | 22 ++ ...st-string-compare_dynamic_partial_trim_string.c | 312 +++++++++++++++++ ...st-string-compare_dynamic_partial_trim_string.h | 22 ++ .../unit/c/test-string-compare_dynamic_string.c | 269 +++++++++++++++ .../unit/c/test-string-compare_dynamic_string.h | 22 ++ .../unit/c/test-string-compare_dynamic_trim.c | 373 +++++++++++++++++++++ .../unit/c/test-string-compare_dynamic_trim.h | 36 ++ .../c/test-string-compare_dynamic_trim_string.c | 373 +++++++++++++++++++++ .../c/test-string-compare_dynamic_trim_string.h | 36 ++ .../tests/unit/c/test-string-compare_except.c | 283 ++++++++++++++++ .../tests/unit/c/test-string-compare_except.h | 22 ++ .../tests/unit/c/test-string-compare_except_trim.c | 296 ++++++++++++++++ .../tests/unit/c/test-string-compare_except_trim.h | 22 ++ .../tests/unit/c/test-string-compare_trim.c | 373 +++++++++++++++++++++ .../tests/unit/c/test-string-compare_trim.h | 36 ++ level_1/fl_string/tests/unit/c/test-string.c | 87 +++++ level_1/fl_string/tests/unit/c/test-string.h | 95 ++++++ 53 files changed, 8218 insertions(+) create mode 100644 level_1/fl_string/data/build/dependencies-tests create mode 100644 level_1/fl_string/data/build/settings-tests create mode 100644 level_1/fl_string/data/build/testfile create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_except.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_except.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_except_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_except_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_trim.c create mode 100644 level_1/fl_string/tests/unit/c/test-string-compare_trim.h create mode 100644 level_1/fl_string/tests/unit/c/test-string.c create mode 100644 level_1/fl_string/tests/unit/c/test-string.h diff --git a/level_1/fl_string/data/build/dependencies-tests b/level_1/fl_string/data/build/dependencies-tests new file mode 100644 index 0000000..54dd2b4 --- /dev/null +++ b/level_1/fl_string/data/build/dependencies-tests @@ -0,0 +1,3 @@ +# fss-0001 + +cmocka 1.* diff --git a/level_1/fl_string/data/build/settings-tests b/level_1/fl_string/data/build/settings-tests new file mode 100644 index 0000000..54b18da --- /dev/null +++ b/level_1/fl_string/data/build/settings-tests @@ -0,0 +1,61 @@ +# fss-0001 +# +# Builds a program that is links to the generated library and is executed to perform tests. +# +# Memory leaks in the test program can be checked for by running valgrind with this executable. +# + +build_name test-fl_string + +version_major 0 +version_minor 7 +version_micro 0 +version_file major +version_target major + +modes individual clang test coverage +modes_default individual test + +build_compiler gcc +build_compiler-clang clang +build_indexer ar +build_indexer_arguments rcs +build_language c + +build_libraries -lc -lcmocka +build_libraries-individual -lf_memory -lf_string -lf_utf -lfl_string + +build_sources_program test-string-compare.c test-string-compare_dynamic.c test-string-compare_dynamic_string.c +build_sources_program test-string-compare_dynamic_partial.c test-string-compare_dynamic_partial_dynamic.c test-string-compare_dynamic_partial_string.c +build_sources_program test-string-compare_dynamic_partial_trim.c test-string-compare_dynamic_partial_trim_dynamic.c test-string-compare_dynamic_partial_trim_string.c +build_sources_program test-string-compare_dynamic_partial_except.c test-string-compare_dynamic_partial_except_dynamic.c test-string-compare_dynamic_partial_except_string.c +build_sources_program test-string-compare_dynamic_partial_except_trim.c test-string-compare_dynamic_partial_except_trim_dynamic.c test-string-compare_dynamic_partial_except_trim_string.c +build_sources_program test-string-compare_except.c test-string-compare_dynamic_except.c test-string-compare_dynamic_except_string.c +build_sources_program test-string-compare_trim.c test-string-compare_dynamic_trim.c test-string-compare_dynamic_trim_string.c +build_sources_program test-string-compare_except_trim.c test-string-compare_dynamic_except_trim.c test-string-compare_dynamic_except_trim_string.c +build_sources_program test-string.c + +build_script no +build_shared yes +build_static no + +path_headers tests/unit/c +path_sources tests/unit/c + +has_path_standard no +preserve_path_headers yes + +search_exclusive yes +search_shared yes +search_static yes + +defines -Ibuild/includes +defines_static -Lbuild/libraries/static +defines_shared -Lbuild/libraries/shared + +flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses +flags-clang -Wno-logical-op-parentheses +flags-test -fstack-protector -Wall +flags-coverage -O0 --coverage -fprofile-abs-path -fprofile-dir=build/coverage/ + +flags_program -fPIE diff --git a/level_1/fl_string/data/build/testfile b/level_1/fl_string/data/build/testfile new file mode 100644 index 0000000..440d8fd --- /dev/null +++ b/level_1/fl_string/data/build/testfile @@ -0,0 +1,55 @@ +# fss-0005 iki-0002 + +settings: + load_build yes + fail exit + + environment PATH LD_LIBRARY_PATH + environment CMOCKA_XML_FILE CMOCKA_MESSAGE_OUTPUT CMOCKA_TEST_ABORT + + # Cmocka is not fully thread-safe, set this to "1" to have cmocka call abort() on a test failure. + #CMOCKA_TEST_ABORT 1 + + # One of: STDOUT, SUBUNIT, TAP, or XML. + #define CMOCKA_MESSAGE_OUTPUT STDOUT + + # When in "XML" output mode, output to this file rather than stdout. + #define CMOCKA_XML_FILE ./out.xml + +main: + build settings individual test + build settings-tests individual test + + operate ld_library_path + + if exist build/programs/shared/test-fl_string + shell build/programs/shared/test-fl_string + + if exist build/programs/static/test-fl_string + shell build/programs/static/test-fl_string + + if not exist build/programs/shared/test-fl_string + and not exist build/programs/static/test-fl_string + operate not_created + +not_created: + print + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' + + exit failure + +ld_library_path: + if define LD_LIBRARY_PATH + and parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if define LD_LIBRARY_PATH + define LD_LIBRARY_PATH 'build/libraries/shared:define:"LD_LIBRARY_PATH"' + + else + if parameter work + define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared' + + else + define LD_LIBRARY_PATH build/libraries/shared diff --git a/level_1/fl_string/tests/unit/c/test-string-compare.c b/level_1/fl_string/tests/unit/c/test-string-compare.c new file mode 100644 index 0000000..a9d785c --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare.c @@ -0,0 +1,269 @@ +#include "test-string.h" +#include "test-string-compare.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_compare__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_compare(string_1s[i].string, string_2s[i].string, string_1s[i].used, string_2s[i].used); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare.h b/level_1/fl_string/tests/unit/c/test-string-compare.h new file mode 100644 index 0000000..b1d6080 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_h +#define _TEST__FL_string_compare_h + +// fl_string_compare() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_compare() + */ +extern void test__fl_string_compare__works(void **state); + +#endif // _TEST__FL_string_compare_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.c new file mode 100644 index 0000000..cd48ee8 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.c @@ -0,0 +1,269 @@ +#include "test-string.h" +#include "test-string-compare_dynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare(string_1s[i], string_2s[i]); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.h new file mode 100644 index 0000000..df38892 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_h +#define _TEST__FL_string_compare_dynamic_h + +// fl_string_dynamic_compare() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare() + */ +extern void test__fl_string_dynamic_compare__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.c new file mode 100644 index 0000000..4d443bf --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.c @@ -0,0 +1,283 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_except.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_except__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except(string_1s[i], string_2s[i], excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except(string_2s[i], string_1s[i], excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.h new file mode 100644 index 0000000..e1c776e --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_except_h +#define _TEST__FL_string_compare_dynamic_except_h + +// fl_string_dynamic_compare_except() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_except() + */ +extern void test__fl_string_dynamic_compare_except__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_except_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.c new file mode 100644 index 0000000..bd4db7f --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.c @@ -0,0 +1,283 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_except_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_except_string__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_string(string_1s[i].string, string_2s[i], string_1s[i].used, excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_string(string_2s[i].string, string_1s[i], string_2s[i].used, excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.h new file mode 100644 index 0000000..b15bd82 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_except_string_h +#define _TEST__FL_string_compare_dynamic_except_string_h + +// fl_string_dynamic_compare_except_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_except_string() + */ +extern void test__fl_string_dynamic_compare_except_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_except_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.c new file mode 100644 index 0000000..27c82c8 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.c @@ -0,0 +1,296 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_except_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_except_trim__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_trim(string_1s[i], string_2s[i], excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_trim(string_2s[i], string_1s[i], excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.h new file mode 100644 index 0000000..4a28796 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_except_trim_h +#define _TEST__FL_string_compare_dynamic_except_trim_h + +// fl_string_dynamic_compare_except_trim() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_except_trim() + */ +extern void test__fl_string_dynamic_compare_except_trim__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_except_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.c new file mode 100644 index 0000000..c4cb52b --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.c @@ -0,0 +1,296 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_except_trim_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_except_trim_string__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_trim_string(string_1s[i].string, string_2s[i], string_1s[i].used, excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_except_trim_string(string_2s[i].string, string_1s[i], string_2s[i].used, excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.h new file mode 100644 index 0000000..75f78ce --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_except_trim_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_except_trim_string_h +#define _TEST__FL_string_compare_dynamic_except_trim_string_h + +// fl_string_dynamic_compare_except_trim_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_except_trim_string() + */ +extern void test__fl_string_dynamic_compare_except_trim_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_except_trim_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.c new file mode 100644 index 0000000..f7b4899 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.c @@ -0,0 +1,299 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + macro_f_string_static_t_initialize("xxxyyy", 0, 6), + + // 3. + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + macro_f_string_static_t_initialize("xxx1yyy", 0, 7), + + // 4. + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxoneyyy", 0, 9), + + // 5. + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + macro_f_string_static_t_initialize("xxxOneyyy", 0, 9), + + // 6. + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0neyyy", 0, 9), + + // 7. + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxxo\0neyyy", 0, 10), + + // 8. + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + macro_f_string_static_t_initialize("xxxone\0yyy", 0, 10), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare(string_1s[i], string_2s[i], f_string_range_empty_c, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare(string_1s[i], string_2s[i], f_string_range_empty_c, range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 4; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare(string_1s[i], string_2s[i], range_1, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare(string_1s[i], string_2s[i], range_1, range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.h new file mode 100644 index 0000000..e384a3a --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_h +#define _TEST__FL_string_compare_dynamic_partial_h + +// fl_string_dynamic_partial_compare() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare() + */ +extern void test__fl_string_dynamic_partial_compare__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.c new file mode 100644 index 0000000..9dc8505 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.c @@ -0,0 +1,296 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_dynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_dynamic__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_dynamic(string_1s[i], string_2s[i], range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_dynamic(string_1s[i], string_2s[i], range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.h new file mode 100644 index 0000000..7b1babd --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_dynamic.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_dynamic_h +#define _TEST__FL_string_compare_dynamic_partial_dynamic_h + +// fl_string_dynamic_partial_compare_dynamic() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_dynamic() + */ +extern void test__fl_string_dynamic_partial_compare_dynamic__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_dynamic_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.c new file mode 100644 index 0000000..9d34301 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.c @@ -0,0 +1,304 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except(string_1s[i], string_2s[i], range_1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except(string_1s[i], string_2s[i], range_1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except(string_1s[i], string_2s[i], range_1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except(string_1s[i], string_2s[i], range_1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.h new file mode 100644 index 0000000..c3d1a03 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_h +#define _TEST__FL_string_compare_dynamic_partial_except_h + +// fl_string_dynamic_partial_compare_except() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except() + */ +extern void test__fl_string_dynamic_partial_compare_except__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.c new file mode 100644 index 0000000..e3789ec --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.c @@ -0,0 +1,301 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except_dynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except_dynamic__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_dynamic(string_1s[i], string_2s[i], range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_dynamic(string_1s[i], string_2s[i], range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.h new file mode 100644 index 0000000..2df3ff9 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_dynamic.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_dynamic_h +#define _TEST__FL_string_compare_dynamic_partial_except_dynamic_h + +// fl_string_dynamic_partial_compare_except_dynamic() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except_dynamic() + */ +extern void test__fl_string_dynamic_partial_compare_except_dynamic__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_dynamic_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.c new file mode 100644 index 0000000..b2dede0 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.c @@ -0,0 +1,304 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except_string__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_string(string_1s[i].string, string_2s[i], 0, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_string(string_1s[i].string, string_2s[i], 0, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_string(string_1s[i].string, string_2s[i], range_1.stop + 1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_string(string_1s[i].string, string_2s[i], range_1.stop + 1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.h new file mode 100644 index 0000000..b6d0289 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_string_h +#define _TEST__FL_string_compare_dynamic_partial_except_string_h + +// fl_string_dynamic_partial_compare_except_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except_string() + */ +extern void test__fl_string_dynamic_partial_compare_except_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.c new file mode 100644 index 0000000..e58f0e7 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.c @@ -0,0 +1,317 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except_trim__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim(string_1s[i], string_2s[i], range_1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim(string_1s[i], string_2s[i], range_1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim(string_1s[i], string_2s[i], range_1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim(string_1s[i], string_2s[i], range_1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.h new file mode 100644 index 0000000..7b4c0ac --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_trim_h +#define _TEST__FL_string_compare_dynamic_partial_except_trim_h + +// fl_string_dynamic_partial_compare_except_trim() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except_trim() + */ +extern void test__fl_string_dynamic_partial_compare_except_trim__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.c new file mode 100644 index 0000000..572dac0 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.c @@ -0,0 +1,314 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except_trim_dynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except_trim_dynamic__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim_dynamic(string_1s[i], string_2s[i], range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim_dynamic(string_1s[i], string_2s[i], range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.h new file mode 100644 index 0000000..7749514 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_dynamic.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_trim_dynamic_h +#define _TEST__FL_string_compare_dynamic_partial_except_trim_dynamic_h + +// fl_string_dynamic_partial_compare_except_trim_dynamic() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except_trim_dynamic() + */ +extern void test__fl_string_dynamic_partial_compare_except_trim_dynamic__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_trim_dynamic_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.c new file mode 100644 index 0000000..05a1c51 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.c @@ -0,0 +1,317 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_except_trim_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_except_trim_string__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim_string(string_1s[i].string, string_2s[i], 0, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim_string(string_1s[i].string, string_2s[i], 0, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_except_trim_string(string_1s[i].string, string_2s[i], range_1.stop + 1, f_string_range_empty_c, excepts_1, excepts_2); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_except_trim_string(string_1s[i].string, string_2s[i], range_1.stop + 1, range_2, excepts_1, excepts_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.h new file mode 100644 index 0000000..3532512 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_except_trim_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_except_trim_string_h +#define _TEST__FL_string_compare_dynamic_partial_except_trim_string_h + +// fl_string_dynamic_partial_compare_except_trim_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_except_trim_string() + */ +extern void test__fl_string_dynamic_partial_compare_except_trim_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_except_trim_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.c new file mode 100644 index 0000000..c8cc6ed --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.c @@ -0,0 +1,299 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_string__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + macro_f_string_static_t_initialize("xxx", 0, 3), + + // 3. + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + macro_f_string_static_t_initialize("xxx1", 0, 4), + + // 4. + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + macro_f_string_static_t_initialize("xxxone", 0, 6), + + // 5. + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + macro_f_string_static_t_initialize("xxxOne", 0, 6), + + // 6. + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + macro_f_string_static_t_initialize("xxx\0ne", 0, 6), + + // 7. + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + macro_f_string_static_t_initialize("xxxo\0ne", 0, 7), + + // 8. + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + macro_f_string_static_t_initialize("xxxone\0", 0, 7), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_string(string_1s[i].string, string_2s[i], 0, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_string(string_1s[i].string, string_2s[i], 0, range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_string(string_1s[i].string + range_1.start, string_2s[i], (range_1.stop - range_1.start) + 1, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_string(string_1s[i].string + range_1.start, string_2s[i], (range_1.stop - range_1.start) + 1, range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.h new file mode 100644 index 0000000..e350b7e --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_string_h +#define _TEST__FL_string_compare_dynamic_partial_string_h + +// fl_string_dynamic_partial_compare_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_string() + */ +extern void test__fl_string_dynamic_partial_compare_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.c new file mode 100644 index 0000000..01345be --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.c @@ -0,0 +1,312 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_trim__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'x', 'x', 'x', '\0', '1', 'y', 'y', 'y' + }; + + f_char_t null_before_one_2[] = { + 'x', 'x', 'x', '\0', '1', ' ', '\0', '\t', 'y', 'y', 'y' + }; + + f_char_t null_before_one_3[] = { + 'x', 'x', 'x', '\0', ' ', '\0', '1', 'y', 'y', 'y' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("xxx yyy", 0, 7), + macro_f_string_static_t_initialize("xxx\tyyy", 0, 7), + macro_f_string_static_t_initialize("xxx\0yyy", 0, 7), + macro_f_string_static_t_initialize("xxx yyy", 0, 10), + macro_f_string_static_t_initialize("xxx \t yyy", 0, 10), + macro_f_string_static_t_initialize("xxx\0 \0\tyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\0 \0yyy", 0, 9), + macro_f_string_static_t_initialize("xxx\0\0\tyyy", 0, 9), + + // 3. + macro_f_string_static_t_initialize("xxx 1yyy", 0, 8), + macro_f_string_static_t_initialize("xxx\t1yyy", 0, 8), + macro_f_string_static_t_initialize(null_before_one_1, 0, 8), + macro_f_string_static_t_initialize("xxx 1 yyy", 0, 11), + macro_f_string_static_t_initialize("xxx 1\t yyy", 0, 11), + macro_f_string_static_t_initialize(null_before_one_2, 0, 11), + macro_f_string_static_t_initialize(null_before_one_3, 0, 10), + macro_f_string_static_t_initialize("xxx1\0\0\tyyy", 0, 10), + + // 4. + macro_f_string_static_t_initialize("xxx oneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\toneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\0oneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx one yyy", 0, 13), + macro_f_string_static_t_initialize("xxx one\t yyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0one \0\tyyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0 \0oneyyy", 0, 12), + macro_f_string_static_t_initialize("xxxone\0\0\tyyy", 0, 12), + + // 5. + macro_f_string_static_t_initialize("xxx Oneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\tOneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\0Oneyyy", 0, 10), + macro_f_string_static_t_initialize("xxx One yyy", 0, 13), + macro_f_string_static_t_initialize("xxx One\t yyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0One \0\tyyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0 \0Oneyyy", 0, 12), + macro_f_string_static_t_initialize("xxxOne\0\0\tyyy", 0, 12), + + // 6. + macro_f_string_static_t_initialize("xxx \0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\t\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxx\0\0neyyy", 0, 10), + macro_f_string_static_t_initialize("xxx \0ne yyy", 0, 13), + macro_f_string_static_t_initialize("xxx \0ne\t yyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0\0ne \0\tyyy", 0, 13), + macro_f_string_static_t_initialize("xxx\0 \0\0neyyy", 0, 12), + macro_f_string_static_t_initialize("xxx\0ne\0\0\tyyy", 0, 12), + + // 7. + macro_f_string_static_t_initialize("xxx o\0neyyy", 0, 11), + macro_f_string_static_t_initialize("xxx\to\0neyyy", 0, 11), + macro_f_string_static_t_initialize("xxx\0o\0neyyy", 0, 11), + macro_f_string_static_t_initialize("xxx o\0ne yyy", 0, 14), + macro_f_string_static_t_initialize("xxx o\0ne\t yyy", 0, 14), + macro_f_string_static_t_initialize("xxx\0o\0ne \0\tyyy", 0, 14), + macro_f_string_static_t_initialize("xxx\0 \0o\0neyyy", 0, 13), + macro_f_string_static_t_initialize("xxxo\0ne\0\0\tyyy", 0, 13), + + // 8. + macro_f_string_static_t_initialize("xxx one\0yyy", 0, 11), + macro_f_string_static_t_initialize("xxx\tone\0yyy", 0, 11), + macro_f_string_static_t_initialize("xxx\0one\0yyy", 0, 11), + macro_f_string_static_t_initialize("xxx one\0 yyy", 0, 14), + macro_f_string_static_t_initialize("xxx one\0\t yyy", 0, 14), + macro_f_string_static_t_initialize("xxx\0one\0 \0\tyyy", 0, 14), + macro_f_string_static_t_initialize("xxx\0 \0one\0yyy", 0, 13), + macro_f_string_static_t_initialize("xxxone\0\0\0\tyyy", 0, 13), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim(string_1s[i], string_2s[i], f_string_range_empty_c, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim(string_1s[i], string_2s[i], f_string_range_empty_c, range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 4; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim(string_1s[i], string_2s[i], range_1, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim(string_1s[i], string_2s[i], range_1, range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.h new file mode 100644 index 0000000..16ba67c --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_trim_h +#define _TEST__FL_string_compare_dynamic_partial_trim_h + +// fl_string_dynamic_partial_compare_trim() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_trim() + */ +extern void test__fl_string_dynamic_partial_compare_trim__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.c new file mode 100644 index 0000000..5171ebf --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.c @@ -0,0 +1,309 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_dynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_trim_dynamic__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + '\0', '1' + }; + + f_char_t null_before_one_2[] = { + '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize(" ", 0, 1), + macro_f_string_static_t_initialize("\t", 0, 1), + macro_f_string_static_t_initialize("\0", 0, 1), + macro_f_string_static_t_initialize(" ", 0, 4), + macro_f_string_static_t_initialize(" \t ", 0, 4), + macro_f_string_static_t_initialize("\0 \0\t", 0, 4), + macro_f_string_static_t_initialize("\0 \0", 0, 3), + macro_f_string_static_t_initialize("\0\0\t", 0, 3), + + // 3. + macro_f_string_static_t_initialize(" 1", 0, 2), + macro_f_string_static_t_initialize("\t1", 0, 2), + macro_f_string_static_t_initialize(null_before_one_1, 0, 2), + macro_f_string_static_t_initialize(" 1 ", 0, 5), + macro_f_string_static_t_initialize(" 1\t ", 0, 5), + macro_f_string_static_t_initialize(null_before_one_2, 0, 5), + macro_f_string_static_t_initialize(null_before_one_3, 0, 4), + macro_f_string_static_t_initialize("1\0\0\t", 0, 4), + + // 4. + macro_f_string_static_t_initialize(" one", 0, 4), + macro_f_string_static_t_initialize("\tone", 0, 4), + macro_f_string_static_t_initialize("\0one", 0, 4), + macro_f_string_static_t_initialize(" one ", 0, 7), + macro_f_string_static_t_initialize(" one\t ", 0, 7), + macro_f_string_static_t_initialize("\0one \0\t", 0, 7), + macro_f_string_static_t_initialize("\0 \0one", 0, 6), + macro_f_string_static_t_initialize("one\0\0\t", 0, 6), + + // 5. + macro_f_string_static_t_initialize(" One", 0, 4), + macro_f_string_static_t_initialize("\tOne", 0, 4), + macro_f_string_static_t_initialize("\0One", 0, 4), + macro_f_string_static_t_initialize(" One ", 0, 7), + macro_f_string_static_t_initialize(" One\t ", 0, 7), + macro_f_string_static_t_initialize("\0One \0\t", 0, 7), + macro_f_string_static_t_initialize("\0 \0One", 0, 6), + macro_f_string_static_t_initialize("One\0\0\t", 0, 6), + + // 6. + macro_f_string_static_t_initialize(" \0ne", 0, 4), + macro_f_string_static_t_initialize("\t\0ne", 0, 4), + macro_f_string_static_t_initialize("\0\0ne", 0, 4), + macro_f_string_static_t_initialize(" \0ne ", 0, 7), + macro_f_string_static_t_initialize(" \0ne\t ", 0, 7), + macro_f_string_static_t_initialize("\0\0ne \0\t", 0, 7), + macro_f_string_static_t_initialize("\0 \0\0ne", 0, 6), + macro_f_string_static_t_initialize("\0ne\0\0\t", 0, 6), + + // 7. + macro_f_string_static_t_initialize(" o\0ne", 0, 5), + macro_f_string_static_t_initialize("\to\0ne", 0, 5), + macro_f_string_static_t_initialize("\0o\0ne", 0, 5), + macro_f_string_static_t_initialize(" o\0ne ", 0, 8), + macro_f_string_static_t_initialize(" o\0ne\t ", 0, 8), + macro_f_string_static_t_initialize("\0o\0ne \0\t", 0, 8), + macro_f_string_static_t_initialize("\0 \0o\0ne", 0, 7), + macro_f_string_static_t_initialize("o\0ne\0\0\t", 0, 7), + + // 8. + macro_f_string_static_t_initialize(" one\0", 0, 5), + macro_f_string_static_t_initialize("\tone\0", 0, 5), + macro_f_string_static_t_initialize("\0one\0", 0, 5), + macro_f_string_static_t_initialize(" one\0 ", 0, 8), + macro_f_string_static_t_initialize(" one\0\t ", 0, 8), + macro_f_string_static_t_initialize("\0one\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("\0 \0one\0", 0, 7), + macro_f_string_static_t_initialize("one\0\0\0\t", 0, 7), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim_dynamic(string_1s[i], string_2s[i], range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim_dynamic(string_1s[i], string_2s[i], f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim_dynamic(string_1s[i], string_2s[i], range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.h new file mode 100644 index 0000000..467c4d8 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_dynamic.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_trim_dynamic_h +#define _TEST__FL_string_compare_dynamic_partial_trim_dynamic_h + +// fl_string_dynamic_partial_compare_trim_dynamic() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_trim_dynamic() + */ +extern void test__fl_string_dynamic_partial_compare_trim_dynamic__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_trim_dynamic_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.c new file mode 100644 index 0000000..561689f --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.c @@ -0,0 +1,312 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_partial_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_partial_compare_trim_string__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'x', 'x', 'x', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'x', 'x', 'x', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'x', 'x', 'x', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("xxx ", 0, 4), + macro_f_string_static_t_initialize("xxx\t", 0, 4), + macro_f_string_static_t_initialize("xxx\0", 0, 4), + macro_f_string_static_t_initialize("xxx ", 0, 7), + macro_f_string_static_t_initialize("xxx \t ", 0, 7), + macro_f_string_static_t_initialize("xxx\0 \0\t", 0, 7), + macro_f_string_static_t_initialize("xxx\0 \0", 0, 6), + macro_f_string_static_t_initialize("xxx\0\0\t", 0, 6), + + // 3. + macro_f_string_static_t_initialize("xxx 1", 0, 5), + macro_f_string_static_t_initialize("xxx\t1", 0, 5), + macro_f_string_static_t_initialize(null_before_one_1, 0, 5), + macro_f_string_static_t_initialize("xxx 1 ", 0, 8), + macro_f_string_static_t_initialize("xxx 1\t ", 0, 8), + macro_f_string_static_t_initialize(null_before_one_2, 0, 8), + macro_f_string_static_t_initialize(null_before_one_3, 0, 7), + macro_f_string_static_t_initialize("xxx1\0\0\t", 0, 7), + + // 4. + macro_f_string_static_t_initialize("xxx one", 0, 7), + macro_f_string_static_t_initialize("xxx\tone", 0, 7), + macro_f_string_static_t_initialize("xxx\0one", 0, 7), + macro_f_string_static_t_initialize("xxx one ", 0, 10), + macro_f_string_static_t_initialize("xxx one\t ", 0, 10), + macro_f_string_static_t_initialize("xxx\0one \0\t", 0, 10), + macro_f_string_static_t_initialize("xxx\0 \0one", 0, 9), + macro_f_string_static_t_initialize("xxxone\0\0\t", 0, 9), + + // 5. + macro_f_string_static_t_initialize("xxx One", 0, 7), + macro_f_string_static_t_initialize("xxx\tOne", 0, 7), + macro_f_string_static_t_initialize("xxx\0One", 0, 7), + macro_f_string_static_t_initialize("xxx One ", 0, 10), + macro_f_string_static_t_initialize("xxx One\t ", 0, 10), + macro_f_string_static_t_initialize("xxx\0One \0\t", 0, 10), + macro_f_string_static_t_initialize("xxx\0 \0One", 0, 9), + macro_f_string_static_t_initialize("xxxOne\0\0\t", 0, 9), + + // 6. + macro_f_string_static_t_initialize("xxx \0ne", 0, 7), + macro_f_string_static_t_initialize("xxx\t\0ne", 0, 7), + macro_f_string_static_t_initialize("xxx\0\0ne", 0, 7), + macro_f_string_static_t_initialize("xxx \0ne ", 0, 10), + macro_f_string_static_t_initialize("xxx \0ne\t ", 0, 10), + macro_f_string_static_t_initialize("xxx\0\0ne \0\t", 0, 10), + macro_f_string_static_t_initialize("xxx\0 \0\0ne", 0, 9), + macro_f_string_static_t_initialize("xxx\0ne\0\0\t", 0, 9), + + // 7. + macro_f_string_static_t_initialize("xxx o\0ne", 0, 8), + macro_f_string_static_t_initialize("xxx\to\0ne", 0, 8), + macro_f_string_static_t_initialize("xxx\0o\0ne", 0, 8), + macro_f_string_static_t_initialize("xxx o\0ne ", 0, 11), + macro_f_string_static_t_initialize("xxx o\0ne\t ", 0, 11), + macro_f_string_static_t_initialize("xxx\0o\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("xxx\0 \0o\0ne", 0, 10), + macro_f_string_static_t_initialize("xxxo\0ne\0\0\t", 0, 10), + + // 8. + macro_f_string_static_t_initialize("xxx one\0", 0, 8), + macro_f_string_static_t_initialize("xxx\tone\0", 0, 8), + macro_f_string_static_t_initialize("xxx\0one\0", 0, 8), + macro_f_string_static_t_initialize("xxx one\0 ", 0, 11), + macro_f_string_static_t_initialize("xxx one\0\t ", 0, 11), + macro_f_string_static_t_initialize("xxx\0one\0 \0\t", 0, 11), + macro_f_string_static_t_initialize("xxx\0 \0one\0", 0, 10), + macro_f_string_static_t_initialize("xxxone\0\0\0\t", 0, 10), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("aa", 0, 2), + macro_f_string_static_t_initialize("aa1", 0, 3), + macro_f_string_static_t_initialize("aaone", 0, 5), + macro_f_string_static_t_initialize("aaOne", 0, 5), + macro_f_string_static_t_initialize("aa\0ne", 0, 5), + macro_f_string_static_t_initialize("aao\0ne", 0, 6), + macro_f_string_static_t_initialize("aaone\0", 0, 6), + }; + + f_string_range_t range_1 = macro_f_string_range_t_initialize(3, 9); + f_string_range_t range_2 = macro_f_string_range_t_initialize(2, 0); + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + uint8_t i = 0; + f_status_t status = F_none; + + // First eight are against empty strings for first argument. + for (; i < 8; ++i) { + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim_string(string_1s[i].string, string_2s[i], 0, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim_string(string_1s[i].string, string_2s[i], 0, range_2); + } + + assert_int_equal(status, expects[i]); + } // for + + for (; i < 64; ++i) { + + range_1.stop = string_1s[i].used - 1; + + if (i % 8 == 0) { + status = fl_string_dynamic_partial_compare_trim_string(string_1s[i].string + range_1.start, string_2s[i], (range_1.stop - range_1.start) + 1, f_string_range_empty_c); + } + else { + range_2.stop = string_2s[i].used - 1; + + status = fl_string_dynamic_partial_compare_trim_string(string_1s[i].string + range_1.start, string_2s[i], (range_1.stop - range_1.start) + 1, range_2); + } + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.h new file mode 100644 index 0000000..f6bc898 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_partial_trim_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_partial_trim_string_h +#define _TEST__FL_string_compare_dynamic_partial_trim_string_h + +// fl_string_dynamic_partial_compare_trim_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_partial_compare_trim_string() + */ +extern void test__fl_string_dynamic_partial_compare_trim_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_partial_trim_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.c new file mode 100644 index 0000000..65aafcb --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.c @@ -0,0 +1,269 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_string__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_string(string_1s[i].string, string_2s[i], string_1s[i].used); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.h new file mode 100644 index 0000000..12b96f3 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_string.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_string_h +#define _TEST__FL_string_compare_dynamic_string_h + +// fl_string_dynamic_compare_string() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_string() + */ +extern void test__fl_string_dynamic_compare_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.c new file mode 100644 index 0000000..1c6e2cb --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.c @@ -0,0 +1,373 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_trim__trims(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize(" ", 0, 1), + macro_f_string_static_t_initialize("\t", 0, 1), + macro_f_string_static_t_initialize(" \0\t", 0, 3), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + const f_string_static_t string_2s[] = { + f_string_empty_s, + f_string_empty_s, + f_string_empty_s, + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space\tspace", 0, 11), + macro_f_string_static_t_initialize("space\t\0 space", 0, 13), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + }; + + const f_status_t expects[] = { + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + }; + + uint8_t i = 0; + + for (; i < 13; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_1s[i], string_2s[i]); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 13; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_2s[i], string_1s[i]); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_1s[i], string_1s[i]); + + assert_int_equal(status, F_equal_to); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_2s[i], string_2s[i]); + + assert_int_equal(status, F_equal_to); + } // for +} + +void test__fl_string_dynamic_compare_trim__something_misses_nothing(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + for (uint8_t i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_1s[i], f_string_empty_s); + + assert_int_equal(status, F_equal_to_not); + } // for +} + +void test__fl_string_dynamic_compare_trim__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim(string_1s[i], string_2s[i]); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.h new file mode 100644 index 0000000..edf45ad --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim.h @@ -0,0 +1,36 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_trim_h +#define _TEST__FL_string_compare_dynamic_trim_h + +// fl_string_dynamic_compare_trim() only returns memory failures. + +/** + * Test that function trims. + * + * @see fl_string_dynamic_compare_trim() + */ +extern void test__fl_string_dynamic_compare_trim__trims(void **state); + +/** + * Test that function doesn't match empty string to a non-empty string. + * + * @see fl_string_dynamic_compare_trim() + */ +extern void test__fl_string_dynamic_compare_trim__something_misses_nothing(void **state); + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_trim() + */ +extern void test__fl_string_dynamic_compare_trim__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.c b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.c new file mode 100644 index 0000000..405757f --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.c @@ -0,0 +1,373 @@ +#include "test-string.h" +#include "test-string-compare_dynamic_trim_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_dynamic_compare_trim_string__trims(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize(" ", 0, 1), + macro_f_string_static_t_initialize("\t", 0, 1), + macro_f_string_static_t_initialize(" \0\t", 0, 3), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + const f_string_static_t string_2s[] = { + f_string_empty_s, + f_string_empty_s, + f_string_empty_s, + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space\tspace", 0, 11), + macro_f_string_static_t_initialize("space\t\0 space", 0, 13), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + }; + + const f_status_t expects[] = { + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + }; + + uint8_t i = 0; + + for (; i < 13; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_1s[i].string, string_2s[i], string_1s[i].used); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 13; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_2s[i].string, string_1s[i], string_2s[i].used); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_1s[i].string, string_1s[i], string_1s[i].used); + + assert_int_equal(status, F_equal_to); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_2s[i].string, string_2s[i], string_2s[i].used); + + assert_int_equal(status, F_equal_to); + } // for +} + +void test__fl_string_dynamic_compare_trim_string__something_misses_nothing(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + for (uint8_t i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_1s[i].string, f_string_empty_s, string_1s[i].used); + + assert_int_equal(status, F_equal_to_not); + } // for +} + +void test__fl_string_dynamic_compare_trim_string__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_dynamic_compare_trim_string(string_1s[i].string, string_2s[i], string_1s[i].used); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.h b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.h new file mode 100644 index 0000000..91e0844 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_dynamic_trim_string.h @@ -0,0 +1,36 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_dynamic_trim_string_h +#define _TEST__FL_string_compare_dynamic_trim_string_h + +// fl_string_dynamic_compare_trim_string() only returns memory failures. + +/** + * Test that function trims. + * + * @see fl_string_dynamic_compare_trim_string() + */ +extern void test__fl_string_dynamic_compare_trim_string__trims(void **state); + +/** + * Test that function doesn't match empty string to a non-empty string. + * + * @see fl_string_dynamic_compare_trim_string() + */ +extern void test__fl_string_dynamic_compare_trim_string__something_misses_nothing(void **state); + +/** + * Test that function works. + * + * @see fl_string_dynamic_compare_trim_string() + */ +extern void test__fl_string_dynamic_compare_trim_string__works(void **state); + +#endif // _TEST__FL_string_compare_dynamic_trim_string_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_except.c b/level_1/fl_string/tests/unit/c/test-string-compare_except.c new file mode 100644 index 0000000..c00b56e --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_except.c @@ -0,0 +1,283 @@ +#include "test-string.h" +#include "test-string-compare_except.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_compare_except__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + macro_f_string_static_t_initialize("SKIP", 0, 4), + + // 3. + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + macro_f_string_static_t_initialize("SKIP1", 0, 5), + + // 4. + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + macro_f_string_static_t_initialize("SKIPone", 0, 7), + + // 5. + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + macro_f_string_static_t_initialize("SKIPOne", 0, 7), + + // 6. + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + macro_f_string_static_t_initialize("SKIP\0ne", 0, 7), + + // 7. + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIPo\0ne", 0, 8), + + // 8. + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + macro_f_string_static_t_initialize("SKIPone\0", 0, 8), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_compare_except(string_1s[i].string, string_2s[i].string, string_1s[i].used, string_2s[i].used, excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_compare_except(string_2s[i].string, string_1s[i].string, string_2s[i].used, string_1s[i].used, excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_except.h b/level_1/fl_string/tests/unit/c/test-string-compare_except.h new file mode 100644 index 0000000..32fff55 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_except.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_except_h +#define _TEST__FL_string_compare_except_h + +// fl_string_compare_except() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_compare_except() + */ +extern void test__fl_string_compare_except__works(void **state); + +#endif // _TEST__FL_string_compare_except_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.c new file mode 100644 index 0000000..485f506 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.c @@ -0,0 +1,296 @@ +#include "test-string.h" +#include "test-string-compare_except_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_compare_except_trim__works(void **state) { + + // A necessary work-around to to have "\01" with the "\0" being separate from the "1". + f_char_t null_before_one_1[] = { + 'S', 'K', 'I', 'P', '\0', '1' + }; + + f_char_t null_before_one_2[] = { + 'S', 'K', 'I', 'P', '\0', '1', ' ', '\0', '\t' + }; + + f_char_t null_before_one_3[] = { + 'S', 'K', 'I', 'P', '\0', ' ', '\0', '1' + }; + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("SKIP ", 0, 5), + macro_f_string_static_t_initialize("SKIP\t", 0, 5), + macro_f_string_static_t_initialize("SKIP\0", 0, 5), + macro_f_string_static_t_initialize("SKIP ", 0, 8), + macro_f_string_static_t_initialize("SKIP \t ", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0\t", 0, 8), + macro_f_string_static_t_initialize("SKIP\0 \0", 0, 7), + macro_f_string_static_t_initialize("SKIP\0\0\t", 0, 7), + + // 3. + macro_f_string_static_t_initialize("SKIP 1", 0, 6), + macro_f_string_static_t_initialize("SKIP\t1", 0, 6), + macro_f_string_static_t_initialize(null_before_one_1, 0, 6), + macro_f_string_static_t_initialize("SKIP 1 ", 0, 9), + macro_f_string_static_t_initialize("SKIP 1\t ", 0, 9), + macro_f_string_static_t_initialize(null_before_one_2, 0, 9), + macro_f_string_static_t_initialize(null_before_one_3, 0, 8), + macro_f_string_static_t_initialize("SKIP1\0\0\t", 0, 8), + + // 4. + macro_f_string_static_t_initialize("SKIP one", 0, 8), + macro_f_string_static_t_initialize("SKIP\tone", 0, 8), + macro_f_string_static_t_initialize("SKIP\0one", 0, 8), + macro_f_string_static_t_initialize("SKIP one ", 0, 11), + macro_f_string_static_t_initialize("SKIP one\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0one \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0one", 0, 10), + macro_f_string_static_t_initialize("SKIPone\0\0\t", 0, 10), + + // 5. + macro_f_string_static_t_initialize("SKIP One", 0, 8), + macro_f_string_static_t_initialize("SKIP\tOne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0One", 0, 8), + macro_f_string_static_t_initialize("SKIP One ", 0, 11), + macro_f_string_static_t_initialize("SKIP One\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0One \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0One", 0, 10), + macro_f_string_static_t_initialize("SKIPOne\0\0\t", 0, 10), + + // 6. + macro_f_string_static_t_initialize("SKIP \0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\t\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP\0\0ne", 0, 8), + macro_f_string_static_t_initialize("SKIP \0ne ", 0, 11), + macro_f_string_static_t_initialize("SKIP \0ne\t ", 0, 11), + macro_f_string_static_t_initialize("SKIP\0\0ne \0\t", 0, 11), + macro_f_string_static_t_initialize("SKIP\0 \0\0ne", 0, 10), + macro_f_string_static_t_initialize("SKIP\0ne\0\0\t", 0, 10), + + // 7. + macro_f_string_static_t_initialize("SKIP o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\to\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP\0o\0ne", 0, 9), + macro_f_string_static_t_initialize("SKIP o\0ne ", 0, 12), + macro_f_string_static_t_initialize("SKIP o\0ne\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0o\0ne \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0o\0ne", 0, 11), + macro_f_string_static_t_initialize("SKIPo\0ne\0\0\t", 0, 11), + + // 8. + macro_f_string_static_t_initialize("SKIP one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\tone\0", 0, 9), + macro_f_string_static_t_initialize("SKIP\0one\0", 0, 9), + macro_f_string_static_t_initialize("SKIP one\0 ", 0, 12), + macro_f_string_static_t_initialize("SKIP one\0\t ", 0, 12), + macro_f_string_static_t_initialize("SKIP\0one\0 \0\t", 0, 12), + macro_f_string_static_t_initialize("SKIP\0 \0one\0", 0, 11), + macro_f_string_static_t_initialize("SKIPone\0\0\0\t", 0, 11), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + f_array_length_t except_1[] = { + 0, 1, 2, 3, + }; + const f_array_lengths_t excepts_1 = macro_f_array_lengths_t_initialize(except_1, 0, 4); + const f_array_lengths_t excepts_2 = f_array_lengths_t_initialize; + uint8_t i = 0; + + for (; i < 64; ++i) { + + const f_status_t status = fl_string_compare_except_trim(string_1s[i].string, string_2s[i].string, string_1s[i].used, string_2s[i].used, excepts_1, excepts_2); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_compare_except_trim(string_2s[i].string, string_1s[i].string, string_2s[i].used, string_1s[i].used, excepts_2, excepts_1); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.h new file mode 100644 index 0000000..68dc8ff --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_except_trim.h @@ -0,0 +1,22 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_except_trim_h +#define _TEST__FL_string_compare_except_trim_h + +// fl_string_compare_except_trim() only returns memory failures. + +/** + * Test that function works. + * + * @see fl_string_compare_except_trim() + */ +extern void test__fl_string_compare_except_trim__works(void **state); + +#endif // _TEST__FL_string_compare_except_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_trim.c b/level_1/fl_string/tests/unit/c/test-string-compare_trim.c new file mode 100644 index 0000000..2627187 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_trim.c @@ -0,0 +1,373 @@ +#include "test-string.h" +#include "test-string-compare_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__fl_string_compare_trim__trims(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize(" ", 0, 1), + macro_f_string_static_t_initialize("\t", 0, 1), + macro_f_string_static_t_initialize(" \0\t", 0, 3), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 13), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + const f_string_static_t string_2s[] = { + f_string_empty_s, + f_string_empty_s, + f_string_empty_s, + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space\tspace", 0, 11), + macro_f_string_static_t_initialize("space\t\0 space", 0, 13), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + }; + + const f_status_t expects[] = { + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + }; + + uint8_t i = 0; + + for (; i < 13; ++i) { + + const f_status_t status = fl_string_compare_trim(string_1s[i].string, string_2s[i].string, string_1s[i].used, string_2s[i].used); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 13; ++i) { + + const f_status_t status = fl_string_compare_trim(string_2s[i].string, string_1s[i].string, string_2s[i].used, string_1s[i].used); + + assert_int_equal(status, expects[i]); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_compare_trim(string_1s[i].string, string_1s[i].string, string_1s[i].used, string_1s[i].used); + + assert_int_equal(status, F_equal_to); + } // for + + for (i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_compare_trim(string_2s[i].string, string_2s[i].string, string_2s[i].used, string_2s[i].used); + + assert_int_equal(status, F_equal_to); + } // for +} + +void test__fl_string_compare_trim__something_misses_nothing(void **state) { + + const f_string_static_t string_1s[] = { + macro_f_string_static_t_initialize("space", 0, 5), + macro_f_string_static_t_initialize(" space", 0, 6), + macro_f_string_static_t_initialize("space ", 0, 6), + macro_f_string_static_t_initialize(" space ", 0, 7), + macro_f_string_static_t_initialize(" \t space \t ", 0, 11), + macro_f_string_static_t_initialize("space space", 0, 11), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + macro_f_string_static_t_initialize(" space\tspace ", 0, 11), + macro_f_string_static_t_initialize("\t\0\tspace\t\0 space \0 ", 0, 19), + }; + + for (uint8_t i = 0; i < 10; ++i) { + + const f_status_t status = fl_string_compare_trim(string_1s[i].string, f_string_empty_s.string, string_1s[i].used, f_string_empty_s.used); + + assert_int_equal(status, F_equal_to_not); + } // for +} + +void test__fl_string_compare_trim__works(void **state) { + + const f_string_static_t string_1s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize(0, 0, 0), + + // 2. + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + + // 3. + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("1", 0, 1), + + // 4. + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("one", 0, 3), + + // 5. + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + + // 6. + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + + // 7. + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + + // 8. + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_string_static_t string_2s[] = { + + // 1. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 2. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 3. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 4. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 5. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 6. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 7. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + + // 8. + macro_f_string_static_t_initialize(0, 0, 0), + macro_f_string_static_t_initialize("", 0, 0), + macro_f_string_static_t_initialize("1", 0, 1), + macro_f_string_static_t_initialize("one", 0, 3), + macro_f_string_static_t_initialize("One", 0, 3), + macro_f_string_static_t_initialize("\0ne", 0, 3), + macro_f_string_static_t_initialize("o\0ne", 0, 4), + macro_f_string_static_t_initialize("one\0", 0, 4), + }; + + const f_status_t expects[] = { + + // 1. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 2. + F_equal_to, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 3. + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 4. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 5. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + + // 6. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + + // 7. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + + // 8. + F_equal_to_not, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to_not, + F_equal_to_not, + F_equal_to, + F_equal_to, + }; + + for (uint8_t i = 0; i < 64; ++i) { + + const f_status_t status = fl_string_compare_trim(string_1s[i].string, string_2s[i].string, string_1s[i].used, string_2s[i].used); + + assert_int_equal(status, expects[i]); + } // for +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string-compare_trim.h b/level_1/fl_string/tests/unit/c/test-string-compare_trim.h new file mode 100644 index 0000000..c0e8acd --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string-compare_trim.h @@ -0,0 +1,36 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_compare_trim_h +#define _TEST__FL_string_compare_trim_h + +// fl_string_compare_trim() only returns memory failures. + +/** + * Test that function trims. + * + * @see fl_string_compare_trim() + */ +extern void test__fl_string_compare_trim__trims(void **state); + +/** + * Test that function doesn't match empty string to a non-empty string. + * + * @see fl_string_compare_trim() + */ +extern void test__fl_string_compare_trim__something_misses_nothing(void **state); + +/** + * Test that function works. + * + * @see fl_string_compare_trim() + */ +extern void test__fl_string_compare_trim__works(void **state); + +#endif // _TEST__FL_string_compare_trim_h diff --git a/level_1/fl_string/tests/unit/c/test-string.c b/level_1/fl_string/tests/unit/c/test-string.c new file mode 100644 index 0000000..e560898 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string.c @@ -0,0 +1,87 @@ +#include "test-string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +const f_string_range_t f_string_range_empty_c = f_string_range_t_initialize; + +int setup(void **state) { + + return 0; +} + +int setdown(void **state) { + + errno = 0; + + return 0; +} + +int main(void) { + + const struct CMUnitTest tests[] = { + + cmocka_unit_test(test__fl_string_compare__works), + cmocka_unit_test(test__fl_string_dynamic_compare__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_dynamic__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except_dynamic__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except_string__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except_trim__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except_trim_dynamic__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_except_trim_string__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_string__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_trim__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_trim_dynamic__works), + cmocka_unit_test(test__fl_string_dynamic_partial_compare_trim_string__works), + cmocka_unit_test(test__fl_string_dynamic_compare_string__works), + cmocka_unit_test(test__fl_string_dynamic_compare_trim__trims), + cmocka_unit_test(test__fl_string_dynamic_compare_trim__something_misses_nothing), + cmocka_unit_test(test__fl_string_dynamic_compare_trim__works), + cmocka_unit_test(test__fl_string_dynamic_compare_trim_string__trims), + cmocka_unit_test(test__fl_string_dynamic_compare_trim_string__something_misses_nothing), + cmocka_unit_test(test__fl_string_dynamic_compare_trim_string__works), + cmocka_unit_test(test__fl_string_dynamic_compare_except__works), + cmocka_unit_test(test__fl_string_dynamic_compare_except_string__works), + cmocka_unit_test(test__fl_string_dynamic_compare_except_trim__works), + cmocka_unit_test(test__fl_string_dynamic_compare_except_trim_string__works), + cmocka_unit_test(test__fl_string_compare_except__works), + cmocka_unit_test(test__fl_string_compare_except_trim__works), + cmocka_unit_test(test__fl_string_compare_trim__trims), + cmocka_unit_test(test__fl_string_compare_trim__something_misses_nothing), + cmocka_unit_test(test__fl_string_compare_trim__works), + + #ifndef _di_level_0_parameter_checking_ + // fl_string_compare() doesn't use parameter checking. + // fl_string_dynamic_compare() doesn't use parameter checking. + // fl_string_dynamic_partial_compare() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_dynamic() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except_dynamic() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except_string() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except_trim() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except_trim_dynamic() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_except_trim_string() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_string() doesn't use parameter checking. + // fl_string_dynamic_partial_compare_trim_dynamic() doesn't use parameter checking. + // fl_string_dynamic_compare_string() doesn't use parameter checking. + // fl_string_dynamic_compare_trim() doesn't use parameter checking. + // fl_string_dynamic_compare_trim_string() doesn't use parameter checking. + // fl_string_dynamic_compare_except() doesn't use parameter checking. + // fl_string_dynamic_compare_except_string() doesn't use parameter checking. + // fl_string_dynamic_compare_except_trim() doesn't use parameter checking. + // fl_string_dynamic_compare_except_trim_string() doesn't use parameter checking. + // fl_string_compare_except() doesn't use parameter checking. + // fl_string_compare_except_trim() doesn't use parameter checking. + // fl_string_compare_trim() doesn't use parameter checking. + #endif // _di_level_0_parameter_checking_ + }; + + return cmocka_run_group_tests(tests, setup, setdown); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_1/fl_string/tests/unit/c/test-string.h b/level_1/fl_string/tests/unit/c/test-string.h new file mode 100644 index 0000000..3c78ff4 --- /dev/null +++ b/level_1/fl_string/tests/unit/c/test-string.h @@ -0,0 +1,95 @@ +/** + * FLL - Level 1 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the string project. + */ +#ifndef _TEST__FL_string_h +#define _TEST__FL_string_h + +// Libc includes. +#include +#include +#include +#include + +// cmocka includes. +#include + +// FLL-1 includes. +#include + +// Test includes. +#include "test-string-compare.h" +#include "test-string-compare_dynamic.h" +#include "test-string-compare_dynamic_partial.h" +#include "test-string-compare_dynamic_partial_dynamic.h" +#include "test-string-compare_dynamic_partial_except.h" +#include "test-string-compare_dynamic_partial_except_dynamic.h" +#include "test-string-compare_dynamic_partial_except_string.h" +#include "test-string-compare_dynamic_partial_except_trim.h" +#include "test-string-compare_dynamic_partial_except_trim_dynamic.h" +#include "test-string-compare_dynamic_partial_except_trim_string.h" +#include "test-string-compare_dynamic_partial_string.h" +#include "test-string-compare_dynamic_partial_trim.h" +#include "test-string-compare_dynamic_partial_trim_dynamic.h" +#include "test-string-compare_dynamic_partial_trim_string.h" +#include "test-string-compare_dynamic_string.h" +#include "test-string-compare_dynamic_trim.h" +#include "test-string-compare_dynamic_trim_string.h" +#include "test-string-compare_dynamic_except.h" +#include "test-string-compare_dynamic_except_string.h" +#include "test-string-compare_dynamic_except_trim.h" +#include "test-string-compare_dynamic_except_trim_string.h" +#include "test-string-compare_except.h" +#include "test-string-compare_except_trim.h" +#include "test-string-compare_trim.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Back ported from 0.7.x here for convenience in tests. +extern const f_string_range_t f_string_range_empty_c; + +/** + * Perform any setup operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setup(void **state); + +/** + * Peform any setdown operations. + * + * @param state + * The test state. + * + * @return + * The status of this function, where 0 means success. + */ +extern int setdown(void **state); + +/** + * Run all tests. + * + * @return + * The final result of the tests. + * + * @see cmocka_run_group_tests() + * @see cmocka_unit_test() + */ +extern int main(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _TEST__FL_string_h -- 1.8.3.1