ImHex/tests/pattern_language/include/test_patterns/test_pattern_enums.hpp

39 lines
1.0 KiB
C++
Raw Normal View History

2021-09-11 21:13:49 +00:00
#pragma once
#include "test_pattern.hpp"
namespace hex::test {
class TestPatternEnums : public TestPattern {
public:
TestPatternEnums() : TestPattern("Enums") {
2021-10-03 10:32:58 +00:00
auto testEnum = create<PatternDataEnum>("TestEnum", "testEnum", 0x08, sizeof(u32), nullptr);
2021-09-11 21:13:49 +00:00
testEnum->setEnumValues({
{u128(0x0000), "A"},
{ i128(0x0C), "B"},
{ u128(0x0D), "C"},
{ u128(0x0E), "D"},
2021-09-11 21:13:49 +00:00
});
2021-09-25 21:31:37 +00:00
testEnum->setEndian(std::endian::big);
2021-09-11 21:13:49 +00:00
addPattern(testEnum);
}
~TestPatternEnums() override = default;
[[nodiscard]] std::string getSourceCode() const override {
2021-09-11 21:13:49 +00:00
return R"(
enum TestEnum : u32 {
A,
2021-09-25 21:31:37 +00:00
B = 0x0C,
2021-09-11 21:13:49 +00:00
C,
D
};
2021-09-25 21:31:37 +00:00
be TestEnum testEnum @ 0x08;
std::assert(testEnum == TestEnum::C, "Invalid enum value");
2021-09-11 21:13:49 +00:00
)";
}
};
}