UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2025 Mike Becker, Olaf Wintermann All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include "cx/test.h" 30 #include "util_allocator.h" 31 32 #include "cx/kv_list.h" 33 34 static int kv_list_test_destr_val; 35 static void kv_list_test_destr(void *data) { 36 kv_list_test_destr_val = *(int*)data; 37 } 38 39 static void *kv_list_test_destr2_extra; 40 static int kv_list_test_destr2_val; 41 static void kv_list_test_destr2(void* extra, void *data) { 42 kv_list_test_destr2_extra = extra; 43 kv_list_test_destr2_val = *(int*)data; 44 } 45 46 CX_TEST(test_kv_list_map_as_list) { 47 CxList *list = cxKvListCreateSimple(sizeof(int)); 48 CX_TEST_DO { 49 CxMap *map = cxKvListAsMap(list); 50 CX_TEST_ASSERT(map != NULL); 51 CxList *list_from_map = cxKvListAsList(map); 52 CX_TEST_ASSERT(list_from_map == list); 53 } 54 cxListFree(list); 55 } 56 57 CX_TEST(test_kv_list_free_as_map) { 58 CxTestingAllocator talloc; 59 cx_testing_allocator_init(&talloc); 60 CX_TEST_DO { 61 CxList *list = cxKvListCreate(&talloc.base, NULL, 1); 62 cxListAddArray(list, "test", 4); 63 CxMap *map = cxKvListAsMap(list); 64 cxMapFree(map); 65 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 66 } 67 cx_testing_allocator_destroy(&talloc); 68 } 69 70 CX_TEST(test_kv_list_free_as_list) { 71 CxTestingAllocator talloc; 72 cx_testing_allocator_init(&talloc); 73 CX_TEST_DO { 74 CxMap *map = cxKvListCreateAsMap(&talloc.base, NULL, sizeof(int)); 75 int x = 5; 76 cxMapPut(map, "test", &x); 77 CxList *list = cxKvListAsList(map); 78 cxListFree(list); 79 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 80 } 81 cx_testing_allocator_destroy(&talloc); 82 } 83 84 CX_TEST(test_kv_list_remove) { 85 CxList *list = cxKvListCreateSimple(sizeof(int)); 86 int x; 87 CX_TEST_DO { 88 CxMap *map = cxKvListAsMap(list); 89 90 x = 13; 91 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 92 x = 37; 93 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 94 x = 47; 95 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); 96 x = 90; 97 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); 98 99 CX_TEST_ASSERT(cxMapSize(map) == 4); 100 CX_TEST_ASSERT(cxListSize(list) == 4); 101 102 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 47); 103 CX_TEST_ASSERT(0 == cxListRemove(list, 2)); 104 CX_TEST_ASSERT(cxListSize(list) == 3); 105 CX_TEST_ASSERT(cxMapSize(map) == 3); 106 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); 107 108 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 109 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 110 CX_TEST_ASSERT(cxListSize(list) == 2); 111 CX_TEST_ASSERT(cxMapSize(map) == 2); 112 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 113 114 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); 115 CX_TEST_ASSERT(0 == cxListRemove(list, 1)); 116 CX_TEST_ASSERT(cxListSize(list) == 1); 117 CX_TEST_ASSERT(cxMapSize(map) == 1); 118 CX_TEST_ASSERT(cxMapGet(map, "hij") == NULL); 119 } 120 cxListFree(list); 121 } 122 123 CX_TEST(test_kv_list_find_and_remove) { 124 CxList *list = cxKvListCreateSimple(sizeof(int)); 125 cxCollectionCompareFunc(list, cx_cmp_int); 126 int x, y; 127 CX_TEST_DO { 128 CxMap *map = cxKvListAsMap(list); 129 130 x = 13; 131 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 132 x = 37; 133 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 134 x = 47; 135 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); 136 x = 90; 137 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); 138 139 CX_TEST_ASSERT(cxMapSize(map) == 4); 140 CX_TEST_ASSERT(cxListSize(list) == 4); 141 142 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 47); 143 y = 47; 144 CX_TEST_ASSERT(2 == cxListFindRemove(list, &y)); 145 CX_TEST_ASSERT(cxListSize(list) == 3); 146 CX_TEST_ASSERT(cxMapSize(map) == 3); 147 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); 148 149 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 150 y = 13; 151 CX_TEST_ASSERT(0 == cxListFindRemove(list, &y)); 152 CX_TEST_ASSERT(cxListSize(list) == 2); 153 CX_TEST_ASSERT(cxMapSize(map) == 2); 154 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 155 156 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); 157 y = 90; 158 CX_TEST_ASSERT(1 == cxListFindRemove(list, &y)); 159 CX_TEST_ASSERT(cxListSize(list) == 1); 160 CX_TEST_ASSERT(cxMapSize(map) == 1); 161 CX_TEST_ASSERT(cxMapGet(map, "hij") == NULL); 162 163 y = 666; 164 CX_TEST_ASSERT(cxListSize(list) == cxListFindRemove(list, &y)); 165 166 y = 37; 167 CX_TEST_ASSERT(0 == cxListFindRemove(list, &y)); 168 CX_TEST_ASSERT(cxListSize(list) == 0); 169 CX_TEST_ASSERT(cxMapSize(map) == 0); 170 171 CX_TEST_ASSERT(0 == cxListFindRemove(list, &y)); 172 } 173 cxListFree(list); 174 } 175 176 CX_TEST(test_kv_list_remove_and_get) { 177 CxList *list = cxKvListCreateSimple(sizeof(int)); 178 int x, y; 179 CX_TEST_DO { 180 CxMap *map = cxKvListAsMap(list); 181 182 x = 13; 183 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 184 x = 37; 185 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 186 x = 47; 187 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); 188 x = 90; 189 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); 190 191 CX_TEST_ASSERT(cxMapSize(map) == 4); 192 CX_TEST_ASSERT(cxListSize(list) == 4); 193 194 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 47); 195 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 2, &y)); 196 CX_TEST_ASSERT(y == 47); 197 CX_TEST_ASSERT(cxListSize(list) == 3); 198 CX_TEST_ASSERT(cxMapSize(map) == 3); 199 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); 200 201 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 202 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 0, &y)); 203 CX_TEST_ASSERT(y == 13); 204 CX_TEST_ASSERT(cxListSize(list) == 2); 205 CX_TEST_ASSERT(cxMapSize(map) == 2); 206 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 207 208 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); 209 CX_TEST_ASSERT(0 == cxListRemoveAndGet(list, 1, &y)); 210 CX_TEST_ASSERT(y == 90); 211 CX_TEST_ASSERT(cxListSize(list) == 1); 212 CX_TEST_ASSERT(cxMapSize(map) == 1); 213 CX_TEST_ASSERT(cxMapGet(map, "hij") == NULL); 214 } 215 cxListFree(list); 216 } 217 218 CX_TEST(test_kv_list_remove_array) { 219 CxList *list = cxKvListCreateSimple(sizeof(int)); 220 int x; 221 CX_TEST_DO { 222 CxMap *map = cxKvListAsMap(list); 223 224 x = 13; 225 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 226 x = 37; 227 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 228 x = 47; 229 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); 230 x = 90; 231 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); 232 233 CX_TEST_ASSERT(cxMapSize(map) == 4); 234 CX_TEST_ASSERT(cxListSize(list) == 4); 235 236 CX_TEST_ASSERT(2 == cxListRemoveArray(list, 1, 2)); 237 CX_TEST_ASSERT(cxMapSize(map) == 2); 238 CX_TEST_ASSERT(cxListSize(list) == 2); 239 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); 240 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); 241 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 242 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); 243 CX_TEST_ASSERT(cxListAt(list, 0) == cxMapGet(map, "xyz")); 244 CX_TEST_ASSERT(cxListAt(list, 1) == cxMapGet(map, "hij")); 245 } 246 cxListFree(list); 247 } 248 249 CX_TEST(test_kv_list_remove_array_and_get) { 250 CxList *list = cxKvListCreateSimple(sizeof(int)); 251 int x; 252 CX_TEST_DO { 253 CxMap *map = cxKvListAsMap(list); 254 255 x = 13; 256 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 257 x = 37; 258 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 259 x = 47; 260 CX_TEST_ASSERT(0 == cxMapPut(map, "efg", &x)); 261 x = 90; 262 CX_TEST_ASSERT(0 == cxMapPut(map, "hij", &x)); 263 264 CX_TEST_ASSERT(cxMapSize(map) == 4); 265 CX_TEST_ASSERT(cxListSize(list) == 4); 266 267 int y[2]; 268 269 CX_TEST_ASSERT(2 == cxListRemoveArrayAndGet(list, 1, 2, y)); 270 CX_TEST_ASSERT(y[0] == 37); 271 CX_TEST_ASSERT(y[1] == 47); 272 CX_TEST_ASSERT(cxMapSize(map) == 2); 273 CX_TEST_ASSERT(cxListSize(list) == 2); 274 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); 275 CX_TEST_ASSERT(cxMapGet(map, "efg") == NULL); 276 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 277 CX_TEST_ASSERT(*(int*)cxMapGet(map, "hij") == 90); 278 CX_TEST_ASSERT(cxListAt(list, 0) == cxMapGet(map, "xyz")); 279 CX_TEST_ASSERT(cxListAt(list, 1) == cxMapGet(map, "hij")); 280 } 281 cxListFree(list); 282 } 283 284 CX_TEST(test_kv_list_map_put) { 285 CxList *list = cxKvListCreateSimple(sizeof(int)); 286 int x; 287 CX_TEST_DO { 288 CxMap *map = cxKvListAsMap(list); 289 290 x = 13; 291 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 292 293 x = 37; 294 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 295 296 CX_TEST_ASSERT(cxMapSize(map) == 2); 297 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 298 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 37); 299 300 CX_TEST_ASSERT(cxListSize(list) == 2); 301 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 13); 302 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 37); 303 } 304 cxListFree(list); 305 } 306 307 CX_TEST(test_kv_list_map_put_ptr) { 308 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 309 int x; 310 CX_TEST_DO { 311 CxMap *map = cxKvListAsMap(list); 312 x = 13; 313 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 314 x = 37; 315 CX_TEST_ASSERT((int*)cxListAt(list, 0) == &x); 316 CX_TEST_ASSERT((int*)cxMapGet(map, "xyz") == &x); 317 } 318 cxListFree(list); 319 } 320 321 CX_TEST(test_kv_list_map_put_not_hashed) { 322 CxList *list = cxKvListCreateSimple(sizeof(int)); 323 int x; 324 CX_TEST_DO { 325 CxMap *map = cxKvListAsMap(list); 326 x = 13; 327 // test with a custom key that was not hashed, yet 328 CxHashKey key = {0}; 329 key.data = "xyz"; 330 key.len = 3; 331 CX_TEST_ASSERT(0 == cxMapPut(map, key, &x)); 332 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 13); 333 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 334 335 // remove and check if the copied key is correctly removed 336 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 337 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 338 } 339 cxListFree(list); 340 } 341 342 CX_TEST(test_kv_list_map_put_overwrite) { 343 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 344 CxTestingAllocator talloc; 345 cx_testing_allocator_init(&talloc); 346 CxAllocator *al = &talloc.base; 347 int *x, *y; 348 CX_TEST_DO { 349 CxMap *map = cxKvListAsMap(list); 350 cxDefineAdvancedDestructor(map, cxFree, al); 351 x = cxMalloc(al, sizeof(int)); 352 y = cxMalloc(al, sizeof(int)); 353 *x = 13; 354 *y = 37; 355 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", x)); 356 CX_TEST_ASSERT(cxCollectionSize(map) == 1); 357 CX_TEST_ASSERT(cxCollectionSize(list) == 1); 358 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 13); 359 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 360 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", y)); 361 CX_TEST_ASSERT(cxCollectionSize(map) == 1); 362 CX_TEST_ASSERT(cxCollectionSize(list) == 1); 363 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 37); 364 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 37); 365 cxMapClear(map); 366 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 367 } 368 cx_testing_allocator_destroy(&talloc); 369 cxListFree(list); 370 } 371 372 CX_TEST(test_kv_list_map_remove) { 373 CxList *list = cxKvListCreateSimple(sizeof(int)); 374 int x; 375 CX_TEST_DO { 376 CxMap *map = cxKvListAsMap(list); 377 378 x = 13; 379 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 380 381 x = 37; 382 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 383 384 CX_TEST_ASSERT(cxMapSize(map) == 2); 385 386 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 387 CX_TEST_ASSERT(cxMapSize(map) == 1); 388 CX_TEST_ASSERT(cxMapGet(map, "abc") != NULL); 389 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 390 391 CX_TEST_ASSERT(cxListSize(list) == 1); 392 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 37); 393 394 CX_TEST_ASSERT(0 != cxMapRemove(map, "xyz")); 395 } 396 cxListFree(list); 397 } 398 399 CX_TEST(test_kv_list_map_remove_and_get) { 400 CxList *list = cxKvListCreateSimple(sizeof(int)); 401 int x, y; 402 CX_TEST_DO { 403 CxMap *map = cxKvListAsMap(list); 404 405 x = 13; 406 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 407 408 x = 37; 409 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 410 411 CX_TEST_ASSERT(cxMapSize(map) == 2); 412 cxDefineDestructor(map, kv_list_test_destr); 413 kv_list_test_destr_val = 0; 414 y = 0; 415 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, "xyz", &y)); 416 CX_TEST_ASSERT(y == 13); 417 // destr not called! 418 CX_TEST_ASSERT(kv_list_test_destr_val == 0); 419 CX_TEST_ASSERT(cxMapSize(map) == 1); 420 CX_TEST_ASSERT(cxMapGet(map, "abc") != NULL); 421 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 422 423 CX_TEST_ASSERT(cxListSize(list) == 1); 424 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 37); 425 426 CX_TEST_ASSERT(0 != cxMapRemove(map, "xyz")); 427 } 428 cxListFree(list); 429 } 430 431 CX_TEST(test_kv_list_set_key) { 432 CxList *list = cxKvListCreateSimple(sizeof(int)); 433 int x; 434 CX_TEST_DO { 435 x = 47; 436 cxListAdd(list, &x); 437 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); 438 // index out of bounds: 439 CX_TEST_ASSERT(0 != cxKvListSetKey(list, 1, "abc")); 440 441 CxMap *map = cxKvListAsMap(list); 442 443 CX_TEST_ASSERT(cxMapSize(map) == 1); 444 445 int *y = cxMapGet(map, "xyz"); 446 CX_TEST_ASSERT(y != NULL); 447 CX_TEST_ASSERT(*y == 47); 448 449 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 450 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 451 452 CX_TEST_ASSERT(cxListSize(list) == 0); 453 454 // now check with a non-prehashed key 455 x = 85; 456 cxListAdd(list, &x); 457 CxHashKey key = {0}; 458 key.data = "abc"; 459 key.len = 3; 460 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, key)); 461 y = cxMapGet(map, "abc"); 462 CX_TEST_ASSERT(y != NULL); 463 CX_TEST_ASSERT(*y == 85); 464 465 CX_TEST_ASSERT(0 == cxMapRemove(map, "abc")); 466 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); 467 468 CX_TEST_ASSERT(cxListSize(list) == 0); 469 } 470 cxListFree(list); 471 } 472 473 CX_TEST(test_kv_list_set_key_already_exists) { 474 CxList *list = cxKvListCreateSimple(sizeof(int)); 475 int x; 476 CX_TEST_DO { 477 x = 47; 478 cxListAdd(list, &x); 479 x = 11; 480 cxListAdd(list, &x); 481 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "xyz")); 482 // already exists 483 CX_TEST_ASSERT(0 != cxKvListSetKey(list, 0, "xyz")); 484 485 CxMap *map = cxKvListAsMap(list); 486 487 CX_TEST_ASSERT(cxMapSize(map) == 1); 488 489 int *y = cxMapGet(map, "xyz"); 490 CX_TEST_ASSERT(y != NULL); 491 CX_TEST_ASSERT(*y == 11); 492 493 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 494 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 495 CX_TEST_ASSERT(cxListSize(list) == 1); 496 497 // now we can assign the key again 498 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); 499 y = cxMapGet(map, "xyz"); 500 CX_TEST_ASSERT(y != NULL); 501 CX_TEST_ASSERT(*y == 47); 502 } 503 cxListFree(list); 504 } 505 506 CX_TEST(test_kv_list_set_key_again) { 507 CxList *list = cxKvListCreateSimple(sizeof(int)); 508 int x; 509 CX_TEST_DO { 510 x = 47; 511 cxListAdd(list, &x); 512 x = 11; 513 cxListAdd(list, &x); 514 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "xyz")); 515 // calling it twice is also okay! 516 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "xyz")); 517 518 CxMap *map = cxKvListAsMap(list); 519 520 CX_TEST_ASSERT(cxMapSize(map) == 1); 521 522 int *y = cxMapGet(map, "xyz"); 523 CX_TEST_ASSERT(y != NULL); 524 CX_TEST_ASSERT(*y == 11); 525 526 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 527 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL); 528 CX_TEST_ASSERT(cxListSize(list) == 1); 529 } 530 cxListFree(list); 531 } 532 533 CX_TEST(test_kv_list_remove_key) { 534 CxList *list = cxKvListCreateSimple(sizeof(int)); 535 int x; 536 CX_TEST_DO { 537 CxMap *map = cxKvListAsMap(list); 538 539 x = 47; 540 cxMapPut(map, "xyz", &x); 541 x = 11; 542 cxMapPut(map, "abc", &x); 543 x = 1337; 544 cxMapPut(map, "efg", &x); 545 CX_TEST_ASSERT(cxMapSize(map) == 3); 546 547 int *y = cxMapGet(map, "abc"); 548 CX_TEST_ASSERT(y != NULL); 549 CX_TEST_ASSERT(*y == 11); 550 551 CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); 552 CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL); 553 CX_TEST_ASSERT(cxMapSize(map) == 2); 554 CX_TEST_ASSERT(cxListSize(list) == 3); 555 556 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 11); 557 558 y = cxMapGet(map, "xyz"); 559 CX_TEST_ASSERT(y != NULL); 560 CX_TEST_ASSERT(*y == 47); 561 562 y = cxMapGet(map, "efg"); 563 CX_TEST_ASSERT(y != NULL); 564 CX_TEST_ASSERT(*y == 1337); 565 566 // idempotence 567 CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); 568 569 // index out of bounds: 570 CX_TEST_ASSERT(0 != cxKvListRemoveKey(list, 3)); 571 } 572 cxListFree(list); 573 } 574 575 CX_TEST(test_kv_list_get_key) { 576 CxList *list = cxKvListCreateSimple(sizeof(int)); 577 int x; 578 CX_TEST_DO { 579 CxMap *map = cxKvListAsMap(list); 580 581 x = 47; 582 cxMapPut(map, "xyz", &x); 583 x = 11; 584 cxMapPut(map, "abc", &x); 585 x = 1337; 586 cxMapPut(map, "efg", &x); 587 CX_TEST_ASSERT(cxMapSize(map) == 3); 588 589 const CxHashKey *key = cxKvListGetKey(list, 1); 590 int *y = cxMapGet(map, *key); 591 CX_TEST_ASSERT(y != NULL); 592 CX_TEST_ASSERT(*y == 11); 593 594 // removing the element 595 CX_TEST_ASSERT(0 == cxMapRemove(map, cx_strn(key->data, key->len))); 596 key = cxKvListGetKey(list, 1); 597 CX_TEST_ASSERT(0 == cx_strcmp(CX_STR("efg"), cx_strn(key->data, key->len))); 598 599 // remove the key of element 600 CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); 601 CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 1)); 602 603 // index out of bounds: 604 CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 3)); 605 } 606 cxListFree(list); 607 } 608 609 CX_TEST(test_kv_list_insert_with_key) { 610 CxList *list = cxKvListCreateSimple(sizeof(int)); 611 int x; 612 CX_TEST_DO { 613 x = 47; 614 cxKvListAdd(list, "xyz", &x); 615 x = 11; 616 cxKvListAdd(list, "abc", &x); 617 x = 1337; 618 cxKvListInsert(list, 1, "efg", &x); 619 620 CX_TEST_ASSERT(cxListSize(list) == 3); 621 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 47); 622 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 1337); 623 CX_TEST_ASSERT(*(int*)cxListAt(list, 2) == 11); 624 625 CxMap *map = cxKvListAsMap(list); 626 CX_TEST_ASSERT(cxMapSize(map) == 3); 627 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 47); 628 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 11); 629 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 1337); 630 } 631 cxListFree(list); 632 } 633 634 CX_TEST(test_kv_list_insert_ptr_with_key) { 635 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 636 int x, y, z; 637 CX_TEST_DO { 638 x = 15; 639 cxKvListAdd(list, "xyz", &x); 640 y = 16; 641 cxKvListAdd(list, "abc", &y); 642 z = 17; 643 cxKvListInsert(list, 1, "efg", &z); 644 x = 47; 645 y = 11; 646 z = 1337; 647 648 CX_TEST_ASSERT(cxListSize(list) == 3); 649 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 47); 650 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 1337); 651 CX_TEST_ASSERT(*(int*)cxListAt(list, 2) == 11); 652 653 CxMap *map = cxKvListAsMap(list); 654 CX_TEST_ASSERT(cxMapSize(map) == 3); 655 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 47); 656 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 11); 657 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 1337); 658 } 659 cxListFree(list); 660 } 661 662 CX_TEST(test_kv_list_insert_array_and_set_keys) { 663 CxList *list = cxKvListCreateSimple(sizeof(int)); 664 CX_TEST_DO { 665 int arr[] = { 13, 21, 34, 55, 89 }; 666 CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5)); 667 CX_TEST_ASSERT(5 == cxListSize(list)); 668 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); 669 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "abc")); 670 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 2, "def")); 671 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 3, "ghi")); 672 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 4, "jkl")); 673 674 CxMap *map = cxKvListAsMap(list); 675 CX_TEST_ASSERT(5 == cxMapSize(map)); 676 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); 677 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 21); 678 CX_TEST_ASSERT(*(int*)cxMapGet(map, "def") == 34); 679 CX_TEST_ASSERT(*(int*)cxMapGet(map, "ghi") == 55); 680 CX_TEST_ASSERT(*(int*)cxMapGet(map, "jkl") == 89); 681 } 682 cxListFree(list); 683 } 684 685 CX_TEST(test_kv_list_list_remove_destr_in_list) { 686 CxList *list = cxKvListCreateSimple(sizeof(int)); 687 int x; 688 CX_TEST_DO { 689 x = 0xabcd; 690 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 691 cxKvListSetKey(list, 0, "xyz"); 692 693 cxDefineDestructor(list, kv_list_test_destr); 694 kv_list_test_destr_val = 0; 695 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 696 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 697 } 698 cxListFree(list); 699 } 700 701 CX_TEST(test_kv_list_list_remove_destr_in_map) { 702 CxList *list = cxKvListCreateSimple(sizeof(int)); 703 int x; 704 CX_TEST_DO { 705 x = 0xabcd; 706 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 707 cxKvListSetKey(list, 0, "xyz"); 708 CxMap *map = cxKvListAsMap(list); 709 cxDefineDestructor(map, kv_list_test_destr); 710 kv_list_test_destr_val = 0; 711 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 712 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 713 } 714 cxListFree(list); 715 } 716 717 CX_TEST(test_kv_list_map_remove_destr_in_list) { 718 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 719 int x; 720 CX_TEST_DO { 721 x = 0xabcd; 722 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 723 CxList *list = cxKvListAsList(map); 724 cxDefineDestructor(list, kv_list_test_destr); 725 kv_list_test_destr_val = 0; 726 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 727 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 728 } 729 cxMapFree(map); 730 } 731 732 CX_TEST(test_kv_list_map_remove_destr_in_map) { 733 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 734 int x; 735 CX_TEST_DO { 736 x = 0xabcd; 737 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 738 739 cxDefineDestructor(map, kv_list_test_destr); 740 kv_list_test_destr_val = 0; 741 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 742 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 743 } 744 cxMapFree(map); 745 } 746 747 CX_TEST(test_kv_list_list_remove_destr2_in_list) { 748 CxList *list = cxKvListCreateSimple(sizeof(int)); 749 int x; 750 CX_TEST_DO { 751 x = 0xabcd; 752 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 753 cxKvListSetKey(list, 0, "xyz"); 754 755 cxDefineAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47); 756 kv_list_test_destr2_val = 0; 757 kv_list_test_destr2_extra = NULL; 758 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 759 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 760 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 761 } 762 cxListFree(list); 763 } 764 765 CX_TEST(test_kv_list_list_remove_destr2_in_map) { 766 CxList *list = cxKvListCreateSimple(sizeof(int)); 767 int x; 768 CX_TEST_DO { 769 x = 0xabcd; 770 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 771 cxKvListSetKey(list, 0, "xyz"); 772 CxMap *map = cxKvListAsMap(list); 773 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47); 774 kv_list_test_destr2_val = 0; 775 kv_list_test_destr2_extra = NULL; 776 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 777 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 778 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 779 } 780 cxListFree(list); 781 } 782 783 CX_TEST(test_kv_list_map_remove_destr2_in_list) { 784 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 785 int x; 786 CX_TEST_DO { 787 x = 0xabcd; 788 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 789 CxList *list = cxKvListAsList(map); 790 cxDefineAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47); 791 kv_list_test_destr2_val = 0; 792 kv_list_test_destr2_extra = NULL; 793 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 794 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 795 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 796 } 797 cxMapFree(map); 798 } 799 800 CX_TEST(test_kv_list_map_remove_destr2_in_map) { 801 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 802 int x; 803 CX_TEST_DO { 804 x = 0xabcd; 805 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 806 807 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47); 808 kv_list_test_destr2_val = 0; 809 kv_list_test_destr2_extra = NULL; 810 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 811 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 812 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 813 } 814 cxMapFree(map); 815 } 816 817 CX_TEST(test_kv_list_list_clear_destr_in_list) { 818 CxList *list = cxKvListCreateSimple(sizeof(int)); 819 int x; 820 CX_TEST_DO { 821 x = 0xabcd; 822 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 823 cxKvListSetKey(list, 0, "xyz"); 824 825 cxDefineDestructor(list, kv_list_test_destr); 826 kv_list_test_destr_val = 0; 827 cxListClear(list); 828 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 829 } 830 cxListFree(list); 831 } 832 833 CX_TEST(test_kv_list_list_clear_destr_in_map) { 834 CxList *list = cxKvListCreateSimple(sizeof(int)); 835 int x; 836 CX_TEST_DO { 837 x = 0xabcd; 838 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 839 cxKvListSetKey(list, 0, "xyz"); 840 CxMap *map = cxKvListAsMap(list); 841 cxDefineDestructor(map, kv_list_test_destr); 842 kv_list_test_destr_val = 0; 843 cxListClear(list); 844 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 845 } 846 cxListFree(list); 847 } 848 849 CX_TEST(test_kv_list_map_clear_destr_in_list) { 850 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 851 int x; 852 CX_TEST_DO { 853 x = 0xabcd; 854 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 855 CxList *list = cxKvListAsList(map); 856 cxDefineDestructor(list, kv_list_test_destr); 857 kv_list_test_destr_val = 0; 858 cxMapClear(map); 859 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 860 } 861 cxMapFree(map); 862 } 863 864 CX_TEST(test_kv_list_map_clear_destr_in_map) { 865 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 866 int x; 867 CX_TEST_DO { 868 x = 0xabcd; 869 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 870 871 cxDefineDestructor(map, kv_list_test_destr); 872 kv_list_test_destr_val = 0; 873 cxMapClear(map); 874 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 875 } 876 cxMapFree(map); 877 } 878 879 CX_TEST(test_kv_list_destr_ptr) { 880 CxMap *map = cxKvListCreateAsMapSimple(CX_STORE_POINTERS); 881 cxDefineDestructor(map, kv_list_test_destr); 882 int x; 883 CX_TEST_DO { 884 x = 0xabcd; 885 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 886 x = 0xef89; 887 kv_list_test_destr_val = 0; 888 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 889 CX_TEST_ASSERT(kv_list_test_destr_val == 0xef89); 890 } 891 cxMapFree(map); 892 } 893 894 CX_TEST(test_kv_list_map_iterator) { 895 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 896 CX_TEST_DO { 897 int x; 898 x = 0xc0ffee; // this element shall be skipped 899 cxListAdd(cxKvListAsList(map), &x); 900 x = 815; 901 cxMapPut(map, "xyz", &x); 902 x = 8016; 903 cxMapPut(map, "abcd", &x); 904 x = 0xbeef; 905 cxListAdd(cxKvListAsList(map), &x); 906 x = 80017; 907 cxMapPut(map, "efghi", &x); 908 909 const CxMapEntry *entry; 910 CxMapIterator it = cxMapIterator(map); 911 CX_TEST_ASSERT(it.elem_count == 3); 912 CX_TEST_ASSERT(it.elem_size == sizeof(CxMapEntry)); 913 914 CX_TEST_ASSERT(cxIteratorValid(it)); 915 CX_TEST_ASSERT(it.index == 0); 916 entry = cxIteratorCurrent(it); 917 CX_TEST_ASSERT(*(int*)entry->value == 815); 918 CX_TEST_ASSERT(entry->key->len == 3); 919 CX_TEST_ASSERT(strncmp(entry->key->data, "xyz", 3) == 0); 920 921 cxIteratorNext(it); 922 CX_TEST_ASSERT(cxIteratorValid(it)); 923 CX_TEST_ASSERT(it.index == 1); 924 entry = cxIteratorCurrent(it); 925 CX_TEST_ASSERT(*(int*)entry->value == 8016); 926 CX_TEST_ASSERT(entry->key->len == 4); 927 CX_TEST_ASSERT(strncmp(entry->key->data, "abcd", 4) == 0); 928 929 cxIteratorNext(it); 930 CX_TEST_ASSERT(cxIteratorValid(it)); 931 CX_TEST_ASSERT(it.index == 2); 932 entry = cxIteratorCurrent(it); 933 CX_TEST_ASSERT(*(int*)entry->value == 80017); 934 CX_TEST_ASSERT(entry->key->len == 5); 935 CX_TEST_ASSERT(strncmp(entry->key->data, "efghi", 5) == 0); 936 937 cxIteratorNext(it); 938 CX_TEST_ASSERT(!cxIteratorValid(it)); 939 940 // remove the first element (which was skipped anyway) and try again 941 cxListRemove(cxKvListAsList(map), 0); 942 it = cxMapIteratorKeys(map); 943 CX_TEST_ASSERT(it.elem_count == 3); 944 CX_TEST_ASSERT(it.elem_size == sizeof(CxHashKey)); 945 946 CX_TEST_ASSERT(cxIteratorValid(it)); 947 CX_TEST_ASSERT(it.index == 0); 948 CxHashKey *key = cxIteratorCurrent(it); 949 CX_TEST_ASSERT(key->len == 3); 950 CX_TEST_ASSERT(strncmp(key->data, "xyz", 3) == 0); 951 } 952 cxMapFree(map); 953 } 954 955 CX_TEST(test_kv_list_map_iterator_no_keys) { 956 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 957 CX_TEST_DO { 958 CxList *list = cxKvListAsList(map); 959 int x; 960 x = 815; 961 cxListAdd(list, &x); 962 x = 8016; 963 cxListAdd(list, &x); 964 x = 80017; 965 cxMapPut(map, "xyz", &x); 966 cxKvListRemoveKey(list, 2); 967 968 // only contains items without keys 969 CxMapIterator it = cxMapIterator(map); 970 CX_TEST_ASSERT(it.elem_count == 0); 971 CX_TEST_ASSERT(!cxIteratorValid(it)); 972 } 973 cxMapFree(map); 974 } 975 976 CX_TEST(test_kv_list_map_iterator_remove) { 977 CxMap *map = cxKvListCreateAsMapSimple(CX_STORE_POINTERS); 978 int x, y, z; 979 CX_TEST_DO { 980 cxDefineDestructor(map, kv_list_test_destr); 981 x = 815; 982 cxMapPut(map, "xyz", &x); 983 y = 8016; 984 cxMapPut(map, "abcd", &y); 985 z = 80017; 986 cxMapPut(map, "efghi", &z); 987 988 kv_list_test_destr_val = 0; 989 CxMapIterator iter = cxMapIteratorValues(map); 990 cx_foreach(int *, elem, iter) { 991 if (*elem == 8016) { 992 cxIteratorFlagRemoval(iter); 993 } 994 } 995 996 CX_TEST_ASSERT(kv_list_test_destr_val == 8016); 997 CX_TEST_ASSERT(cxMapSize(map) == 2); 998 CX_TEST_ASSERT(cxMapGet(map, "abcd") == NULL); 999 CxList *list = cxKvListAsList(map); 1000 CX_TEST_ASSERT(cxListSize(list) == 2); 1001 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 815); 1002 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 80017); 1003 } 1004 cxMapFree(map); 1005 } 1006 1007 CX_TEST(test_kv_list_list_iterator_remove) { 1008 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 1009 CX_TEST_DO { 1010 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xf00); 1011 int x; 1012 x = 815; 1013 cxMapPut(map, "xyz", &x); 1014 x = 8016; 1015 cxMapPut(map, "abcd", &x); 1016 x = 80017; 1017 cxMapPut(map, "efghi", &x); 1018 1019 CxList *list = cxKvListAsList(map); 1020 kv_list_test_destr2_val = 0; 1021 kv_list_test_destr2_extra = NULL; 1022 CxIterator iter = cxListIterator(list); 1023 cx_foreach(int *, elem, iter) { 1024 if (*elem == 8016) { 1025 cxIteratorFlagRemoval(iter); 1026 } 1027 } 1028 1029 CX_TEST_ASSERT(kv_list_test_destr2_val == 8016); 1030 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xf00); 1031 CX_TEST_ASSERT(cxMapSize(map) == 2); 1032 CX_TEST_ASSERT(cxMapGet(map, "abcd") == NULL); 1033 CX_TEST_ASSERT(cxListSize(list) == 2); 1034 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 815); 1035 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efghi") == 80017); 1036 } 1037 cxMapFree(map); 1038 } 1039 1040 CxTestSuite *cx_test_suite_kv_list_specifics(void) { 1041 CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); 1042 1043 cx_test_register(suite, test_kv_list_map_as_list); 1044 cx_test_register(suite, test_kv_list_free_as_map); 1045 cx_test_register(suite, test_kv_list_free_as_list); 1046 cx_test_register(suite, test_kv_list_remove); 1047 cx_test_register(suite, test_kv_list_find_and_remove); 1048 cx_test_register(suite, test_kv_list_remove_and_get); 1049 cx_test_register(suite, test_kv_list_remove_array); 1050 cx_test_register(suite, test_kv_list_remove_array_and_get); 1051 cx_test_register(suite, test_kv_list_map_put); 1052 cx_test_register(suite, test_kv_list_map_put_ptr); 1053 cx_test_register(suite, test_kv_list_map_put_not_hashed); 1054 cx_test_register(suite, test_kv_list_map_put_overwrite); 1055 cx_test_register(suite, test_kv_list_map_remove); 1056 cx_test_register(suite, test_kv_list_map_remove_and_get); 1057 cx_test_register(suite, test_kv_list_set_key); 1058 cx_test_register(suite, test_kv_list_set_key_already_exists); 1059 cx_test_register(suite, test_kv_list_set_key_again); 1060 cx_test_register(suite, test_kv_list_remove_key); 1061 cx_test_register(suite, test_kv_list_get_key); 1062 cx_test_register(suite, test_kv_list_insert_with_key); 1063 cx_test_register(suite, test_kv_list_insert_ptr_with_key); 1064 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); 1065 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); 1066 cx_test_register(suite, test_kv_list_list_remove_destr_in_map); 1067 cx_test_register(suite, test_kv_list_map_remove_destr_in_list); 1068 cx_test_register(suite, test_kv_list_map_remove_destr_in_map); 1069 cx_test_register(suite, test_kv_list_list_remove_destr2_in_list); 1070 cx_test_register(suite, test_kv_list_list_remove_destr2_in_map); 1071 cx_test_register(suite, test_kv_list_map_remove_destr2_in_list); 1072 cx_test_register(suite, test_kv_list_map_remove_destr2_in_map); 1073 cx_test_register(suite, test_kv_list_list_clear_destr_in_list); 1074 cx_test_register(suite, test_kv_list_list_clear_destr_in_map); 1075 cx_test_register(suite, test_kv_list_map_clear_destr_in_list); 1076 cx_test_register(suite, test_kv_list_map_clear_destr_in_map); 1077 cx_test_register(suite, test_kv_list_destr_ptr); 1078 cx_test_register(suite, test_kv_list_map_iterator); 1079 cx_test_register(suite, test_kv_list_map_iterator_no_keys); 1080 cx_test_register(suite, test_kv_list_map_iterator_remove); 1081 cx_test_register(suite, test_kv_list_list_iterator_remove); 1082 1083 return suite; 1084 } 1085