From: Olaf Wintermann Date: Fri, 23 Jan 2026 15:58:21 +0000 (+0100) Subject: add test_note_store_new_notebook_async_fail X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add test_note_store_new_notebook_async_fail --- diff --git a/application/tests/test-store.c b/application/tests/test-store.c index 06ce0c9..44f0744 100644 --- a/application/tests/test-store.c +++ b/application/tests/test-store.c @@ -223,6 +223,60 @@ CX_TEST(test_note_store_new_notebook_async) { } } +CX_TEST(test_note_store_new_notebook_async_fail) { + CX_TEST_DO { + UiObject *obj = ui_dummy_object(); + + NoteStore *store = note_store_get(); + CX_TEST_ASSERT(store); + + // Create a new notebook (this should work) + Resource res0 = { 0 }; + res0.nodename = "new_notebook_failtest"; + res0.parent_id = store->root->resource_id; + res0.iscollection = TRUE; + + int64_t result[2] = { 0, -1 }; + note_store_new_notebook_async(obj, &res0, test_new_notebook_result, result); + ui_exec_buffered_mainthread_calls_wait(3); + + CX_TEST_ASSERT(result[0] > 0); + CX_TEST_ASSERT(result[1] == 0); + + CX_TEST_ASSERT(!note_store_reload()); + store = note_store_get(); + + CX_TEST_ASSERT(store && store->root && store->root->children); + size_t count1 = cxListSize(store->root->children); + + // Create a second notebook with the same name + // This should fail + + Resource res1 = { 0 }; + res1.nodename = "new_notebook_failtest"; + res1.parent_id = store->root->resource_id; + res1.iscollection = TRUE; + + result[0] = 0; + result[1] = -1; + note_store_new_notebook_async(obj, &res1, test_new_notebook_result, result); + ui_exec_buffered_mainthread_calls_wait(3); + + CX_TEST_ASSERT(result[0] == 0); + CX_TEST_ASSERT(result[1] != 0); + + CX_TEST_ASSERT(!note_store_reload()); + store = note_store_get(); + + CX_TEST_ASSERT(store && store->root && store->root->children); + size_t count2 = cxListSize(store->root->children); + + CX_TEST_ASSERT(count1 == count2); + + ui_close(obj); + } +} + static void test_update_resource_result(UiEvent *event, int error, void *userdata) { int *ptr = userdata; *ptr = error; diff --git a/application/tests/test-store.h b/application/tests/test-store.h index cdaf80c..086f3e9 100644 --- a/application/tests/test-store.h +++ b/application/tests/test-store.h @@ -42,6 +42,7 @@ CX_TEST(test_user_settings_is_valid); CX_TEST(test_note_store_reload); CX_TEST(test_note_store_new_resource_async); CX_TEST(test_note_store_new_notebook_async); +CX_TEST(test_note_store_new_notebook_async_fail); CX_TEST(test_note_store_update_resource_async); CX_TEST(test_note_store_save_notebook_async); CX_TEST(test_note_store_save_notebook_async_with_move); diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 5e69a5d..2df046d 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -59,6 +59,7 @@ int main(int argc, char **argv) { cx_test_register(suite, test_note_store_reload); cx_test_register(suite, test_note_store_new_resource_async); cx_test_register(suite, test_note_store_new_notebook_async); + cx_test_register(suite, test_note_store_new_notebook_async_fail); cx_test_register(suite, test_note_store_update_resource_async); cx_test_register(suite, test_note_store_save_notebook_async); cx_test_register(suite, test_note_store_save_notebook_async_with_move);