diff --git a/src/tests/.gitignore b/src/tests/.gitignore index 3f6ca42f3..6eb059732 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -20,4 +20,5 @@ list.t path.t file.t directory.t +grid.t *.log diff --git a/src/tests/Makefile b/src/tests/Makefile index d8bc4af33..0d42bc000 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 color.t list.t path.t file.t directory.t + cmd.t util.t color.t list.t path.t file.t directory.t grid.t CFLAGS = -I. -I.. -I../.. -Wall -pedantic -ggdb3 -fno-rtti LFLAGS = -L/usr/local/lib -lncurses -llua OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \ @@ -92,3 +92,6 @@ file.t: file.t.o $(OBJECTS) test.o directory.t: directory.t.o $(OBJECTS) test.o g++ directory.t.o $(OBJECTS) test.o $(LFLAGS) -o directory.t +grid.t: grid.t.o $(OBJECTS) test.o + g++ grid.t.o $(OBJECTS) test.o $(LFLAGS) -o grid.t + diff --git a/src/tests/grid.t.cpp b/src/tests/grid.t.cpp new file mode 100644 index 000000000..6de895ab3 --- /dev/null +++ b/src/tests/grid.t.cpp @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 + +Context context; + +int main (int argc, char** argv) +{ + UnitTest ut (30); + + Grid g; + ut.is (g.width (), 0, "Zero width for uninitialized grid"); + ut.is (g.height (), 0, "Zero height for uninitialized grid"); + + g.add (2, 2, false); + ut.is (g.width (), 3, "Width of 3 columns"); + ut.is (g.height (), 3, "Height of 3 rows"); + + Grid g2; + g2.add (0, 1, "value"); + g2.add (1, 0, "value"); + ut.is (g2.width (), 2, "Width of 2 columns"); + ut.is (g2.height (), 2, "Height of 2 rows"); + ut.is (g2.byRow (0, 0), NULL, "Gap at 0,0"); + ut.ok (g2.byRow (0, 1), "Cell at 0,0"); + ut.ok (g2.byRow (1, 0), "Cell at 0,0"); + ut.is (g2.byRow (1, 1), NULL, "Gap at 1,1"); + + Grid g3; + for (int i = 0; i < 14; ++i) + g3.add (i / 4, i % 4, "value"); + + for (int i = 0; i < 20; ++i) + if (i < 14) + ut.ok (g3.byRow (i / 4, i % 4), "g3 good cell"); + else + ut.is (g3.byRow (i / 4, i % 4), NULL, "g3 missing cell"); + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////