Merge branch '2.0.0' of tasktools.org:task into 2.0.0

This commit is contained in:
Paul Beckingham
2011-04-13 00:22:03 -04:00
15 changed files with 2180 additions and 275 deletions

View File

@@ -49,8 +49,8 @@
#include <algorithm>
#include <iostream>
#include "Context.h"
#include "API.h"
#include <Context.h>
#include <API.h>
extern Context context;
Task* the_task = NULL;
@@ -122,14 +122,6 @@ static int api_task_feature (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
static int api_task_aliases ()
{
return {};
}
*/
////////////////////////////////////////////////////////////////////////////////
// Returns values from .taskrc, by name.
static int api_task_get_config (lua_State* L)
@@ -139,54 +131,6 @@ static int api_task_get_config (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
-- Temporarily sets .taskrc values, by name.
static int api_task_set_config (name, value)
{
}
////////////////////////////////////////////////////////////////////////////////
-- Returns an internationalized string, by string ID, from the appropriate
-- locale-based strings file.
static int api_task_i18n_string (id)
{
return "le foo"
}
////////////////////////////////////////////////////////////////////////////////
-- Returns a list of tips, from the appropriate locale-based tips file.
static int api_task_i18n_tips ()
{
return {}
}
////////////////////////////////////////////////////////////////////////////////
-- Returns the name of the current command.
static int api_task_get_command ()
{
return "list"
}
////////////////////////////////////////////////////////////////////////////////
-- Returns a list of string messages generated so far.
static int api_task_get_header_messages ()
{
return {}
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_footnote_messages ()
{
return {}
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_debug_messages (lua_State* L)
{
}
*/
////////////////////////////////////////////////////////////////////////////////
static int api_task_header_message (lua_State* L)
{
@@ -222,33 +166,6 @@ static int api_task_exit (lua_State* L)
return 0;
}
/*
////////////////////////////////////////////////////////////////////////////////
-- Shuts off the hook system for any subsequent hook calls for this command.
static int api_task_inhibit_further_hooks ()
{
}
////////////////////////////////////////////////////////////////////////////////
-- Returns a table that contains a complete copy of the task.
static int api_task_get (lua_State* L)
{
return 1;
}
////////////////////////////////////////////////////////////////////////////////
-- Creates a new task from the data specified in the table t.
static int api_task_add (t)
{
}
////////////////////////////////////////////////////////////////////////////////
-- Modifies the task described in the table t.
static int api_task_modify (t)
{
}
*/
////////////////////////////////////////////////////////////////////////////////
// -- 'id' is the task id passed to the hook function. Date attributes are
// -- returned as a numeric epoch offset. Tags and annotations are returned
@@ -274,14 +191,6 @@ static int api_task_get_description (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_annotations (id)
{
return task.annotations
}
*/
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_project (lua_State* L)
{
@@ -304,14 +213,6 @@ static int api_task_get_priority (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_tags (id)
{
return task.tags
}
*/
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_status (lua_State* L)
{
@@ -391,14 +292,6 @@ static int api_task_get_end (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_recur (id)
{
return task.recur
}
*/
////////////////////////////////////////////////////////////////////////////////
static int api_task_get_until (lua_State* L)
{
@@ -433,77 +326,6 @@ static int api_task_get_wait (lua_State* L)
return 1;
}
/*
////////////////////////////////////////////////////////////////////////////////
-- 'id' is the task id passed to the hook function. Date attributes are
-- expected as numeric epoch offsets. Tags and annotations are expected
-- as tables. A nil value indicates a missing value.
static int api_task_set_description (id, value)
{
task.description = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_annotations (id, value)
{
task.annotations = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_project (id, value)
{
task.project = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_priority (id, value)
{
task.priority = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_tags (id, value)
{
task.tags = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_status (id, value)
{
task.status = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_due (id, value)
{
task.due_date = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_start (id, value)
{
task.start_date = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_recur (id, value)
{
task.recur = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_until (id, value)
{
task.until_date = value
}
////////////////////////////////////////////////////////////////////////////////
static int api_task_set_wait (id, value)
{
task.wait_date = value
}
*/
////////////////////////////////////////////////////////////////////////////////
API::API ()
: L (NULL)
@@ -532,62 +354,22 @@ void API::initialize ()
lua_pushcfunction (L, api_task_lua_version); lua_setglobal (L, "task_lua_version");
lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os");
lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature");
/*
lua_pushcfunction (L, api_task_aliases); lua_setglobal (L, "task_aliases");
*/
lua_pushcfunction (L, api_task_get_config); lua_setglobal (L, "task_get_config");
/*
lua_pushcfunction (L, api_task_set_config); lua_setglobal (L, "task_set_config");
lua_pushcfunction (L, api_task_i18n_string); lua_setglobal (L, "task_i18n_string");
lua_pushcfunction (L, api_task_i18n_tips); lua_setglobal (L, "task_i18n_tips");
lua_pushcfunction (L, api_task_get_command); lua_setglobal (L, "task_get_command");
lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "task_get_header_messages");
lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "task_get_footnote_messages");
lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "task_get_debug_messages");
*/
lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message");
lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message");
lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message");
lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit");
/*
lua_pushcfunction (L, api_task_inhibit_further_hooks); lua_setglobal (L, "task_inhibit_further_hooks");
lua_pushcfunction (L, api_task_get); lua_setglobal (L, "task_get");
lua_pushcfunction (L, api_task_add); lua_setglobal (L, "task_add");
lua_pushcfunction (L, api_task_modify); lua_setglobal (L, "task_modify");
*/
lua_pushcfunction (L, api_task_get_uuid); lua_setglobal (L, "task_get_uuid");
lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "task_get_description");
/*
lua_pushcfunction (L, api_task_get_annotations); lua_setglobal (L, "task_get_annotations");
*/
lua_pushcfunction (L, api_task_get_project); lua_setglobal (L, "task_get_project");
lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "task_get_priority");
/*
lua_pushcfunction (L, api_task_get_tags); lua_setglobal (L, "task_get_tags");
*/
lua_pushcfunction (L, api_task_get_status); lua_setglobal (L, "task_get_status");
lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "task_get_due");
lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "task_get_entry");
lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "task_get_start");
lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "task_get_end");
/*
lua_pushcfunction (L, api_task_get_recur); lua_setglobal (L, "task_get_recur");
*/
lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "task_get_until");
lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "task_get_wait");
/*
lua_pushcfunction (L, api_task_set_description); lua_setglobal (L, "task_set_description");
lua_pushcfunction (L, api_task_set_annotations); lua_setglobal (L, "task_set_annotations");
lua_pushcfunction (L, api_task_set_project); lua_setglobal (L, "task_set_project");
lua_pushcfunction (L, api_task_set_priority); lua_setglobal (L, "task_set_priority");
lua_pushcfunction (L, api_task_set_tags); lua_setglobal (L, "task_set_tags");
lua_pushcfunction (L, api_task_set_status); lua_setglobal (L, "task_set_status");
lua_pushcfunction (L, api_task_set_due); lua_setglobal (L, "task_set_due");
lua_pushcfunction (L, api_task_set_start); lua_setglobal (L, "task_set_start");
lua_pushcfunction (L, api_task_set_recur); lua_setglobal (L, "task_set_recur");
lua_pushcfunction (L, api_task_set_until); lua_setglobal (L, "task_set_until");
lua_pushcfunction (L, api_task_set_wait); lua_setglobal (L, "task_set_wait");
*/
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -32,13 +32,13 @@
#include <vector>
#include <string>
#include "Task.h"
#include <Task.h>
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
class API

View File

@@ -3,21 +3,21 @@ include_directories (${CMAKE_SOURCE_DIR}/src
set (task_SRCS API.cpp API.h Att.cpp Att.h Cmd.cpp Cmd.h Color.cpp Color.h
Config.cpp Config.h Context.cpp Context.h Date.cpp Date.h
Directory.cpp Directory.h Duration.cpp Duration.h File.cpp
File.h Filter.cpp Filter.h feedback.cpp Grid.cpp Grid.h Hooks.cpp
Hooks.h JSON.cpp JSON.h Keymap.cpp Keymap.h Location.cpp
Location.h Nibbler.cpp Nibbler.h Path.cpp Path.h Permission.cpp
Permission.h Record.cpp Record.h Rectangle.cpp Rectangle.h
Sequence.cpp Sequence.h Subst.cpp Subst.h TDB.cpp TDB.h Table.cpp
Table.h Task.cpp Task.h Taskmod.cpp Taskmod.h Thread.cpp Thread.h
Timer.cpp Timer.h Transport.cpp Transport.h TransportSSH.cpp
TransportSSH.h TransportRSYNC.cpp TransportRSYNC.h
TransportCurl.cpp TransportCurl.h Tree.cpp Tree.h burndown.cpp
command.cpp custom.cpp dependency.cpp diag.cpp edit.cpp
export.cpp history.cpp i18n.h import.cpp interactive.cpp
recur.cpp report.cpp rules.cpp rx.cpp rx.h text.cpp text.h
utf8.cpp utf8.h util.cpp util.h Uri.cpp Uri.h Variant.cpp
Variant.h)
Directory.cpp Directory.h DOM.cpp DOM.h Duration.cpp Duration.h
File.cpp File.h Filter.cpp Filter.h feedback.cpp Grid.cpp Grid.h
Hooks.cpp Hooks.h JSON.cpp JSON.h Keymap.cpp Keymap.h
Location.cpp Location.h Nibbler.cpp Nibbler.h Path.cpp Path.h
Permission.cpp Permission.h Record.cpp Record.h Rectangle.cpp
Rectangle.h Sequence.cpp Sequence.h Subst.cpp Subst.h TDB.cpp
TDB.h Table.cpp TDB2.cpp TDB2.h Table.h Task.cpp Task.h
Taskmod.cpp Taskmod.h Thread.cpp Thread.h Timer.cpp Timer.h
Transport.cpp Transport.h TransportSSH.cpp TransportSSH.h
TransportRSYNC.cpp TransportRSYNC.h TransportCurl.cpp
TransportCurl.h Tree.cpp Tree.h burndown.cpp command.cpp
custom.cpp dependency.cpp diag.cpp edit.cpp export.cpp
history.cpp i18n.h import.cpp interactive.cpp recur.cpp
report.cpp rules.cpp rx.cpp rx.h text.cpp text.h utf8.cpp utf8.h
util.cpp util.h Uri.cpp Uri.h Variant.cpp Variant.h)
add_library (task STATIC ${task_SRCS})
add_executable (task_executable main.cpp)

View File

@@ -51,10 +51,12 @@ Context::Context ()
, subst ()
, task ()
, tdb ()
, tdb2 ()
, program ("")
, file_override ("")
, var_overrides ("")
, cmd ()
, dom ()
, inShadow (false)
, terminal_width (0)
, terminal_height (0)

View File

@@ -35,7 +35,9 @@
#include "Cmd.h"
#include "Task.h"
#include "TDB.h"
#include "TDB2.h"
#include "Hooks.h"
#include "DOM.h"
class Context
{
@@ -50,7 +52,6 @@ public:
void initialize2 (int, char**); // all startup
void initialize (); // for reinitializing
int run (); // task classic
int interactive (); // task interactive (not implemented)
int dispatch (std::string&); // command handler dispatch
void shadow (); // shadow file update
@@ -84,6 +85,7 @@ public:
Subst subst;
Task task;
TDB tdb;
TDB2 tdb2;
std::string program;
std::vector <std::string> args;
std::string file_override;
@@ -93,6 +95,7 @@ public:
std::vector <std::string> tagAdditions;
std::vector <std::string> tagRemovals;
Hooks hooks;
DOM dom;
std::vector <std::string> headers;
std::vector <std::string> footnotes;

96
src/DOM.cpp Normal file
View File

@@ -0,0 +1,96 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <DOM.h>
////////////////////////////////////////////////////////////////////////////////
DOM::DOM ()
{
}
////////////////////////////////////////////////////////////////////////////////
DOM::~DOM ()
{
}
////////////////////////////////////////////////////////////////////////////////
const int DOM::getInteger (const std::string& name)
{
return 0;
}
////////////////////////////////////////////////////////////////////////////////
const double DOM::getReal (const std::string& name)
{
return 0.0;
}
////////////////////////////////////////////////////////////////////////////////
const bool DOM::getBoolean (const std::string& name)
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
const time_t DOM::getDate (const std::string& name)
{
return 0;
}
////////////////////////////////////////////////////////////////////////////////
const std::string DOM::get (const std::string& name)
{
return "";
}
////////////////////////////////////////////////////////////////////////////////
void DOM::set (const std::string& name, const bool value)
{
}
////////////////////////////////////////////////////////////////////////////////
void DOM::set (const std::string& name, const int value)
{
}
////////////////////////////////////////////////////////////////////////////////
void DOM::set (const std::string& name, const double value)
{
}
////////////////////////////////////////////////////////////////////////////////
void DOM::set (const std::string& name, const time_t value)
{
}
////////////////////////////////////////////////////////////////////////////////
void DOM::set (const std::string& name, const std::string& value)
{
}
////////////////////////////////////////////////////////////////////////////////

55
src/DOM.h Normal file
View File

@@ -0,0 +1,55 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_DOM
#define INCLUDED_DOM
#include <string>
#include <time.h>
class DOM
{
public:
DOM ();
~DOM ();
const int getInteger (const std::string&);
const double getReal (const std::string&);
const bool getBoolean (const std::string&);
const time_t getDate (const std::string&);
const std::string get (const std::string&);
void set (const std::string&, const bool);
void set (const std::string&, const int);
void set (const std::string&, const double);
void set (const std::string&, const time_t);
void set (const std::string&, const std::string&);
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

View File

@@ -73,6 +73,22 @@ Hook& Hook::operator= (const Hook& other)
////////////////////////////////////////////////////////////////////////////////
Hooks::Hooks ()
{
/*
// New 2.x hooks.
validTaskEvents.push_back ("on-task-add");
validTaskEvents.push_back ("on-task-modify");
validTaskEvents.push_back ("on-task-complete");
validTaskEvents.push_back ("on-task-delete");
validProgramEvents.push_back ("on-launch");
validProgramEvents.push_back ("on-exit");
validProgramEvents.push_back ("on-file-read");
validProgramEvents.push_back ("on-file-write");
validProgramEvents.push_back ("on-synch");
validProgramEvents.push_back ("on-gc");
*/
// Obsolete 1.x hooks.
validProgramEvents.push_back ("post-start");
validProgramEvents.push_back ("post-commit");
validProgramEvents.push_back ("pre-fatal-error");

1696
src/TDB2.cpp Normal file

File diff suppressed because it is too large Load Diff

112
src/TDB2.h Normal file
View File

@@ -0,0 +1,112 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_TDB2
#define INCLUDED_TDB2
#include <map>
#include <vector>
#include <string>
class TDB2
{
public:
private:
};
/*
#include "Location.h"
#include "Filter.h"
#include "Task.h"
// Length of longest line.
#define T_LINE_MAX 32768
class TDB
{
public:
TDB (); // Default constructor
~TDB (); // Destructor
TDB (const TDB&);
TDB& operator= (const TDB&);
void clear ();
void location (const std::string&);
void lock (bool lockFile = true);
void unlock ();
int load (std::vector <Task>&, Filter&);
int loadPending (std::vector <Task>&, Filter&);
int loadCompleted (std::vector <Task>&, Filter&);
const std::vector <Task>& getAllPending ();
const std::vector <Task>& getAllNew ();
const std::vector <Task>& getAllCompleted ();
const std::vector <Task>& getAllModified ();
void add (const Task&); // Single task add to pending
void update (const Task&); // Single task update to pending
int commit (); // Write out all tasks
int gc (); // Clean up pending
int nextId ();
void undo ();
void merge (const std::string&);
std::string uuid (int) const;
int id (const std::string&) const;
private:
FILE* openAndLock (const std::string&);
void writeUndo (const Task&, FILE*);
void writeUndo (const Task&, const Task&, FILE*);
bool uuidAlreadyUsed (const std::string&);
bool uuidAlreadyUsed (const std::string&, const std::vector <Task>&);
private:
std::vector <Location> mLocations;
bool mLock;
bool mAllOpenAndLocked;
int mId;
std::vector <Task> mPending; // Contents of pending.data
std::vector <Task> mCompleted; // Contents of pending.data
std::vector <Task> mNew; // Uncommitted new tasks
std::vector <Task> mModified; // Uncommitted modified tasks
std::map <int, std::string> mI2U; // ID -> UUID map
std::map <std::string, int> mU2I; // UUID -> ID map
};
*/
#endif
////////////////////////////////////////////////////////////////////////////////

View File

@@ -25,26 +25,14 @@
//
////////////////////////////////////////////////////////////////////////////////
//#include <iostream>
#include <sstream>
//#include <pwd.h>
#include <stdio.h>
#include <sys/ioctl.h>
//#include <stdlib.h>
//#include <string.h>
#include "Context.h"
//#include "text.h"
//#include "util.h"
#include "main.h"
#include "i18n.h"
#include "../cmake.h"
////////////////////////////////////////////////////////////////////////////////
int Context::interactive ()
{
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int Context::getWidth ()
{

View File

@@ -64,29 +64,7 @@ int main (int argc, char** argv)
try
{
context.initialize (argc, argv);
/* From old 2.0.0
std::string::size_type task = context.program.find ("/task");
std::string::size_type t = context.program.find ("/t");
std::string::size_type cal = context.program.find ("/cal");
if (context.program != "task" &&
context.program != "t" &&
context.program != "cal" &&
(task == std::string::npos || context.program.length () != task + 5) &&
(t == std::string::npos || context.program.length () != t + 2) &&
(cal == std::string::npos || context.program.length () != cal + 4))
status = context.handleInteractive ();
else
status = context.run ();
*/
std::string::size_type itask = context.program.find ("/itask");
if (context.program == "itask" ||
(itask != std::string::npos && context.program.length () == itask + 5))
status = context.interactive ();
else
status = context.run ();
status = context.run ();
}
catch (std::string& error)

1
test/.gitignore vendored
View File

@@ -27,6 +27,7 @@ t.benchmark.t
t.t
taskmod.t
tdb.t
tdb2.t
text.t
transport.t
tree.t

View File

@@ -4,6 +4,7 @@ include_directories (${CMAKE_SOURCE_DIR}/src
${TASK_INCLUDE_DIRS})
set (test_SRCS date.t t.t tdb.t duration.t t.benchmark.t text.t autocomplete.t
tdb2.t
seq.t record.t att.t subst.t nibbler.t filt.t cmd.t config.t
util.t color.t list.t path.t file.t grid.t directory.t rx.t
taskmod.t rectangle.t tree.t tree2.t uri.t json.t variant.t)

175
test/tdb2.t.cpp Normal file
View File

@@ -0,0 +1,175 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <unistd.h>
#include "main.h"
#include "test.h"
Context context;
////////////////////////////////////////////////////////////////////////////////
void get (std::vector <Task>& pending, std::vector <Task>& completed)
{
TDB tdb;
tdb.location (".");
tdb.lock ();
tdb.loadPending (pending, context.filter);
tdb.loadCompleted (completed, context.filter);
tdb.unlock ();
}
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (1);
try
{
t.pass ("sample");
/*
// Remove any residual test file.
unlink ("./pending.data");
unlink ("./completed.data");
unlink ("./undo.data");
// Set the context to allow GC.
context.config.set ("gc", "on");
// Try reading an empty database.
Filter filter;
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.
TDB tdb;
tdb.location (".");
tdb.lock ();
Task task ("[name:\"value\"]");
tdb.add (task); // P0 C0 N1 M0
tdb.unlock ();
pending.clear ();
completed.clear ();
get (pending, completed);
t.ok (pending.size () == 0, "TDB add -> no commit -> empty");
t.ok (completed.size () == 0, "TDB add -> no commit -> empty");
// Add with commit.
tdb.lock ();
tdb.add (task); // P0 C0 N1 M0
tdb.commit (); // P1 C0 N0 M0
tdb.unlock ();
get (pending, completed);
t.ok (pending.size () == 1, "TDB add -> commit -> saved");
t.is (pending[0].get ("name"), "value", "TDB load name=value");
t.is (pending[0].id, 1, "TDB load verification id=1");
t.ok (completed.size () == 0, "TDB add -> commit -> saved");
// Update with commit.
pending.clear ();
completed.clear ();
tdb.lock ();
tdb.load (all, context.filter);
all[0].set ("name", "value2");
tdb.update (all[0]); // P1 C0 N0 M1
tdb.commit (); // P1 C0 N0 M0
tdb.unlock ();
pending.clear ();
completed.clear ();
get (pending, completed);
t.ok (all.size () == 1, "TDB update -> commit -> saved");
t.is (all[0].get ("name"), "value2", "TDB load name=value2");
t.is (all[0].id, 1, "TDB load verification id=1");
// GC.
all.clear ();
tdb.lock ();
tdb.loadPending (all, context.filter);
all[0].setStatus (Task::completed);
tdb.update (all[0]); // P1 C0 N0 M1
Task t2 ("[foo:\"bar\" status:\"pending\"]");
tdb.add (t2); // P1 C0 N1 M1
tdb.commit ();
tdb.unlock ();
pending.clear ();
completed.clear ();
get (pending, completed);
t.is (pending.size (), (size_t)2, "TDB before gc pending #2");
t.is (pending[0].id, 1, "TDB before gc pending id 1");
t.is (pending[0].getStatus (), Task::completed, "TDB before gc pending status completed");
t.is (pending[1].id, 2, "TDB before gc pending id 2");
t.is (pending[1].getStatus (), Task::pending, "TDB before gc pending status pending");
t.is (completed.size (), (size_t)0, "TDB before gc completed 0");
tdb.gc (); // P1 C1 N0 M0
pending.clear ();
completed.clear ();
get (pending, completed);
t.is (pending.size (), (size_t)1, "TDB after gc pending #1");
t.is (pending[0].id, 1, "TDB after gc pending id 2");
t.is (pending[0].getStatus (), Task::pending, "TDB after gc pending status pending");
t.is (completed.size (), (size_t)1, "TDB after gc completed #1");
t.is (completed[0].getStatus (), Task::completed, "TDB after gc completed status completed");
*/
}
catch (std::string& error)
{
t.diag (error);
return -1;
}
catch (...)
{
t.diag ("Unknown error.");
return -2;
}
unlink ("./pending.data");
unlink ("./completed.data");
unlink ("./undo.data");
return 0;
}
////////////////////////////////////////////////////////////////////////////////