]> uap-core.de Git - note.git/commitdiff
add test_note_store_update_note_async main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 7 Feb 2026 11:48:15 +0000 (12:48 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 7 Feb 2026 11:48:15 +0000 (12:48 +0100)
application/note.c
application/store.c
application/store.h
application/tests/test-editor.c
application/tests/test-store.c
application/tests/test-store.h
application/tests/testmain.c

index 49bf8e5fc1ffc950ffdb90f96c5dc4ef225356b6..f6c028f124c2734b8af6f5c692983c5e43473ba6 100644 (file)
@@ -204,7 +204,7 @@ void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
         // new note
         note_store_new_note_async(obj, note, NULL, NULL);
     } else {
         // new note
         note_store_new_note_async(obj, note, NULL, NULL);
     } else {
-        note_store_save_note_async(obj, note, NULL, NULL);
+        note_store_update_note_async(obj, note, NULL, NULL);
     }
     
     if(note->resource->attachments) {
     }
     
     if(note->resource->attachments) {
index 1d29baa441beea58f356752c124e654e32c78189..b5734a93ecd958c6305d6fca45c2046fdfceca87 100644 (file)
@@ -617,7 +617,7 @@ void note_store_get_notes_async(UiObject* obj, int64_t parent_resource_id, listr
 
 
 typedef struct GetNoteContentJob {
 
 
 typedef struct GetNoteContentJob {
-    int64_t note_id;
+    int64_t resource_id;
     stringresult_func resultcb;
     void *userdata;
     cxmutstr result;
     stringresult_func resultcb;
     void *userdata;
     cxmutstr result;
@@ -626,12 +626,12 @@ typedef struct GetNoteContentJob {
 
 
 
 
 
 
-cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t note_id) {
+cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t resource_id) {
     cxmutstr content = (cxmutstr){NULL, 0};
     
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_GET_CONTENT);
     cxmutstr content = (cxmutstr){NULL, 0};
     
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_GET_CONTENT);
-    dbuQuerySetParamInt64(q, 1, note_id);
+    dbuQuerySetParamInt64(q, 1, resource_id);
     
     if(dbuQueryExec(q)) {
         dbuQueryFree(q);
     
     if(dbuQueryExec(q)) {
         dbuQueryFree(q);
@@ -671,15 +671,15 @@ static void uithr_get_note_content_finished(UiEvent *event, GetNoteContentJob *j
 }
 
 static int qthr_get_note_content(GetNoteContentJob *job) {
 }
 
 static int qthr_get_note_content(GetNoteContentJob *job) {
-    job->result = note_store_get_note_content(job->a, job->note_id);
+    job->result = note_store_get_note_content(job->a, job->resource_id);
     return 0;
 }
 
     return 0;
 }
 
-void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t note_id, stringresult_func resultcb, void *userdata) {
+void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t resource_id, stringresult_func resultcb, void *userdata) {
     GetNoteContentJob *job = malloc(sizeof(GetNoteContentJob));
     job->result = (cxmutstr){NULL, 0};
     job->a = a;
     GetNoteContentJob *job = malloc(sizeof(GetNoteContentJob));
     job->result = (cxmutstr){NULL, 0};
     job->a = a;
-    job->note_id = note_id;
+    job->resource_id = resource_id;
     job->resultcb = resultcb;
     job->userdata = userdata;
     ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_get_note_content, job, (ui_callback)uithr_get_note_content_finished, job);
     job->resultcb = resultcb;
     job->userdata = userdata;
     ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_get_note_content, job, (ui_callback)uithr_get_note_content_finished, job);
@@ -759,11 +759,11 @@ void note_store_new_note_async(UiObject *obj, Note *note, execresult_func result
 }
 
 
 }
 
 
-static int qthr_save_note(SaveNoteJob *job) {
+static int qthr_update_note(SaveNoteJob *job) {
     Resource *n = job->note->resource;
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_SAVE);
     Resource *n = job->note->resource;
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_SAVE);
-    dbuQuerySetParamString(q, 1, cx_str(n->displayname));
+    dbuQuerySetParamString(q, 1, cx_str(n->nodename));
     dbuQuerySetParamString(q, 2, cx_str(n->displayname));
     dbuQuerySetParamString(q, 3, cx_strcast(n->content));
     dbuQuerySetParamInt64(q, 4, n->resource_id);
     dbuQuerySetParamString(q, 2, cx_str(n->displayname));
     dbuQuerySetParamString(q, 3, cx_strcast(n->content));
     dbuQuerySetParamInt64(q, 4, n->resource_id);
@@ -781,13 +781,13 @@ static int qthr_save_note(SaveNoteJob *job) {
     return 0;
 }
 
     return 0;
 }
 
