122 static int kv_list_test_destr_val; |
122 static int kv_list_test_destr_val; |
123 static void kv_list_test_destr(void *data) { |
123 static void kv_list_test_destr(void *data) { |
124 kv_list_test_destr_val = *(int*)data; |
124 kv_list_test_destr_val = *(int*)data; |
125 } |
125 } |
126 |
126 |
|
127 CX_TEST(test_kv_list_list_remove_destr_in_list) { |
|
128 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
129 int x; |
|
130 CX_TEST_DO { |
|
131 x = 0xabcd; |
|
132 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
|
133 cxKvListSetKey(list, 0, "xyz"); |
|
134 |
|
135 cxDefineDestructor(list, kv_list_test_destr); |
|
136 kv_list_test_destr_val = 0; |
|
137 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); |
|
138 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
139 } |
|
140 cxListFree(list); |
|
141 } |
|
142 |
|
143 CX_TEST(test_kv_list_list_remove_destr_in_map) { |
|
144 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
145 int x; |
|
146 CX_TEST_DO { |
|
147 x = 0xabcd; |
|
148 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
|
149 cxKvListSetKey(list, 0, "xyz"); |
|
150 CxMap *map = cxKvListAsMap(list); |
|
151 cxDefineDestructor(map, kv_list_test_destr); |
|
152 kv_list_test_destr_val = 0; |
|
153 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); |
|
154 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
155 } |
|
156 cxListFree(list); |
|
157 } |
|
158 |
127 CX_TEST(test_kv_list_map_remove_destr_in_list) { |
159 CX_TEST(test_kv_list_map_remove_destr_in_list) { |
128 CxList *list = cxKvListCreateSimple(sizeof(int)); |
160 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
129 int x; |
161 int x; |
130 CX_TEST_DO { |
162 CX_TEST_DO { |
131 x = 0xabcd; |
163 x = 0xabcd; |
132 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
164 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
133 cxKvListSetKey(list, 0, "xyz"); |
165 CxList *list = cxKvListAsList(map); |
134 |
166 cxDefineDestructor(list, kv_list_test_destr); |
135 cxDefineDestructor(list, kv_list_test_destr); |
167 kv_list_test_destr_val = 0; |
136 kv_list_test_destr_val = 0; |
168 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
137 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); |
169 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
138 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
170 } |
139 } |
171 cxMapFree(map); |
140 cxListFree(list); |
|
141 } |
172 } |
142 |
173 |
143 CX_TEST(test_kv_list_map_remove_destr_in_map) { |
174 CX_TEST(test_kv_list_map_remove_destr_in_map) { |
144 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
175 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
145 int x; |
176 int x; |
148 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
179 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
149 |
180 |
150 cxDefineDestructor(map, kv_list_test_destr); |
181 cxDefineDestructor(map, kv_list_test_destr); |
151 kv_list_test_destr_val = 0; |
182 kv_list_test_destr_val = 0; |
152 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
183 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
|
184 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
185 } |
|
186 cxMapFree(map); |
|
187 } |
|
188 |
|
189 CX_TEST(test_kv_list_list_clear_destr_in_list) { |
|
190 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
191 int x; |
|
192 CX_TEST_DO { |
|
193 x = 0xabcd; |
|
194 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
|
195 cxKvListSetKey(list, 0, "xyz"); |
|
196 |
|
197 cxDefineDestructor(list, kv_list_test_destr); |
|
198 kv_list_test_destr_val = 0; |
|
199 cxListClear(list); |
|
200 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
201 } |
|
202 cxListFree(list); |
|
203 } |
|
204 |
|
205 CX_TEST(test_kv_list_list_clear_destr_in_map) { |
|
206 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
207 int x; |
|
208 CX_TEST_DO { |
|
209 x = 0xabcd; |
|
210 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); |
|
211 cxKvListSetKey(list, 0, "xyz"); |
|
212 CxMap *map = cxKvListAsMap(list); |
|
213 cxDefineDestructor(map, kv_list_test_destr); |
|
214 kv_list_test_destr_val = 0; |
|
215 cxListClear(list); |
|
216 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
217 } |
|
218 cxListFree(list); |
|
219 } |
|
220 |
|
221 CX_TEST(test_kv_list_map_clear_destr_in_list) { |
|
222 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
|
223 int x; |
|
224 CX_TEST_DO { |
|
225 x = 0xabcd; |
|
226 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
227 CxList *list = cxKvListAsList(map); |
|
228 cxDefineDestructor(list, kv_list_test_destr); |
|
229 kv_list_test_destr_val = 0; |
|
230 cxMapClear(map); |
|
231 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
|
232 } |
|
233 cxMapFree(map); |
|
234 } |
|
235 |
|
236 CX_TEST(test_kv_list_map_clear_destr_in_map) { |
|
237 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
|
238 int x; |
|
239 CX_TEST_DO { |
|
240 x = 0xabcd; |
|
241 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
|
242 |
|
243 cxDefineDestructor(map, kv_list_test_destr); |
|
244 kv_list_test_destr_val = 0; |
|
245 cxMapClear(map); |
153 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
246 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); |
154 } |
247 } |
155 cxMapFree(map); |
248 cxMapFree(map); |
156 } |
249 } |
157 |
250 |
161 cx_test_register(suite, test_kv_list_map_as_list); |
254 cx_test_register(suite, test_kv_list_map_as_list); |
162 cx_test_register(suite, test_kv_list_free_as_map); |
255 cx_test_register(suite, test_kv_list_free_as_map); |
163 cx_test_register(suite, test_kv_list_free_as_list); |
256 cx_test_register(suite, test_kv_list_free_as_list); |
164 cx_test_register(suite, test_kv_list_map_put); |
257 cx_test_register(suite, test_kv_list_map_put); |
165 cx_test_register(suite, test_kv_list_map_remove); |
258 cx_test_register(suite, test_kv_list_map_remove); |
|
259 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); |
|
260 cx_test_register(suite, test_kv_list_list_remove_destr_in_map); |
166 cx_test_register(suite, test_kv_list_map_remove_destr_in_list); |
261 cx_test_register(suite, test_kv_list_map_remove_destr_in_list); |
167 cx_test_register(suite, test_kv_list_map_remove_destr_in_map); |
262 cx_test_register(suite, test_kv_list_map_remove_destr_in_map); |
|
263 cx_test_register(suite, test_kv_list_list_clear_destr_in_list); |
|
264 cx_test_register(suite, test_kv_list_list_clear_destr_in_map); |
|
265 cx_test_register(suite, test_kv_list_map_clear_destr_in_list); |
|
266 cx_test_register(suite, test_kv_list_map_clear_destr_in_map); |
168 |
267 |
169 return suite; |
268 return suite; |
170 } |
269 } |