- Corrected maintenance of the _lines vector during TDB2::add_line.
- Implemented TDB2::modify_task undo maintenance.
- Added unit tests for TDB2.  Which fail.
This commit is contained in:
Paul Beckingham 2011-08-27 16:33:19 -04:00
parent ab931b6af2
commit 0eec42ce4a
2 changed files with 60 additions and 30 deletions

View file

@ -134,6 +134,7 @@ void TF2::add_line (const std::string& line)
{ {
// std::cout << "# TF2::add_line " << _file._data << "\n"; // std::cout << "# TF2::add_line " << _file._data << "\n";
_lines.push_back (line);
_added_lines.push_back (line); _added_lines.push_back (line);
_dirty = true; _dirty = true;
} }
@ -466,17 +467,17 @@ void TDB2::modify (const Task& task)
else else
pending.modify_task (task); pending.modify_task (task);
// TODO Add undo data lines:
// time <time> // time <time>
// old <task> // old <task>
// new <task> // new <task>
// --- // ---
/* Task original;
undo.add_line ("time " + format (time (NULL)) + "\n"); get (task.get ("uuid"), original);
undo.add_line ("time " + Date ().toEpochString () + "\n");
undo.add_line ("old " + original.composeF4 ()); undo.add_line ("old " + original.composeF4 ());
undo.add_line ("new " + task.composeF4 ()); undo.add_line ("new " + task.composeF4 ());
undo.add_line ("---\n"); undo.add_line ("---\n");
*/
// Add modified task to backlog. // Add modified task to backlog.
backlog.modify_task (task); backlog.modify_task (task);

View file

@ -32,44 +32,73 @@
Context context; Context context;
////////////////////////////////////////////////////////////////////////////////
void get (std::vector <Task>& pending, std::vector <Task>& completed)
{
TDB tdb;
tdb.location (".");
tdb.lock ();
tdb.loadPending (pending);
tdb.loadCompleted (completed);
tdb.unlock ();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (1); UnitTest t (15);
try try
{ {
t.pass ("sample"); // Remove any residual test files.
/* rmdir ("./extensions");
// Remove any residual test file.
unlink ("./pending.data"); unlink ("./pending.data");
unlink ("./completed.data"); unlink ("./completed.data");
unlink ("./undo.data"); unlink ("./undo.data");
unlink ("./backlog.data");
unlink ("./synch.key");
// Set the context to allow GC. // Set the context to allow GC.
context.config.set ("gc", "on"); context.config.set ("gc", "on");
// Try reading an empty database. TDB2 tdb2;
Filter filter; tdb2.set_location (".");
std::vector <Task> all;
std::vector <Task> pending;
std::vector <Task> completed;
get (pending, completed);
t.ok (pending.size () == 0, "TDB Read empty pending");
t.ok (completed.size () == 0, "TDB Read empty completed");
// Add without commit. // Try reading an empty database.
std::vector <Task> pending = tdb2.pending.get_tasks ();
std::vector <Task> completed = tdb2.completed.get_tasks ();
std::vector <std::string> undo = tdb2.undo.get_lines ();
std::vector <std::string> backlog = tdb2.backlog.get_lines ();
std::vector <std::string> synch_key = tdb2.synch_key.get_lines ();
t.is ((int) pending.size (), 0, "TDB2 Read empty pending");
t.is ((int) completed.size (), 0, "TDB2 Read empty completed");
t.is ((int) undo.size (), 0, "TDB2 Read empty undo");
t.is ((int) backlog.size (), 0, "TDB2 Read empty backlog");
t.is ((int) synch_key.size (), 0, "TDB2 Read empty synch_key");
// Add a task.
Task task ("[name:\"value\"]");
tdb2.add (task);
pending = tdb2.pending.get_tasks ();
completed = tdb2.completed.get_tasks ();
undo = tdb2.undo.get_lines ();
backlog = tdb2.backlog.get_lines ();
synch_key = tdb2.synch_key.get_lines ();
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
t.is ((int) undo.size (), 3, "TDB2 after add, 3 undo lines");
t.is ((int) backlog.size (), 1, "TDB2 after add, 1 backlog line");
t.is ((int) synch_key.size (), 0, "TDB2 after add, 0 synch_key");
task.set ("description", "This is a test");
tdb2.modify (task);
pending = tdb2.pending.get_tasks ();
completed = tdb2.completed.get_tasks ();
undo = tdb2.undo.get_lines ();
backlog = tdb2.backlog.get_lines ();
synch_key = tdb2.synch_key.get_lines ();
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
t.is ((int) undo.size (), 7, "TDB2 after add, 7 undo lines");
t.is ((int) backlog.size (), 2, "TDB2 after add, 2 backlog line");
t.is ((int) synch_key.size (), 0, "TDB2 after add, 0 synch_key");
/*
TDB tdb; TDB tdb;
tdb.location ("."); tdb.location (".");
tdb.lock (); tdb.lock ();
@ -101,7 +130,7 @@ int main (int argc, char** argv)
completed.clear (); completed.clear ();
tdb.lock (); tdb.lock ();
tdb.load (all, context.filter); tdb.load (all);
all[0].set ("name", "value2"); all[0].set ("name", "value2");
tdb.update (all[0]); // P1 C0 N0 M1 tdb.update (all[0]); // P1 C0 N0 M1
tdb.commit (); // P1 C0 N0 M0 tdb.commit (); // P1 C0 N0 M0
@ -119,7 +148,7 @@ int main (int argc, char** argv)
all.clear (); all.clear ();
tdb.lock (); tdb.lock ();
tdb.loadPending (all, context.filter); tdb.loadPending (all);
all[0].setStatus (Task::completed); all[0].setStatus (Task::completed);
tdb.update (all[0]); // P1 C0 N0 M1 tdb.update (all[0]); // P1 C0 N0 M1
Task t2 ("[foo:\"bar\" status:\"pending\"]"); Task t2 ("[foo:\"bar\" status:\"pending\"]");