From 6e14fafd82b8f4e4fa545da734165584f35f92d8 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 5 Feb 2026 18:33:26 +0100 Subject: [PATCH] add test_note_store_new_note_async --- application/tests/test-store.c | 39 ++++++++++++++++++++++++++++++++++ application/tests/test-store.h | 1 + application/tests/testmain.c | 1 + 3 files changed, 41 insertions(+) diff --git a/application/tests/test-store.c b/application/tests/test-store.c index 8d72d21..de60f66 100644 --- a/application/tests/test-store.c +++ b/application/tests/test-store.c @@ -722,3 +722,42 @@ CX_TEST(test_note_store_save_repository_async) { ui_close(obj); } } + +static void note_created(UiEvent *event, int error, void *userdata) { + int *ret = userdata; + *ret = error; +} + +CX_TEST(test_note_store_new_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); + + Note *note = cxZalloc(a, sizeof(Note)); + Resource *res = cxZalloc(a, sizeof(Resource)); + res->nodename = cx_strdup_a(a, "note1").ptr; + res->content = cx_strdup_a(a, "Hello World"); + res->parent_id = parent->resource_id; + note->resource = res; + + int error = -1; + note_store_new_note_async(obj, note, note_created, &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); + + // cleanup + ui_close(obj); + } +} diff --git a/application/tests/test-store.h b/application/tests/test-store.h index 2a9099c..5af9b6a 100644 --- a/application/tests/test-store.h +++ b/application/tests/test-store.h @@ -50,6 +50,7 @@ CX_TEST(test_note_store_get_notebook_by_id); 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); #ifdef __cplusplus diff --git a/application/tests/testmain.c b/application/tests/testmain.c index f570fbe..d57d51d 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -71,6 +71,7 @@ int main(int argc, char **argv) { cx_test_register(suite, test_note_store_delete_empty_collection_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_parse_markdown_para); cx_test_register(suite, test_parse_markdown_formatting_simple); -- 2.47.3