From 2e044682e1c3934d14530c358e1425a2a58d989f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 2 Sep 2025 21:25:37 -0500 Subject: [PATCH] chore(hash): line up HASHKEY_PTR and HASHKEY_STR ctor with verified behavior --- storm/hash/Hashkey.cpp | 12 ++++++++++++ storm/hash/Hashkey.hpp | 8 +++++--- test/Hash.cpp | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/storm/hash/Hashkey.cpp b/storm/hash/Hashkey.cpp index 96047e1..5f860b0 100644 --- a/storm/hash/Hashkey.cpp +++ b/storm/hash/Hashkey.cpp @@ -6,6 +6,10 @@ bool HASHKEY_NONE::operator==(const HASHKEY_NONE& key) { return true; } +HASHKEY_PTR::HASHKEY_PTR() { + this->m_key = nullptr; +} + HASHKEY_PTR::HASHKEY_PTR(void* key) { this->m_key = key; } @@ -14,6 +18,14 @@ bool HASHKEY_PTR::operator==(const HASHKEY_PTR& key) { return this->m_key == key.m_key; } +HASHKEY_STR::HASHKEY_STR() { + this->m_str = nullptr; +} + +HASHKEY_STR::HASHKEY_STR(const char* str) { + this->m_str = SStrDupA(str, __FILE__, __LINE__); +} + HASHKEY_STR::~HASHKEY_STR() { if (this->m_str) { SMemFree(this->m_str, __FILE__, __LINE__, 0x0); diff --git a/storm/hash/Hashkey.hpp b/storm/hash/Hashkey.hpp index ccaa496..4df6115 100644 --- a/storm/hash/Hashkey.hpp +++ b/storm/hash/Hashkey.hpp @@ -4,10 +4,10 @@ class HASHKEY_PTR { public: // Member variables - void* m_key = nullptr; + void* m_key; // Member functions - HASHKEY_PTR() = default; + HASHKEY_PTR(); HASHKEY_PTR(void* key); bool operator==(const HASHKEY_PTR& key); }; @@ -15,9 +15,11 @@ class HASHKEY_PTR { class HASHKEY_STR { public: // Member variables - char* m_str = nullptr; + char* m_str; // Member functions + HASHKEY_STR(); + HASHKEY_STR(const char* str); ~HASHKEY_STR(); HASHKEY_STR& operator=(const char* str); bool operator==(const char* str); diff --git a/test/Hash.cpp b/test/Hash.cpp index 155cb7c..41b0ac2 100644 --- a/test/Hash.cpp +++ b/test/Hash.cpp @@ -14,6 +14,26 @@ typedef void* TestExportObjectHandle; typedef void* TestExportLockedHandle; +TEST_CASE("HASHKEY_PTR", "[hash]") { + SECTION("constructs correctly") { + HASHKEY_PTR key1; + HASHKEY_PTR key2; + REQUIRE(key1.operator==(key2)); + + void* ptr = reinterpret_cast(0xDEAFBEEF); + HASHKEY_PTR key3 = { ptr }; + HASHKEY_PTR key4 = { ptr }; + REQUIRE(key3.operator==(key4)); + } +} + +TEST_CASE("HASHKEY_STR", "[hash]") { + SECTION("constructs correctly") { + HASHKEY_STR key = { "foo" }; + REQUIRE(key.operator==("foo")); + } +} + TEST_CASE("TSHashTable", "[hash]") { SECTION("constructs correctly") { TSHashTable hashTable;