testing: Added a new unit testing framework

This commit is contained in:
Daniel Marjamäki 2008-10-12 17:31:04 +00:00
parent f01ab43eed
commit b5706fc546
3 changed files with 112 additions and 0 deletions

10
testrunner.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "testsuite.h"
int main()
{
TestSuite::runTests();
return 0;
}

75
testsuite.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "testsuite.h"
#include <iostream>
#include <list>
/**
* TestRegistry
**/
class TestRegistry
{
private:
std::list<TestSuite *> _tests;
public:
static TestRegistry &theInstance()
{
static TestRegistry testreg;
return testreg;
}
void addTest( TestSuite *t )
{
_tests.push_back( t );
}
void removeTest( TestSuite *t )
{
_tests.remove( t );
}
const std::list<TestSuite *> &tests() const
{ return _tests; }
};
/**
* TestSuite
**/
TestSuite::TestSuite(const std::string &_name) : classname(_name)
{
TestRegistry::theInstance().addTest(this);
}
TestSuite::~TestSuite()
{
TestRegistry::theInstance().removeTest(this);
}
void TestSuite::printTests()
{
const std::list<TestSuite *> &tests = TestRegistry::theInstance().tests();
for ( std::list<TestSuite *>::const_iterator it = tests.begin(); it != tests.end(); ++it )
{
std::cout << (*it)->classname << std::endl;
}
}
void TestSuite::runTests()
{
const std::list<TestSuite *> &tests = TestRegistry::theInstance().tests();
for ( std::list<TestSuite *>::const_iterator it = tests.begin(); it != tests.end(); ++it )
{
(*it)->run();
}
}

27
testsuite.h Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
#include <string>
class TestSuite
{
protected:
std::string classname;
virtual void run() = 0;
public:
TestSuite(const std::string &_name);
~TestSuite();
static void printTests();
static void runTests();
};
#define TEST_CASE( NAME ) std::cout << classname << "::" << #NAME << std::endl; NAME ();
/*
#define ASSERT_EQUALS( EXPECTED , ACTUAL )
*/