57 lines
919 B
C++
57 lines
919 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
/*
|
|
test implementation interface
|
|
*/
|
|
class ITest
|
|
{
|
|
public:
|
|
ITest();
|
|
virtual ~ITest() = default;
|
|
|
|
protected:
|
|
virtual void run() = 0;
|
|
|
|
friend class TestRunner;
|
|
};
|
|
|
|
/*
|
|
test runner singleton class
|
|
*/
|
|
class TestRunner
|
|
{
|
|
public:
|
|
void runTests()
|
|
{
|
|
for (auto& test : _tests)
|
|
test->run();
|
|
}
|
|
|
|
static TestRunner& get()
|
|
{
|
|
static TestRunner instance;
|
|
return instance;
|
|
}
|
|
|
|
protected:
|
|
void registerTest(ITest* test) { _tests.push_back(test); }
|
|
friend class ITest;
|
|
|
|
private:
|
|
TestRunner();
|
|
TestRunner(const TestRunner&) = delete;
|
|
TestRunner& operator=(const TestRunner&) = delete;
|
|
|
|
std::vector<ITest*> _tests;
|
|
};
|
|
|
|
/*
|
|
test cctor
|
|
*/
|
|
inline ITest::ITest()
|
|
{
|
|
TestRunner::get().registerTest(this);
|
|
}
|