diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index fc08bc045..88a6088ae 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -378,7 +378,6 @@ namespace hex::pl { void setPointedAtPattern(PatternData *pattern) { this->m_pointedAt = pattern; - this->m_pointedAt->setVariableName("*" + this->getDisplayName()); } [[nodiscard]] PatternData* getPointedAtPattern() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ad46be186..378edf2f5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,7 @@ set(AVAILABLE_TESTS RValues Namespaces ExtraSemicolon + Pointers ) diff --git a/tests/include/test_patterns/test_pattern_enums.hpp b/tests/include/test_patterns/test_pattern_enums.hpp index ed0524fa2..eb8651d29 100644 --- a/tests/include/test_patterns/test_pattern_enums.hpp +++ b/tests/include/test_patterns/test_pattern_enums.hpp @@ -7,13 +7,14 @@ namespace hex::test { class TestPatternEnums : public TestPattern { public: TestPatternEnums() : TestPattern("Enums"){ - auto testEnum = create("TestEnum", "testEnum", 0x120, sizeof(u32)); + auto testEnum = create("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"); )"; } diff --git a/tests/include/test_patterns/test_pattern_pointers.hpp b/tests/include/test_patterns/test_pattern_pointers.hpp new file mode 100644 index 000000000..00ebd0d48 --- /dev/null +++ b/tests/include/test_patterns/test_pattern_pointers.hpp @@ -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("", "placementPointer", 0x0C, sizeof(u8)); + auto pointedTo = create("u32", "", 0x49, sizeof(u32)); + placementPointer->setPointedAtPattern(pointedTo); + addPattern(placementPointer); + } + + } + ~TestPatternPointers() override = default; + + [[nodiscard]] + std::string getSourceCode() const override { + return R"( + u32 *placementPointer : u8 @ 0x0C; + )"; + } + + }; + +} \ No newline at end of file diff --git a/tests/source/main.cpp b/tests/source/main.cpp index e64640089..6683bc9cc 100644 --- a/tests/source/main.cpp +++ b/tests/source/main.cpp @@ -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; } } diff --git a/tests/source/tests.cpp b/tests/source/tests.cpp index 833ba72bd..e5e5a824b 100644 --- a/tests/source/tests.cpp +++ b/tests/source/tests.cpp @@ -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) }; \ No newline at end of file