diff --git a/src/DOM.cpp b/src/DOM.cpp index b400ad16c..042314bb0 100644 --- a/src/DOM.cpp +++ b/src/DOM.cpp @@ -25,7 +25,18 @@ // //////////////////////////////////////////////////////////////////////////////// +#include #include +#include "../cmake.h" + +#ifdef HAVE_LIBLUA +extern "C" +{ + #include +} +#endif + +extern Context context; //////////////////////////////////////////////////////////////////////////////// DOM::DOM () @@ -62,8 +73,67 @@ const time_t DOM::getDate (const std::string& name) } //////////////////////////////////////////////////////////////////////////////// +// TODO . <-- context.tdb2 +// TODO . <-- context.tdb2 +// rc. <-- context.config +// TODO report.. <-- context.reports +// TODO stats. <-- context.stats +// +// system. <-- context.system +// system.version +// system.lua.version +// system.os const std::string DOM::get (const std::string& name) { + int len = name.length (); + + // rc. --> context.config + if (len > 3 && + name.substr (0, 3) == "rc.") + { + return context.config.get (name.substr (3)); + } + + // TODO . + // TODO . + // TODO report. + // TODO stats. + + // system. --> Implement locally. + else if (len > 7 && + name.substr (0, 7) == "system.") + { + // Taskwarrior version number. + if (name.substr (7) == "version") + return VERSION; + +#ifdef HAVE_LIBLUA + // Lua version number. + else if (name.substr (7) == "lua.version") + return LUA_RELEASE; +#endif + + // OS type. + else if (name.substr (7) == "os") +#if defined (DARWIN) + return "Darwin"; +#elif defined (SOLARIS) + return "Solaris"; +#elif defined (CYGWIN) + return "Cygwin"; +#elif defined (OPENBSD) + return "OpenBSD"; +#elif defined (HAIKU) + return "Haiku"; +#elif defined (FREEBSD) + return "FreeBSD"; +#elif defined (LINUX) + return "Linux"; +#else + return ""; +#endif + } + return ""; } diff --git a/test/.gitignore b/test/.gitignore index b512d39c0..27743f6fb 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -8,6 +8,7 @@ color.t config.t date.t directory.t +dom.t duration.t file.t filt.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1fcbdfc68..ab8f3c878 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,11 +3,11 @@ include_directories (${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/test ${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) +set (test_SRCS att.t autocomplete.t cmd.t color.t config.t date.t directory.t + dom.t duration.t file.t filt.t grid.t json.t list.t nibbler.t + path.t record.t rectangle.t rx.t seq.t subst.t t.benchmark.t t.t + taskmod.t tdb.t tdb2.t text.t tree.t tree2.t uri.t util.t + variant.t) add_custom_target (test ./run_all DEPENDS ${test_SRCS} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) diff --git a/test/dom.t.cpp b/test/dom.t.cpp new file mode 100644 index 000000000..78bd6faac --- /dev/null +++ b/test/dom.t.cpp @@ -0,0 +1,71 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include +#include "../cmake.h" +#include +#include + +#ifdef HAVE_LIBLUA +extern "C" +{ + #include +} +#endif + +Context context; + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (2); + + try + { + DOM dom; + + t.is (dom.get ("system.version"), VERSION, "DOM system.version -> VERSION"); + t.is (dom.get ("system.lua.version"), LUA_RELEASE, "DOM system.lua.version -> LUA_RELEASE"); + } + + catch (std::string& error) + { + t.diag (error); + return -1; + } + + catch (...) + { + t.diag ("Unknown error."); + return -2; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +