tests: Added more tests

This commit is contained in:
WerWolv
2021-09-11 23:13:49 +02:00
parent 254b204d6c
commit 3d15a108af
13 changed files with 351 additions and 21 deletions

View File

@@ -5,18 +5,30 @@
#include <hex/pattern_language/pattern_data.hpp>
#define TEST(name) (hex::test::TestPattern*) new hex::test::TestPattern ## name ()
namespace hex::test {
using namespace pl;
enum class Mode {
Succeeding,
Failing
};
class TestPattern {
public:
TestPattern() = default;
explicit TestPattern(const std::string &name, Mode mode = Mode::Succeeding) : m_mode(mode) {
TestPattern::s_tests.insert({ name, this });
}
virtual ~TestPattern() {
for (auto &pattern : this->m_patterns)
delete pattern;
}
template<typename T>
static T* createVariablePattern(u64 offset, size_t size, const std::string &typeName, const std::string &varName) {
static T* create(u64 offset, size_t size, const std::string &typeName, const std::string &varName) {
auto pattern = new T(offset, size);
pattern->setTypeName(typeName);
pattern->setVariableName(varName);
@@ -24,16 +36,37 @@ namespace hex::test {
return pattern;
}
[[nodiscard]]
virtual std::string getSourceCode() const = 0;
[[nodiscard]]
virtual const std::vector<pl::PatternData*>& getPatterns() const final { return this->m_patterns; }
virtual void addPattern(pl::PatternData *pattern) final {
virtual const std::vector<PatternData*>& getPatterns() const final { return this->m_patterns; }
virtual void addPattern(PatternData *pattern) final {
this->m_patterns.push_back(pattern);
}
[[nodiscard]]
auto failing() {
this->m_mode = Mode::Failing;
return this;
}
[[nodiscard]]
Mode getMode() {
return this->m_mode;
}
[[nodiscard]]
static auto& getTests() {
return TestPattern::s_tests;
}
private:
std::vector<pl::PatternData*> m_patterns;
std::vector<PatternData*> m_patterns;
Mode m_mode;
static inline std::map<std::string, TestPattern*> s_tests;
};
}