ImHex/tests/include/test_patterns/test_pattern_enums.hpp

41 lines
1.0 KiB
C++

#pragma once
#include "test_pattern.hpp"
namespace hex::test {
class TestPatternEnums : public TestPattern {
public:
TestPatternEnums() : TestPattern("Enums"){
auto testEnum = create<PatternDataEnum>("TestEnum", "testEnum", 0x08, sizeof(u32));
testEnum->setEnumValues({
{ u128(0x0000), "A" },
{ s128(0x0C), "B" },
{ u128(0x0D), "C" },
{ u128(0x0E), "D" },
});
testEnum->setEndian(std::endian::big);
addPattern(testEnum);
}
~TestPatternEnums() override = default;
[[nodiscard]]
std::string getSourceCode() const override {
return R"(
enum TestEnum : u32 {
A,
B = 0x0C,
C,
D
};
be TestEnum testEnum @ 0x08;
std::assert(testEnum == TestEnum::C, "Invalid enum value");
)";
}
};
}