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) {