1.1 --- a/test/test_list.c Sat Jan 22 10:29:48 2022 +0100 1.2 +++ b/test/test_list.c Sat Jan 22 17:15:14 2022 +0100 1.3 @@ -223,12 +223,12 @@ 1.4 1.5 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]); 1.6 CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 1.7 - cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); 1.8 + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); 1.9 CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 1.10 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 1.11 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 1.12 1.13 - cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); 1.14 + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); 1.15 CU_ASSERT_PTR_EQUAL(end, &nodes[2]) 1.16 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) 1.17 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) 1.18 @@ -759,6 +759,38 @@ 1.19 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 1.20 } 1.21 1.22 +void test_hl_linked_list_iterator_impl(CxList list) { 1.23 + int i = 0; 1.24 + for (CxIterator iter = cxListBegin(list); cxIteratorValid(&iter); cxIteratorNext(&iter)) { 1.25 + CU_ASSERT_EQUAL(iter.index, (size_t) i) 1.26 + int *x = cxIteratorCurrent(&iter); 1.27 + CU_ASSERT_EQUAL(*x, i) 1.28 + i++; 1.29 + } 1.30 + CU_ASSERT_EQUAL(i, 10) 1.31 + cxLinkedListDestroy(list); 1.32 + CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 1.33 +} 1.34 + 1.35 +void test_hl_linked_list_iterator(void) { 1.36 + cxTestingAllocatorReset(); 1.37 + CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); 1.38 + for (int i = 0; i < 10; i++) { 1.39 + cxListAdd(list, &i); 1.40 + } 1.41 + test_hl_linked_list_iterator_impl(list); 1.42 +} 1.43 + 1.44 +void test_hl_ptr_linked_list_iterator(void) { 1.45 + cxTestingAllocatorReset(); 1.46 + CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); 1.47 + int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 1.48 + for (int i = 0; i < 10; i++) { 1.49 + cxListAdd(list, &data[i]); 1.50 + } 1.51 + test_hl_linked_list_iterator_impl(list); 1.52 +} 1.53 + 1.54 void test_hl_ptr_linked_list_create(void) { 1.55 cxTestingAllocatorReset(); 1.56 1.57 @@ -887,9 +919,9 @@ 1.58 cxListAdd(list, &b); 1.59 cxListAdd(list, &c); 1.60 1.61 - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) 1.62 - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) 1.63 - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) 1.64 + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) 1.65 + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) 1.66 + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) 1.67 CU_ASSERT_PTR_NULL(cxListAt(list, 3)) 1.68 1.69 cxLinkedListDestroy(list); 1.70 @@ -997,6 +1029,7 @@ 1.71 cu_add_test(suite, test_hl_linked_list_at); 1.72 cu_add_test(suite, test_hl_linked_list_find); 1.73 cu_add_test(suite, test_hl_linked_list_sort); 1.74 + cu_add_test(suite, test_hl_linked_list_iterator); 1.75 1.76 suite = CU_add_suite("high level pointer linked list", NULL, NULL); 1.77 1.78 @@ -1007,6 +1040,7 @@ 1.79 cu_add_test(suite, test_hl_ptr_linked_list_at); 1.80 cu_add_test(suite, test_hl_ptr_linked_list_find); 1.81 cu_add_test(suite, test_hl_ptr_linked_list_sort); 1.82 + cu_add_test(suite, test_hl_ptr_linked_list_iterator); 1.83 1.84 CU_basic_set_mode(UCX_CU_BRM); 1.85