Merge branch 'unit-tests' into 1.9.1

This commit is contained in:
Paul Beckingham 2010-02-23 01:05:57 -05:00
commit 3f2c68377c
3 changed files with 74 additions and 1 deletions

View file

@ -20,4 +20,5 @@ list.t
path.t
file.t
directory.t
grid.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 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

69
src/tests/grid.t.cpp Normal file
View file

@ -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 <Context.h>
#include <Grid.h>
#include <test.h>
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;
}
////////////////////////////////////////////////////////////////////////////////