67 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
67 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
68 } |
68 } |
69 cx_testing_allocator_destroy(&talloc); |
69 cx_testing_allocator_destroy(&talloc); |
70 } |
70 } |
71 |
71 |
|
72 CX_TEST(test_kv_list_remove) { |
|
73 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
74 int x; |
|
75 CX_TEST_DO { |
|
76 CxMap *map = cxKvListAsMap(list); |
|
77 |
|
78 x = 13; |
|
79 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
80 x = 37; |
|
81 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); |
|
82 x = 47; |
|
83 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); |
|
84 x = 90; |
|
85 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); |
|
86 |
|
87 CX_TEST_ASSERT(cxMapSize(map) == 4); |
|
88 CX_TEST_ASSERT(cxListSize(list) == 4); |
|
89 |
|
90 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 47); |
|
91 CX_TEST_ASSERT(0 == cxListRemove(list, 2)); |
|
92 CX_TEST_ASSERT(cxListSize(list) == 3); |
|
93 CX_TEST_ASSERT(cxMapSize(map) == 3); |
|
94 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); |
|
95 |
|
96 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); |
|
97 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); |
|
98 CX_TEST_ASSERT(cxListSize(list) == 2); |
|
99 CX_TEST_ASSERT(cxMapSize(map) == 2); |
|
100 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); |
|
101 |
|
102 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); |
|
103 CX_TEST_ASSERT(0 == cxListRemove(list, 1)); |
|
104 CX_TEST_ASSERT(cxListSize(list) == 1); |
|
105 CX_TEST_ASSERT(cxMapSize(map) == 1); |
|
106 CX_TEST_ASSERT(cxMapGet(map, "hij") == NULL); |
|
107 } |
|
108 cxListFree(list); |
|
109 } |
|
110 |
|
111 CX_TEST(test_kv_list_remove_and_get) { |
|
112 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
113 int x, y; |
|
114 CX_TEST_DO { |
|
115 CxMap *map = cxKvListAsMap(list); |
|
116 |
|
117 x = 13; |
|
118 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
119 x = 37; |
|
120 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); |
|
121 x = 47; |
|
122 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); |
|
123 x = 90; |
|
124 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); |
|
125 |
|
126 CX_TEST_ASSERT(cxMapSize(map) == 4); |
|
127 CX_TEST_ASSERT(cxListSize(list) == 4); |
|
128 |
|
129 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 47); |
|
130 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 2, &y)); |
|
131 CX_TEST_ASSERT(y == 47); |
|
132 CX_TEST_ASSERT(cxListSize(list) == 3); |
|
133 CX_TEST_ASSERT(cxMapSize(map) == 3); |
|
134 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); |
|
135 |
|
136 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); |
|
137 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 0, &y)); |
|
138 CX_TEST_ASSERT(y == 13); |
|
139 CX_TEST_ASSERT(cxListSize(list) == 2); |
|
140 CX_TEST_ASSERT(cxMapSize(map) == 2); |
|
141 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); |
|
142 |
|
143 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); |
|
144 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 1, &y)); |
|
145 CX_TEST_ASSERT(y == 90); |
|
146 CX_TEST_ASSERT(cxListSize(list) == 1); |
|
147 CX_TEST_ASSERT(cxMapSize(map) == 1); |
|
148 CX_TEST_ASSERT(cxMapGet(map, "hij") == NULL); |
|
149 } |
|
150 cxListFree(list); |
|
151 } |
|
152 |
|
153 CX_TEST(test_kv_list_remove_array) { |
|
154 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
155 int x; |
|
156 CX_TEST_DO { |
|
157 CxMap *map = cxKvListAsMap(list); |
|
158 |
|
159 x = 13; |
|
160 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
161 x = 37; |
|
162 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); |
|
163 x = 47; |
|
164 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); |
|
165 x = 90; |
|
166 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); |
|
167 |
|
168 CX_TEST_ASSERT(cxMapSize(map) == 4); |
|
169 CX_TEST_ASSERT(cxListSize(list) == 4); |
|
170 |
|
171 CX_TEST_ASSERT(2 == cxListRemoveArray(list, 1, 2)); |
|
172 CX_TEST_ASSERT(cxMapSize(map) == 2); |
|
173 CX_TEST_ASSERT(cxListSize(list) == 2); |
|
174 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); |
|
175 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); |
|
176 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); |
|
177 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); |
|
178 CX_TEST_ASSERT(cxListAt(list, 0) == cxMapGet(map, "xyz")); |
|
179 CX_TEST_ASSERT(cxListAt(list, 1) == cxMapGet(map, "hij")); |
|
180 } |
|
181 cxListFree(list); |
|
182 } |
|
183 |
|
184 CX_TEST(test_kv_list_remove_array_and_get) { |
|
185 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
186 int x; |
|
187 CX_TEST_DO { |
|
188 CxMap *map = cxKvListAsMap(list); |
|
189 |
|
190 x = 13; |
|
191 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
192 x = 37; |
|
193 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); |
|
194 x = 47; |
|
195 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); |
|
196 x = 90; |
|
197 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); |
|
198 |
|
199 CX_TEST_ASSERT(cxMapSize(map) == 4); |
|
200 CX_TEST_ASSERT(cxListSize(list) == 4); |
|
201 |
|
202 int y[2]; |
|
203 |
|
204 CX_TEST_ASSERT(2 == cxListRemoveArrayAndGet(list, 1, 2, y)); |
|
205 CX_TEST_ASSERT(y[0] == 37); |
|
206 CX_TEST_ASSERT(y[1] == 47); |
|
207 CX_TEST_ASSERT(cxMapSize(map) == 2); |
|
208 CX_TEST_ASSERT(cxListSize(list) == 2); |
|
209 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); |
|
210 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); |
|
211 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); |
|
212 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); |
|
213 CX_TEST_ASSERT(cxListAt(list, 0) == cxMapGet(map, "xyz")); |
|
214 CX_TEST_ASSERT(cxListAt(list, 1) == cxMapGet(map, "hij")); |
|
215 } |
|
216 cxListFree(list); |
|
217 } |
|
218 |
72 CX_TEST(test_kv_list_map_put) { |
219 CX_TEST(test_kv_list_map_put) { |
73 CxList *list = cxKvListCreateSimple(sizeof(int)); |
220 CxList *list = cxKvListCreateSimple(sizeof(int)); |
74 int x; |
221 int x; |
75 CX_TEST_DO { |
222 CX_TEST_DO { |
76 CxMap *map = cxKvListAsMap(list); |
223 CxMap *map = cxKvListAsMap(list); |
329 CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); |
476 CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); |
330 |
477 |
331 cx_test_register(suite, test_kv_list_map_as_list); |
478 cx_test_register(suite, test_kv_list_map_as_list); |
332 cx_test_register(suite, test_kv_list_free_as_map); |
479 cx_test_register(suite, test_kv_list_free_as_map); |
333 cx_test_register(suite, test_kv_list_free_as_list); |
480 cx_test_register(suite, test_kv_list_free_as_list); |
|
481 cx_test_register(suite, test_kv_list_remove); |
|
482 cx_test_register(suite, test_kv_list_remove_and_get); |
|
483 cx_test_register(suite, test_kv_list_remove_array); |
|
484 cx_test_register(suite, test_kv_list_remove_array_and_get); |
334 cx_test_register(suite, test_kv_list_map_put); |
485 cx_test_register(suite, test_kv_list_map_put); |
335 cx_test_register(suite, test_kv_list_map_put_ptr); |
486 cx_test_register(suite, test_kv_list_map_put_ptr); |
336 cx_test_register(suite, test_kv_list_map_remove); |
487 cx_test_register(suite, test_kv_list_map_remove); |
337 cx_test_register(suite, test_kv_list_set_key); |
488 cx_test_register(suite, test_kv_list_set_key); |
338 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); |
489 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); |