From 4af2b2dc13eb7a22f2f5f14859121e72ae4adea5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 4 Jul 2009 14:11:10 -0400 Subject: [PATCH] Unit Tests - color.t - Implemented tests for round-trip color name <--> code testing. --- src/tests/.gitignore | 1 + src/tests/Makefile | 5 +++- src/tests/color.t.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/tests/color.t.cpp diff --git a/src/tests/.gitignore b/src/tests/.gitignore index 1bfbd5509..1d2e75a87 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -16,4 +16,5 @@ filt.t cmd.t config.t util.t +color.t *.log diff --git a/src/tests/Makefile b/src/tests/Makefile index ca9e62919..c53c328a0 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -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 + diff --git a/src/tests/color.t.cpp b/src/tests/color.t.cpp new file mode 100644 index 000000000..04b6b21f9 --- /dev/null +++ b/src/tests/color.t.cpp @@ -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 +#include +#include +#include + +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; +} + +////////////////////////////////////////////////////////////////////////////////