test/test_list.c

changeset 494
6ce8cfa10a96
parent 492
188942a7308b
child 495
2856c74e18ba
equal deleted inserted replaced
493:e3469b497eff 494:6ce8cfa10a96
221 memset(nodes, 0, 4 * sizeof(struct node)); 221 memset(nodes, 0, 4 * sizeof(struct node));
222 begin = end = NULL; 222 begin = end = NULL;
223 223
224 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]); 224 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]);
225 CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 225 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
226 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); 226 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]);
227 CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 227 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
228 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 228 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
229 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 229 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
230 230
231 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); 231 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]);
232 CU_ASSERT_PTR_EQUAL(end, &nodes[2]) 232 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
233 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) 233 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
234 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) 234 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
235 235
236 // test with begin, end / next 236 // test with begin, end / next
757 cxLinkedListDestroy(list); 757 cxLinkedListDestroy(list);
758 cxLinkedListDestroy(exp); 758 cxLinkedListDestroy(exp);
759 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 759 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
760 } 760 }
761 761
762 void test_hl_linked_list_iterator_impl(CxList list) {
763 int i = 0;
764 for (CxIterator iter = cxListBegin(list); cxIteratorValid(&iter); cxIteratorNext(&iter)) {
765 CU_ASSERT_EQUAL(iter.index, (size_t) i)
766 int *x = cxIteratorCurrent(&iter);
767 CU_ASSERT_EQUAL(*x, i)
768 i++;
769 }
770 CU_ASSERT_EQUAL(i, 10)
771 cxLinkedListDestroy(list);
772 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
773 }
774
775 void test_hl_linked_list_iterator(void) {
776 cxTestingAllocatorReset();
777 CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
778 for (int i = 0; i < 10; i++) {
779 cxListAdd(list, &i);
780 }
781 test_hl_linked_list_iterator_impl(list);
782 }
783
784 void test_hl_ptr_linked_list_iterator(void) {
785 cxTestingAllocatorReset();
786 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
787 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
788 for (int i = 0; i < 10; i++) {
789 cxListAdd(list, &data[i]);
790 }
791 test_hl_linked_list_iterator_impl(list);
792 }
793
762 void test_hl_ptr_linked_list_create(void) { 794 void test_hl_ptr_linked_list_create(void) {
763 cxTestingAllocatorReset(); 795 cxTestingAllocatorReset();
764 796
765 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 797 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
766 798
885 int a = 5, b = 47, c = 13; 917 int a = 5, b = 47, c = 13;
886 cxListAdd(list, &a); 918 cxListAdd(list, &a);
887 cxListAdd(list, &b); 919 cxListAdd(list, &b);
888 cxListAdd(list, &c); 920 cxListAdd(list, &c);
889 921
890 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) 922 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
891 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) 923 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
892 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) 924 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
893 CU_ASSERT_PTR_NULL(cxListAt(list, 3)) 925 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
894 926
895 cxLinkedListDestroy(list); 927 cxLinkedListDestroy(list);
896 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 928 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
897 } 929 }
995 cu_add_test(suite, test_hl_linked_list_insert); 1027 cu_add_test(suite, test_hl_linked_list_insert);
996 cu_add_test(suite, test_hl_linked_list_remove); 1028 cu_add_test(suite, test_hl_linked_list_remove);
997 cu_add_test(suite, test_hl_linked_list_at); 1029 cu_add_test(suite, test_hl_linked_list_at);
998 cu_add_test(suite, test_hl_linked_list_find); 1030 cu_add_test(suite, test_hl_linked_list_find);
999 cu_add_test(suite, test_hl_linked_list_sort); 1031 cu_add_test(suite, test_hl_linked_list_sort);
1032 cu_add_test(suite, test_hl_linked_list_iterator);
1000 1033
1001 suite = CU_add_suite("high level pointer linked list", NULL, NULL); 1034 suite = CU_add_suite("high level pointer linked list", NULL, NULL);
1002 1035
1003 cu_add_test(suite, test_hl_ptr_linked_list_create); 1036 cu_add_test(suite, test_hl_ptr_linked_list_create);
1004 cu_add_test(suite, test_hl_ptr_linked_list_add); 1037 cu_add_test(suite, test_hl_ptr_linked_list_add);
1005 cu_add_test(suite, test_hl_ptr_linked_list_insert); 1038 cu_add_test(suite, test_hl_ptr_linked_list_insert);
1006 cu_add_test(suite, test_hl_ptr_linked_list_remove); 1039 cu_add_test(suite, test_hl_ptr_linked_list_remove);
1007 cu_add_test(suite, test_hl_ptr_linked_list_at); 1040 cu_add_test(suite, test_hl_ptr_linked_list_at);
1008 cu_add_test(suite, test_hl_ptr_linked_list_find); 1041 cu_add_test(suite, test_hl_ptr_linked_list_find);
1009 cu_add_test(suite, test_hl_ptr_linked_list_sort); 1042 cu_add_test(suite, test_hl_ptr_linked_list_sort);
1043 cu_add_test(suite, test_hl_ptr_linked_list_iterator);
1010 1044
1011 CU_basic_set_mode(UCX_CU_BRM); 1045 CU_basic_set_mode(UCX_CU_BRM);
1012 1046
1013 int exitcode; 1047 int exitcode;
1014 if (CU_basic_run_tests()) { 1048 if (CU_basic_run_tests()) {

mercurial