TCString as PassByValue
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user