/////////////////////////////////////////////////////////////////////////// Tests for the basic cxxbridge functionality. This focuses on the methods with complex cxxbridge implementations, rather than those with complex Rust implementations but simple APIs, like sync.
| 42 | // complex cxxbridge implementations, rather than those with complex Rust |
| 43 | // implementations but simple APIs, like sync. |
| 44 | int TEST_NAME(int, char**) { |
| 45 | UnitTest t; |
| 46 | std::string str; |
| 47 | |
| 48 | auto replica = tc::new_replica_in_memory(); |
| 49 | auto uuid = tc::uuid_v4(); |
| 50 | auto uuid2 = tc::uuid_v4(); |
| 51 | t.is(uuid2str(uuid).size(), (size_t)36, "uuid string is the right length"); |
| 52 | |
| 53 | rust::Vec<tc::Operation> ops; |
| 54 | auto task = tc::create_task(uuid, ops); |
| 55 | t.is(uuid2str(task->get_uuid()), uuid2str(uuid), "new task has correct uuid"); |
| 56 | task->update("status", "pending", ops); |
| 57 | task->update("description", "a task", ops); |
| 58 | task->update("description", "a cool task", ops); |
| 59 | tc::add_undo_point(ops); |
| 60 | task->delete_task(ops); |
| 61 | |
| 62 | t.is(ops[0].is_create(), true, "ops[0] is create"); |
| 63 | t.is(uuid2str(ops[0].get_uuid()), uuid2str(uuid), "ops[0] has correct uuid"); |
| 64 | |
| 65 | t.is(ops[1].is_update(), true, "ops[1] is update"); |
| 66 | t.is(uuid2str(ops[1].get_uuid()), uuid2str(uuid), "ops[1] has correct uuid"); |
| 67 | ops[1].get_property(str); |
| 68 | t.is(str, "status", "ops[1] property is 'status'"); |
| 69 | t.ok(ops[1].get_value(str), "get_value succeeds"); |
| 70 | t.is(str, "pending", "ops[1] value is 'pending'"); |
| 71 | t.ok(!ops[1].get_old_value(str), "get_old_value has no old value"); |
| 72 | |
| 73 | t.is(ops[2].is_update(), true, "ops[2] is update"); |
| 74 | t.is(uuid2str(ops[2].get_uuid()), uuid2str(uuid), "ops[2] has correct uuid"); |
| 75 | ops[2].get_property(str); |
| 76 | t.is(str, "description", "ops[2] property is 'description'"); |
| 77 | t.ok(ops[2].get_value(str), "get_value succeeds"); |
| 78 | t.is(str, "a task", "ops[2] value is 'a task'"); |
| 79 | t.ok(!ops[2].get_old_value(str), "get_old_value has no old value"); |
| 80 | |
| 81 | t.is(ops[3].is_update(), true, "ops[3] is update"); |
| 82 | t.is(uuid2str(ops[3].get_uuid()), uuid2str(uuid), "ops[3] has correct uuid"); |
| 83 | ops[3].get_property(str); |
| 84 | t.is(str, "description", "ops[3] property is 'description'"); |
| 85 | t.ok(ops[3].get_value(str), "get_value succeeds"); |
| 86 | t.is(str, "a cool task", "ops[3] value is 'a cool task'"); |
| 87 | t.ok(ops[3].get_old_value(str), "get_old_value succeeds"); |
| 88 | t.is(str, "a task", "ops[3] old value is 'a task'"); |
| 89 | |
| 90 | t.is(ops[4].is_undo_point(), true, "ops[4] is undo_point"); |
| 91 | |
| 92 | t.is(ops[5].is_delete(), true, "ops[5] is delete"); |
| 93 | t.is(uuid2str(ops[5].get_uuid()), uuid2str(uuid), "ops[5] has correct uuid"); |
| 94 | auto old_task = ops[5].get_old_task(); |
| 95 | // old_task is in arbitrary order, so just check that status is in there. |
| 96 | bool found = false; |
| 97 | for (auto& pv : old_task) { |
| 98 | std::string p = static_cast<std::string>(pv.prop); |
| 99 | if (p == "status") { |
| 100 | std::string v = static_cast<std::string>(pv.value); |
| 101 | t.is(v, "pending", "old_task has status:pending"); |
nothing calls this directly
no test coverage detected