1
0
mirror of synced 2024-12-12 07:51:05 +01:00
ImHex/tests/include/test_patterns/test_pattern_bitfields.hpp
2021-09-12 20:29:05 +02:00

44 lines
1.4 KiB
C++

#pragma once
#include "test_pattern.hpp"
namespace hex::test {
class TestPatternBitfields : public TestPattern {
public:
TestPatternBitfields() : TestPattern("Bitfields") {
auto testBitfield = create<PatternDataBitfield>("TestBitfield", "testBitfield", 0x12, (4 * 4) / 8);
testBitfield->setEndian(std::endian::big);
testBitfield->setFields({
create<PatternDataBitfieldField>("", "a", 0x12, 0, 4),
create<PatternDataBitfieldField>("", "b", 0x12, 4, 4),
create<PatternDataBitfieldField>("", "c", 0x12, 8, 4),
create<PatternDataBitfieldField>("", "d", 0x12, 12, 4)
});
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");
)";
}
};
}