diff -r 25108c15e2d4 -r b4c3e0b4c3d5 tests/test_list.c --- a/tests/test_list.c Sun May 04 11:46:13 2025 +0200 +++ b/tests/test_list.c Sun May 04 12:15:03 2025 +0200 @@ -1477,6 +1477,63 @@ free(testdata); }) +roll_out_test_combos(remove_and_get, { + int testdata[10]; + for (unsigned i = 0 ; i < 10 ; i++) { + testdata[i] = 2*i; + cxListAdd(list, &testdata[i]); + } + if (isptrlist) { + int *x; + CX_TEST_ASSERT(cxListPop(list, &x) == 0); + CX_TEST_ASSERT(*x == 18); + CX_TEST_ASSERT(cxListPop(list, &x) == 0); + CX_TEST_ASSERT(*x == 16); + CX_TEST_ASSERT(cxListPopFront(list, &x) == 0); + CX_TEST_ASSERT(*x == 0); + CX_TEST_ASSERT(cxListPopFront(list, &x) == 0); + CX_TEST_ASSERT(*x == 2); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 3, &x) == 0); + CX_TEST_ASSERT(*x == 10); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 3, &x) == 0); + CX_TEST_ASSERT(*x == 12); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 8, &x) != 0); + CX_TEST_ASSERT(*x == 12); + + *x = 1337; + cxListClear(list); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 0, &x) != 0); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 1, &x) != 0); + CX_TEST_ASSERT(cxListPop(list, &x) != 0); + CX_TEST_ASSERT(cxListPopFront(list, &x) != 0); + CX_TEST_ASSERT(*x == 1337); + } else { + int x; + CX_TEST_ASSERT(cxListPop(list, &x) == 0); + CX_TEST_ASSERT(x == 18); + CX_TEST_ASSERT(cxListPop(list, &x) == 0); + CX_TEST_ASSERT(x == 16); + CX_TEST_ASSERT(cxListPopFront(list, &x) == 0); + CX_TEST_ASSERT(x == 0); + CX_TEST_ASSERT(cxListPopFront(list, &x) == 0); + CX_TEST_ASSERT(x == 2); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 3, &x) == 0); + CX_TEST_ASSERT(x == 10); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 3, &x) == 0); + CX_TEST_ASSERT(x == 12); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 8, &x) != 0); + CX_TEST_ASSERT(x == 12); + + x = 1337; + cxListClear(list); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 0, &x) != 0); + CX_TEST_ASSERT(cxListRemoveAndGet(list, 1, &x) != 0); + CX_TEST_ASSERT(cxListPop(list, &x) != 0); + CX_TEST_ASSERT(cxListPopFront(list, &x) != 0); + CX_TEST_ASSERT(x == 1337); + } +}) + static unsigned test_remove_array_destr_ctr; static void test_remove_array_destr(cx_attr_unused void *d) { test_remove_array_destr_ctr++; @@ -1544,7 +1601,7 @@ } for (unsigned int i = 4 ; i < 8 ; i++) { if (isptrlist) { - CX_TEST_ASSERT(targetp[i] == 0); + CX_TEST_ASSERT(targetp[i] == NULL); } else { CX_TEST_ASSERT(targete[i] == 0); } @@ -1658,12 +1715,12 @@ // Change the first element int v1new = 99; CX_TEST_ASSERT(cxListSet(list, 0, &v1new) == 0); - CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 99); + CX_TEST_ASSERT(*(int *) cxListFirst(list) == 99); // Change the last element int v3new = 101; CX_TEST_ASSERT(cxListSet(list, 2, &v3new) == 0); - CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 101); + CX_TEST_ASSERT(*(int *) cxListLast(list) == 101); // Try index out of bounds int oob = 1337; @@ -2013,6 +2070,8 @@ cx_test_register(suite, test_list_parl_insert_sorted); cx_test_register(suite, test_list_arl_remove); cx_test_register(suite, test_list_parl_remove); + cx_test_register(suite, test_list_arl_remove_and_get); + cx_test_register(suite, test_list_parl_remove_and_get); cx_test_register(suite, test_list_arl_remove_array); cx_test_register(suite, test_list_parl_remove_array); cx_test_register(suite, test_list_arl_find_remove); @@ -2116,6 +2175,8 @@ cx_test_register(suite, test_list_pll_insert_sorted); cx_test_register(suite, test_list_ll_remove); cx_test_register(suite, test_list_pll_remove); + cx_test_register(suite, test_list_ll_remove_and_get); + cx_test_register(suite, test_list_pll_remove_and_get); cx_test_register(suite, test_list_ll_remove_array); cx_test_register(suite, test_list_pll_remove_array); cx_test_register(suite, test_list_ll_find_remove);