feat: add testrunner and test interface
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user