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
     1.1 --- a/test/test_map.cpp	Sun Oct 23 13:32:46 2022 +0200
     1.2 +++ b/test/test_map.cpp	Sun Oct 23 13:39:44 2022 +0200
     1.3 @@ -249,4 +249,32 @@
     1.4  
     1.5      cxMapDestroy(map);
     1.6      EXPECT_TRUE(allocator.verify());
     1.7 +}
     1.8 +
     1.9 +TEST(CxHashMap, Clear) {
    1.10 +    CxTestingAllocator allocator;
    1.11 +    auto map = cxHashMapCreate(&allocator, 0);
    1.12 +    auto hmap = reinterpret_cast<struct cx_hash_map_s *>(map);
    1.13 +    EXPECT_GT(hmap->bucket_count, 0);
    1.14 +    cx_for_n(i, hmap->bucket_count) {
    1.15 +        EXPECT_EQ(hmap->buckets[i], nullptr);
    1.16 +    }
    1.17 +    EXPECT_EQ(map->size, 0);
    1.18 +    EXPECT_EQ(map->allocator, &allocator);
    1.19 +
    1.20 +    cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
    1.21 +    cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
    1.22 +    cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
    1.23 +
    1.24 +    EXPECT_EQ(map->size, 3);
    1.25 +
    1.26 +    cxMapClear(map);
    1.27 +
    1.28 +    EXPECT_EQ(map->size, 0);
    1.29 +    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 1")), nullptr);
    1.30 +    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 2")), nullptr);
    1.31 +    EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 3")), nullptr);
    1.32 +
    1.33 +    cxMapDestroy(map);
    1.34 +    EXPECT_TRUE(allocator.verify());
    1.35  }
    1.36 \ No newline at end of file

mercurial