TCString as PassByValue

This commit is contained in:
Dustin J. Mitchell
2022-02-17 04:11:06 +00:00
parent 2eee761644
commit 471119dbdf
17 changed files with 853 additions and 569 deletions

View File

@@ -8,7 +8,7 @@
static void test_replica_creation(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NOT_NULL(rep);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_replica_free(rep);
}
@@ -16,28 +16,28 @@ static void test_replica_creation(void) {
static void test_replica_creation_disk(void) {
TCReplica *rep = tc_replica_new_on_disk(tc_string_borrow("test-db"), NULL);
TEST_ASSERT_NOT_NULL(rep);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_replica_free(rep);
}
// undo on an empty in-memory TCReplica does nothing
static void test_replica_undo_empty(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
int undone;
int rv = tc_replica_undo(rep, &undone);
TEST_ASSERT_EQUAL(TC_RESULT_OK, rv);
TEST_ASSERT_EQUAL(0, undone);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_replica_free(rep);
}
// adding an undo point succeeds
static void test_replica_add_undo_point(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_replica_add_undo_point(rep, true));
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_replica_free(rep);
}
@@ -48,10 +48,10 @@ static void test_replica_working_set(void) {
TCUuid uuid, uuid1, uuid2, uuid3;
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_replica_rebuild_working_set(rep, true));
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
ws = tc_replica_working_set(rep);
TEST_ASSERT_EQUAL(0, tc_working_set_len(ws));
@@ -62,7 +62,7 @@ static void test_replica_working_set(void) {
uuid1 = tc_task_get_uuid(task1);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_replica_rebuild_working_set(rep, true));
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
task2 = tc_replica_new_task(rep, TC_STATUS_PENDING, tc_string_borrow("task2"));
TEST_ASSERT_NOT_NULL(task2);
@@ -73,7 +73,7 @@ static void test_replica_working_set(void) {
uuid3 = tc_task_get_uuid(task3);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_replica_rebuild_working_set(rep, false));
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
// finish task2 to leave a "hole"
tc_task_to_mut(task2, rep);
@@ -81,7 +81,7 @@ static void test_replica_working_set(void) {
tc_task_to_immut(task2);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_replica_rebuild_working_set(rep, false));
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_task_free(task1);
tc_task_free(task2);
@@ -115,17 +115,17 @@ static void test_replica_working_set(void) {
// When tc_replica_undo is passed NULL for undone_out, it still succeeds
static void test_replica_undo_empty_null_undone_out(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
int rv = tc_replica_undo(rep, NULL);
TEST_ASSERT_EQUAL(TC_RESULT_OK, rv);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_replica_free(rep);
}
// creating a task succeeds and the resulting task looks good
static void test_replica_task_creation(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -136,10 +136,10 @@ static void test_replica_task_creation(void) {
TCUuid uuid = tc_task_get_uuid(task);
TEST_ASSERT_EQUAL(TC_STATUS_PENDING, tc_task_get_status(task));
TCString *desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc);
TEST_ASSERT_EQUAL_STRING("my task", tc_string_content(desc));
tc_string_free(desc);
TCString desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc.ptr);
TEST_ASSERT_EQUAL_STRING("my task", tc_string_content(&desc));
tc_string_free(&desc);
tc_task_free(task);
@@ -157,18 +157,18 @@ static void test_replica_task_creation(void) {
// When tc_replica_undo is passed NULL for undone_out, it still succeeds
static void test_replica_sync_local(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
mkdir("test-sync-server", 0755); // ignore error, if dir already exists
TCString *err = NULL;
TCString err;
TCServer *server = tc_server_new_local(tc_string_borrow("test-sync-server"), &err);
TEST_ASSERT_NOT_NULL(server);
TEST_ASSERT_NULL(err);
TEST_ASSERT_NULL(err.ptr);
int rv = tc_replica_sync(rep, server, false);
TEST_ASSERT_EQUAL(TC_RESULT_OK, rv);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
tc_server_free(server);
tc_replica_free(rep);
@@ -176,20 +176,20 @@ static void test_replica_sync_local(void) {
// test error handling
server = tc_server_new_local(tc_string_borrow("/no/such/directory"), &err);
TEST_ASSERT_NULL(server);
TEST_ASSERT_NOT_NULL(err);
tc_string_free(err);
TEST_ASSERT_NOT_NULL(err.ptr);
tc_string_free(&err);
}
// When tc_replica_undo is passed NULL for undone_out, it still succeeds
static void test_replica_remote_server(void) {
TCString *err = NULL;
TCString err;
TCServer *server = tc_server_new_remote(
tc_string_borrow("tc.freecinc.com"),
tc_uuid_new_v4(),
tc_string_borrow("\xf0\x28\x8c\x28"), // NOTE: not utf-8
&err);
TEST_ASSERT_NOT_NULL(server);
TEST_ASSERT_NULL(err);
TEST_ASSERT_NULL(err.ptr);
// can't actually do anything with this server!
@@ -199,7 +199,7 @@ static void test_replica_remote_server(void) {
// a replica with tasks in it returns an appropriate list of tasks and list of uuids
static void test_replica_all_tasks(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task1 = tc_replica_new_task(
rep,
@@ -225,13 +225,13 @@ static void test_replica_all_tasks(void) {
bool seen1, seen2 = false;
for (size_t i = 0; i < tasks.len; i++) {
TCTask *task = tasks.items[i];
TCString *descr = tc_task_get_description(task);
if (0 == strcmp(tc_string_content(descr), "task1")) {
TCString descr = tc_task_get_description(task);
if (0 == strcmp(tc_string_content(&descr), "task1")) {
seen1 = true;
} else if (0 == strcmp(tc_string_content(descr), "task2")) {
} else if (0 == strcmp(tc_string_content(&descr), "task2")) {
seen2 = true;
}
tc_string_free(descr);
tc_string_free(&descr);
}
TEST_ASSERT_TRUE(seen1);
TEST_ASSERT_TRUE(seen2);
@@ -267,7 +267,7 @@ static void test_replica_all_tasks(void) {
// importing a task succeeds and the resulting task looks good
static void test_replica_task_import(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCUuid uuid;
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_uuid_from_str(tc_string_borrow("23cb25e0-5d1a-4932-8131-594ac6d3a843"), &uuid));
@@ -277,10 +277,10 @@ static void test_replica_task_import(void) {
TEST_ASSERT_EQUAL_MEMORY(uuid.bytes, tc_task_get_uuid(task).bytes, sizeof(uuid.bytes));
TEST_ASSERT_EQUAL(TC_STATUS_PENDING, tc_task_get_status(task));
TCString *desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc);
TEST_ASSERT_EQUAL_STRING("", tc_string_content(desc)); // default value
tc_string_free(desc);
TCString desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc.ptr);
TEST_ASSERT_EQUAL_STRING("", tc_string_content(&desc)); // default value
tc_string_free(&desc);
tc_task_free(task);
@@ -298,13 +298,13 @@ static void test_replica_task_import(void) {
// importing a task succeeds and the resulting task looks good
static void test_replica_get_task_not_found(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCUuid uuid;
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_uuid_from_str(tc_string_borrow("23cb25e0-5d1a-4932-8131-594ac6d3a843"), &uuid));
TCTask *task = tc_replica_get_task(rep, uuid);
TEST_ASSERT_NULL(task);
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
}
int replica_tests(void) {

View File

@@ -5,103 +5,110 @@
// creating strings does not crash
static void test_string_creation(void) {
TCString *s = tc_string_borrow("abcdef");
tc_string_free(s);
TCString s = tc_string_borrow("abcdef");
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// creating cloned strings does not crash
static void test_string_cloning(void) {
char *abcdef = strdup("abcdef");
TCString *s = tc_string_clone(abcdef);
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_clone(abcdef);
TEST_ASSERT_NOT_NULL(s.ptr);
free(abcdef);
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(s));
tc_string_free(s);
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(&s));
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// creating cloned strings with invalid utf-8 does not crash
// ..but content is NULL and content_and_len returns the value
static void test_string_cloning_invalid_utf8(void) {
TCString *s = tc_string_clone("\xf0\x28\x8c\x28");
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_clone("\xf0\x28\x8c\x28");
TEST_ASSERT_NOT_NULL(s.ptr);
// NOTE: this is not one of the cases where invalid UTF-8 results in NULL,
// but that may change.
size_t len;
const char *buf = tc_string_content_with_len(s, &len);
const char *buf = tc_string_content_with_len(&s, &len);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_EQUAL(4, len);
TEST_ASSERT_EQUAL_MEMORY("\xf0\x28\x8c\x28", buf, len);
tc_string_free(s);
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// borrowed strings echo back their content
static void test_string_borrowed_strings_echo(void) {
TCString *s = tc_string_borrow("abcdef");
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_borrow("abcdef");
TEST_ASSERT_NOT_NULL(s.ptr);
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(s));
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(&s));
size_t len;
const char *buf = tc_string_content_with_len(s, &len);
const char *buf = tc_string_content_with_len(&s, &len);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_EQUAL(6, len);
TEST_ASSERT_EQUAL_MEMORY("abcdef", buf, len);
tc_string_free(s);
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// cloned strings echo back their content
static void test_string_cloned_strings_echo(void) {
char *orig = strdup("abcdef");
TCString *s = tc_string_clone(orig);
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_clone(orig);
TEST_ASSERT_NOT_NULL(s.ptr);
free(orig);
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(s));
TEST_ASSERT_EQUAL_STRING("abcdef", tc_string_content(&s));
size_t len;
const char *buf = tc_string_content_with_len(s, &len);
const char *buf = tc_string_content_with_len(&s, &len);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_EQUAL(6, len);
TEST_ASSERT_EQUAL_MEMORY("abcdef", buf, len);
tc_string_free(s);
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// tc_clone_with_len can have NULs, and tc_string_content returns NULL for
// strings containing embedded NULs
static void test_string_content_null_for_embedded_nuls(void) {
TCString *s = tc_string_clone_with_len("ab\0de", 5);
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_clone_with_len("ab\0de", 5);
TEST_ASSERT_NOT_NULL(s.ptr);
TEST_ASSERT_NULL(tc_string_content(s));
TEST_ASSERT_NULL(tc_string_content(&s));
size_t len;
const char *buf = tc_string_content_with_len(s, &len);
const char *buf = tc_string_content_with_len(&s, &len);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_EQUAL(5, len);
TEST_ASSERT_EQUAL_MEMORY("ab\0de", buf, len);
tc_string_free(s);
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
// tc_string_clone_with_len will accept invalid utf-8, but then tc_string_content
// returns NULL.
static void test_string_clone_with_len_invalid_utf8(void) {
TCString *s = tc_string_clone_with_len("\xf0\x28\x8c\x28", 4);
TEST_ASSERT_NOT_NULL(s);
TCString s = tc_string_clone_with_len("\xf0\x28\x8c\x28", 4);
TEST_ASSERT_NOT_NULL(s.ptr);
TEST_ASSERT_NULL(tc_string_content(s));
TEST_ASSERT_NULL(tc_string_content(&s));
size_t len;
const char *buf = tc_string_content_with_len(s, &len);
const char *buf = tc_string_content_with_len(&s, &len);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_EQUAL(4, len);
TEST_ASSERT_EQUAL_MEMORY("\xf0\x28\x8c\x28", buf, len);
tc_string_free(s);
tc_string_free(&s);
TEST_ASSERT_NULL(s.ptr);
}
int string_tests(void) {

View File

@@ -6,7 +6,7 @@
// creating a task succeeds and the resulting task looks good
static void test_task_creation(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -16,10 +16,10 @@ static void test_task_creation(void) {
TEST_ASSERT_EQUAL(TC_STATUS_PENDING, tc_task_get_status(task));
TCString *desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc);
TEST_ASSERT_EQUAL_STRING("my task", tc_string_content(desc));
tc_string_free(desc);
TCString desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc.ptr);
TEST_ASSERT_EQUAL_STRING("my task", tc_string_content(&desc));
tc_string_free(&desc);
tc_task_free(task);
@@ -29,7 +29,7 @@ static void test_task_creation(void) {
// freeing a mutable task works, marking it immutable
static void test_task_free_mutable_task(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -57,7 +57,7 @@ static void test_task_free_mutable_task(void) {
// updating status on a task works
static void test_task_get_set_status(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -81,7 +81,7 @@ static void test_task_get_set_status(void) {
// updating description on a task works
static void test_task_get_set_description(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -89,22 +89,22 @@ static void test_task_get_set_description(void) {
tc_string_borrow("my task"));
TEST_ASSERT_NOT_NULL(task);
TCString *desc;
TCString desc;
tc_task_to_mut(task, rep);
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_set_description(task, tc_string_borrow("updated")));
TEST_ASSERT_TRUE(desc = tc_task_get_description(task));
TEST_ASSERT_NOT_NULL(desc);
TEST_ASSERT_EQUAL_STRING("updated", tc_string_content(desc));
tc_string_free(desc);
desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc.ptr);
TEST_ASSERT_EQUAL_STRING("updated", tc_string_content(&desc));
tc_string_free(&desc);
tc_task_to_immut(task);
desc = tc_task_get_description(task);
TEST_ASSERT_NOT_NULL(desc);
TEST_ASSERT_EQUAL_STRING("updated", tc_string_content(desc));
tc_string_free(desc);
TEST_ASSERT_NOT_NULL(desc.ptr);
TEST_ASSERT_EQUAL_STRING("updated", tc_string_content(&desc));
tc_string_free(&desc);
tc_task_free(task);
@@ -114,7 +114,7 @@ static void test_task_get_set_description(void) {
// updating entry on a task works
static void test_task_get_set_entry(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -141,7 +141,7 @@ static void test_task_get_set_entry(void) {
// updating wait on a task works
static void test_task_get_set_wait_and_is_waiting(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -175,7 +175,7 @@ static void test_task_get_set_wait_and_is_waiting(void) {
// updating modified on a task works
static void test_task_get_set_modified(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -202,7 +202,7 @@ static void test_task_get_set_modified(void) {
// starting and stopping a task works, as seen by tc_task_is_active
static void test_task_start_stop_is_active(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -227,7 +227,7 @@ static void test_task_start_stop_is_active(void) {
// tc_task_done and delete work and set the status
static void test_task_done_and_delete(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -250,7 +250,7 @@ static void test_task_done_and_delete(void) {
// adding and removing tags to a task works, and invalid tags are rejected
static void test_task_add_remove_has_tag(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -263,33 +263,33 @@ static void test_task_add_remove_has_tag(void) {
TEST_ASSERT_FALSE(tc_task_has_tag(task, tc_string_borrow("next")));
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_add_tag(task, tc_string_borrow("next")));
TEST_ASSERT_NULL(tc_task_error(task));
TEST_ASSERT_NULL(tc_task_error(task).ptr);
TEST_ASSERT_TRUE(tc_task_has_tag(task, tc_string_borrow("next")));
// invalid - synthetic tag
TEST_ASSERT_EQUAL(TC_RESULT_ERROR, tc_task_add_tag(task, tc_string_borrow("PENDING")));
TCString *err = tc_task_error(task);
TEST_ASSERT_NOT_NULL(err);
tc_string_free(err);
TCString err = tc_task_error(task);
TEST_ASSERT_NOT_NULL(err.ptr);
tc_string_free(&err);
// invald - not a valid tag string
TEST_ASSERT_EQUAL(TC_RESULT_ERROR, tc_task_add_tag(task, tc_string_borrow("my tag")));
err = tc_task_error(task);
TEST_ASSERT_NOT_NULL(err);
tc_string_free(err);
TEST_ASSERT_NOT_NULL(err.ptr);
tc_string_free(&err);
// invald - not utf-8
TEST_ASSERT_EQUAL(TC_RESULT_ERROR, tc_task_add_tag(task, tc_string_borrow("\xf0\x28\x8c\x28")));
err = tc_task_error(task);
TEST_ASSERT_NOT_NULL(err);
tc_string_free(err);
TEST_ASSERT_NOT_NULL(err.ptr);
tc_string_free(&err);
TEST_ASSERT_TRUE(tc_task_has_tag(task, tc_string_borrow("next")));
// remove the tag
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_remove_tag(task, tc_string_borrow("next")));
TEST_ASSERT_NULL(tc_task_error(task));
TEST_ASSERT_NULL(tc_task_error(task).ptr);
TEST_ASSERT_FALSE(tc_task_has_tag(task, tc_string_borrow("next")));
@@ -300,7 +300,7 @@ static void test_task_add_remove_has_tag(void) {
// get_tags returns the list of tags
static void test_task_get_tags(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -316,10 +316,10 @@ static void test_task_get_tags(void) {
int found_pending = false, found_next = false;
for (size_t i = 0; i < tags.len; i++) {
if (strcmp("PENDING", tc_string_content(tags.items[i])) == 0) {
if (strcmp("PENDING", tc_string_content(&tags.items[i])) == 0) {
found_pending = true;
}
if (strcmp("next", tc_string_content(tags.items[i])) == 0) {
if (strcmp("next", tc_string_content(&tags.items[i])) == 0) {
found_next = true;
}
}
@@ -336,7 +336,7 @@ static void test_task_get_tags(void) {
// annotation manipulation (add, remove, list, free)
static void test_task_annotations(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -356,22 +356,22 @@ static void test_task_annotations(void) {
ann.entry = 1644623411;
ann.description = tc_string_borrow("ann1");
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_add_annotation(task, &ann));
TEST_ASSERT_NULL(ann.description);
TEST_ASSERT_NULL(ann.description.ptr);
ann.entry = 1644623422;
ann.description = tc_string_borrow("ann2");
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_add_annotation(task, &ann));
TEST_ASSERT_NULL(ann.description);
TEST_ASSERT_NULL(ann.description.ptr);
anns = tc_task_get_annotations(task);
int found1 = false, found2 = false;
for (size_t i = 0; i < anns.len; i++) {
if (0 == strcmp("ann1", tc_string_content(anns.items[i].description))) {
if (0 == strcmp("ann1", tc_string_content(&anns.items[i].description))) {
TEST_ASSERT_EQUAL(anns.items[i].entry, 1644623411);
found1 = true;
}
if (0 == strcmp("ann2", tc_string_content(anns.items[i].description))) {
if (0 == strcmp("ann2", tc_string_content(&anns.items[i].description))) {
TEST_ASSERT_EQUAL(anns.items[i].entry, 1644623422);
found2 = true;
}
@@ -389,7 +389,7 @@ static void test_task_annotations(void) {
// UDA manipulation (add, remove, list, free)
static void test_task_udas(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(
rep,
@@ -399,11 +399,11 @@ static void test_task_udas(void) {
tc_task_to_mut(task, rep);
TCString *value;
TCString value;
TCUdaList udas;
TEST_ASSERT_NULL(tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1")));
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")));
TEST_ASSERT_NULL(tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1")).ptr);
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")).ptr);
udas = tc_task_get_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
@@ -422,25 +422,25 @@ static void test_task_udas(void) {
tc_string_borrow("vvv")));
value = tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1"));
TEST_ASSERT_NOT_NULL(value);
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(value));
tc_string_free(value);
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")));
TEST_ASSERT_NOT_NULL(value.ptr);
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(&value));
tc_string_free(&value);
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")).ptr);
udas = tc_task_get_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
TEST_ASSERT_EQUAL(1, udas.len);
TEST_ASSERT_EQUAL_STRING("ns", tc_string_content(udas.items[0].ns));
TEST_ASSERT_EQUAL_STRING("u1", tc_string_content(udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(udas.items[0].value));
TEST_ASSERT_EQUAL_STRING("ns", tc_string_content(&udas.items[0].ns));
TEST_ASSERT_EQUAL_STRING("u1", tc_string_content(&udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(&udas.items[0].value));
tc_uda_list_free(&udas);
udas = tc_task_get_legacy_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
TEST_ASSERT_EQUAL(1, udas.len);
TEST_ASSERT_NULL(udas.items[0].ns);
TEST_ASSERT_EQUAL_STRING("ns.u1", tc_string_content(udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(udas.items[0].value));
TEST_ASSERT_NULL(udas.items[0].ns.ptr);
TEST_ASSERT_EQUAL_STRING("ns.u1", tc_string_content(&udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(&udas.items[0].value));
tc_uda_list_free(&udas);
TEST_ASSERT_EQUAL(TC_RESULT_OK,
@@ -449,14 +449,14 @@ static void test_task_udas(void) {
tc_string_borrow("legv")));
value = tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1"));
TEST_ASSERT_NOT_NULL(value);
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(value));
tc_string_free(value);
TEST_ASSERT_NOT_NULL(value.ptr);
TEST_ASSERT_EQUAL_STRING("vvv", tc_string_content(&value));
tc_string_free(&value);
value = tc_task_get_legacy_uda(task, tc_string_borrow("leg1"));
TEST_ASSERT_NOT_NULL(value);
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(value));
tc_string_free(value);
TEST_ASSERT_NOT_NULL(value.ptr);
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(&value));
tc_string_free(&value);
udas = tc_task_get_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
@@ -473,7 +473,7 @@ static void test_task_udas(void) {
tc_string_borrow("ns"),
tc_string_borrow("u1")));
TEST_ASSERT_NULL(tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1")));
TEST_ASSERT_NULL(tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1")).ptr);
TEST_ASSERT_EQUAL(TC_RESULT_OK,
tc_task_remove_uda(task,
@@ -483,24 +483,24 @@ static void test_task_udas(void) {
udas = tc_task_get_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
TEST_ASSERT_EQUAL(1, udas.len);
TEST_ASSERT_EQUAL_STRING("", tc_string_content(udas.items[0].ns));
TEST_ASSERT_EQUAL_STRING("leg1", tc_string_content(udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(udas.items[0].value));
TEST_ASSERT_EQUAL_STRING("", tc_string_content(&udas.items[0].ns));
TEST_ASSERT_EQUAL_STRING("leg1", tc_string_content(&udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(&udas.items[0].value));
tc_uda_list_free(&udas);
udas = tc_task_get_legacy_udas(task);
TEST_ASSERT_NOT_NULL(udas.items);
TEST_ASSERT_EQUAL(1, udas.len);
TEST_ASSERT_NULL(udas.items[0].ns);
TEST_ASSERT_EQUAL_STRING("leg1", tc_string_content(udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(udas.items[0].value));
TEST_ASSERT_NULL(udas.items[0].ns.ptr);
TEST_ASSERT_EQUAL_STRING("leg1", tc_string_content(&udas.items[0].key));
TEST_ASSERT_EQUAL_STRING("legv", tc_string_content(&udas.items[0].value));
tc_uda_list_free(&udas);
TEST_ASSERT_EQUAL(TC_RESULT_OK,
tc_task_remove_legacy_uda(task,
tc_string_borrow("leg1")));
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")));
TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1")).ptr);
TEST_ASSERT_EQUAL(TC_RESULT_OK,
tc_task_remove_legacy_uda(task,
@@ -523,8 +523,8 @@ static void test_task_udas(void) {
static void tckvlist_assert_key(TCKVList *list, char *key, char *value) {
TEST_ASSERT_NOT_NULL(list);
for (size_t i = 0; i < list->len; i++) {
if (0 == strcmp(tc_string_content(list->items[i].key), key)) {
TEST_ASSERT_EQUAL_STRING(value, tc_string_content(list->items[i].value));
if (0 == strcmp(tc_string_content(&list->items[i].key), key)) {
TEST_ASSERT_EQUAL_STRING(value, tc_string_content(&list->items[i].value));
return;
}
}
@@ -534,7 +534,7 @@ static void tckvlist_assert_key(TCKVList *list, char *key, char *value) {
// get_tags returns the list of tags
static void test_task_taskmap(void) {
TCReplica *rep = tc_replica_new_in_memory();
TEST_ASSERT_NULL(tc_replica_error(rep));
TEST_ASSERT_NULL(tc_replica_error(rep).ptr);
TCTask *task = tc_replica_new_task(rep, TC_STATUS_PENDING, tc_string_borrow("my task"));
TEST_ASSERT_NOT_NULL(task);

View File

@@ -22,11 +22,11 @@ static void test_uuid_to_buf(void) {
// converting UUIDs to a buf works
static void test_uuid_to_str(void) {
TCUuid u = tc_uuid_nil();
TCString *s = tc_uuid_to_str(u);
TCString s = tc_uuid_to_str(u);
TEST_ASSERT_EQUAL_STRING(
"00000000-0000-0000-0000-000000000000",
tc_string_content(s));
tc_string_free(s);
tc_string_content(&s));
tc_string_free(&s);
}
// converting valid UUIDs from string works