| 248 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 7")), "val 7"), 0); |
248 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 7")), "val 7"), 0); |
| 249 |
249 |
| 250 cxMapDestroy(map); |
250 cxMapDestroy(map); |
| 251 EXPECT_TRUE(allocator.verify()); |
251 EXPECT_TRUE(allocator.verify()); |
| 252 } |
252 } |
| |
253 |
| |
254 TEST(CxHashMap, Clear) { |
| |
255 CxTestingAllocator allocator; |
| |
256 auto map = cxHashMapCreate(&allocator, 0); |
| |
257 auto hmap = reinterpret_cast<struct cx_hash_map_s *>(map); |
| |
258 EXPECT_GT(hmap->bucket_count, 0); |
| |
259 cx_for_n(i, hmap->bucket_count) { |
| |
260 EXPECT_EQ(hmap->buckets[i], nullptr); |
| |
261 } |
| |
262 EXPECT_EQ(map->size, 0); |
| |
263 EXPECT_EQ(map->allocator, &allocator); |
| |
264 |
| |
265 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); |
| |
266 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); |
| |
267 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); |
| |
268 |
| |
269 EXPECT_EQ(map->size, 3); |
| |
270 |
| |
271 cxMapClear(map); |
| |
272 |
| |
273 EXPECT_EQ(map->size, 0); |
| |
274 EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 1")), nullptr); |
| |
275 EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 2")), nullptr); |
| |
276 EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 3")), nullptr); |
| |
277 |
| |
278 cxMapDestroy(map); |
| |
279 EXPECT_TRUE(allocator.verify()); |
| |
280 } |