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

44 lines
1.5 KiB
C++
Raw Normal View History

2021-09-12 18:28:32 +00:00
#pragma once
#include "test_pattern.hpp"
namespace hex::test {
class TestPatternBitfields : public TestPattern {
public:
TestPatternBitfields() : TestPattern("Bitfields") {
2021-10-03 10:32:58 +00:00
auto testBitfield = create<PatternDataBitfield>("TestBitfield", "testBitfield", 0x12, (4 * 4) / 8, nullptr);
2021-09-12 18:28:32 +00:00
testBitfield->setEndian(std::endian::big);
testBitfield->setFields({
2021-10-03 10:32:58 +00:00
create<PatternDataBitfieldField>("", "a", 0x12, 0, 4, nullptr),
create<PatternDataBitfieldField>("", "b", 0x12, 4, 4, nullptr),
create<PatternDataBitfieldField>("", "c", 0x12, 8, 4, nullptr),
create<PatternDataBitfieldField>("", "d", 0x12, 12, 4, nullptr)
2021-09-12 18:28:32 +00:00
});
addPattern(testBitfield);
}
~TestPatternBitfields() override = default;
[[nodiscard]]
std::string getSourceCode() const override {
return R"(
bitfield TestBitfield {
a : 4;
b : 4;
c : 4;
d : 4;
};
be TestBitfield testBitfield @ 0x12;
std::assert(testBitfield.a == 0x0A, "Field A invalid");
std::assert(testBitfield.b == 0x00, "Field B invalid");
std::assert(testBitfield.c == 0x04, "Field C invalid");
std::assert(testBitfield.d == 0x03, "Field D invalid");
)";
}
};
}