-void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
+void note_store_update_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
     SaveNoteJob *job = malloc(sizeof(SaveNoteJob));
     job->note = note;
     job->resultcb = resultcb;
     job->userdata = userdata;
     job->error = 0;
     SaveNoteJob *job = malloc(sizeof(SaveNoteJob));
     job->note = note;
     job->resultcb = resultcb;
     job->userdata = userdata;
     job->error = 0;
-    ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_save_note, job, (ui_callback)uithr_save_note_finished, job);
+    ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_update_note, job, (ui_callback)uithr_save_note_finished, job);
 }
 
 
 }
 
 
index b78e70939c2fd962748c4ea64223c28c912f5064..95dd33f30d6aa65b803b9bfe8a86eaf3eaa7545d 100644 (file)
@@ -124,11 +124,11 @@ int64_t note_store_count_children(int64_t resource_id);
 CxList* note_store_get_notes(const CxAllocator *a, int64_t parent_collection_id);
 void note_store_get_notes_async(UiObject *obj, int64_t parent_resource_id, listresult_func resultcb, void *userdata);
 
 CxList* note_store_get_notes(const CxAllocator *a, int64_t parent_collection_id);
 void note_store_get_notes_async(UiObject *obj, int64_t parent_resource_id, listresult_func resultcb, void *userdata);
 
-cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t note_id);
-void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t note_id, stringresult_func resultcb, void *userdata);
+cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t resource_id);
+void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t resource_id, stringresult_func resultcb, void *userdata);
 
 void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
 
 void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
-void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
+void note_store_update_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
 
 void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata);
 
 
 void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata);
 
index bb9c6cdd79b90e84ca1d8ddfe2873a709ea38cf9..4683eb7f6508534908c8ba3148d50c9d69aa0465 100644 (file)
@@ -165,6 +165,10 @@ CX_TEST(test_parse_markdown_formatting_simple) {
         CX_TEST_ASSERT(t3->type == MD_SPAN_EM);
         CX_TEST_ASSERT(!cx_strcmp(mdnode_get_text(t3), cx_str("emphasis")));
         
         CX_TEST_ASSERT(t3->type == MD_SPAN_EM);
         CX_TEST_ASSERT(!cx_strcmp(mdnode_get_text(t3), cx_str("emphasis")));
         
+        // TODO: Test deactivated, because the MD_FLAG_UNDERLINE flag
+        //       deactivates the __strong__ syntax.
+        //       Renable it, when we have a new markdown parser
+        /*
         doc = parse_markdown(cx_str("test *begin __bold__ text* end"));
         CX_TEST_ASSERT(doc);
         CX_TEST_ASSERT(doc->content);
         doc = parse_markdown(cx_str("test *begin __bold__ text* end"));
         CX_TEST_ASSERT(doc);
         CX_TEST_ASSERT(doc->content);
@@ -195,6 +199,7 @@ CX_TEST(test_parse_markdown_formatting_simple) {
         CX_TEST_ASSERT(!em_t2->next);
         CX_TEST_ASSERT(em_t2->text.ptr);
         CX_TEST_ASSERT(!cx_strcmp(cx_strcast(em_t2->text), cx_str(" text")));
         CX_TEST_ASSERT(!em_t2->next);
         CX_TEST_ASSERT(em_t2->text.ptr);
         CX_TEST_ASSERT(!cx_strcmp(cx_strcast(em_t2->text), cx_str(" text")));
+        */
     }
 }
 
     }
 }
 
