tests/test_hash_key.c

changeset 1664
e5a8c41ecb58
parent 1498
d20c0d30ab3d
--- a/tests/test_hash_key.c	Wed Dec 24 11:53:40 2025 +0100
+++ b/tests/test_hash_key.c	Wed Dec 24 12:00:33 2025 +0100
@@ -61,6 +61,21 @@
     }
 }
 
+CX_TEST(test_hash_key_from_pointer_to_another_key) {
+    CxHashKey k = CX_HASH_KEY("one key");
+    CX_TEST_DO {
+        const CxHashKey *p1 = &k;
+        CxHashKey *p2 = &k;
+        CxHashKey k1 = CX_HASH_KEY(p1);
+        CxHashKey k2 = CX_HASH_KEY(p2);
+        CX_TEST_ASSERT(0 == cx_hash_key_cmp(&k, &k1));
+        CX_TEST_ASSERT(0 == cx_hash_key_cmp(&k, &k2));
+        // check that this did not copy the data
+        CX_TEST_ASSERT(k.data == k1.data);
+        CX_TEST_ASSERT(k.data == k2.data);
+    }
+}
+
 CX_TEST(test_hash_key_int_functions) {
     uint32_t a = 0xabc01337u;
     uint64_t b = 0xabc0133747110815ull;
@@ -177,6 +192,7 @@
     CxTestSuite *suite = cx_test_suite_new("hash_key");
 
     cx_test_register(suite, test_hash_key_functions);
+    cx_test_register(suite, test_hash_key_from_pointer_to_another_key);
     cx_test_register(suite, test_hash_key_int_functions);
     cx_test_register(suite, test_hash_key_macro);
     cx_test_register(suite, test_hash_key_cmp);

mercurial