// new note
note_store_new_note_async(obj, note, NULL, NULL);
} else {
- note_store_save_note_async(obj, note, NULL, NULL);
+ note_store_update_note_async(obj, note, NULL, NULL);
}
if(note->resource->attachments) {
typedef struct GetNoteContentJob {
- int64_t note_id;
+ int64_t resource_id;
stringresult_func resultcb;
void *userdata;
cxmutstr result;
-cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t note_id) {
+cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t resource_id) {
cxmutstr content = (cxmutstr){NULL, 0};
DBUQuery *q = connection->createQuery(connection, NULL);
dbuQuerySetSQL(q, SQL_NOTE_GET_CONTENT);
- dbuQuerySetParamInt64(q, 1, note_id);
+ dbuQuerySetParamInt64(q, 1, resource_id);
if(dbuQueryExec(q)) {
dbuQueryFree(q);
}
static int qthr_get_note_content(GetNoteContentJob *job) {
- job->result = note_store_get_note_content(job->a, job->note_id);
+ job->result = note_store_get_note_content(job->a, job->resource_id);
return 0;
}
-void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t note_id, stringresult_func resultcb, void *userdata) {
+void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t resource_id, stringresult_func resultcb, void *userdata) {
GetNoteContentJob *job = malloc(sizeof(GetNoteContentJob));
job->result = (cxmutstr){NULL, 0};
job->a = a;
- job->note_id = note_id;
+ job->resource_id = resource_id;
job->resultcb = resultcb;
job->userdata = userdata;
ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_get_note_content, job, (ui_callback)uithr_get_note_content_finished, job);
}
-static int qthr_save_note(SaveNoteJob *job) {
+static int qthr_update_note(SaveNoteJob *job) {
Resource *n = job->note->resource;
DBUQuery *q = connection->createQuery(connection, NULL);
dbuQuerySetSQL(q, SQL_NOTE_SAVE);
- dbuQuerySetParamString(q, 1, cx_str(n->displayname));
+ dbuQuerySetParamString(q, 1, cx_str(n->nodename));
dbuQuerySetParamString(q, 2, cx_str(n->displayname));
dbuQuerySetParamString(q, 3, cx_strcast(n->content));
dbuQuerySetParamInt64(q, 4, n->resource_id);
return 0;
}
-void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
+void note_store_update_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
SaveNoteJob *job = malloc(sizeof(SaveNoteJob));
job->note = note;
job->resultcb = resultcb;
job->userdata = userdata;
job->error = 0;
- ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_save_note, job, (ui_callback)uithr_save_note_finished, job);
+ ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_update_note, job, (ui_callback)uithr_save_note_finished, job);
}
CxList* note_store_get_notes(const CxAllocator *a, int64_t parent_collection_id);
void note_store_get_notes_async(UiObject *obj, int64_t parent_resource_id, listresult_func resultcb, void *userdata);
-cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t note_id);
-void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t note_id, stringresult_func resultcb, void *userdata);
+cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t resource_id);
+void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t resource_id, stringresult_func resultcb, void *userdata);
void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
-void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
+void note_store_update_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata);
CX_TEST_ASSERT(t3->type == MD_SPAN_EM);
CX_TEST_ASSERT(!cx_strcmp(mdnode_get_text(t3), cx_str("emphasis")));
+ // TODO: Test deactivated, because the MD_FLAG_UNDERLINE flag
+ // deactivates the __strong__ syntax.
+ // Renable it, when we have a new markdown parser
+ /*
doc = parse_markdown(cx_str("test *begin __bold__ text* end"));
CX_TEST_ASSERT(doc);
CX_TEST_ASSERT(doc->content);
CX_TEST_ASSERT(!em_t2->next);
CX_TEST_ASSERT(em_t2->text.ptr);
CX_TEST_ASSERT(!cx_strcmp(cx_strcast(em_t2->text), cx_str(" text")));
+ */
}
}
MDNode *t4;
CX_TEST_DO {
- doc = parse_markdown(cx_str("test *begin __bold__ end*"));
+ //doc = parse_markdown(cx_str("test *begin __bold__ end*"));
+ doc = parse_markdown(cx_str("test *begin **bold** end*"));
CX_TEST_ASSERT(doc);
CX_TEST_ASSERT(doc->content);
p0 = doc->content;
MDNode *li1text_bold;
CX_TEST_DO {
- doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 __bold__\n\nend"));
+ //doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 __bold__\n\nend"));
+ doc = parse_markdown(cx_str("Test Paragraph\n\n - List1\n - List2 **bold**\n\nend"));
CX_TEST_ASSERT(doc);
// paragraph structure
}
CX_TEST(test_mddoc_linearization) {
- MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin __bold__ text* end"));
+ //MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin __bold__ text* end"));
+ MDDoc *doc = parse_markdown(cx_str("# heading 1\n\ntest *begin **bold** text* end"));
CX_TEST_DO {
MDDocLinear md = mddoc_linearization(doc);
}
}
-static void note_created(UiEvent *event, int error, void *userdata) {
+static void note_saved(UiEvent *event, int error, void *userdata) {
int *ret = userdata;
*ret = error;
}
note->resource = res;
int error = -1;
- note_store_new_note_async(obj, note, note_created, &error);
+ note_store_new_note_async(obj, note, note_saved, &error);
ui_exec_buffered_mainthread_calls_wait(3);
CX_TEST_ASSERT(error == 0);
CX_TEST_ASSERT(note->resource_id == note->resource->resource_id);
CX_TEST_ASSERT(note->note_id > 0);
+ // cleanup
+ ui_close(obj);
+ }
+}
+
+static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) {
+ cxmutstr *ptr = userdata;
+ *ptr = result;
+}
+
+CX_TEST(test_note_store_update_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);
+
+ // create a new note first
+ Note *note = cxZalloc(a, sizeof(Note));
+ Resource *res = cxZalloc(a, sizeof(Resource));
+ res->nodename = cx_strdup_a(a, "note2").ptr;
+ res->content = cx_strdup_a(a, "Hello World 2");
+ res->parent_id = parent->resource_id;
+ note->resource = res;
+
+ int error = -1;
+ note_store_new_note_async(obj, note, note_saved, &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);
+
+ // now test the update
+ note->type = 3;
+ cxFree(a, note->resource->nodename);
+ note->resource->nodename = cx_strdup_a(a, "note2_renamed").ptr;
+ cxFree(a, note->resource->content.ptr);
+ note->resource->content = cx_strdup_a(a, "note2 new content");
+
+ int64_t note_id = note->note_id;
+ int64_t resource_id = note->resource_id;
+ error = -1;
+ note_store_update_note_async(obj, note, note_saved, &error);
+ ui_exec_buffered_mainthread_calls_wait(3);
+
+ CX_TEST_ASSERT(error == 0);
+ CX_TEST_ASSERT(note->note_id == note_id);
+ CX_TEST_ASSERT(note->resource_id == resource_id);
+
+ CxList *notes = note_store_get_notes(a, parent->resource_id);
+ Note *updated_note = NULL;
+ CxIterator i = cxListIterator(notes);
+ cx_foreach(Note *, n, i) {
+ if(n->note_id == note_id) {
+ updated_note = n;
+ break;
+ }
+ }
+
+ CX_TEST_ASSERT(updated_note);
+ CX_TEST_ASSERT(updated_note->resource);
+ CX_TEST_ASSERT(!cx_strcmp(updated_note->resource->nodename, note->resource->nodename));
+
+ cxmutstr content = note_store_get_note_content(a, resource_id);
+ CX_TEST_ASSERT(!cx_strcmp(content, note->resource->content));
+
+
// cleanup
ui_close(obj);
}
CX_TEST(test_note_store_delete_collection_async);
CX_TEST(test_note_store_save_repository_async);
CX_TEST(test_note_store_new_note_async);
+CX_TEST(test_note_store_update_note_async);
#ifdef __cplusplus
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_note_store_update_note_async);
cx_test_register(suite, test_parse_markdown_para);
cx_test_register(suite, test_parse_markdown_formatting_simple);