mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 08:59:07 +00:00
chore(hash): line up HASHKEY_PTR and HASHKEY_STR ctor with verified behavior
This commit is contained in:
parent
adc8cb6200
commit
2e044682e1
3 changed files with 37 additions and 3 deletions
|
|
@ -6,6 +6,10 @@ bool HASHKEY_NONE::operator==(const HASHKEY_NONE& key) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HASHKEY_PTR::HASHKEY_PTR() {
|
||||||
|
this->m_key = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
HASHKEY_PTR::HASHKEY_PTR(void* key) {
|
HASHKEY_PTR::HASHKEY_PTR(void* key) {
|
||||||
this->m_key = key;
|
this->m_key = key;
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +18,14 @@ bool HASHKEY_PTR::operator==(const HASHKEY_PTR& key) {
|
||||||
return this->m_key == key.m_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() {
|
HASHKEY_STR::~HASHKEY_STR() {
|
||||||
if (this->m_str) {
|
if (this->m_str) {
|
||||||
SMemFree(this->m_str, __FILE__, __LINE__, 0x0);
|
SMemFree(this->m_str, __FILE__, __LINE__, 0x0);
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
class HASHKEY_PTR {
|
class HASHKEY_PTR {
|
||||||
public:
|
public:
|
||||||
// Member variables
|
// Member variables
|
||||||
void* m_key = nullptr;
|
void* m_key;
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
HASHKEY_PTR() = default;
|
HASHKEY_PTR();
|
||||||
HASHKEY_PTR(void* key);
|
HASHKEY_PTR(void* key);
|
||||||
bool operator==(const HASHKEY_PTR& key);
|
bool operator==(const HASHKEY_PTR& key);
|
||||||
};
|
};
|
||||||
|
|
@ -15,9 +15,11 @@ class HASHKEY_PTR {
|
||||||
class HASHKEY_STR {
|
class HASHKEY_STR {
|
||||||
public:
|
public:
|
||||||
// Member variables
|
// Member variables
|
||||||
char* m_str = nullptr;
|
char* m_str;
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
HASHKEY_STR();
|
||||||
|
HASHKEY_STR(const char* str);
|
||||||
~HASHKEY_STR();
|
~HASHKEY_STR();
|
||||||
HASHKEY_STR& operator=(const char* str);
|
HASHKEY_STR& operator=(const char* str);
|
||||||
bool operator==(const char* str);
|
bool operator==(const char* str);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,26 @@ typedef void* TestExportObjectHandle;
|
||||||
|
|
||||||
typedef void* TestExportLockedHandle;
|
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<void*>(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]") {
|
TEST_CASE("TSHashTable", "[hash]") {
|
||||||
SECTION("constructs correctly") {
|
SECTION("constructs correctly") {
|
||||||
TSHashTable<TestHashObject, HASHKEY_STRI> hashTable;
|
TSHashTable<TestHashObject, HASHKEY_STRI> hashTable;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue