]> uap-core.de Git - note.git/commitdiff
add test_note_store_new_notebook_async_fail main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 23 Jan 2026 15:58:21 +0000 (16:58 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 23 Jan 2026 15:58:21 +0000 (16:58 +0100)
application/tests/test-store.c
application/tests/test-store.h
application/tests/testmain.c

index 06ce0c9052e49a25c978da4234e77fbfb46d4cfd..44f0744cc85ca875772f779a7726aabf1215878a 100644 (file)
@@ -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;
index cdaf80cbde7a8177bc6478822253fecb38c81647..086f3e98fb2757a96b2b09313710baba268d6b6e 100644 (file)
@@ -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);
index 5e69a5dc0068082b0d23157e7b18c8f470bb5105..2df046dfd73c401bafc1c273dd84f5f5f7cac013 100644 (file)
@@ -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);