add test for cxMapClear()

Sun, 23 Oct 2022 13:39:44 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 23 Oct 2022 13:39:44 +0200
changeset 594
d90cfa6721f9
parent 593
ea9b41b5ebbc
child 595
0da254bf23e6

add test for cxMapClear()

test/test_map.cpp file | annotate | diff | comparison | revisions
--- a/test/test_map.cpp	Sun Oct 23 13:32:46 2022 +0200
+++ b/test/test_map.cpp	Sun Oct 23 13:39:44 2022 +0200
@@ -249,4 +249,32 @@
 
     cxMapDestroy(map);
     EXPECT_TRUE(allocator.verify());
+}
+
+TEST(CxHashMap, Clear) {
+    CxTestingAllocator allocator;
+    auto map = cxHashMapCreate(&allocator, 0);
+    auto hmap = reinterpret_cast<struct cx_hash_map_s *>(map);
+    EXPECT_GT(hmap->bucket_count, 0);
+    cx_for_n(i, hmap->bucket_count) {
+        EXPECT_EQ(hmap->buckets[i], nullptr);
+    }
+    EXPECT_EQ(map->size, 0);
+    EXPECT_EQ(map->allocator, &allocator);
+
+    cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
+    cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
+    cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
+
+    EXPECT_EQ(map->size, 3);
+
+    cxMapClear(map);
+
+    EXPECT_EQ(map->size, 0);
+    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 1")), nullptr);
+    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 2")), nullptr);
+    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 3")), nullptr);
+
+    cxMapDestroy(map);
+    EXPECT_TRUE(allocator.verify());
 }
\ No newline at end of file

mercurial