47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <QString>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace Cevo {
|
|
|
|
enum class TestResult { None, Passed, Failed };
|
|
|
|
QString testResultText(TestResult result);
|
|
|
|
// Equivalent of TestCase.pas's TTestCase: a single named test, logging its
|
|
// own output and result as it runs.
|
|
class TestCase {
|
|
public:
|
|
virtual ~TestCase() = default;
|
|
|
|
QString name;
|
|
TestResult testResult = TestResult::None;
|
|
QString log;
|
|
|
|
virtual void initialize() { testResult = TestResult::None; }
|
|
virtual void run() {}
|
|
virtual void finalize() {}
|
|
void evaluate(bool passed) { testResult = passed ? TestResult::Passed : TestResult::Failed; }
|
|
void pass() { testResult = TestResult::Passed; }
|
|
void fail() { testResult = TestResult::Failed; }
|
|
};
|
|
|
|
// Equivalent of TestCase.pas's TTestCases: an owning collection of test
|
|
// cases, run in sequence.
|
|
class TestCases {
|
|
public:
|
|
TestCase *addNew(const QString &name, std::unique_ptr<TestCase> testCase);
|
|
void run();
|
|
|
|
int count() const { return static_cast<int>(m_items.size()); }
|
|
TestCase *at(int index) const { return m_items.at(static_cast<size_t>(index)).get(); }
|
|
|
|
private:
|
|
std::vector<std::unique_ptr<TestCase>> m_items;
|
|
};
|
|
|
|
} // namespace Cevo
|