testing: Added a new unit testing framework
This commit is contained in:
parent
f01ab43eed
commit
b5706fc546
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include "testsuite.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
TestSuite::runTests();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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 )
|
||||
*/
|
||||
|
Loading…
Reference in New Issue