From ab4ac4be898e7b350593f1c4616d5a97d061661d Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 8 Jan 2026 18:32:45 +0100 Subject: [PATCH] add init_note_store test --- application/Makefile | 1 + application/tests/test-store.c | 39 ++++++++++++++++++++++++++++ application/tests/test-store.h | 46 ++++++++++++++++++++++++++++++++++ application/tests/testmain.c | 16 ++++++++++++ ui/common/properties.c | 35 ++++++++++++++++++++++---- ui/ui/toolkit.h | 1 + 6 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 application/tests/test-store.c create mode 100644 application/tests/test-store.h diff --git a/application/Makefile b/application/Makefile index 27eb93b..8e85c67 100644 --- a/application/Makefile +++ b/application/Makefile @@ -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/test-store.c 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 index 0000000..453cb6a --- /dev/null +++ b/application/tests/test-store.c @@ -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 index 0000000..b918cf3 --- /dev/null +++ b/application/tests/test-store.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_STORE_H +#define TEST_STORE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +CX_TEST(test_init_note_store); + + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_STORE_H */ + diff --git a/application/tests/testmain.c b/application/tests/testmain.c index f65c907..4da0c05 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -26,13 +26,29 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include +#include + +#include + #include "test-editor.h" +#include "test-store.h" 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"); + 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); diff --git a/ui/common/properties.c b/ui/common/properties.c index 642603d..10c1181 100644 --- a/ui/common/properties.c +++ b/ui/common/properties.c @@ -62,6 +62,8 @@ static UiBool load_on_startup = TRUE; 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; } @@ -77,13 +79,26 @@ void ui_set_properties_data(const char *str, size_t len) { } char* ui_getappdir(void) { - if(ui_appname() == NULL) { + if(ui_appname() == NULL && config_root == 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" @@ -95,6 +110,16 @@ char* ui_getappdir(void) { #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; @@ -209,10 +234,10 @@ void uic_load_app_properties() { 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) { diff --git a/ui/ui/toolkit.h b/ui/ui/toolkit.h index 94c77f0..606420e 100644 --- a/ui/ui/toolkit.h +++ b/ui/ui/toolkit.h @@ -700,6 +700,7 @@ UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v)); 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); -- 2.47.3