--- a/test/test_list.c Sat Jan 22 10:29:48 2022 +0100 +++ b/test/test_list.c Sat Jan 22 17:15:14 2022 +0100 @@ -223,12 +223,12 @@ cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]); CU_ASSERT_PTR_EQUAL(end, &nodes[0]) - cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); CU_ASSERT_PTR_EQUAL(end, &nodes[1]) CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) - cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); CU_ASSERT_PTR_EQUAL(end, &nodes[2]) CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) @@ -759,6 +759,38 @@ CU_ASSERT_TRUE(cxTestingAllocatorVerify()) } +void test_hl_linked_list_iterator_impl(CxList list) { + int i = 0; + for (CxIterator iter = cxListBegin(list); cxIteratorValid(&iter); cxIteratorNext(&iter)) { + CU_ASSERT_EQUAL(iter.index, (size_t) i) + int *x = cxIteratorCurrent(&iter); + CU_ASSERT_EQUAL(*x, i) + i++; + } + CU_ASSERT_EQUAL(i, 10) + cxLinkedListDestroy(list); + CU_ASSERT_TRUE(cxTestingAllocatorVerify()) +} + +void test_hl_linked_list_iterator(void) { + cxTestingAllocatorReset(); + CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)); + for (int i = 0; i < 10; i++) { + cxListAdd(list, &i); + } + test_hl_linked_list_iterator_impl(list); +} + +void test_hl_ptr_linked_list_iterator(void) { + cxTestingAllocatorReset(); + CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int); + int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + for (int i = 0; i < 10; i++) { + cxListAdd(list, &data[i]); + } + test_hl_linked_list_iterator_impl(list); +} + void test_hl_ptr_linked_list_create(void) { cxTestingAllocatorReset(); @@ -887,9 +919,9 @@ cxListAdd(list, &b); cxListAdd(list, &c); - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) - CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) + CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) CU_ASSERT_PTR_NULL(cxListAt(list, 3)) cxLinkedListDestroy(list); @@ -997,6 +1029,7 @@ cu_add_test(suite, test_hl_linked_list_at); cu_add_test(suite, test_hl_linked_list_find); cu_add_test(suite, test_hl_linked_list_sort); + cu_add_test(suite, test_hl_linked_list_iterator); suite = CU_add_suite("high level pointer linked list", NULL, NULL); @@ -1007,6 +1040,7 @@ cu_add_test(suite, test_hl_ptr_linked_list_at); cu_add_test(suite, test_hl_ptr_linked_list_find); cu_add_test(suite, test_hl_ptr_linked_list_sort); + cu_add_test(suite, test_hl_ptr_linked_list_iterator); CU_basic_set_mode(UCX_CU_BRM);