Unit Tests - Config

- Added unit tests for Config.  Why didn't I do this a year ago?
- Shut off old 1.7.0 code (gulp).
- Task now thoroughly broken, and only 1.8.0 can help.
This commit is contained in:
Paul Beckingham 2009-06-07 16:31:10 -04:00
parent d702ba8f24
commit 7a219c999e
8 changed files with 121 additions and 49 deletions

View file

@ -270,7 +270,7 @@ const std::string Config::get (
}
////////////////////////////////////////////////////////////////////////////////
bool Config::get (const std::string& key, bool default_value)
bool Config::get (const std::string& key, const bool default_value)
{
if ((*this).find (key) != (*this).end ())
{

View file

@ -44,7 +44,7 @@ public:
const std::string get (const char*, const char*);
const std::string get (const std::string&);
const std::string get (const std::string&, const std::string&);
bool get (const std::string&, bool);
bool get (const std::string&, const bool);
int get (const std::string&, const int);
double get (const std::string&, const double);
void set (const std::string&, const int);

View file

@ -57,49 +57,6 @@ Context::Context ()
#endif
}
////////////////////////////////////////////////////////////////////////////////
Context::Context (const Context& other)
{
throw std::string ("unimplemented Context::Context");
config = other.config;
filter = other.filter;
keymap = other.keymap;
sequence = other.sequence;
subst = other.subst;
task = other.task;
tdb = other.tdb;
stringtable = other.stringtable;
program = other.program;
args = other.args;
cmd = other.cmd;
messages = other.messages;
footnotes = other.footnotes;
}
////////////////////////////////////////////////////////////////////////////////
Context& Context::operator= (const Context& other)
{
throw std::string ("unimplemented Context::operator=");
if (this != &other)
{
config = other.config;
filter = other.filter;
keymap = other.keymap;
sequence = other.sequence;
subst = other.subst;
task = other.task;
tdb = other.tdb;
stringtable = other.stringtable;
program = other.program;
args = other.args;
cmd = other.cmd;
messages = other.messages;
footnotes = other.footnotes;
}
return *this;
}
////////////////////////////////////////////////////////////////////////////////
Context::~Context ()
{

View file

@ -41,8 +41,6 @@ class Context
{
public:
Context (); // Default constructor
Context (const Context&); // Copy constructor
Context& operator= (const Context&); // Assignment operator
~Context (); // Destructor
void initialize (int, char**); // all startup

View file

@ -310,6 +310,7 @@ int main (int argc, char** argv)
status = context.run ();
// start OBSOLETE
/*
TDB tdb;
std::string dataLocation = expandPath (context.config.get ("data.location"));
tdb.dataDirectory (dataLocation);
@ -332,6 +333,8 @@ int main (int argc, char** argv)
}
std::cout << runTaskCommand (context.args, tdb);
*/
// end OBSOLETE
}
catch (std::string& error)
@ -345,7 +348,6 @@ int main (int argc, char** argv)
std::cerr << context.stringtable.get (100, "Unknown error.") << std::endl;
return -2;
}
// end OBSOLETE
return status;
}

View file

@ -15,3 +15,4 @@ nibbler.t
subst.t
filt.t
cmd.t
config.t

View file

@ -1,6 +1,6 @@
PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
parse.t seq.t att.t stringtable.t record.t nibbler.t subst.t filt.t \
cmd.t
cmd.t config.t
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib
OBJECTS = ../TDB.o ../TDB2.o ../T.o ../T2.o ../parse.o ../text.o ../Date.o \
@ -73,3 +73,6 @@ filt.t: filt.t.o $(OBJECTS) test.o
cmd.t: cmd.t.o $(OBJECTS) test.o
g++ cmd.t.o $(OBJECTS) test.o $(LFLAGS) -o cmd.t
config.t: config.t.o $(OBJECTS) test.o
g++ config.t.o $(OBJECTS) test.o $(LFLAGS) -o config.t

111
src/tests/config.t.cpp Normal file
View file

@ -0,0 +1,111 @@
////////////////////////////////////////////////////////////////////////////////
// task - a command line task list manager.
//
// Copyright 2006 - 2009, Paul Beckingham.
// 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 <Context.h>
#include <test.h>
Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (18);
// void set (const std::string&, const int);
// int get (const std::string&, const int);
Config c;
c.set ("int1", 0);
t.is (c.get ("int1", 9), 0, "Config::set/get int");
c.set ("int2", 3);
t.is (c.get ("int2", 9), 3, "Config::set/get int");
c.set ("int3", -9);
t.is (c.get ("int3", 9), -9, "Config::set/get int");
// void set (const std::string&, const double);
// double get (const std::string&, const double);
c.set ("double1", 0.0);
t.is (c.get ("double1", 9.0), 0.0, "Config::set/get double");
c.set ("double2", 3.0);
t.is (c.get ("double2", 9.0), 3.0, "Config::set/get double");
c.set ("double3", -9.0);
t.is (c.get ("double3", 9.0), -9.0, "Config::set/get double");
// void set (const std::string&, const std::string&);
c.set ("str1", "one");
t.is (c.get ("str1", ""), "one", "Config::set/get std::string");
c.set ("str1", "");
t.is (c.get ("str1", "no"), "", "Config::set/get std::string");
// const std::string get (const char*);
c.set ("str1", "one");
t.is (c.get ((char*) "str1"), (char*)"one", "Config::set/get char*");
// const std::string get (const char*, const char*);
c.set ("str1", "one");
t.is (c.get ((char*)"str1", (char*)""), "one", "Config::set/get char*");
c.set ("str1", "");
t.is (c.get ((char*)"str1", (char*)"no"), "", "Config::set/get char*");
// const std::string get (const std::string&);
c.set ("str1", "one");
t.is (c.get (std::string ("str1")), "one", "Config::set/get std::string");
c.set ("str1", "");
t.is (c.get (std::string ("str1")), "", "Config::set/get std::string");
// const std::string get (const std::string&, const std::string&);
c.set ("str1", "one");
t.is (c.get (std::string ("str1"), std::string ("no")), "one", "Config::set/get std::string");
c.set ("str1", "");
t.is (c.get (std::string ("str1"), std::string ("no")), "", "Config::set/get std::string");
// bool get (const std::string&, const bool);
c.set ("bool1", false);
t.is (c.get (std::string ("bool1"), (bool)true), false, "Config::set/get bool");
c.set ("bool1", true);
t.is (c.get (std::string ("bool1"), (bool)false), true, "Config::set/get bool");
// void all (std::vector <std::string>&);
std::vector <std::string> all;
c.all (all);
// 8 created in this test program.
// 22 default report setting created in Config::Config.
t.is (all.size (), (size_t) 8 + 22, "Config::all");
return 0;
}
////////////////////////////////////////////////////////////////////////////////