]> uap-core.de Git - note.git/commitdiff
add init_note_store test main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 8 Jan 2026 17:32:45 +0000 (18:32 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 8 Jan 2026 17:32:45 +0000 (18:32 +0100)
application/Makefile
application/tests/test-store.c [new file with mode: 0644]
application/tests/test-store.h [new file with mode: 0644]
application/tests/testmain.c
ui/common/properties.c
ui/ui/toolkit.h

index 27eb93bdaac3ef84840d9b55862611af78e06ea0..8e85c673cb00d4116d4423d38abaadd7dbc1fa0e 100644 (file)
@@ -49,6 +49,7 @@ MAIN_OBJ = ../build/application/main$(OBJ_EXT)
        
 TEST_SRC  = tests/testmain.c
 TEST_SRC += tests/test-editor.c
        
 TEST_SRC  = tests/testmain.c
 TEST_SRC += tests/test-editor.c
+TEST_SRC += tests/test-store.c
        
 TEST_OBJ = $(TEST_SRC:%.c=../build/application/%$(OBJ_EXT))
        
        
 TEST_OBJ = $(TEST_SRC:%.c=../build/application/%$(OBJ_EXT))
        
diff --git a/application/tests/test-store.c b/application/tests/test-store.c
new file mode 100644 (file)
index 0000000..453cb6a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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-store.h"
+
+#include "../store.h"
+
+CX_TEST(test_init_note_store) {
+    CX_TEST_DO {
+        int ret = init_note_store();
+        
+        CX_TEST_ASSERT(ret == 0);
+    }
+}
diff --git a/application/tests/test-store.h b/application/tests/test-store.h
new file mode 100644 (file)
index 0000000..b918cf3
--- /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_STORE_H
+#define TEST_STORE_H
+
+#include <cx/test.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CX_TEST(test_init_note_store);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_STORE_H */
+
index f65c9079887e39977ba2dcf0b7fa0a5edf2bb4cc..4da0c0580d0b6df83bce12b9232d9c32a2120079 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdlib.h>
 #include <cx/test.h>
 
 #include <cx/test.h>
 
+#include <ui/ui.h>
+
+#include <sys/stat.h>
+
 #include "test-editor.h"
 #include "test-editor.h"
+#include "test-store.h"
 
 int main(int argc, char **argv) {
 
 int main(int argc, char **argv) {
+    struct stat s;
+    if(!stat("notetestdata", &s)) {
+        system("rm -Rf notetestdata");
+    }
+    
+    ui_setappdir("notetestdata");
+    ui_init(NULL, 0, NULL);
+    
     CxTestSuite *suite = cx_test_suite_new("note");
     
     CxTestSuite *suite = cx_test_suite_new("note");
     
+    cx_test_register(suite, test_init_note_store);
+    
     cx_test_register(suite, test_parse_markdown_para);
     cx_test_register(suite, test_parse_markdown_formatting_simple);
     cx_test_register(suite, test_parse_markdown_formatting_nested);
     cx_test_register(suite, test_parse_markdown_para);
     cx_test_register(suite, test_parse_markdown_formatting_simple);
     cx_test_register(suite, test_parse_markdown_formatting_nested);
index 642603da398d26f74faabc48f1ac20b945036bcb..10c118195a23eed77a077b5ee69eb59a993d352b 100644 (file)
@@ -62,6 +62,8 @@ static UiBool load_on_startup = TRUE;
 static void *properties_data = NULL;
 static size_t properties_data_length = 0;
 
 static void *properties_data = NULL;
 static size_t properties_data_length = 0;
 
+static char *config_root = NULL;
+
 void ui_load_properties_file_on_startup(UiBool enable) {
     load_on_startup = enable;
 }
 void ui_load_properties_file_on_startup(UiBool enable) {
     load_on_startup = enable;
 }
@@ -77,13 +79,26 @@ void ui_set_properties_data(const char *str, size_t len) {
 }
 
 char* ui_getappdir(void) {
 }
 
 char* ui_getappdir(void) {
-    if(ui_appname() == NULL) {
+    if(ui_appname() == NULL && config_root == NULL) {
         return NULL;
     }
 
     return ui_configfile(NULL);
 }
 
         return NULL;
     }
 
     return ui_configfile(NULL);
 }
 
+void ui_setappdir(const char *path) {
+    free(config_root);
+    if(path) {
+        cxmutstr cfgpath = cx_strdup(path);
+        config_root = cfgpath.ptr;
+        if(cfgpath.length > 0 && cfgpath.ptr[cfgpath.length-1] == '/') {
+            config_root[cfgpath.length-1] = 0;
+        }
+    } else {
+        config_root = NULL;
+    }
+}
+
 #ifndef _WIN32
 #define UI_PATH_SEPARATOR '/'
 #define UI_ENV_HOME "HOME"
 #ifndef _WIN32
 #define UI_PATH_SEPARATOR '/'
 #define UI_ENV_HOME "HOME"
@@ -95,6 +110,16 @@ char* ui_getappdir(void) {
 #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME"
 
 char* ui_configfile(const char *name) {
 #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME"
 
 char* ui_configfile(const char *name) {
+    if(config_root) {
+        if(!name) {
+            return strdup(config_root);
+        } else if(name[0] == '/') {
+            return cx_strdup(cx_strcat(CX_NULLSTR, 2, cx_str(config_root), cx_str(name))).ptr;
+        } else {
+            return cx_strdup(cx_strcat(CX_NULLSTR, 3, cx_str(config_root), cx_str("/"), cx_str(name))).ptr;
+        }
+    }
+    
     const char *appname = ui_appname();
     if(!appname) {
         return NULL;
     const char *appname = ui_appname();
     if(!appname) {
         return NULL;
@@ -209,10 +234,10 @@ void uic_load_app_properties() {
         return;
     }
     
         return;
     }
     
-    if(!ui_appname()) {
-        // applications without name cannot load app properties
-        return;
-    }
+    //if(!ui_appname()) {
+    //    // applications without name cannot load app properties
+    //    return;
+    //}
     
     char *dir = ui_configfile(NULL);
     if(!dir) {
     
     char *dir = ui_configfile(NULL);
     if(!dir) {
index 94c77f01b103693af936b6b2367848dfcdbd24b1..606420e693432f6210068f3fdad744db5f591f9d 100644 (file)
@@ -700,6 +700,7 @@ UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));
 
 
 UIEXPORT char* ui_getappdir(void);
 
 
 UIEXPORT char* ui_getappdir(void);
+UIEXPORT void ui_setappdir(const char *path);
 UIEXPORT char* ui_configfile(const char *name);
 
 UIEXPORT UiCondVar* ui_condvar_create(void);
 UIEXPORT char* ui_configfile(const char *name);
 
 UIEXPORT UiCondVar* ui_condvar_create(void);