@@ -210,7 +215,8 @@ CX_TEST(test_parse_markdown_formatting_nested) {
     MDNode *t4;
     
     CX_TEST_DO {
     MDNode *t4;
     
     CX_TEST_DO {
-        doc = parse_markdown(cx_str("test *begin __bold__ end*"));
+        //doc = parse_markdown(cx_str("test *begin __bold__ end*"));
+        doc = parse_markdown(cx_str("test *begin **bold** end*"));
         CX_TEST_ASSERT(doc);
         CX_TEST_ASSERT(doc->content);
         p0 = doc->content;
         CX_TEST_ASSERT(doc);
         CX_TEST_ASSERT(doc->content);
         p0 = doc->content;
@@ -253,7 +259,8 @@ CX_TEST(test_parse_markdown_list) {
     MDNode *li1text_bold;
     
     CX_TEST_DO {
     MDNode *li1text_bold;
     
     CX_TEST_DO {
-        doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 __bold__\n\nend"));
+        //doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 __bold__\n\nend"));
+        doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 **bold**\n\nend"));
         CX_TEST_ASSERT(doc);
         
         // paragraph structure
         CX_TEST_ASSERT(doc);
         
         // paragraph structure
@@ -310,7 +317,8 @@ static int section_style_sort(MDDocStyleSection *s1, MDDocStyleSection *s2) {
 }
 
 CX_TEST(test_mddoc_linearization) {
 }
 
 CX_TEST(test_mddoc_linearization) {
-    MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin __bold__ text* end"));
+    //MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin __bold__ text* end"));
+    MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin **bold** text* end"));
     
     CX_TEST_DO {
         MDDocLinear md = mddoc_linearization(doc);
     
     CX_TEST_DO {
         MDDocLinear md = mddoc_linearization(doc);
index de60f667f60be9e1721fd5acbf5563bce11c9719..b88f6f9832957e054e02550d478f2791cb186897 100644 (file)
@@ -723,7 +723,7 @@ CX_TEST(test_note_store_save_repository_async) {
     }
 }
 
     }
 }
 
-static void note_created(UiEvent *event, int error, void *userdata) {
+static void note_saved(UiEvent *event, int error, void *userdata) {
     int *ret = userdata;
     *ret = error;
 }
     int *ret = userdata;
     *ret = error;
 }
@@ -748,7 +748,7 @@ CX_TEST(test_note_store_new_note_async) {
         note->resource = res;
         
         int error = -1;
         note->resource = res;
         
         int error = -1;
-        note_store_new_note_async(obj, note, note_created, &error);
+        note_store_new_note_async(obj, note, note_saved, &error);
         ui_exec_buffered_mainthread_calls_wait(3);
         
         CX_TEST_ASSERT(error == 0);
         ui_exec_buffered_mainthread_calls_wait(3);
         
         CX_TEST_ASSERT(error == 0);
@@ -757,6 +757,81 @@ CX_TEST(test_note_store_new_note_async) {
         CX_TEST_ASSERT(note->resource_id == note->resource->resource_id);
         CX_TEST_ASSERT(note->note_id > 0);
         
         CX_TEST_ASSERT(note->resource_id == note->resource->resource_id);
         CX_TEST_ASSERT(note->note_id > 0);
         
+        // cleanup
+        ui_close(obj);
+    }
+}
+
+static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) {
+    cxmutstr *ptr = userdata;
+    *ptr = result;
+}
+CX_TEST(test_note_store_update_note_async) {
+    CX_TEST_DO {
+        UiObject *obj = ui_dummy_object();
+        NoteStore *store = note_store_get();
+        const CxAllocator *a = store->mp->allocator;
+        
+        CX_TEST_ASSERT(store && store->root && store->root->children);
+        CX_TEST_ASSERT(cxListSize(store->root->children) > 0);
+        
+        Resource *parent = cxListAt(store->root->children, 0);
+        CX_TEST_ASSERT(parent);
+        
+        // create a new note first
+        Note *note = cxZalloc(a, sizeof(Note));
+        Resource *res = cxZalloc(a, sizeof(Resource));
+        res->nodename = cx_strdup_a(a, "note2").ptr;
+        res->content = cx_strdup_a(a, "Hello World 2");
+        res->parent_id = parent->resource_id;
+        note->resource = res;
+        
+        int error = -1;
+        note_store_new_note_async(obj, note, note_saved, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        CX_TEST_ASSERT(note->resource_id > 0);
+        CX_TEST_ASSERT(note->resource->resource_id > 0);
+        CX_TEST_ASSERT(note->resource_id == note->resource->resource_id);
+        CX_TEST_ASSERT(note->note_id > 0);
+        
+        // now test the update
+        note->type = 3;
+        cxFree(a, note->resource->nodename);
+        note->resource->nodename = cx_strdup_a(a, "note2_renamed").ptr;
+        cxFree(a, note->resource->content.ptr);
+        note->resource->content = cx_strdup_a(a, "note2 new content");
+        
+        int64_t note_id = note->note_id;
+        int64_t resource_id = note->resource_id;
+        error = -1;
+        note_store_update_note_async(obj, note, note_saved, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        CX_TEST_ASSERT(note->note_id == note_id);
+        CX_TEST_ASSERT(note->resource_id == resource_id);
+        
+        CxList *notes = note_store_get_notes(a, parent->resource_id);
+        Note *updated_note = NULL;
+        CxIterator i = cxListIterator(notes);
+        cx_foreach(Note *, n, i) {
+            if(n->note_id == note_id) {
+                updated_note = n;
+                break;
+            }
+        }
+        
+        CX_TEST_ASSERT(updated_note);
+        CX_TEST_ASSERT(updated_note->resource);
+        CX_TEST_ASSERT(!cx_strcmp(updated_note->resource->nodename, note->resource->nodename));
+        
+        cxmutstr content = note_store_get_note_content(a, resource_id);
+        CX_TEST_ASSERT(!cx_strcmp(content, note->resource->content));
+        
+        
         // cleanup
         ui_close(obj);
     }
         // cleanup
         ui_close(obj);
     }
index 5af9b6a05bc10a62bf232ceda810e9c800ae151f..975c6d6d4f0c5ff27b98dee3f87f65f56c00fa4f 100644 (file)
@@ -51,6 +51,7 @@ CX_TEST(test_note_store_delete_empty_collection_async);
 CX_TEST(test_note_store_delete_collection_async);
 CX_TEST(test_note_store_save_repository_async);
 CX_TEST(test_note_store_new_note_async);
 CX_TEST(test_note_store_delete_collection_async);
 CX_TEST(test_note_store_save_repository_async);
 CX_TEST(test_note_store_new_note_async);
+CX_TEST(test_note_store_update_note_async);
 
 
 #ifdef __cplusplus
 
 
 #ifdef __cplusplus
index d57d51d14a0df7ecd52e60711ca388d26e11c430..e5f7d99b18c5514385e1bae5f02ed6b02eee6fb6 100644 (file)
@@ -72,6 +72,7 @@ int main(int argc, char **argv) {
     cx_test_register(suite, test_note_store_delete_collection_async);
     cx_test_register(suite, test_note_store_save_repository_async);
     cx_test_register(suite, test_note_store_new_note_async);
     cx_test_register(suite, test_note_store_delete_collection_async);
     cx_test_register(suite, test_note_store_save_repository_async);
     cx_test_register(suite, test_note_store_new_note_async);
+    cx_test_register(suite, test_note_store_update_note_async);
     
     cx_test_register(suite, test_parse_markdown_para);
     cx_test_register(suite, test_parse_markdown_formatting_simple);
     
     cx_test_register(suite, test_parse_markdown_para);
     cx_test_register(suite, test_parse_markdown_formatting_simple);