]> uap-core.de Git - note.git/commitdiff
add test_note_store_save_notebook_async_with_move
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 18 Jan 2026 15:50:22 +0000 (16:50 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 18 Jan 2026 15:50:22 +0000 (16:50 +0100)
application/tests/test-store.c
application/tests/test-store.h
application/tests/testmain.c

index f48d39d4659aafa4f629ffa8b601307c6c89620c..8df1184182f27334565957efc2aabea5c896c1db 100644 (file)
@@ -332,6 +332,104 @@ CX_TEST(test_note_store_save_notebook_async) {
     }
 }
 
+CX_TEST(test_note_store_save_notebook_async_with_move) {
+    CX_TEST_DO {
+        UiObject *obj = ui_dummy_object();
+        
+        NoteStore *store = note_store_get();
+        CX_TEST_ASSERT(store);
+        
+        // prepare test: create 2 groups and 1 child
+        Resource *res0 = cxZalloc(store->mp->allocator, sizeof(Resource));
+        res0->parent_id = store->root->resource_id;
+        res0->nodename = cx_strdup_a(store->mp->allocator, "movetest_group1").ptr;
+        
+        int error = -1;
+        note_store_save_notebook_async(obj, res0, 0, test_save_notebook_result, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        CX_TEST_ASSERT(res0->resource_id != 0);
+        
+        Resource *res1 = cxZalloc(store->mp->allocator, sizeof(Resource));
+        res1->parent_id = store->root->resource_id;
+        res1->nodename = cx_strdup_a(store->mp->allocator, "movetest_group2").ptr;
+        
+        error = -1;
+        note_store_save_notebook_async(obj, res1, 0, test_save_notebook_result, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        CX_TEST_ASSERT(res1->resource_id != 0);
+        
+        Resource *res2 = cxZalloc(store->mp->allocator, sizeof(Resource));
+        res2->parent_id = res0->resource_id;
+        res2->nodename = cx_strdup_a(store->mp->allocator, "group1_child").ptr;
+        
+        error = -1;
+        note_store_save_notebook_async(obj, res2, 0, test_save_notebook_result, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        CX_TEST_ASSERT(res2->resource_id != 0);
+        
+        // Move Test: move group1_child to movetest_group2, also rename the resource
+        int64_t prev_parent_id = res2->parent_id;
+        res2->parent_id = res1->resource_id;
+        res2->nodename = cx_strdup_a(store->mp->allocator, "child_moved_to_group2").ptr;
+        
+        error = -1;
+        note_store_save_notebook_async(obj, res2, prev_parent_id, test_save_notebook_result, &error);
+        ui_exec_buffered_mainthread_calls_wait(3);
+        
+        CX_TEST_ASSERT(error == 0);
+        size_t group1_size = 0;
+        size_t group2_size = 0;
+        if(res0->children) {
+            group1_size = cxListSize(res0->children);
+        }
+        if(res1->children) {
+            group2_size = cxListSize(res1->children);
+        }
+        
+        CX_TEST_ASSERT(group1_size == 0);
+        CX_TEST_ASSERT(group2_size == 1);
+        
+        Resource *test_res2 = cxListAt(res1->children, 0);
+        CX_TEST_ASSERT(res2 == test_res2);
+        
+        // reload store and check again
+        int64_t group1_id = res0->resource_id;
+        int64_t group2_id = res1->resource_id;
+        
+        CX_TEST_ASSERT(!note_store_reload());
+        store = note_store_get();
+        CX_TEST_ASSERT(store && store->root && store->root->children);
+        
+        Resource *test_res0 = note_store_get_notebook_by_id(store, group1_id);
+        Resource *test_res1 = note_store_get_notebook_by_id(store, group2_id);
+        
+        CX_TEST_ASSERT(test_res0 && test_res1);
+        CX_TEST_ASSERT(!cx_strcmp(test_res0->nodename, "movetest_group1"));
+        CX_TEST_ASSERT(!cx_strcmp(test_res1->nodename, "movetest_group2"));
+        
+        group1_size = 0;
+        group2_size = 0;
+        if(test_res0->children) {
+            group1_size = cxListSize(test_res0->children);
+        }
+        if(test_res1->children) {
+            group2_size = cxListSize(test_res1->children);
+        }
+        
+        CX_TEST_ASSERT(group1_size == 0);
+        CX_TEST_ASSERT(group2_size == 1);
+        
+        test_res2 = cxListAt(test_res1->children, 0);
+        CX_TEST_ASSERT(!cx_strcmp(test_res2->nodename, "child_moved_to_group2"));
+    }
+}
+
 CX_TEST(test_note_store_get_notebook_by_id) {
     // it is important that this test is run after some other tests
     // created some resources
index eefcb130fea42f49a9b156036b69ff763de09580..3644559c576a5bfbdbf18e71651c37180b9c8adf 100644 (file)
@@ -44,6 +44,7 @@ CX_TEST(test_note_store_new_resource_async);
 CX_TEST(test_note_store_new_notebook_async);
 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);
 CX_TEST(test_note_store_get_notebook_by_id);
 
 
index a0cbc0688f1a0ef93d9077b64c66986338dd2a38..7b07644b7e111afdf6c5be6fb9c91fb0bccd7d05 100644 (file)
@@ -61,6 +61,7 @@ int main(int argc, char **argv) {
     cx_test_register(suite, test_note_store_new_notebook_async);
     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);
     cx_test_register(suite, test_note_store_get_notebook_by_id);
     
     cx_test_register(suite, test_parse_markdown_para);