test/test_list.c

changeset 506
18782bbe3607
parent 503
a89857072ace
child 507
2e8878770de0
equal deleted inserted replaced
505:03e9151bea32 506:18782bbe3607
555 555
556 destroy_test_data(begin); 556 destroy_test_data(begin);
557 destroy_test_data(expected); 557 destroy_test_data(expected);
558 } 558 }
559 559
560 void test_hl_linked_list_create(void) { 560 static void test_linked_list_create(CxList *list) {
561 cxTestingAllocatorReset();
562
563 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
564
565 CU_ASSERT_EQUAL(list->size, 0) 561 CU_ASSERT_EQUAL(list->size, 0)
566 CU_ASSERT_EQUAL(list->capacity, (size_t) -1) 562 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
567 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) 563 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
564 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
565
566 cxListDestroy(list);
567 }
568
569 void test_hl_linked_list_create(void) {
570 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
568 CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) 571 CU_ASSERT_EQUAL(list->itemsize, sizeof(int))
569 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) 572 test_linked_list_create(list);
570
571 cxListDestroy(list);
572 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
573 } 573 }
574 574
575 void test_hl_ptr_linked_list_create(void) { 575 void test_hl_ptr_linked_list_create(void) {
576 cxTestingAllocatorReset();
577
578 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 576 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
579
580 CU_ASSERT_EQUAL(list->size, 0)
581 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
582 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
583 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *)) 577 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *))
584 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) 578 test_linked_list_create(list);
585
586 cxListDestroy(list);
587 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
588 } 579 }
589 580
590 void test_hl_linked_list_from_array(void) { 581 void test_hl_linked_list_from_array(void) {
591 cxTestingAllocatorReset();
592
593 int data[] = {2, 4, 5, 7, 10, 15}; 582 int data[] = {2, 4, 5, 7, 10, 15};
594 583
595 CxList *expected = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 584 CxList *expected = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
596 for (int i = 0; i < 5; i++) cxListAdd(expected, &data[i]); 585 for (int i = 0; i < 5; i++) cxListAdd(expected, &data[i]);
597 586
599 588
600 CU_ASSERT_TRUE(0 == cxListCompare(list, expected)) 589 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
601 590
602 cxListDestroy(list); 591 cxListDestroy(list);
603 cxListDestroy(expected); 592 cxListDestroy(expected);
604 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
605 } 593 }
606 594
607 void test_hl_linked_list_add(void) { 595 void test_hl_linked_list_add(void) {
608 cxTestingAllocatorReset();
609
610 int data; 596 int data;
611 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 597 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
612 598
613 data = 5; 599 data = 5;
614 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) 600 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
624 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp); 610 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp);
625 CU_ASSERT_TRUE(0 == cxListCompare(list, expected)) 611 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
626 612
627 cxListDestroy(list); 613 cxListDestroy(list);
628 cxListDestroy(expected); 614 cxListDestroy(expected);
629 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
630 } 615 }
631 616
632 void test_hl_ptr_linked_list_add(void) { 617 void test_hl_ptr_linked_list_add(void) {
633 cxTestingAllocatorReset();
634
635 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 618 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
636 619
637 int a = 5, b = 47, c = 13; 620 int a = 5, b = 47, c = 13;
638 621
639 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0) 622 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
654 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9) 637 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9)
655 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10) 638 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10)
656 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11) 639 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11)
657 640
658 cxListDestroy(list); 641 cxListDestroy(list);
659 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
660 } 642 }
661 643
662 void test_hl_linked_list_insert(void) { 644 void test_hl_linked_list_insert(void) {
663 cxTestingAllocatorReset();
664
665 int data; 645 int data;
666 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 646 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
667 647
668 data = 5; 648 data = 5;
669 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0) 649 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0)
686 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 4, exp); 666 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 4, exp);
687 CU_ASSERT_TRUE(0 == cxListCompare(list, expected)) 667 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
688 668
689 cxListDestroy(list); 669 cxListDestroy(list);
690 cxListDestroy(expected); 670 cxListDestroy(expected);
691 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
692 } 671 }
693 672
694 void test_hl_ptr_linked_list_insert(void) { 673 void test_hl_ptr_linked_list_insert(void) {
695 cxTestingAllocatorReset();
696
697 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 674 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
698 675
699 int a = 5, b = 47, c = 13, d = 42; 676 int a = 5, b = 47, c = 13, d = 42;
700 677
701 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0) 678 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0)
715 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) 692 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
716 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) 693 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
717 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) 694 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
718 695
719 cxListDestroy(list); 696 cxListDestroy(list);
720 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
721 } 697 }
722 698
723 void test_hl_linked_list_remove(void) { 699 void test_hl_linked_list_remove(void) {
724 cxTestingAllocatorReset();
725
726 int data[] = {5, 47, 42, 13}; 700 int data[] = {5, 47, 42, 13};
727 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, 701 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
728 sizeof(int), 4, data); 702 sizeof(int), 4, data);
729 703
730 CU_ASSERT_EQUAL(list->size, 4) 704 CU_ASSERT_EQUAL(list->size, 4)
755 CU_ASSERT_TRUE(list->capacity >= list->size) 729 CU_ASSERT_TRUE(list->capacity >= list->size)
756 730
757 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) 731 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
758 732
759 cxListDestroy(list); 733 cxListDestroy(list);
760 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
761 } 734 }
762 735
763 void test_hl_ptr_linked_list_remove(void) { 736 void test_hl_ptr_linked_list_remove(void) {
764 cxTestingAllocatorReset();
765
766 int a = 5, b = 47, c = 42, d = 13; 737 int a = 5, b = 47, c = 42, d = 13;
767 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 738 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
768 739
769 cxListAdd(list, &a); 740 cxListAdd(list, &a);
770 cxListAdd(list, &b); 741 cxListAdd(list, &b);
799 CU_ASSERT_TRUE(list->capacity >= list->size) 770 CU_ASSERT_TRUE(list->capacity >= list->size)
800 771
801 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) 772 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
802 773
803 cxListDestroy(list); 774 cxListDestroy(list);
804 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
805 } 775 }
806 776
807 void test_hl_linked_list_at(void) { 777 void test_hl_linked_list_at(void) {
808 cxTestingAllocatorReset();
809
810 int data[] = {5, 47, 13}; 778 int data[] = {5, 47, 13};
811 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, 779 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
812 sizeof(int), 3, data); 780 sizeof(int), 3, data);
813 781
814 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) 782 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
815 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) 783 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
816 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) 784 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
817 CU_ASSERT_PTR_NULL(cxListAt(list, 3)) 785 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
818 786
819 cxListDestroy(list); 787 cxListDestroy(list);
820 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
821 } 788 }
822 789
823 void test_hl_ptr_linked_list_at(void) { 790 void test_hl_ptr_linked_list_at(void) {
824 cxTestingAllocatorReset();
825
826 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 791 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
827 792
828 int a = 5, b = 47, c = 13; 793 int a = 5, b = 47, c = 13;
829 cxListAdd(list, &a); 794 cxListAdd(list, &a);
830 cxListAdd(list, &b); 795 cxListAdd(list, &b);
834 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) 799 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
835 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) 800 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
836 CU_ASSERT_PTR_NULL(cxListAt(list, 3)) 801 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
837 802
838 cxListDestroy(list); 803 cxListDestroy(list);
839 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
840 } 804 }
841 805
842 void test_hl_linked_list_find(void) { 806 void test_hl_linked_list_find(void) {
843 cxTestingAllocatorReset();
844
845 int data[] = {5, 47, 13}; 807 int data[] = {5, 47, 13};
846 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, 808 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
847 sizeof(int), 3, data); 809 sizeof(int), 3, data);
848 CU_ASSERT_EQUAL(list->size, 3) 810 CU_ASSERT_EQUAL(list->size, 3)
849 CU_ASSERT_TRUE(list->capacity >= list->size) 811 CU_ASSERT_TRUE(list->capacity >= list->size)
860 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) 822 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
861 criteria = -5; 823 criteria = -5;
862 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) 824 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
863 825
864 cxListDestroy(list); 826 cxListDestroy(list);
865 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
866 } 827 }
867 828
868 void test_hl_ptr_linked_list_find(void) { 829 void test_hl_ptr_linked_list_find(void) {
869 cxTestingAllocatorReset();
870
871 int a = 5, b = 47, c = 13, criteria; 830 int a = 5, b = 47, c = 13, criteria;
872 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 831 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
873 832
874 cxListAdd(list, &a); 833 cxListAdd(list, &a);
875 cxListAdd(list, &b); 834 cxListAdd(list, &b);
890 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) 849 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
891 b = -5; 850 b = -5;
892 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) 851 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
893 852
894 cxListDestroy(list); 853 cxListDestroy(list);
895 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
896 } 854 }
897 855
898 void test_hl_linked_list_sort(void) { 856 void test_hl_linked_list_sort(void) {
899 int expected[] = { 857 int expected[] = {
900 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, 858 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
910 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, 868 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
911 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, 869 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
912 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, 870 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
913 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 871 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
914 }; 872 };
915
916 cxTestingAllocatorReset();
917
918 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, scrambled); 873 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, scrambled);
919 CxList *exp = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, expected); 874 CxList *exp = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, expected);
920 875
921 cxListSort(list); 876 cxListSort(list);
922 CU_ASSERT_TRUE(0 == cxListCompare(list, exp)) 877 CU_ASSERT_TRUE(0 == cxListCompare(list, exp))
923 878
924 cxListDestroy(list); 879 cxListDestroy(list);
925 cxListDestroy(exp); 880 cxListDestroy(exp);
926 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
927 } 881 }
928 882
929 void test_hl_ptr_linked_list_sort(void) { 883 void test_hl_ptr_linked_list_sort(void) {
930 int expected[] = { 884 int expected[] = {
931 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, 885 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
942 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, 896 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
943 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, 897 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
944 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 898 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
945 }; 899 };
946 900
947 cxTestingAllocatorReset();
948
949 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 901 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
950 902
951 for (int i = 0; i < 100; i++) { 903 for (int i = 0; i < 100; i++) {
952 cxListAdd(list, &scrambled[i]); 904 cxListAdd(list, &scrambled[i]);
953 } 905 }
957 for (int i = 0; i < 100; i++) { 909 for (int i = 0; i < 100; i++) {
958 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i]) 910 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i])
959 } 911 }
960 912
961 cxListDestroy(list); 913 cxListDestroy(list);
962 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
963 } 914 }
964 915
965 void test_hl_linked_list_iterator_impl(CxList *list) { 916 void test_hl_linked_list_iterator_impl(CxList *list) {
966 int i = 0; 917 int i = 0;
967 CxIterator iter = cxListBegin(list); 918 CxIterator iter = cxListBegin(list);
977 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 2) 928 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 2)
978 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 4) 929 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 4)
979 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 6) 930 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 6)
980 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 4), 8) 931 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 4), 8)
981 cxListDestroy(list); 932 cxListDestroy(list);
982 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
983 } 933 }
984 934
985 void test_hl_linked_list_iterator(void) { 935 void test_hl_linked_list_iterator(void) {
986 cxTestingAllocatorReset();
987 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 936 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
988 for (int i = 0; i < 10; i++) { 937 for (int i = 0; i < 10; i++) {
989 cxListAdd(list, &i); 938 cxListAdd(list, &i);
990 } 939 }
991 test_hl_linked_list_iterator_impl(list); 940 test_hl_linked_list_iterator_impl(list);
992 } 941 }
993 942
994 void test_hl_ptr_linked_list_iterator(void) { 943 void test_hl_ptr_linked_list_iterator(void) {
995 cxTestingAllocatorReset();
996 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 944 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
997 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 945 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
998 for (int i = 0; i < 10; i++) { 946 for (int i = 0; i < 10; i++) {
999 cxListAdd(list, &data[i]); 947 cxListAdd(list, &data[i]);
1000 } 948 }
1001 test_hl_linked_list_iterator_impl(list); 949 test_hl_linked_list_iterator_impl(list);
1002 } 950 }
1003 951
1004 void test_hl_linked_list_insert_via_iterator(void) { 952 void test_hl_linked_list_insert_via_iterator(void) {
1005 cxTestingAllocatorReset();
1006 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 953 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
1007 for (int i = 0; i < 5; i++) { 954 for (int i = 0; i < 5; i++) {
1008 cxListAdd(list, &i); 955 cxListAdd(list, &i);
1009 } 956 }
1010 CxIterator iter = cxListIterator(list, 2); 957 CxIterator iter = cxListIterator(list, 2);
1041 cmp_int, sizeof(int), 10, expdata); 988 cmp_int, sizeof(int), 10, expdata);
1042 989
1043 CU_ASSERT_EQUAL(0, cxListCompare(list, expected)) 990 CU_ASSERT_EQUAL(0, cxListCompare(list, expected))
1044 cxListDestroy(list); 991 cxListDestroy(list);
1045 cxListDestroy(expected); 992 cxListDestroy(expected);
1046 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
1047 } 993 }
1048 994
1049 void test_hl_ptr_linked_list_insert_via_iterator(void) { 995 void test_hl_ptr_linked_list_insert_via_iterator(void) {
1050 int testdata[] = {0, 1, 2, 3, 4, 10, 20, 30, 40, 50}; 996 int testdata[] = {0, 1, 2, 3, 4, 10, 20, 30, 40, 50};
1051 cxTestingAllocatorReset();
1052 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 997 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
1053 int i; 998 int i;
1054 for (i = 0; i < 5; i++) { 999 for (i = 0; i < 5; i++) {
1055 cxListAdd(list, &testdata[i]); 1000 cxListAdd(list, &testdata[i]);
1056 } 1001 }
1082 for (i = 0; i < 10; i++) { 1027 for (i = 0; i < 10; i++) {
1083 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expdata[i]) 1028 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expdata[i])
1084 } 1029 }
1085 1030
1086 cxListDestroy(list); 1031 cxListDestroy(list);
1032 }
1033
1034 static void test_setup_allocator(void) {
1035 cxTestingAllocatorReset();
1036 }
1037
1038 static void test_verify_allocator(void) {
1087 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 1039 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
1088 } 1040 }
1089 1041
1090 int main() { 1042 int main() {
1091 CU_pSuite suite = NULL; 1043 CU_pSuite suite = NULL;
1110 cu_add_test(suite, test_linked_list_remove); 1062 cu_add_test(suite, test_linked_list_remove);
1111 cu_add_test(suite, test_linked_list_size); 1063 cu_add_test(suite, test_linked_list_size);
1112 cu_add_test(suite, test_linked_list_sort); 1064 cu_add_test(suite, test_linked_list_sort);
1113 cu_add_test(suite, test_linked_list_reverse); 1065 cu_add_test(suite, test_linked_list_reverse);
1114 1066
1115 suite = CU_add_suite("high level linked list", NULL, NULL); 1067 suite = CU_add_suite_with_setup_and_teardown(
1068 "high level linked list", NULL, NULL,
1069 test_setup_allocator, test_verify_allocator);
1116 1070
1117 cu_add_test(suite, test_hl_linked_list_create); 1071 cu_add_test(suite, test_hl_linked_list_create);
1118 cu_add_test(suite, test_hl_linked_list_from_array); 1072 cu_add_test(suite, test_hl_linked_list_from_array);
1119 cu_add_test(suite, test_hl_linked_list_add); 1073 cu_add_test(suite, test_hl_linked_list_add);
1120 cu_add_test(suite, test_hl_linked_list_insert); 1074 cu_add_test(suite, test_hl_linked_list_insert);
1123 cu_add_test(suite, test_hl_linked_list_find); 1077 cu_add_test(suite, test_hl_linked_list_find);
1124 cu_add_test(suite, test_hl_linked_list_sort); 1078 cu_add_test(suite, test_hl_linked_list_sort);
1125 cu_add_test(suite, test_hl_linked_list_iterator); 1079 cu_add_test(suite, test_hl_linked_list_iterator);
1126 cu_add_test(suite, test_hl_linked_list_insert_via_iterator); 1080 cu_add_test(suite, test_hl_linked_list_insert_via_iterator);
1127 1081
1128 suite = CU_add_suite("high level pointer linked list", NULL, NULL); 1082 suite = CU_add_suite_with_setup_and_teardown(
1083 "high level pointer linked list", NULL, NULL,
1084 test_setup_allocator, test_verify_allocator);
1129 1085
1130 cu_add_test(suite, test_hl_ptr_linked_list_create); 1086 cu_add_test(suite, test_hl_ptr_linked_list_create);
1131 cu_add_test(suite, test_hl_ptr_linked_list_add); 1087 cu_add_test(suite, test_hl_ptr_linked_list_add);
1132 cu_add_test(suite, test_hl_ptr_linked_list_insert); 1088 cu_add_test(suite, test_hl_ptr_linked_list_insert);
1133 cu_add_test(suite, test_hl_ptr_linked_list_remove); 1089 cu_add_test(suite, test_hl_ptr_linked_list_remove);

mercurial