From: Olaf Wintermann Date: Sat, 7 Feb 2026 11:48:15 +0000 (+0100) Subject: add test_note_store_update_note_async X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add test_note_store_update_note_async --- diff --git a/application/note.c b/application/note.c index 49bf8e5..f6c028f 100644 --- a/application/note.c +++ b/application/note.c @@ -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 { - note_store_save_note_async(obj, note, NULL, NULL); + note_store_update_note_async(obj, note, NULL, NULL); } if(note->resource->attachments) { diff --git a/application/store.c b/application/store.c index 1d29baa..b5734a9 100644 --- a/application/store.c +++ b/application/store.c @@ -617,7 +617,7 @@ void note_store_get_notes_async(UiObject* obj, int64_t parent_resource_id, listr typedef struct GetNoteContentJob { - int64_t note_id; + int64_t resource_id; 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); - dbuQuerySetParamInt64(q, 1, note_id); + dbuQuerySetParamInt64(q, 1, resource_id); 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) { - 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; } -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; - 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); @@ -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); - 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); @@ -781,13 +781,13 @@ static int qthr_save_note(SaveNoteJob *job) { 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; - 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); } diff --git a/application/store.h b/application/store.h index b78e709..95dd33f 100644 --- a/application/store.h +++ b/application/store.h @@ -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); -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_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); diff --git a/application/tests/test-editor.c b/application/tests/test-editor.c index bb9c6cd..4683eb7 100644 --- a/application/tests/test-editor.c +++ b/application/tests/test-editor.c @@ -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"))); + // 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); @@ -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"))); + */ } } @@ -210,7 +215,8 @@ CX_TEST(test_parse_markdown_formatting_nested) { 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; @@ -253,7 +259,8 @@ CX_TEST(test_parse_markdown_list) { 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 @@ -310,7 +317,8 @@ static int section_style_sort(MDDocStyleSection *s1, MDDocStyleSection *s2) { } 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); diff --git a/application/tests/test-store.c b/application/tests/test-store.c index de60f66..b88f6f9 100644 --- a/application/tests/test-store.c +++ b/application/tests/test-store.c @@ -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; } @@ -748,7 +748,7 @@ CX_TEST(test_note_store_new_note_async) { 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); @@ -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); + // 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); } diff --git a/application/tests/test-store.h b/application/tests/test-store.h index 5af9b6a..975c6d6 100644 --- a/application/tests/test-store.h +++ b/application/tests/test-store.h @@ -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_update_note_async); #ifdef __cplusplus diff --git a/application/tests/testmain.c b/application/tests/testmain.c index d57d51d..e5f7d99 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -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_update_note_async); cx_test_register(suite, test_parse_markdown_para); cx_test_register(suite, test_parse_markdown_formatting_simple);