}
}
+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;
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);
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);