tests: Added pointer test
This commit is contained in:
parent
b323d711cf
commit
62656f4c51
@ -378,7 +378,6 @@ namespace hex::pl {
|
||||
|
||||
void setPointedAtPattern(PatternData *pattern) {
|
||||
this->m_pointedAt = pattern;
|
||||
this->m_pointedAt->setVariableName("*" + this->getDisplayName());
|
||||
}
|
||||
|
||||
[[nodiscard]] PatternData* getPointedAtPattern() {
|
||||
|
@ -18,6 +18,7 @@ set(AVAILABLE_TESTS
|
||||
RValues
|
||||
Namespaces
|
||||
ExtraSemicolon
|
||||
Pointers
|
||||
)
|
||||
|
||||
|
||||
|
@ -7,13 +7,14 @@ namespace hex::test {
|
||||
class TestPatternEnums : public TestPattern {
|
||||
public:
|
||||
TestPatternEnums() : TestPattern("Enums"){
|
||||
auto testEnum = create<PatternDataEnum>("TestEnum", "testEnum", 0x120, sizeof(u32));
|
||||
auto testEnum = create<PatternDataEnum>("TestEnum", "testEnum", 0x08, sizeof(u32));
|
||||
testEnum->setEnumValues({
|
||||
{ u128(0x0000), "A" },
|
||||
{ s128(0x1234), "B" },
|
||||
{ u128(0x1235), "C" },
|
||||
{ u128(0x1236), "D" },
|
||||
{ s128(0x0C), "B" },
|
||||
{ u128(0x0D), "C" },
|
||||
{ u128(0x0E), "D" },
|
||||
});
|
||||
testEnum->setEndian(std::endian::big);
|
||||
|
||||
addPattern(testEnum);
|
||||
}
|
||||
@ -24,12 +25,14 @@ namespace hex::test {
|
||||
return R"(
|
||||
enum TestEnum : u32 {
|
||||
A,
|
||||
B = 0x1234,
|
||||
B = 0x0C,
|
||||
C,
|
||||
D
|
||||
};
|
||||
|
||||
TestEnum testEnum @ 0x120;
|
||||
be TestEnum testEnum @ 0x08;
|
||||
|
||||
std::assert(testEnum == TestEnum::C, "Invalid enum value");
|
||||
)";
|
||||
}
|
||||
|
||||
|
30
tests/include/test_patterns/test_pattern_pointers.hpp
Normal file
30
tests/include/test_patterns/test_pattern_pointers.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "test_pattern.hpp"
|
||||
|
||||
namespace hex::test {
|
||||
|
||||
class TestPatternPointers : public TestPattern {
|
||||
public:
|
||||
TestPatternPointers() : TestPattern("Pointers") {
|
||||
// placementPointer
|
||||
{
|
||||
auto placementPointer = create<PatternDataPointer>("", "placementPointer", 0x0C, sizeof(u8));
|
||||
auto pointedTo = create<PatternDataUnsigned>("u32", "", 0x49, sizeof(u32));
|
||||
placementPointer->setPointedAtPattern(pointedTo);
|
||||
addPattern(placementPointer);
|
||||
}
|
||||
|
||||
}
|
||||
~TestPatternPointers() override = default;
|
||||
|
||||
[[nodiscard]]
|
||||
std::string getSourceCode() const override {
|
||||
return R"(
|
||||
u32 *placementPointer : u8 @ 0x0C;
|
||||
)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -97,7 +97,7 @@ int test(int argc, char **argv) {
|
||||
auto &controlPattern = *currTest->getPatterns().at(i);
|
||||
|
||||
if (evaluatedPattern != controlPattern) {
|
||||
hex::log::fatal("Pattern with name {}:{} didn't match template", patterns->at(i)->getTypeName(), patterns->at(i)->getVariableName());
|
||||
hex::log::fatal("Pattern with name {}:{} didn't match template", evaluatedPattern.getTypeName(), evaluatedPattern.getVariableName());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "test_patterns/test_pattern_rvalues.hpp"
|
||||
#include "test_patterns/test_pattern_namespaces.hpp"
|
||||
#include "test_patterns/test_pattern_extra_semicolon.hpp"
|
||||
#include "test_patterns/test_pattern_pointers.hpp"
|
||||
|
||||
std::array Tests = {
|
||||
TEST(Placement),
|
||||
@ -27,5 +28,6 @@ std::array Tests = {
|
||||
TEST(Math),
|
||||
TEST(RValues),
|
||||
TEST(Namespaces),
|
||||
TEST(ExtraSemicolon)
|
||||
TEST(ExtraSemicolon),
|
||||
TEST(Pointers)
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user