]> uap-core.de Git - note.git/commitdiff
add test_text_search_strcasestr
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 31 Jan 2026 19:31:20 +0000 (20:31 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 31 Jan 2026 19:31:20 +0000 (20:31 +0100)
application/Makefile
application/tests/test-note.c [new file with mode: 0644]
application/tests/test-note.h [new file with mode: 0644]
application/tests/testmain.c

index 8e85c673cb00d4116d4423d38abaadd7dbc1fa0e..6ca16039dbb3494360eca6b27c3bf997e246c7f4 100644 (file)
@@ -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 (file)
index 0000000..0accaa6
--- /dev/null
@@ -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 (file)
index 0000000..44fe7f5
--- /dev/null
@@ -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 <cx/test.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CX_TEST(test_text_search_strcasestr);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_NOTE_H */
+
index 58280ce4e923ca34ad79f89089f809e9b1f471d4..49fe83135ab3360cd52d44b6b68ac96d6751a288 100644 (file)
 #include <ui/ui.h>
 
 #include <sys/stat.h>
+#include <locale.h>
 
 #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);