tests/test_hash_map.c

Wed, 08 Jan 2025 20:06:37 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 08 Jan 2025 20:06:37 +0100
changeset 1115
6db21dee4929
parent 1114
ad5eeb256242
permissions
-rw-r--r--

create specialized map iterators - fixes #550

785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/test.h"
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include "cx/hash_map.h"
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 CX_TEST(test_hash_map_create) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 CxMap *map = cxHashMapCreate(allocator, 1, 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 struct cx_hash_map_s *hmap = (struct cx_hash_map_s *) map;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 CX_TEST_ASSERT(hmap->bucket_count > 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 for(size_t i = 0 ; i < hmap->bucket_count ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 CX_TEST_ASSERT(hmap->buckets[i] == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
45 CX_TEST_ASSERT(map->collection.elem_size == 1);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
46 CX_TEST_ASSERT(map->collection.size == 0);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
47 CX_TEST_ASSERT(map->collection.allocator == allocator);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
48 CX_TEST_ASSERT(!map->collection.store_pointer);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
49 CX_TEST_ASSERT(map->collection.cmpfunc == NULL);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
50 CX_TEST_ASSERT(map->collection.simple_destructor == NULL);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
51 CX_TEST_ASSERT(map->collection.advanced_destructor == NULL);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
52 CX_TEST_ASSERT(map->collection.destructor_data == NULL);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
54 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 CX_TEST(test_hash_map_create_store_pointers) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 struct cx_hash_map_s *hmap = (struct cx_hash_map_s *) map;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 CX_TEST_ASSERT(hmap->bucket_count > 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 for (size_t i = 0; i < hmap->bucket_count; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 CX_TEST_ASSERT(hmap->buckets[i] == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
71 CX_TEST_ASSERT(map->collection.size == 0);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
72 CX_TEST_ASSERT(map->collection.allocator == allocator);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
73 CX_TEST_ASSERT(map->collection.store_pointer);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
74 CX_TEST_ASSERT(map->collection.elem_size == sizeof(void *));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
76 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 CX_TEST(test_hash_map_rehash) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 7);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 cxMapPut(map, "key 1", (void *) "val 1");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 cxMapPut(map, "key 2", (void *) "val 2");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 cxMapPut(map, "key 3", (void *) "val 3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 cxMapPut(map, "foo 4", (void *) "val 4");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 cxMapPut(map, "key 5", (void *) "val 5");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 cxMapPut(map, "key 6", (void *) "val 6");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 cxMapPut(map, "bar 7", (void *) "val 7");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 cxMapPut(map, "key 8", (void *) "val 8");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 cxMapPut(map, "key 9", (void *) "val 9");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 cxMapPut(map, "key 10", (void *) "val 10");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 CX_TEST_ASSERT(((struct cx_hash_map_s *)map)->bucket_count == 7);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 int result = cxMapRehash(map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 CX_TEST_ASSERT(result == 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 CX_TEST_ASSERT(((struct cx_hash_map_s *)map)->bucket_count == 25);
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
104 CX_TEST_ASSERT(map->collection.size == 10);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 1"), "val 1"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 2"), "val 2"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 3"), "val 3"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "foo 4"), "val 4"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 5"), "val 5"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 6"), "val 6"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "bar 7"), "val 7"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 8"), "val 8"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 9"), "val 9"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key 10"), "val 10"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
117 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 CX_TEST(test_hash_map_rehash_not_required) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 8);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 cxMapPut(map, "key 1", (void *) "val 1");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 cxMapPut(map, "key 2", (void *) "val 2");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 cxMapPut(map, "key 3", (void *) "val 3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 cxMapPut(map, "key 4", (void *) "val 4");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 cxMapPut(map, "key 5", (void *) "val 5");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 cxMapPut(map, "key 6", (void *) "val 6");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 // 6/8 does not exceed 0.75, therefore the function should not rehash
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 int result = cxMapRehash(map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 CX_TEST_ASSERT(result == 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 CX_TEST_ASSERT(((struct cx_hash_map_s *)map)->bucket_count == 8);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
142 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 CX_TEST(test_hash_map_clear) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 cxMapPut(map, "key 1", (void *) "val 1");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 cxMapPut(map, "key 2", (void *) "val 2");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 cxMapPut(map, "key 3", (void *) "val 3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
159 CX_TEST_ASSERT(map->collection.size == 3);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 cxMapClear(map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
163 CX_TEST_ASSERT(map->collection.size == 0);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 CX_TEST_ASSERT(cxMapGet(map, "key 2") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
168 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 CX_TEST(test_hash_map_store_ucx_strings) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 // create the map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 CxMap *map = cxHashMapCreate(allocator, sizeof(cxstring), 8);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 // define some strings
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 cxstring s1 = CX_STR("this");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 cxstring s2 = CX_STR("is");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 cxstring s3 = CX_STR("a");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 cxstring s4 = CX_STR("test");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 cxstring s5 = CX_STR("setup");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 // put them into the map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 cxMapPut(map, "s1", &s1);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 cxMapPut(map, "s2", &s2);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 cxMapPut(map, "s3", &s3);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 cxMapPut(map, "s4", &s4);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 // overwrite a value
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 cxMapPut(map, "s1", &s5);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 // look up a string
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 cxstring * s3p = cxMapGet(map, "s3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 CX_TEST_ASSERT(s3p->length == s3.length);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 CX_TEST_ASSERT(s3p->ptr == s3.ptr);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 CX_TEST_ASSERT(s3p != &s3);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 // remove a string
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
205 cxstring ret = {0};
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
206 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, "s2", &ret));
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
207 CX_TEST_ASSERT(map->collection.size == 3);
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
208 CX_TEST_ASSERT(0 == cx_strcmp(ret, cx_str("is")));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 // iterate
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 bool s3found = false, s4found = false, s5found = false;
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
212 CxMapIterator iter = cxMapIteratorValues(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 cx_foreach(cxstring*, s, iter) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 s3found |= s3.ptr == s->ptr;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 s4found |= s4.ptr == s->ptr;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 s5found |= s5.ptr == s->ptr;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 CX_TEST_ASSERT(s3found && s4found && s5found);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
220 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 CX_TEST(test_hash_map_remove_via_iterator) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 4);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 cxMapPut(map, "key 1", (void *) "val 1");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 cxMapPut(map, "key 2", (void *) "val 2");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 cxMapPut(map, "key 3", (void *) "val 3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 cxMapPut(map, "key 4", (void *) "val 4");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 cxMapPut(map, "key 5", (void *) "val 5");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 cxMapPut(map, "key 6", (void *) "val 6");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
240 CxMapIterator iter = cxMapMutIterator(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 cx_foreach(CxMapEntry*, entry, iter) {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
242 if (((const char *)entry->key->data)[4] % 2 == 1) cxIteratorFlagRemoval(iter);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
244 CX_TEST_ASSERT(map->collection.size == 3);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
245 CX_TEST_ASSERT(iter.index == map->collection.size);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 CX_TEST_ASSERT(cxMapGet(map, "key 2") != NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 CX_TEST_ASSERT(cxMapGet(map, "key 4") != NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 CX_TEST_ASSERT(cxMapGet(map, "key 5") == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 CX_TEST_ASSERT(cxMapGet(map, "key 6") != NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
254 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
260 struct test_destr_struct {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
261 char *str;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
262 };
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
263
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
264 static void test_simple_destructor(void *d) {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
265 struct test_destr_struct *data = d;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
266 strcpy(data->str, "OK");
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 static void test_advanced_destructor(
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 926
diff changeset
270 cx_attr_unused void *unused,
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
271 void *d
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 ) {
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
273 test_simple_destructor(d);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 static CX_TEST_SUBROUTINE(verify_any_destructor, CxMap *map) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 CxHashKey k1 = cx_hash_key_str("key 1");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 CxHashKey k2 = cx_hash_key_str("key 2");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 CxHashKey k3 = cx_hash_key_str("key 3");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 CxHashKey k4 = cx_hash_key_str("key 4");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 CxHashKey k5 = cx_hash_key_str("key 5");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 char v1[] = "val 1";
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 char v2[] = "val 2";
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 char v3[] = "val 3";
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 char v4[] = "val 4";
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 char v5[] = "val 5";
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
288 char v6[] = "val 6";
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
289 char v7[] = "val 7";
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
291 struct test_destr_struct d1 = {v1};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
292 struct test_destr_struct d2 = {v2};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
293 struct test_destr_struct d3 = {v3};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
294 struct test_destr_struct d4 = {v4};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
295 struct test_destr_struct d5 = {v5};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
296 struct test_destr_struct d6 = {v6};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
297 struct test_destr_struct d7 = {v7};
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
298
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
299 void *v1data = &d1;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
300 void *v2data = &d2;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
301 void *v3data = &d3;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
302 void *v4data = &d4;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
303 void *v5data = &d5;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
304 void *v6data = &d6;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
305 void *v7data = &d7;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
306
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
307 cxMapPut(map, k1, v1data);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
308 cxMapPut(map, k2, v2data);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
309 cxMapPut(map, k3, v3data);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
310 cxMapPut(map, k4, v4data);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
312 CX_TEST_ASSERT(0 == cxMapRemove(map, k2));
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
313 if (map->collection.store_pointer) {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
314 struct test_destr_struct *r;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
315 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, k3, &r));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
316 CX_TEST_ASSERT(r == &d3);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
317 } else {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
318 struct test_destr_struct r;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
319 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, k3, &r));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
320 CX_TEST_ASSERT(r.str == v3);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
321 }
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 CX_TEST_ASSERT(0 == strcmp(v1, "val 1"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 CX_TEST_ASSERT(0 == strcmp(v2, "OK"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 CX_TEST_ASSERT(0 == strcmp(v3, "val 3"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 CX_TEST_ASSERT(0 == strcmp(v4, "val 4"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 CX_TEST_ASSERT(0 == strcmp(v5, "val 5"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
329 // put k5, overwrite k1, put new k3
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
330 cxMapPut(map, k5, v5data);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
331 cxMapPut(map, k1, v6data);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
332 cxMapPut(map, k3, v7data);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
334 // destructor the value behind k1 was called, but for k3 not
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
335 CX_TEST_ASSERT(0 == strcmp(v1, "OK"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336 CX_TEST_ASSERT(0 == strcmp(v3, "val 3"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
338 // now remove k1 via key iterator and k5 (val 5) via value iterator
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
339 v1[0] = 'y'; // mark v1 and check that destr is not called for previous val
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 {
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
341 CxMapIterator iter = cxMapMutIteratorKeys(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 cx_foreach(CxHashKey*, key, iter) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 if (((char*)key->data)[4] == '1') cxIteratorFlagRemoval(iter);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 {
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
347 CxMapIterator iter = cxMapMutIteratorValues(map);
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
348 cx_foreach(struct test_destr_struct*, v, iter) {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
349 if (v->str[4] == '5') cxIteratorFlagRemoval(iter);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
353 CX_TEST_ASSERT(0 == strcmp(v1, "yK"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 CX_TEST_ASSERT(0 == strcmp(v2, "OK"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 CX_TEST_ASSERT(0 == strcmp(v3, "val 3"));
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
356 CX_TEST_ASSERT(0 == strcmp(v4, "val 4"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 CX_TEST_ASSERT(0 == strcmp(v5, "OK"));
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
358 CX_TEST_ASSERT(0 == strcmp(v6, "OK"));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
359 CX_TEST_ASSERT(0 == strcmp(v7, "val 7"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
361 // mark the already destroyed items
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
362 // and check that they are not destroyed again
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 v1[0] = v2[0] = v4[0] = v5[0] = 'c';
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
365 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 CX_TEST_ASSERT(0 == strcmp(v1, "cK"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 CX_TEST_ASSERT(0 == strcmp(v2, "cK"));
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
369 CX_TEST_ASSERT(0 == strcmp(v3, "val 3"));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
370 CX_TEST_ASSERT(0 == strcmp(v4, "OK"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 CX_TEST_ASSERT(0 == strcmp(v5, "cK"));
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
372 CX_TEST_ASSERT(0 == strcmp(v6, "OK"));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
373 CX_TEST_ASSERT(0 == strcmp(v7, "OK"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
376 CX_TEST(test_hash_map_simple_destructor_objects) {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
377 CxTestingAllocator talloc;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
378 cx_testing_allocator_init(&talloc);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
379 CxAllocator *allocator = &talloc.base;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
380 CX_TEST_DO {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
381 CxMap *map = cxHashMapCreate(allocator,
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
382 sizeof(struct test_destr_struct), 0);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
383 map->collection.simple_destructor = test_simple_destructor;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
384 CX_TEST_CALL_SUBROUTINE(verify_any_destructor, map);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
385 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
386 }
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
387 cx_testing_allocator_destroy(&talloc);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
388 }
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
389
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
390 CX_TEST(test_hash_map_advanced_destructor_objects) {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
391 CxTestingAllocator talloc;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
392 cx_testing_allocator_init(&talloc);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
393 CxAllocator *allocator = &talloc.base;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
394 CX_TEST_DO {
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
395 CxMap *map = cxHashMapCreate(allocator,
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
396 sizeof(struct test_destr_struct), 0);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
397 map->collection.advanced_destructor = test_advanced_destructor;
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
398 CX_TEST_CALL_SUBROUTINE(verify_any_destructor, map);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
399 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
400 }
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
401 cx_testing_allocator_destroy(&talloc);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
402 }
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
403
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
404 CX_TEST(test_hash_map_simple_destructor_pointers) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
405 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
406 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
407 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
408 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
409 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0);
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
410 map->collection.simple_destructor = test_simple_destructor;
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
411 CX_TEST_CALL_SUBROUTINE(verify_any_destructor, map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
412 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
413 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
414 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
415 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
416
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
417 CX_TEST(test_hash_map_advanced_destructor_pointers) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
418 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
419 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
420 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
421 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
422 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0);
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
423 map->collection.advanced_destructor = test_advanced_destructor;
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
424 CX_TEST_CALL_SUBROUTINE(verify_any_destructor, map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
425 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
426 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
427 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
428 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
429
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
430 CX_TEST(test_empty_map_size) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
431 CX_TEST_DO {
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
432 CX_TEST_ASSERT(cxEmptyMap->collection.size == 0);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
433 CX_TEST_ASSERT(cxMapSize(cxEmptyMap) == 0);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
434 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
435 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
436
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
437 CX_TEST(test_empty_map_iterator) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
438 CxMap *map = cxEmptyMap;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
439
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
440 CxMapIterator it1 = cxMapIterator(map);
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
441 CxMapIterator it2 = cxMapIteratorValues(map);
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
442 CxMapIterator it3 = cxMapIteratorKeys(map);
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
443 CxMapIterator it4 = cxMapMutIterator(map);
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
444 CxMapIterator it5 = cxMapMutIteratorValues(map);
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
445 CxMapIterator it6 = cxMapMutIteratorKeys(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
446
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
447 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
448 CX_TEST_ASSERT(!cxIteratorValid(it1));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
449 CX_TEST_ASSERT(!cxIteratorValid(it2));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
450 CX_TEST_ASSERT(!cxIteratorValid(it3));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
451 CX_TEST_ASSERT(!cxIteratorValid(it4));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
452 CX_TEST_ASSERT(!cxIteratorValid(it5));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
453 CX_TEST_ASSERT(!cxIteratorValid(it6));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
454
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
455 int c = 0;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
456 cx_foreach(void*, data, it1) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
457 cx_foreach(void*, data, it2) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
458 cx_foreach(void*, data, it3) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
459 cx_foreach(void*, data, it4) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
460 cx_foreach(void*, data, it5) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
461 cx_foreach(void*, data, it6) c++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
462 CX_TEST_ASSERT(c == 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
463 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
464 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
465
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
466 CX_TEST(test_empty_map_no_ops) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
467 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
468 // assertion not possible
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
469 // test that no segfault happens and valgrind is happy
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
470 cxMapClear(cxEmptyMap);
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
471 cxMapFree(cxEmptyMap);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
472 CX_TEST_ASSERT(true);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
473 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
474 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
475
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
476 CX_TEST(test_empty_map_get) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
477 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
478 CxHashKey key = cx_hash_key_str("test");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
479 CX_TEST_ASSERT(cxMapGet(cxEmptyMap, key) == NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
480 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
481 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
482
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
483 CX_TEST(test_hash_map_generics) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
484 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
485 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
486 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
487 CX_TEST_DO {
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
488 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
489 cxMapPut(map, "test", "test");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
490 cxMapPut(map, cx_mutstr("foo"), "bar");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
491 cxMapPut(map, cx_str("hallo"), "welt");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
492
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
493 CX_TEST_ASSERT(map->collection.size == 3);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
494 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "test"), "test"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
495 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "foo"), "bar"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
496 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "hallo"), "welt"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
497
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
498 CX_TEST_ASSERT(0 == cxMapRemove(map, cx_str("test")));
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
499 const char *hallo = "hallo";
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
500 CX_TEST_ASSERT(0 == cxMapRemove(map, hallo));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
501 cxMapPut(map, cx_hash_key_str("key"), "value");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
502
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
503 CX_TEST_ASSERT(map->collection.size == 2);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
504 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "key"), "value"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
505 CX_TEST_ASSERT(0 == strcmp(cxMapGet(map, "foo"), "bar"));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
506
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
507 const char *r1, *r2;
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
508 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, "key", &r1));
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
509 CX_TEST_ASSERT(0 == strcmp(r1, "value"));
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
510 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, cx_str("foo"), &r2));
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
511 CX_TEST_ASSERT(0 == strcmp(r2, "bar"));
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
512 r2 = "nope";
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
513 CX_TEST_ASSERT(0 != cxMapRemoveAndGet(map, cx_hash_key("notfound",9), &r2));
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
514 CX_TEST_ASSERT(0 == strcmp(r2, "nope"));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
515
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
516 CX_TEST_ASSERT(map->collection.size == 0);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
517
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
518 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
519 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
520 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
521 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
522 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
523
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
524 struct test_map_kv {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
525 const char *key;
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
526 const char *value;
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
527 };
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
528
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
529 static struct test_map_kv const test_map_operations[] = {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
530 {"key 1", "test"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
531 {"key 2", "blub"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
532 {"key 3", "hallo"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
533 {"key 2", "foobar"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
534 {"key 4", "value 4"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
535 {"key 5", "value 5"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
536 {"key 6", "value 6"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
537 {"key 4", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
538 {"key 7", "value 7"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
539 {"key 8", "value 8"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
540 {"does not exist", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
541 {"key 9", "value 9"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
542 {"key 6", "other value"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
543 {"key 7", "something else"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
544 {"key 8", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
545 {"key 2", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
546 {"key 8", "new value"},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
547 };
926
8fdd8d78c14b fix several survivors of east-const and some missing consts
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
548 static const size_t test_map_operations_len =
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
549 sizeof(test_map_operations) / sizeof(struct test_map_kv);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
550 static struct test_map_kv test_map_reference[] = {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
551 {"key 1", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
552 {"key 2", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
553 {"key 3", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
554 {"key 4", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
555 {"key 5", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
556 {"key 6", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
557 {"key 7", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
558 {"key 8", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
559 {"key 9", NULL},
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
560 };
926
8fdd8d78c14b fix several survivors of east-const and some missing consts
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
561 static const size_t test_map_reference_len =
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
562 sizeof(test_map_reference) / sizeof(struct test_map_kv);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
563
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
564 static void test_map_reference_put(const char *key, const char *value) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
565 for (size_t i = 0 ; i < test_map_reference_len ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
566 if (0 == strcmp(key, test_map_reference[i].key)) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
567 test_map_reference[i].value = value;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
568 return;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
569 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
570 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
571 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
572
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
573 static const char *test_map_reference_get(const char *key) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
574 for (size_t i = 0 ; i < test_map_reference_len ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
575 if (0 == strcmp(key, test_map_reference[i].key)) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
576 return test_map_reference[i].value;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
577 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
578 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
579 return NULL;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
580 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
581
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
582 static const char *test_map_reference_remove(const char *key) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
583 for (size_t i = 0 ; i < test_map_reference_len ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
584 if (0 == strcmp(key, test_map_reference[i].key)) {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
585 const char *ret = test_map_reference[i].value;
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
586 test_map_reference[i].value = NULL;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
587 return ret;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
588 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
589 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
590 return NULL;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
591 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
592
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
593 static size_t test_map_reference_size(void) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
594 size_t size = 0;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
595 for (size_t i = 0; i < test_map_reference_len; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
596 if (test_map_reference[i].value != NULL) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
597 size++;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
598 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
599 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
600 return size;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
601 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
602
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
603 static CX_TEST_SUBROUTINE(verify_map_contents, CxMap *map) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
604 // verify that the reference map has same size (i.e. no other keys are mapped)
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
605 CX_TEST_ASSERT(map->collection.size == test_map_reference_size());
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
606
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
607 // verify key iterator
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
608 {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
609 // collect the keys from the map iterator
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
610 CxMapIterator keyiter = cxMapIteratorKeys(map);
850
b2bc48c2b251 add iterator over raw C arrays - closes #389
Mike Becker <universe@uap-core.de>
parents: 785
diff changeset
611 CX_TEST_ASSERT(keyiter.elem_size == sizeof(CxHashKey));
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
612 CX_TEST_ASSERT(keyiter.elem_count == map->collection.size);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
613 CxHashKey *keys = calloc(map->collection.size, sizeof(CxHashKey));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
614 cx_foreach(CxHashKey*, elem, keyiter) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
615 keys[keyiter.index] = *elem;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
616 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
617 CX_TEST_ASSERT(keyiter.index == map->collection.size);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
618 // verify that all keys are mapped to values in reference map
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
619 for (size_t i = 0 ; i < map->collection.size ; i++) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
620 cxmutstr ksz = cx_strdup(cx_strn(keys[i].data, keys[i].len));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
621 CX_TEST_ASSERT(test_map_reference_get(ksz.ptr) != NULL);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
622 cx_strfree(&ksz);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
623 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
624 free(keys);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
625 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
626
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
627 // verify value iterator
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
628 {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
629 // by using that the values in our test data are unique strings
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
630 // we can re-use a similar approach as above
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
631 CxMapIterator valiter = cxMapIteratorValues(map);
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
632 CX_TEST_ASSERT(valiter.elem_size == map->collection.elem_size);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
633 CX_TEST_ASSERT(valiter.elem_count == map->collection.size);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
634 const char ** values = calloc(map->collection.size, sizeof(const char *));
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
635 cx_foreach(const char *, elem, valiter) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
636 values[valiter.index] = elem;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
637 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
638 CX_TEST_ASSERT(valiter.index == map->collection.size);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
639 // verify that all values are present in the reference map
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
640 for (size_t i = 0 ; i < map->collection.size ; i++) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
641 bool found = false;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
642 for (size_t j = 0; j < test_map_reference_len ; j++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
643 if (test_map_reference[j].value == values[i]) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
644 found = true;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
645 break;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
646 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
647 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
648 CX_TEST_ASSERTM(found, "A value was not found in the reference map");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
649 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
650 free(values);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
651 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
652
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
653 // verify pair iterator
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
654 {
1115
6db21dee4929 create specialized map iterators - fixes #550
Mike Becker <universe@uap-core.de>
parents: 1114
diff changeset
655 CxMapIterator pairiter = cxMapIterator(map);
850
b2bc48c2b251 add iterator over raw C arrays - closes #389
Mike Becker <universe@uap-core.de>
parents: 785
diff changeset
656 CX_TEST_ASSERT(pairiter.elem_size == sizeof(CxMapEntry));
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
657 CX_TEST_ASSERT(pairiter.elem_count == map->collection.size);
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
658 struct test_map_kv *pairs = calloc(map->collection.size, sizeof(struct test_map_kv));
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
659 cx_foreach(CxMapEntry*, entry, pairiter) {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
660 const CxHashKey *key = entry->key;
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
661 pairs[pairiter.index].key = cx_strdup(cx_strn(key->data, key->len)).ptr;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
662 pairs[pairiter.index].value = entry->value;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
663 }
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
664 CX_TEST_ASSERT(pairiter.index == map->collection.size);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
665 // verify that all pairs are present in the reference map
856
6bbbf219251d fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
666 for (size_t i = 0 ; i < map->collection.size ; i++) {
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
667 CX_TEST_ASSERT(test_map_reference_get(pairs[i].key) == pairs[i].value);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
668 // this was strdup'ed
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
669 free((void*)pairs[i].key);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
670 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
671 free(pairs);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
672 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
673 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
674
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
675 CX_TEST(test_hash_map_basic_operations) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
676 CxTestingAllocator talloc;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
677 cx_testing_allocator_init(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
678 CxAllocator *allocator = &talloc.base;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
679 CX_TEST_DO {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
680 // create the map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
681 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 8);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
682
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
683 // clear the reference map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
684 for (size_t i = 0 ; i < test_map_reference_len ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
685 test_map_reference[i].value = NULL;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
686 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
687
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
688 // verify iterators for empty map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
689 CX_TEST_CALL_SUBROUTINE(verify_map_contents, map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
690
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
691 // execute operations and verify results
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
692 for (size_t i = 0 ; i < test_map_operations_len ; i++) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
693 struct test_map_kv kv = test_map_operations[i];
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
694 CxHashKey key = cx_hash_key_str(kv.key);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
695 key.hash = 0; // force the hash map to compute the hash
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
696 if (kv.value != NULL) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
697 // execute a put operation and verify that the exact value can be read back
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
698 test_map_reference_put(kv.key, kv.value);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
699 int result = cxMapPut(map, key, (void *) kv.value);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
700 CX_TEST_ASSERT(result == 0);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
701 void *added = cxMapGet(map, key);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
702 CX_TEST_ASSERT(0 == memcmp(kv.value, added, strlen(kv.value)));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
703 } else {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
704 // execute a remove and verify that the removed element was returned (or NULL)
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 856
diff changeset
705 const char *found = test_map_reference_remove(kv.key);
994
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
706 void *removed = (void*) 0x1337;
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
707 int result = cxMapRemoveAndGet(map, key, &removed);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
708 if (found == NULL) {
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
709 CX_TEST_ASSERT(0 != result);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
710 CX_TEST_ASSERT(removed == (void*) 0x1337);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
711 } else {
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
712 CX_TEST_ASSERT(0 == result);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
713 CX_TEST_ASSERT(removed == found);
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
714 }
3603bdf4a78b remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
715
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
716 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
717 // compare the current map state with the reference map
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
718 CX_TEST_CALL_SUBROUTINE(verify_map_contents, map);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
719 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
720
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
721 // destroy the map and verify the memory (de)allocations
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
722 cxMapFree(map);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
723 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
724 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
725 cx_testing_allocator_destroy(&talloc);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
726 }
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
727
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
728 CxTestSuite *cx_test_suite_hash_map(void) {
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
729 CxTestSuite *suite = cx_test_suite_new("map");
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
730
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
731 cx_test_register(suite, test_hash_map_create);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
732 cx_test_register(suite, test_hash_map_create_store_pointers);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
733 cx_test_register(suite, test_hash_map_basic_operations);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
734 cx_test_register(suite, test_hash_map_rehash);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
735 cx_test_register(suite, test_hash_map_rehash_not_required);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
736 cx_test_register(suite, test_hash_map_clear);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
737 cx_test_register(suite, test_hash_map_store_ucx_strings);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
738 cx_test_register(suite, test_hash_map_remove_via_iterator);
1114
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
739 cx_test_register(suite, test_hash_map_simple_destructor_objects);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
740 cx_test_register(suite, test_hash_map_advanced_destructor_objects);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
741 cx_test_register(suite, test_hash_map_simple_destructor_pointers);
ad5eeb256242 fix that overwriting a map element did not call any destructor function
Mike Becker <universe@uap-core.de>
parents: 1111
diff changeset
742 cx_test_register(suite, test_hash_map_advanced_destructor_pointers);
785
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
743 cx_test_register(suite, test_empty_map_no_ops);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
744 cx_test_register(suite, test_empty_map_size);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
745 cx_test_register(suite, test_empty_map_get);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
746 cx_test_register(suite, test_empty_map_iterator);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
747 cx_test_register(suite, test_hash_map_generics);
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
748
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
749 return suite;
bb18daa62d5f migrate map tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
750 }

mercurial