Unit Tests - color.t

- Implemented tests for round-trip color name <--> code testing.
This commit is contained in:
Paul Beckingham 2009-07-04 14:11:10 -04:00
parent 69e839724d
commit 4af2b2dc13
3 changed files with 75 additions and 1 deletions

View file

@ -16,4 +16,5 @@ filt.t
cmd.t
config.t
util.t
color.t
*.log

View file

@ -1,6 +1,6 @@
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
config.t seq.t att.t stringtable.t record.t nibbler.t subst.t filt.t \
cmd.t util.t
cmd.t util.t color.t
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -lncurses
OBJECTS = ../TDB.o ../Task.o ../text.o ../Date.o ../Table.o ../Duration.o \
@ -75,3 +75,6 @@ config.t: config.t.o $(OBJECTS) test.o
util.t: util.t.o $(OBJECTS) test.o
g++ util.t.o $(OBJECTS) test.o $(LFLAGS) -o util.t
color.t: color.t.o $(OBJECTS) test.o
g++ color.t.o $(OBJECTS) test.o $(LFLAGS) -o color.t

70
src/tests/color.t.cpp Normal file
View file

@ -0,0 +1,70 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <color.h>
#include <test.h>
Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
char* colors[] =
{
"off",
"bold", "underline", "bold_underline",
"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",
"bold_black", "bold_red", "bold_green", "bold_yellow", "bold_blue",
"bold_magenta", "bold_cyan", "bold_white",
"underline_black", "underline_red", "underline_green", "underline_yellow",
"underline_blue", "underline_magenta", "underline_cyan", "underline_white",
"bold_underline_black", "bold_underline_red", "bold_underline_green",
"bold_underline_yellow", "bold_underline_blue", "bold_underline_magenta",
"bold_underline_cyan", "bold_underline_white",
"on_black", "on_red", "on_green", "on_yellow", "on_blue", "on_magenta",
"on_cyan", "on_white",
"on_bright_black", "on_bright_red", "on_bright_green", "on_bright_yellow",
"on_bright_blue", "on_bright_magenta", "on_bright_cyan", "on_bright_white",
};
#define NUM_COLORS (sizeof (colors) / sizeof (colors[0]))
UnitTest t (NUM_COLORS + 2);
for (unsigned int i = 0; i < NUM_COLORS; ++i)
t.is (std::string (colors[i]),
Text::colorName (Text::colorCode (colors[i])),
std::string ("round-trip ") + colors[i]);
t.is (Text::colorName (Text::nocolor), "", "nocolor == \'\'");
t.is (Text::colorCode (""), Text::nocolor, "\'\' == nocolor");
return 0;
}
////////////////////////////////////////////////////////////////////////////////