diff --git a/testrunner.cpp b/testrunner.cpp new file mode 100644 index 000000000..6f0f85399 --- /dev/null +++ b/testrunner.cpp @@ -0,0 +1,10 @@ + +#include "testsuite.h" + + +int main() +{ + TestSuite::runTests(); + return 0; +} + diff --git a/testsuite.cpp b/testsuite.cpp new file mode 100644 index 000000000..17cb28f18 --- /dev/null +++ b/testsuite.cpp @@ -0,0 +1,75 @@ + +#include "testsuite.h" + +#include +#include + + + +/** + * TestRegistry + **/ + +class TestRegistry +{ +private: + std::list _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 &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 &tests = TestRegistry::theInstance().tests(); + + for ( std::list::const_iterator it = tests.begin(); it != tests.end(); ++it ) + { + std::cout << (*it)->classname << std::endl; + } +} + +void TestSuite::runTests() +{ + const std::list &tests = TestRegistry::theInstance().tests(); + + for ( std::list::const_iterator it = tests.begin(); it != tests.end(); ++it ) + { + (*it)->run(); + } +} + diff --git a/testsuite.h b/testsuite.h new file mode 100644 index 000000000..73f6b9971 --- /dev/null +++ b/testsuite.h @@ -0,0 +1,27 @@ + +#include +#include + + +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 ) +*/ +