- Made unit tests compile nad run again.

- Removed tests from distibution.
This commit is contained in:
Paul Beckingham 2008-05-17 22:46:50 -04:00
parent 42493dbdee
commit 0b37b6a980
5 changed files with 286 additions and 30 deletions

View file

@ -1,24 +0,0 @@
PROJECT = t.t tdb.t
CFLAGS = -I.. -I../../../library/include -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -L../../../library/lib -lcompany -lpcre -lncurses -lcurl
all: $(PROJECT)
install: $(PROJECT)
@echo unimplemented
test: $(PROJECT)
@echo unimplemented
clean:
-rm *.o $(PROJECT)
.cpp.o:
g++ -c $(CFLAGS) $<
t.t: t.t.o ../T.o ../parse.o ../../../library/lib/libcompany.a
g++ t.t.o ../T.o ../parse.o $(LFLAGS) -o t.t
tdb.t: tdb.t.o ../TDB.o ../T.o ../parse.o ../../../library/lib/libcompany.a
g++ tdb.t.o ../TDB.o ../T.o ../parse.o $(LFLAGS) -o tdb.t

View file

@ -1,8 +1,9 @@
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
#include <T.h>
#include <library.h>
#include "../T.h"
#include "../task.h"
#include "test.h"
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)

View file

@ -4,8 +4,9 @@
#include <iostream>
#include <unistd.h>
#include <TDB.h>
#include <library.h>
#include "../TDB.h"
#include "../task.h"
#include "test.h"
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
@ -116,10 +117,10 @@ int main (int argc, char** argv)
return -2;
}
/*
unlink ("./pending.data");
unlink ("./completed.data");
*/
return 0;
}

254
src/tests/test.cpp Normal file
View file

@ -0,0 +1,254 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2007, 2008, Paul Beckingham. All rights reserved.
//
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <library.h>
static int total = 0;
static int counter = 0;
///////////////////////////////////////////////////////////////////////////////
static void check (void)
{
if (counter > total)
std::cout << "# Warning: There are more tests than planned."
<< std::endl;
}
///////////////////////////////////////////////////////////////////////////////
void plan (int quantity)
{
total = quantity;
std::cout << "1.." << quantity << std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void ok (bool expression, const std::string& name)
{
++counter;
if (expression)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void notok (bool expression, const std::string& name)
{
++counter;
if (!expression)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (bool actual, bool expected, const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: "
<< expected
<< std::endl
<< "# got: "
<< actual
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (size_t actual, size_t expected, const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: "
<< expected
<< std::endl
<< "# got: "
<< actual
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (int actual, int expected, const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: "
<< expected
<< std::endl
<< "# got: "
<< actual
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (double actual, double expected, const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: "
<< expected
<< std::endl
<< "# got: "
<< actual
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (char actual, char expected, const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: "
<< expected
<< std::endl
<< "# got: "
<< actual
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void is (
const std::string& actual,
const std::string& expected,
const std::string& name)
{
++counter;
if (actual == expected)
std::cout << "ok "
<< counter
<< " - "
<< name
<< std::endl;
else
std::cout << "not ok "
<< counter
<< " - "
<< name
<< std::endl
<< "# expected: '"
<< expected
<< "'"
<< std::endl
<< "# got: '"
<< actual
<< "'"
<< std::endl;
check ();
}
///////////////////////////////////////////////////////////////////////////////
void diag (const std::string& text)
{
std::string trimmed = trim (text, " \t\n\r\f");
std::cout << "# " << trimmed << std::endl;
}
///////////////////////////////////////////////////////////////////////////////
void pass (const std::string& text)
{
++counter;
std::cout << "ok "
<< counter
<< " "
<< text
<< std::endl;
}
///////////////////////////////////////////////////////////////////////////////
void fail (const std::string& text)
{
++counter;
std::cout << "not ok "
<< counter
<< " "
<< text
<< std::endl;
}
///////////////////////////////////////////////////////////////////////////////

24
src/tests/test.h Normal file
View file

@ -0,0 +1,24 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2007, 2008, Paul Beckingham. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_TEST
#define INCLUDED_TEST
#include <string>
void plan (int);
void ok (bool, const std::string&);
void notok (bool, const std::string&);
void is (bool, bool, const std::string&);
void is (int, int, const std::string&);
void is (size_t, size_t, const std::string&);
void is (double, double, const std::string&);
void is (char, char, const std::string&);
void is (const std::string&, const std::string&, const std::string&);
void diag (const std::string&);
void fail (const std::string&);
void pass (const std::string&);
#endif
////////////////////////////////////////////////////////////////////////////////