MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / TEST_NAME

Function TEST_NAME

test/tdb2_test.cpp:46–132  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

44
45////////////////////////////////////////////////////////////////////////////////
46int TEST_NAME(int, char**) {
47 UnitTest t(12);
48 Context context;
49 Context::setContext(&context);
50
51 // Ensure environment has no influence.
52 unsetenv("TASKDATA");
53 unsetenv("TASKRC");
54
55 try {
56 cleardb();
57
58 // Set the context to allow GC.
59 context.config.set("gc", 1);
60 context.config.set("debug", 1);
61
62 context.tdb2.open_replica(".", /*create_if_missing=*/true, /*read_write=*/true);
63
64 // Try reading an empty database.
65 std::vector<Task> pending = context.tdb2.pending_tasks();
66 std::vector<Task> completed = context.tdb2.completed_tasks();
67 int num_reverts_possible = context.tdb2.num_reverts_possible();
68 int num_local_changes = context.tdb2.num_local_changes();
69
70 t.is((int)pending.size(), 0, "TDB2 Read empty pending");
71 t.is((int)completed.size(), 0, "TDB2 Read empty completed");
72 t.is((int)num_reverts_possible, 0, "TDB2 Read empty undo");
73 t.is((int)num_local_changes, 0, "TDB2 Read empty backlog");
74
75 // Add a task.
76 Task task(R"([description:"description" name:"value"])");
77 context.tdb2.add(task);
78
79 pending = context.tdb2.pending_tasks();
80 completed = context.tdb2.completed_tasks();
81 num_reverts_possible = context.tdb2.num_reverts_possible();
82 num_local_changes = context.tdb2.num_local_changes();
83
84 t.is((int)pending.size(), 1, "TDB2 after add, 1 pending task");
85 t.is((int)completed.size(), 0, "TDB2 after add, 0 completed tasks");
86 t.is((int)num_reverts_possible, 1, "TDB2 after add, 1 revert possible");
87 t.is((int)num_local_changes, 6, "TDB2 after add, 6 local changes");
88
89 task.set("description", "This is a test");
90 context.tdb2.modify(task);
91
92 pending = context.tdb2.pending_tasks();
93 completed = context.tdb2.completed_tasks();
94 num_reverts_possible = context.tdb2.num_reverts_possible();
95 num_local_changes = context.tdb2.num_local_changes();
96
97 t.is((int)pending.size(), 1, "TDB2 after set, 1 pending task");
98 t.is((int)completed.size(), 0, "TDB2 after set, 0 completed tasks");
99 t.is((int)num_reverts_possible, 1, "TDB2 after set, 1 revert possible");
100
101 // At this point, there may be 7 or 8 local changes, depending on whether
102 // the `modified` property changed between the `add` and `modify`
103 // invocation. That only happens if the clock ticks over to the next second

Callers

nothing calls this directly

Calls 12

cleardbFunction · 0.85
setMethod · 0.80
open_replicaMethod · 0.80
pending_tasksMethod · 0.80
completed_tasksMethod · 0.80
num_reverts_possibleMethod · 0.80
num_local_changesMethod · 0.80
isMethod · 0.80
okMethod · 0.80
addMethod · 0.45
modifyMethod · 0.45
diagMethod · 0.45

Tested by

no test coverage detected