From 4dbced892699326e33c8010bc4d6ddc9940a602a Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 31 Jan 2026 20:31:20 +0100 Subject: [PATCH] add test_text_search_strcasestr --- application/Makefile | 1 + application/tests/test-note.c | 62 +++++++++++++++++++++++++++++++++++ application/tests/test-note.h | 46 ++++++++++++++++++++++++++ application/tests/testmain.c | 8 ++++- 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 application/tests/test-note.c create mode 100644 application/tests/test-note.h diff --git a/application/Makefile b/application/Makefile index 8e85c67..6ca1603 100644 --- a/application/Makefile +++ b/application/Makefile @@ -50,6 +50,7 @@ MAIN_OBJ = ../build/application/main$(OBJ_EXT) TEST_SRC = tests/testmain.c TEST_SRC += tests/test-editor.c TEST_SRC += tests/test-store.c +TEST_SRC += tests/test-note.c TEST_OBJ = $(TEST_SRC:%.c=../build/application/%$(OBJ_EXT)) diff --git a/application/tests/test-note.c b/application/tests/test-note.c new file mode 100644 index 0000000..0accaa6 --- /dev/null +++ b/application/tests/test-note.c @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test-note.h" + +#include "../note.h" + + +CX_TEST(test_text_search_strcasestr) { + CX_TEST_DO { + cxstring str = cx_str("Hello World\nöäüOAUÖÄÜ!\nend line"); + + cxstring result = text_search_strcasestr(str, cx_str("end")); + CX_TEST_ASSERT(!cx_strcmp(result, "end line")); + CX_TEST_ASSERT(result.ptr > str.ptr && result.ptr < str.ptr+str.length); + + result = text_search_strcasestr(str, cx_str("EnD")); + CX_TEST_ASSERT(!cx_strcmp(result, "end line")); + + result = text_search_strcasestr(str, cx_str("öäü")); + CX_TEST_ASSERT(!cx_strcmp(result, "öäüOAUÖÄÜ!\nend line")); + + // unicode not supported yet + //result = text_search_strcasestr(str, cx_str("ÖÄÜ")); + //CX_TEST_ASSERT(!cx_strcmp(result, "öäüOAUÖÄÜ!\nend line")); + + result = text_search_strcasestr(str, cx_str("hello")); + CX_TEST_ASSERT(!cx_strcmp(result, str)); + + result = text_search_strcasestr(str, cx_str("HELLO")); + CX_TEST_ASSERT(!cx_strcmp(result, str)); + + // test non-match + result = text_search_strcasestr(str, cx_str("World!")); + CX_TEST_ASSERT(result.ptr == NULL && result.length == 0); + } +} diff --git a/application/tests/test-note.h b/application/tests/test-note.h new file mode 100644 index 0000000..44fe7f5 --- /dev/null +++ b/application/tests/test-note.h @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TEST_NOTE_H +#define TEST_NOTE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +CX_TEST(test_text_search_strcasestr); + + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_NOTE_H */ + diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 58280ce..49fe831 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -32,18 +32,22 @@ #include #include +#include #include "test-editor.h" #include "test-store.h" +#include "test-note.h" #include "../types.h" int main(int argc, char **argv) { + setlocale(LC_ALL, "de_DE.UTF-8"); + struct stat s; if(!stat("notetestdata", &s)) { system("rm -Rf notetestdata"); } - + ui_setappdir("notetestdata"); ui_init(NULL, 0, NULL); register_types(); @@ -74,6 +78,8 @@ int main(int argc, char **argv) { cx_test_register(suite, test_parse_markdown_list); cx_test_register(suite, test_mddoc_linearization); + cx_test_register(suite, test_text_search_strcasestr); + cx_test_run_stdout(suite); int err = suite->failure > 0 ? 1 : 0; cx_test_suite_free(suite); -- 2.47.3