hashing utility for register and node IDs
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I69ac08e875982456fe81c7e65b1135411f25af81
diff --git a/test/meson.build b/test/meson.build
index cbe7fbc..2025c64 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -32,6 +32,7 @@
'bit_string_test',
'flyweight_test',
'operator_register_test',
+ 'test-util-hash',
]
foreach g : gtests
diff --git a/test/test-util-hash.cpp b/test/test-util-hash.cpp
new file mode 100644
index 0000000..ba35625
--- /dev/null
+++ b/test/test-util-hash.cpp
@@ -0,0 +1,24 @@
+#include <hei_util.hpp>
+
+#include "gtest/gtest.h"
+
+using namespace libhei;
+
+TEST(UtilHash, TestSet1)
+{
+ std::string s{"SOME_RANDOM_STRING"};
+
+ uint8_t h1 = 0xBE;
+ uint16_t h2 = 0xF2DD;
+ uint32_t h3 = 0xDFB31440;
+ uint64_t h4 = 0xD0D3828Ec49F687C;
+ NodeId_t h5 = 0xF2DD; // 2-byte field
+ RegisterId_t h6 = static_cast<RegisterId_t>(0x31D080); // 3-byte field
+
+ EXPECT_EQ(h1, hash<uint8_t>(s));
+ EXPECT_EQ(h2, hash<uint16_t>(s));
+ EXPECT_EQ(h3, hash<uint32_t>(s));
+ EXPECT_EQ(h4, hash<uint64_t>(s));
+ EXPECT_EQ(h5, hash<NodeId_t>(s));
+ EXPECT_EQ(h6, hash<RegisterId_t>(s));
+}