tests/test_kv_list.c

changeset 1605
55b13f583356
parent 1582
32b82c424252
equal deleted inserted replaced
1604:68b75c091028 1605:55b13f583356
42 kv_list_test_destr2_extra = extra; 42 kv_list_test_destr2_extra = extra;
43 kv_list_test_destr2_val = *(int*)data; 43 kv_list_test_destr2_val = *(int*)data;
44 } 44 }
45 45
46 CX_TEST(test_kv_list_map_as_list) { 46 CX_TEST(test_kv_list_map_as_list) {
47 CxList *list = cxKvListCreateSimple(sizeof(int)); 47 CxList *list = cxKvListCreate(NULL, sizeof(int));
48 CX_TEST_DO { 48 CX_TEST_DO {
49 CxMap *map = cxKvListAsMap(list); 49 CxMap *map = cxKvListAsMap(list);
50 CX_TEST_ASSERT(map != NULL); 50 CX_TEST_ASSERT(map != NULL);
51 CxList *list_from_map = cxKvListAsList(map); 51 CxList *list_from_map = cxKvListAsList(map);
52 CX_TEST_ASSERT(list_from_map == list); 52 CX_TEST_ASSERT(list_from_map == list);
56 56
57 CX_TEST(test_kv_list_free_as_map) { 57 CX_TEST(test_kv_list_free_as_map) {
58 CxTestingAllocator talloc; 58 CxTestingAllocator talloc;
59 cx_testing_allocator_init(&talloc); 59 cx_testing_allocator_init(&talloc);
60 CX_TEST_DO { 60 CX_TEST_DO {
61 CxList *list = cxKvListCreate(&talloc.base, NULL, 1); 61 CxList *list = cxKvListCreate(&talloc.base, 1);
62 cxListAddArray(list, "test", 4); 62 cxListAddArray(list, "test", 4);
63 CxMap *map = cxKvListAsMap(list); 63 CxMap *map = cxKvListAsMap(list);
64 cxMapFree(map); 64 cxMapFree(map);
65 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 65 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
66 } 66 }
69 69
70 CX_TEST(test_kv_list_free_as_list) { 70 CX_TEST(test_kv_list_free_as_list) {
71 CxTestingAllocator talloc; 71 CxTestingAllocator talloc;
72 cx_testing_allocator_init(&talloc); 72 cx_testing_allocator_init(&talloc);
73 CX_TEST_DO { 73 CX_TEST_DO {
74 CxMap *map = cxKvListCreateAsMap(&talloc.base, NULL, sizeof(int)); 74 CxMap *map = cxKvListCreateAsMap(&talloc.base, sizeof(int));
75 int x = 5; 75 int x = 5;
76 cxMapPut(map, "test", &x); 76 cxMapPut(map, "test", &x);
77 CxList *list = cxKvListAsList(map); 77 CxList *list = cxKvListAsList(map);
78 cxListFree(list); 78 cxListFree(list);
79 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 79 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
80 } 80 }
81 cx_testing_allocator_destroy(&talloc); 81 cx_testing_allocator_destroy(&talloc);
82 } 82 }
83 83
84 CX_TEST(test_kv_list_remove) { 84 CX_TEST(test_kv_list_remove) {
85 CxList *list = cxKvListCreateSimple(sizeof(int)); 85 CxList *list = cxKvListCreate(NULL, sizeof(int));
86 int x; 86 int x;
87 CX_TEST_DO { 87 CX_TEST_DO {
88 CxMap *map = cxKvListAsMap(list); 88 CxMap *map = cxKvListAsMap(list);
89 89
90 x = 13; 90 x = 13;
119 } 119 }
120 cxListFree(list); 120 cxListFree(list);
121 } 121 }
122 122
123 CX_TEST(test_kv_list_find_and_remove) { 123 CX_TEST(test_kv_list_find_and_remove) {
124 CxList *list = cxKvListCreateSimple(sizeof(int)); 124 CxList *list = cxKvListCreate(NULL, sizeof(int));
125 cxCollectionCompareFunc(list, cx_cmp_int); 125 cxSetCompareFunc(list, cx_cmp_int);
126 int x, y; 126 int x, y;
127 CX_TEST_DO { 127 CX_TEST_DO {
128 CxMap *map = cxKvListAsMap(list); 128 CxMap *map = cxKvListAsMap(list);
129 129
130 x = 13; 130 x = 13;
172 } 172 }
173 cxListFree(list); 173 cxListFree(list);
174 } 174 }
175 175
176 CX_TEST(test_kv_list_remove_and_get) { 176 CX_TEST(test_kv_list_remove_and_get) {
177 CxList *list = cxKvListCreateSimple(sizeof(int)); 177 CxList *list = cxKvListCreate(NULL, sizeof(int));
178 int x, y; 178 int x, y;
179 CX_TEST_DO { 179 CX_TEST_DO {
180 CxMap *map = cxKvListAsMap(list); 180 CxMap *map = cxKvListAsMap(list);
181 181
182 x = 13; 182 x = 13;
214 } 214 }
215 cxListFree(list); 215 cxListFree(list);
216 } 216 }
217 217
218 CX_TEST(test_kv_list_remove_array) { 218 CX_TEST(test_kv_list_remove_array) {
219 CxList *list = cxKvListCreateSimple(sizeof(int)); 219 CxList *list = cxKvListCreate(NULL, sizeof(int));
220 int x; 220 int x;
221 CX_TEST_DO { 221 CX_TEST_DO {
222 CxMap *map = cxKvListAsMap(list); 222 CxMap *map = cxKvListAsMap(list);
223 223
224 x = 13; 224 x = 13;
245 } 245 }
246 cxListFree(list); 246 cxListFree(list);
247 } 247 }
248 248
249 CX_TEST(test_kv_list_remove_array_and_get) { 249 CX_TEST(test_kv_list_remove_array_and_get) {
250 CxList *list = cxKvListCreateSimple(sizeof(int)); 250 CxList *list = cxKvListCreate(NULL, sizeof(int));
251 int x; 251 int x;
252 CX_TEST_DO { 252 CX_TEST_DO {
253 CxMap *map = cxKvListAsMap(list); 253 CxMap *map = cxKvListAsMap(list);
254 254
255 x = 13; 255 x = 13;
280 } 280 }
281 cxListFree(list); 281 cxListFree(list);
282 } 282 }
283 283
284 CX_TEST(test_kv_list_map_put) { 284 CX_TEST(test_kv_list_map_put) {
285 CxList *list = cxKvListCreateSimple(sizeof(int)); 285 CxList *list = cxKvListCreate(NULL, sizeof(int));
286 int x; 286 int x;
287 CX_TEST_DO { 287 CX_TEST_DO {
288 CxMap *map = cxKvListAsMap(list); 288 CxMap *map = cxKvListAsMap(list);
289 289
290 x = 13; 290 x = 13;
303 } 303 }
304 cxListFree(list); 304 cxListFree(list);
305 } 305 }
306 306
307 CX_TEST(test_kv_list_map_put_ptr) { 307 CX_TEST(test_kv_list_map_put_ptr) {
308 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 308 CxList *list = cxKvListCreate(NULL, CX_STORE_POINTERS);
309 int x; 309 int x;
310 CX_TEST_DO { 310 CX_TEST_DO {
311 CxMap *map = cxKvListAsMap(list); 311 CxMap *map = cxKvListAsMap(list);
312 x = 13; 312 x = 13;
313 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 313 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
317 } 317 }
318 cxListFree(list); 318 cxListFree(list);
319 } 319 }
320 320
321 CX_TEST(test_kv_list_map_put_not_hashed) { 321 CX_TEST(test_kv_list_map_put_not_hashed) {
322 CxList *list = cxKvListCreateSimple(sizeof(int)); 322 CxList *list = cxKvListCreate(NULL, sizeof(int));
323 int x; 323 int x;
324 CX_TEST_DO { 324 CX_TEST_DO {
325 CxMap *map = cxKvListAsMap(list); 325 CxMap *map = cxKvListAsMap(list);
326 x = 13; 326 x = 13;
327 // test with a custom key that was not hashed, yet 327 // test with a custom key that was not hashed, yet
338 } 338 }
339 cxListFree(list); 339 cxListFree(list);
340 } 340 }
341 341
342 CX_TEST(test_kv_list_map_put_overwrite) { 342 CX_TEST(test_kv_list_map_put_overwrite) {
343 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 343 CxList *list = cxKvListCreate(NULL, CX_STORE_POINTERS);
344 CxTestingAllocator talloc; 344 CxTestingAllocator talloc;
345 cx_testing_allocator_init(&talloc); 345 cx_testing_allocator_init(&talloc);
346 CxAllocator *al = &talloc.base; 346 CxAllocator *al = &talloc.base;
347 int *x, *y; 347 int *x, *y;
348 CX_TEST_DO { 348 CX_TEST_DO {
349 CxMap *map = cxKvListAsMap(list); 349 CxMap *map = cxKvListAsMap(list);
350 cxDefineAdvancedDestructor(map, cxFree, al); 350 cxSetAdvancedDestructor(map, cxFree, al);
351 x = cxMalloc(al, sizeof(int)); 351 x = cxMalloc(al, sizeof(int));
352 y = cxMalloc(al, sizeof(int)); 352 y = cxMalloc(al, sizeof(int));
353 *x = 13; 353 *x = 13;
354 *y = 37; 354 *y = 37;
355 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", x)); 355 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", x));
368 cx_testing_allocator_destroy(&talloc); 368 cx_testing_allocator_destroy(&talloc);
369 cxListFree(list); 369 cxListFree(list);
370 } 370 }
371 371
372 CX_TEST(test_kv_list_map_remove) { 372 CX_TEST(test_kv_list_map_remove) {
373 CxList *list = cxKvListCreateSimple(sizeof(int)); 373 CxList *list = cxKvListCreate(NULL, sizeof(int));
374 int x; 374 int x;
375 CX_TEST_DO { 375 CX_TEST_DO {
376 CxMap *map = cxKvListAsMap(list); 376 CxMap *map = cxKvListAsMap(list);
377 377
378 x = 13; 378 x = 13;
395 } 395 }
396 cxListFree(list); 396 cxListFree(list);
397 } 397 }
398 398
399 CX_TEST(test_kv_list_map_remove_and_get) { 399 CX_TEST(test_kv_list_map_remove_and_get) {
400 CxList *list = cxKvListCreateSimple(sizeof(int)); 400 CxList *list = cxKvListCreate(NULL, sizeof(int));
401 int x, y; 401 int x, y;
402 CX_TEST_DO { 402 CX_TEST_DO {
403 CxMap *map = cxKvListAsMap(list); 403 CxMap *map = cxKvListAsMap(list);
404 404
405 x = 13; 405 x = 13;
407 407
408 x = 37; 408 x = 37;
409 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x)); 409 CX_TEST_ASSERT(0 == cxMapPut(map, "abc", &x));
410 410
411 CX_TEST_ASSERT(cxMapSize(map) == 2); 411 CX_TEST_ASSERT(cxMapSize(map) == 2);
412 cxDefineDestructor(map, kv_list_test_destr); 412 cxSetDestructor(map, kv_list_test_destr);
413 kv_list_test_destr_val = 0; 413 kv_list_test_destr_val = 0;
414 y = 0; 414 y = 0;
415 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, "xyz", &y)); 415 CX_TEST_ASSERT(0 == cxMapRemoveAndGet(map, "xyz", &y));
416 CX_TEST_ASSERT(y == 13); 416 CX_TEST_ASSERT(y == 13);
417 // destr not called! 417 // destr not called!
427 } 427 }
428 cxListFree(list); 428 cxListFree(list);
429 } 429 }
430 430
431 CX_TEST(test_kv_list_set_key) { 431 CX_TEST(test_kv_list_set_key) {
432 CxList *list = cxKvListCreateSimple(sizeof(int)); 432 CxList *list = cxKvListCreate(NULL, sizeof(int));
433 int x; 433 int x;
434 CX_TEST_DO { 434 CX_TEST_DO {
435 x = 47; 435 x = 47;
436 cxListAdd(list, &x); 436 cxListAdd(list, &x);
437 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); 437 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz"));
469 } 469 }
470 cxListFree(list); 470 cxListFree(list);
471 } 471 }
472 472
473 CX_TEST(test_kv_list_set_key_already_exists) { 473 CX_TEST(test_kv_list_set_key_already_exists) {
474 CxList *list = cxKvListCreateSimple(sizeof(int)); 474 CxList *list = cxKvListCreate(NULL, sizeof(int));
475 int x; 475 int x;
476 CX_TEST_DO { 476 CX_TEST_DO {
477 x = 47; 477 x = 47;
478 cxListAdd(list, &x); 478 cxListAdd(list, &x);
479 x = 11; 479 x = 11;
502 } 502 }
503 cxListFree(list); 503 cxListFree(list);
504 } 504 }
505 505
506 CX_TEST(test_kv_list_set_key_again) { 506 CX_TEST(test_kv_list_set_key_again) {
507 CxList *list = cxKvListCreateSimple(sizeof(int)); 507 CxList *list = cxKvListCreate(NULL, sizeof(int));
508 int x; 508 int x;
509 CX_TEST_DO { 509 CX_TEST_DO {
510 x = 47; 510 x = 47;
511 cxListAdd(list, &x); 511 cxListAdd(list, &x);
512 x = 11; 512 x = 11;
529 } 529 }
530 cxListFree(list); 530 cxListFree(list);
531 } 531 }
532 532
533 CX_TEST(test_kv_list_remove_key) { 533 CX_TEST(test_kv_list_remove_key) {
534 CxList *list = cxKvListCreateSimple(sizeof(int)); 534 CxList *list = cxKvListCreate(NULL, sizeof(int));
535 int x; 535 int x;
536 CX_TEST_DO { 536 CX_TEST_DO {
537 CxMap *map = cxKvListAsMap(list); 537 CxMap *map = cxKvListAsMap(list);
538 538
539 x = 47; 539 x = 47;
571 } 571 }
572 cxListFree(list); 572 cxListFree(list);
573 } 573 }
574 574
575 CX_TEST(test_kv_list_get_key) { 575 CX_TEST(test_kv_list_get_key) {
576 CxList *list = cxKvListCreateSimple(sizeof(int)); 576 CxList *list = cxKvListCreate(NULL, sizeof(int));
577 int x; 577 int x;
578 CX_TEST_DO { 578 CX_TEST_DO {
579 CxMap *map = cxKvListAsMap(list); 579 CxMap *map = cxKvListAsMap(list);
580 580
581 x = 47; 581 x = 47;
605 } 605 }
606 cxListFree(list); 606 cxListFree(list);
607 } 607 }
608 608
609 CX_TEST(test_kv_list_insert_with_key) { 609 CX_TEST(test_kv_list_insert_with_key) {
610 CxList *list = cxKvListCreateSimple(sizeof(int)); 610 CxList *list = cxKvListCreate(NULL, sizeof(int));
611 int x; 611 int x;
612 CX_TEST_DO { 612 CX_TEST_DO {
613 x = 47; 613 x = 47;
614 cxKvListAdd(list, "xyz", &x); 614 cxKvListAdd(list, "xyz", &x);
615 x = 11; 615 x = 11;
630 } 630 }
631 cxListFree(list); 631 cxListFree(list);
632 } 632 }
633 633
634 CX_TEST(test_kv_list_insert_ptr_with_key) { 634 CX_TEST(test_kv_list_insert_ptr_with_key) {
635 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS); 635 CxList *list = cxKvListCreate(NULL, CX_STORE_POINTERS);
636 int x, y, z; 636 int x, y, z;
637 CX_TEST_DO { 637 CX_TEST_DO {
638 x = 15; 638 x = 15;
639 cxKvListAdd(list, "xyz", &x); 639 cxKvListAdd(list, "xyz", &x);
640 y = 16; 640 y = 16;
658 } 658 }
659 cxListFree(list); 659 cxListFree(list);
660 } 660 }
661 661
662 CX_TEST(test_kv_list_insert_array_and_set_keys) { 662 CX_TEST(test_kv_list_insert_array_and_set_keys) {
663 CxList *list = cxKvListCreateSimple(sizeof(int)); 663 CxList *list = cxKvListCreate(NULL, sizeof(int));
664 CX_TEST_DO { 664 CX_TEST_DO {
665 int arr[] = { 13, 21, 34, 55, 89 }; 665 int arr[] = { 13, 21, 34, 55, 89 };
666 CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5)); 666 CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5));
667 CX_TEST_ASSERT(5 == cxListSize(list)); 667 CX_TEST_ASSERT(5 == cxListSize(list));
668 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); 668 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz"));
681 } 681 }
682 cxListFree(list); 682 cxListFree(list);
683 } 683 }
684 684
685 CX_TEST(test_kv_list_list_remove_destr_in_list) { 685 CX_TEST(test_kv_list_list_remove_destr_in_list) {
686 CxList *list = cxKvListCreateSimple(sizeof(int)); 686 CxList *list = cxKvListCreate(NULL, sizeof(int));
687 int x; 687 int x;
688 CX_TEST_DO { 688 CX_TEST_DO {
689 x = 0xabcd; 689 x = 0xabcd;
690 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 690 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
691 cxKvListSetKey(list, 0, "xyz"); 691 cxKvListSetKey(list, 0, "xyz");
692 692
693 cxDefineDestructor(list, kv_list_test_destr); 693 cxSetDestructor(list, kv_list_test_destr);
694 kv_list_test_destr_val = 0; 694 kv_list_test_destr_val = 0;
695 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 695 CX_TEST_ASSERT(0 == cxListRemove(list, 0));
696 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 696 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
697 } 697 }
698 cxListFree(list); 698 cxListFree(list);
699 } 699 }
700 700
701 CX_TEST(test_kv_list_list_remove_destr_in_map) { 701 CX_TEST(test_kv_list_list_remove_destr_in_map) {
702 CxList *list = cxKvListCreateSimple(sizeof(int)); 702 CxList *list = cxKvListCreate(NULL, sizeof(int));
703 int x; 703 int x;
704 CX_TEST_DO { 704 CX_TEST_DO {
705 x = 0xabcd; 705 x = 0xabcd;
706 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 706 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
707 cxKvListSetKey(list, 0, "xyz"); 707 cxKvListSetKey(list, 0, "xyz");
708 CxMap *map = cxKvListAsMap(list); 708 CxMap *map = cxKvListAsMap(list);
709 cxDefineDestructor(map, kv_list_test_destr); 709 cxSetDestructor(map, kv_list_test_destr);
710 kv_list_test_destr_val = 0; 710 kv_list_test_destr_val = 0;
711 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 711 CX_TEST_ASSERT(0 == cxListRemove(list, 0));
712 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 712 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
713 } 713 }
714 cxListFree(list); 714 cxListFree(list);
715 } 715 }
716 716
717 CX_TEST(test_kv_list_map_remove_destr_in_list) { 717 CX_TEST(test_kv_list_map_remove_destr_in_list) {
718 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 718 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
719 int x; 719 int x;
720 CX_TEST_DO { 720 CX_TEST_DO {
721 x = 0xabcd; 721 x = 0xabcd;
722 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 722 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
723 CxList *list = cxKvListAsList(map); 723 CxList *list = cxKvListAsList(map);
724 cxDefineDestructor(list, kv_list_test_destr); 724 cxSetDestructor(list, kv_list_test_destr);
725 kv_list_test_destr_val = 0; 725 kv_list_test_destr_val = 0;
726 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 726 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
727 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 727 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
728 } 728 }
729 cxMapFree(map); 729 cxMapFree(map);
730 } 730 }
731 731
732 CX_TEST(test_kv_list_map_remove_destr_in_map) { 732 CX_TEST(test_kv_list_map_remove_destr_in_map) {
733 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 733 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
734 int x; 734 int x;
735 CX_TEST_DO { 735 CX_TEST_DO {
736 x = 0xabcd; 736 x = 0xabcd;
737 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 737 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
738 738
739 cxDefineDestructor(map, kv_list_test_destr); 739 cxSetDestructor(map, kv_list_test_destr);
740 kv_list_test_destr_val = 0; 740 kv_list_test_destr_val = 0;
741 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 741 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
742 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 742 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
743 } 743 }
744 cxMapFree(map); 744 cxMapFree(map);
745 } 745 }
746 746
747 CX_TEST(test_kv_list_list_remove_destr2_in_list) { 747 CX_TEST(test_kv_list_list_remove_destr2_in_list) {
748 CxList *list = cxKvListCreateSimple(sizeof(int)); 748 CxList *list = cxKvListCreate(NULL, sizeof(int));
749 int x; 749 int x;
750 CX_TEST_DO { 750 CX_TEST_DO {
751 x = 0xabcd; 751 x = 0xabcd;
752 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 752 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
753 cxKvListSetKey(list, 0, "xyz"); 753 cxKvListSetKey(list, 0, "xyz");
754 754
755 cxDefineAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47); 755 cxSetAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47);
756 kv_list_test_destr2_val = 0; 756 kv_list_test_destr2_val = 0;
757 kv_list_test_destr2_extra = NULL; 757 kv_list_test_destr2_extra = NULL;
758 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 758 CX_TEST_ASSERT(0 == cxListRemove(list, 0));
759 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 759 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd);
760 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 760 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47);
761 } 761 }
762 cxListFree(list); 762 cxListFree(list);
763 } 763 }
764 764
765 CX_TEST(test_kv_list_list_remove_destr2_in_map) { 765 CX_TEST(test_kv_list_list_remove_destr2_in_map) {
766 CxList *list = cxKvListCreateSimple(sizeof(int)); 766 CxList *list = cxKvListCreate(NULL, sizeof(int));
767 int x; 767 int x;
768 CX_TEST_DO { 768 CX_TEST_DO {
769 x = 0xabcd; 769 x = 0xabcd;
770 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 770 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
771 cxKvListSetKey(list, 0, "xyz"); 771 cxKvListSetKey(list, 0, "xyz");
772 CxMap *map = cxKvListAsMap(list); 772 CxMap *map = cxKvListAsMap(list);
773 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47); 773 cxSetAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47);
774 kv_list_test_destr2_val = 0; 774 kv_list_test_destr2_val = 0;
775 kv_list_test_destr2_extra = NULL; 775 kv_list_test_destr2_extra = NULL;
776 CX_TEST_ASSERT(0 == cxListRemove(list, 0)); 776 CX_TEST_ASSERT(0 == cxListRemove(list, 0));
777 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 777 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd);
778 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 778 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47);
779 } 779 }
780 cxListFree(list); 780 cxListFree(list);
781 } 781 }
782 782
783 CX_TEST(test_kv_list_map_remove_destr2_in_list) { 783 CX_TEST(test_kv_list_map_remove_destr2_in_list) {
784 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 784 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
785 int x; 785 int x;
786 CX_TEST_DO { 786 CX_TEST_DO {
787 x = 0xabcd; 787 x = 0xabcd;
788 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 788 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
789 CxList *list = cxKvListAsList(map); 789 CxList *list = cxKvListAsList(map);
790 cxDefineAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47); 790 cxSetAdvancedDestructor(list, kv_list_test_destr2, (void*)0xef47);
791 kv_list_test_destr2_val = 0; 791 kv_list_test_destr2_val = 0;
792 kv_list_test_destr2_extra = NULL; 792 kv_list_test_destr2_extra = NULL;
793 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 793 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
794 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 794 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd);
795 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 795 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47);
796 } 796 }
797 cxMapFree(map); 797 cxMapFree(map);
798 } 798 }
799 799
800 CX_TEST(test_kv_list_map_remove_destr2_in_map) { 800 CX_TEST(test_kv_list_map_remove_destr2_in_map) {
801 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 801 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
802 int x; 802 int x;
803 CX_TEST_DO { 803 CX_TEST_DO {
804 x = 0xabcd; 804 x = 0xabcd;
805 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 805 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
806 806
807 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47); 807 cxSetAdvancedDestructor(map, kv_list_test_destr2, (void*)0xef47);
808 kv_list_test_destr2_val = 0; 808 kv_list_test_destr2_val = 0;
809 kv_list_test_destr2_extra = NULL; 809 kv_list_test_destr2_extra = NULL;
810 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); 810 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
811 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd); 811 CX_TEST_ASSERT(kv_list_test_destr2_val == 0xabcd);
812 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47); 812 CX_TEST_ASSERT(kv_list_test_destr2_extra == (void*)0xef47);
813 } 813 }
814 cxMapFree(map); 814 cxMapFree(map);
815 } 815 }
816 816
817 CX_TEST(test_kv_list_list_clear_destr_in_list) { 817 CX_TEST(test_kv_list_list_clear_destr_in_list) {
818 CxList *list = cxKvListCreateSimple(sizeof(int)); 818 CxList *list = cxKvListCreate(NULL, sizeof(int));
819 int x; 819 int x;
820 CX_TEST_DO { 820 CX_TEST_DO {
821 x = 0xabcd; 821 x = 0xabcd;
822 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 822 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
823 cxKvListSetKey(list, 0, "xyz"); 823 cxKvListSetKey(list, 0, "xyz");
824 824
825 cxDefineDestructor(list, kv_list_test_destr); 825 cxSetDestructor(list, kv_list_test_destr);
826 kv_list_test_destr_val = 0; 826 kv_list_test_destr_val = 0;
827 cxListClear(list); 827 cxListClear(list);
828 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 828 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
829 } 829 }
830 cxListFree(list); 830 cxListFree(list);
831 } 831 }
832 832
833 CX_TEST(test_kv_list_list_clear_destr_in_map) { 833 CX_TEST(test_kv_list_list_clear_destr_in_map) {
834 CxList *list = cxKvListCreateSimple(sizeof(int)); 834 CxList *list = cxKvListCreate(NULL, sizeof(int));
835 int x; 835 int x;
836 CX_TEST_DO { 836 CX_TEST_DO {
837 x = 0xabcd; 837 x = 0xabcd;
838 CX_TEST_ASSERT(0 == cxListAdd(list, &x)); 838 CX_TEST_ASSERT(0 == cxListAdd(list, &x));
839 cxKvListSetKey(list, 0, "xyz"); 839 cxKvListSetKey(list, 0, "xyz");
840 CxMap *map = cxKvListAsMap(list); 840 CxMap *map = cxKvListAsMap(list);
841 cxDefineDestructor(map, kv_list_test_destr); 841 cxSetDestructor(map, kv_list_test_destr);
842 kv_list_test_destr_val = 0; 842 kv_list_test_destr_val = 0;
843 cxListClear(list); 843 cxListClear(list);
844 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 844 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
845 } 845 }
846 cxListFree(list); 846 cxListFree(list);
847 } 847 }
848 848
849 CX_TEST(test_kv_list_map_clear_destr_in_list) { 849 CX_TEST(test_kv_list_map_clear_destr_in_list) {
850 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 850 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
851 int x; 851 int x;
852 CX_TEST_DO { 852 CX_TEST_DO {
853 x = 0xabcd; 853 x = 0xabcd;
854 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 854 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
855 CxList *list = cxKvListAsList(map); 855 CxList *list = cxKvListAsList(map);
856 cxDefineDestructor(list, kv_list_test_destr); 856 cxSetDestructor(list, kv_list_test_destr);
857 kv_list_test_destr_val = 0; 857 kv_list_test_destr_val = 0;
858 cxMapClear(map); 858 cxMapClear(map);
859 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 859 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
860 } 860 }
861 cxMapFree(map); 861 cxMapFree(map);
862 } 862 }
863 863
864 CX_TEST(test_kv_list_map_clear_destr_in_map) { 864 CX_TEST(test_kv_list_map_clear_destr_in_map) {
865 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 865 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
866 int x; 866 int x;
867 CX_TEST_DO { 867 CX_TEST_DO {
868 x = 0xabcd; 868 x = 0xabcd;
869 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 869 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
870 870
871 cxDefineDestructor(map, kv_list_test_destr); 871 cxSetDestructor(map, kv_list_test_destr);
872 kv_list_test_destr_val = 0; 872 kv_list_test_destr_val = 0;
873 cxMapClear(map); 873 cxMapClear(map);
874 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); 874 CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd);
875 } 875 }
876 cxMapFree(map); 876 cxMapFree(map);
877 } 877 }
878 878
879 CX_TEST(test_kv_list_destr_ptr) { 879 CX_TEST(test_kv_list_destr_ptr) {
880 CxMap *map = cxKvListCreateAsMapSimple(CX_STORE_POINTERS); 880 CxMap *map = cxKvListCreateAsMap(NULL, CX_STORE_POINTERS);
881 cxDefineDestructor(map, kv_list_test_destr); 881 cxSetDestructor(map, kv_list_test_destr);
882 int x; 882 int x;
883 CX_TEST_DO { 883 CX_TEST_DO {
884 x = 0xabcd; 884 x = 0xabcd;
885 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); 885 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x));
886 x = 0xef89; 886 x = 0xef89;
890 } 890 }
891 cxMapFree(map); 891 cxMapFree(map);
892 } 892 }
893 893
894 CX_TEST(test_kv_list_map_iterator) { 894 CX_TEST(test_kv_list_map_iterator) {
895 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 895 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
896 CX_TEST_DO { 896 CX_TEST_DO {
897 int x; 897 int x;
898 x = 0xc0ffee; // this element shall be skipped 898 x = 0xc0ffee; // this element shall be skipped
899 cxListAdd(cxKvListAsList(map), &x); 899 cxListAdd(cxKvListAsList(map), &x);
900 x = 815; 900 x = 815;
951 } 951 }
952 cxMapFree(map); 952 cxMapFree(map);
953 } 953 }
954 954
955 CX_TEST(test_kv_list_map_iterator_no_keys) { 955 CX_TEST(test_kv_list_map_iterator_no_keys) {
956 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 956 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
957 CX_TEST_DO { 957 CX_TEST_DO {
958 CxList *list = cxKvListAsList(map); 958 CxList *list = cxKvListAsList(map);
959 int x; 959 int x;
960 x = 815; 960 x = 815;
961 cxListAdd(list, &x); 961 cxListAdd(list, &x);
972 } 972 }
973 cxMapFree(map); 973 cxMapFree(map);
974 } 974 }
975 975
976 CX_TEST(test_kv_list_map_iterator_remove) { 976 CX_TEST(test_kv_list_map_iterator_remove) {
977 CxMap *map = cxKvListCreateAsMapSimple(CX_STORE_POINTERS); 977 CxMap *map = cxKvListCreateAsMap(NULL, CX_STORE_POINTERS);
978 int x, y, z; 978 int x, y, z;
979 CX_TEST_DO { 979 CX_TEST_DO {
980 cxDefineDestructor(map, kv_list_test_destr); 980 cxSetDestructor(map, kv_list_test_destr);
981 x = 815; 981 x = 815;
982 cxMapPut(map, "xyz", &x); 982 cxMapPut(map, "xyz", &x);
983 y = 8016; 983 y = 8016;
984 cxMapPut(map, "abcd", &y); 984 cxMapPut(map, "abcd", &y);
985 z = 80017; 985 z = 80017;
1003 } 1003 }
1004 cxMapFree(map); 1004 cxMapFree(map);
1005 } 1005 }
1006 1006
1007 CX_TEST(test_kv_list_list_iterator_remove) { 1007 CX_TEST(test_kv_list_list_iterator_remove) {
1008 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); 1008 CxMap *map = cxKvListCreateAsMap(NULL, sizeof(int));
1009 CX_TEST_DO { 1009 CX_TEST_DO {
1010 cxDefineAdvancedDestructor(map, kv_list_test_destr2, (void*)0xf00); 1010 cxSetAdvancedDestructor(map, kv_list_test_destr2, (void*)0xf00);
1011 int x; 1011 int x;
1012 x = 815; 1012 x = 815;
1013 cxMapPut(map, "xyz", &x); 1013 cxMapPut(map, "xyz", &x);
1014 x = 8016; 1014 x = 8016;
1015 cxMapPut(map, "abcd", &x); 1015 cxMapPut(map, "abcd", &x);

mercurial