tests/test_hash_map.c

changeset 993
b642eca4b956
parent 985
68754c7de906
child 994
3603bdf4a78b
equal deleted inserted replaced
992:14ca894190fd 993:b642eca4b956
54 CX_TEST_ASSERT(map->collection.store_pointer); 54 CX_TEST_ASSERT(map->collection.store_pointer);
55 CX_TEST_ASSERT(map->collection.elem_size == sizeof(void *)); 55 CX_TEST_ASSERT(map->collection.elem_size == sizeof(void *));
56 cxMapStoreObjects(map); 56 cxMapStoreObjects(map);
57 CX_TEST_ASSERT(!map->collection.store_pointer); 57 CX_TEST_ASSERT(!map->collection.store_pointer);
58 58
59 cxMapDestroy(map); 59 cxMapFree(map);
60 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 60 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
61 } 61 }
62 cx_testing_allocator_destroy(&talloc); 62 cx_testing_allocator_destroy(&talloc);
63 } 63 }
64 64
76 CX_TEST_ASSERT(map->collection.size == 0); 76 CX_TEST_ASSERT(map->collection.size == 0);
77 CX_TEST_ASSERT(map->collection.allocator == allocator); 77 CX_TEST_ASSERT(map->collection.allocator == allocator);
78 CX_TEST_ASSERT(map->collection.store_pointer); 78 CX_TEST_ASSERT(map->collection.store_pointer);
79 CX_TEST_ASSERT(map->collection.elem_size == sizeof(void *)); 79 CX_TEST_ASSERT(map->collection.elem_size == sizeof(void *));
80 80
81 cxMapDestroy(map); 81 cxMapFree(map);
82 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 82 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
83 } 83 }
84 cx_testing_allocator_destroy(&talloc); 84 cx_testing_allocator_destroy(&talloc);
85 } 85 }
86 86
117 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "bar 7"), "val 7")); 117 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "bar 7"), "val 7"));
118 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 8"), "val 8")); 118 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 8"), "val 8"));
119 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 9"), "val 9")); 119 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 9"), "val 9"));
120 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 10"), "val 10")); 120 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 10"), "val 10"));
121 121
122 cxMapDestroy(map); 122 cxMapFree(map);
123 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 123 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
124 } 124 }
125 cx_testing_allocator_destroy(&talloc); 125 cx_testing_allocator_destroy(&talloc);
126 } 126 }
127 127
142 // 6/8 does not exceed 0.75, therefore the function should not rehash 142 // 6/8 does not exceed 0.75, therefore the function should not rehash
143 int result = cxMapRehash(map); 143 int result = cxMapRehash(map);
144 CX_TEST_ASSERT(result == 0); 144 CX_TEST_ASSERT(result == 0);
145 CX_TEST_ASSERT(((struct cx_hash_map_s *)map)->bucket_count == 8); 145 CX_TEST_ASSERT(((struct cx_hash_map_s *)map)->bucket_count == 8);
146 146
147 cxMapDestroy(map); 147 cxMapFree(map);
148 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 148 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
149 } 149 }
150 cx_testing_allocator_destroy(&talloc); 150 cx_testing_allocator_destroy(&talloc);
151 } 151 }
152 152
168 CX_TEST_ASSERT(map->collection.size == 0); 168 CX_TEST_ASSERT(map->collection.size == 0);
169 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL); 169 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL);
170 CX_TEST_ASSERT(cxMapGet(map, "key 2") == NULL); 170 CX_TEST_ASSERT(cxMapGet(map, "key 2") == NULL);
171 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL); 171 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL);
172 172
173 cxMapDestroy(map); 173 cxMapFree(map);
174 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 174 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
175 } 175 }
176 cx_testing_allocator_destroy(&talloc); 176 cx_testing_allocator_destroy(&talloc);
177 } 177 }
178 178
218 s4found |= s4.ptr == s->ptr; 218 s4found |= s4.ptr == s->ptr;
219 s5found |= s5.ptr == s->ptr; 219 s5found |= s5.ptr == s->ptr;
220 } 220 }
221 CX_TEST_ASSERT(s3found && s4found && s5found); 221 CX_TEST_ASSERT(s3found && s4found && s5found);
222 222
223 cxMapDestroy(map); 223 cxMapFree(map);
224 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 224 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
225 } 225 }
226 cx_testing_allocator_destroy(&talloc); 226 cx_testing_allocator_destroy(&talloc);
227 } 227 }
228 228
252 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL); 252 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL);
253 CX_TEST_ASSERT(cxMapGet(map, "key 4") != NULL); 253 CX_TEST_ASSERT(cxMapGet(map, "key 4") != NULL);
254 CX_TEST_ASSERT(cxMapGet(map, "key 5") == NULL); 254 CX_TEST_ASSERT(cxMapGet(map, "key 5") == NULL);
255 CX_TEST_ASSERT(cxMapGet(map, "key 6") != NULL); 255 CX_TEST_ASSERT(cxMapGet(map, "key 6") != NULL);
256 256
257 cxMapDestroy(map); 257 cxMapFree(map);
258 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 258 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
259 } 259 }
260 cx_testing_allocator_destroy(&talloc); 260 cx_testing_allocator_destroy(&talloc);
261 } 261 }
262 262
331 CX_TEST_ASSERT(0 == strcmp(v4, "OK")); 331 CX_TEST_ASSERT(0 == strcmp(v4, "OK"));
332 CX_TEST_ASSERT(0 == strcmp(v5, "OK")); 332 CX_TEST_ASSERT(0 == strcmp(v5, "OK"));
333 333
334 v1[0] = v2[0] = v4[0] = v5[0] = 'c'; 334 v1[0] = v2[0] = v4[0] = v5[0] = 'c';
335 335
336 cxMapDestroy(map); 336 cxMapFree(map);
337 337
338 CX_TEST_ASSERT(0 == strcmp(v1, "cK")); 338 CX_TEST_ASSERT(0 == strcmp(v1, "cK"));
339 CX_TEST_ASSERT(0 == strcmp(v2, "cK")); 339 CX_TEST_ASSERT(0 == strcmp(v2, "cK"));
340 CX_TEST_ASSERT(0 == strcmp(v3, "OK")); 340 CX_TEST_ASSERT(0 == strcmp(v3, "OK"));
341 CX_TEST_ASSERT(0 == strcmp(v4, "cK")); 341 CX_TEST_ASSERT(0 == strcmp(v4, "cK"));
407 CX_TEST(test_empty_map_no_ops) { 407 CX_TEST(test_empty_map_no_ops) {
408 CX_TEST_DO { 408 CX_TEST_DO {
409 // assertion not possible 409 // assertion not possible
410 // test that no segfault happens and valgrind is happy 410 // test that no segfault happens and valgrind is happy
411 cxMapClear(cxEmptyMap); 411 cxMapClear(cxEmptyMap);
412 cxMapDestroy(cxEmptyMap); 412 cxMapFree(cxEmptyMap);
413 CX_TEST_ASSERT(true); 413 CX_TEST_ASSERT(true);
414 } 414 }
415 } 415 }
416 416
417 CX_TEST(test_empty_map_get) { 417 CX_TEST(test_empty_map_get) {
451 r = cxMapRemoveAndGet(map, cx_str("foo")); 451 r = cxMapRemoveAndGet(map, cx_str("foo"));
452 if (r != NULL) map->collection.size = 47; 452 if (r != NULL) map->collection.size = 47;
453 453
454 CX_TEST_ASSERT(map->collection.size == 0); 454 CX_TEST_ASSERT(map->collection.size == 0);
455 455
456 cxMapDestroy(map); 456 cxMapFree(map);
457 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 457 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
458 } 458 }
459 cx_testing_allocator_destroy(&talloc); 459 cx_testing_allocator_destroy(&talloc);
460 } 460 }
461 461
647 // compare the current map state with the reference map 647 // compare the current map state with the reference map
648 CX_TEST_CALL_SUBROUTINE(verify_map_contents, map); 648 CX_TEST_CALL_SUBROUTINE(verify_map_contents, map);
649 } 649 }
650 650
651 // destroy the map and verify the memory (de)allocations 651 // destroy the map and verify the memory (de)allocations
652 cxMapDestroy(map); 652 cxMapFree(map);
653 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 653 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
654 } 654 }
655 cx_testing_allocator_destroy(&talloc); 655 cx_testing_allocator_destroy(&talloc);
656 } 656 }
657 657

mercurial