| 2674 | 2683 | 
| 2675 roll_out_test_combos(clone_alloc_fail_into_pll, { | 2684 roll_out_test_combos(clone_alloc_fail_into_pll, { | 
| 2676     CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); | 2685     CxList *target = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); | 
| 2677     CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); | 2686     CX_TEST_CALL_SUBROUTINE(verify_clone_alloc_fail, target, list, true); | 
| 2678 }) | 2687 }) | 
|  | 2688 | 
|  | 2689 static CX_TEST_SUBROUTINE(verify_difference, bool sorted, bool alloc_fail) { | 
|  | 2690     CxTestingAllocator talloc; | 
|  | 2691     cx_testing_allocator_init(&talloc); | 
|  | 2692 | 
|  | 2693     CxList *dst = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); | 
|  | 2694     cxDefineAdvancedDestructor(dst, cxFree, &talloc); | 
|  | 2695     CxList *minuend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); | 
|  | 2696     CxList *subtrahend = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int)); | 
|  | 2697 | 
|  | 2698     int dst_data[] = { | 
|  | 2699         47, 178, 176, 83, 109, 149, 192, 38, 101, 116, 121, 73, 94, 197, 91, 79, 158, 86, 190, 138, 100, 39, 30, 144, | 
|  | 2700         35, 182, 155, 84, 139, 186, 67, 123, 62, 37, 3, 64, 172, 56, 160, 1, 156, 132, 131, 49, 10, 126, 171, 145, 77, | 
|  | 2701         107 | 
|  | 2702     }; | 
|  | 2703     int minuend_data[] = { | 
|  | 2704         153, 106, 171, 130, 74, 173, 150, 94, 27, 92, 70, 175, 200, 20, 29, 161, 88, 116, 71, 53, 199, 124, 32, 9, 76, | 
|  | 2705         151, 33, 51, 37, 65, 176, 49, 12, 162, 28, 85, 4, 177, 198, 54, 109, 188, 44, 77, 194, 63, 41, 129, 97, 83 | 
|  | 2706     }; | 
|  | 2707     int subtrahend_data[] = { | 
|  | 2708         75, 137, 176, 111, 85, 27, 197, 141, 46, 103, 69, 146, 49, 79, 63, 130, 154, 45, 38, 139, 193, 90, 64, 142, 115, | 
|  | 2709         120, 78, 100, 101, 42, 21, 1, 161, 10, 114, 198, 181, 178, 136, 188, 59, 41, 73, 99, 151, 144, 118, 53, 199, 71 | 
|  | 2710     }; | 
|  | 2711 | 
|  | 2712     { | 
|  | 2713         CxList *tmp = cxArrayListCreateSimple(sizeof(int), 50); | 
|  | 2714         cxListAddArray(tmp, dst_data, 50); | 
|  | 2715         cxListClone(dst, tmp, test_clone_func, &talloc.base, NULL); | 
|  | 2716         cxListFree(tmp); | 
|  | 2717     } | 
|  | 2718     cxListAddArray(minuend, minuend_data, 50); | 
|  | 2719     cxListAddArray(subtrahend, subtrahend_data, 50); | 
|  | 2720     if (sorted) { | 
|  | 2721         cxListSort(dst); | 
|  | 2722         cxListSort(minuend); | 
|  | 2723         cxListSort(subtrahend); | 
|  | 2724     } | 
|  | 2725 | 
|  | 2726     // expected 36 elements stay in dst, and 36 will be added from the difference | 
|  | 2727     size_t expected_len = 72; | 
|  | 2728     int expected_unsorted[] = { | 
|  | 2729         47, 83, 109, 149, 192, 116, 121, 94, 91, 158, 86, 190, 138, 39, 30, 35, 182, 155, 84, 186, 67, 123, 62, 37, | 
|  | 2730         3, 172, 56, 160, 156, 132, 131, 126, 171, 145, 77, 107, | 
|  | 2731         153, 106, 171, 74, 173, 150, 94, 92, 70, 175, 200, 20, 29, 88, 116, 124, 32, 9, 76, 33, 51, 37, 65, 12, 162, | 
|  | 2732         28, 4, 177, 54, 109, 44, 77, 194, 129, 97, 83 | 
|  | 2733     }; | 
|  | 2734     int expected_sorted[] = { | 
|  | 2735         3, 30, 35, 37, 39, 47, 56, 62, 67, 77, 83, 84, 86, 91, 94, 107, 109, 116, 121, 123, 126, 131, 132, 138, 145, | 
|  | 2736         149, 155, 156, 158, 160, 171, 172, 182, 186, 190, 192, | 
|  | 2737         4, 9, 12, 20, 28, 29, 32, 33, 37, 44, 51, 54, 65, 70, 74, 76, 77, 83, 88, 92, 94, 97, 106, 109, 116, 124, 129, | 
|  | 2738         150, 153, 162, 171, 173, 175, 177, 194, 200 | 
|  | 2739     }; | 
|  | 2740 | 
|  | 2741     if (alloc_fail) { | 
|  | 2742         test_clone_func_max_enabled = true; | 
|  | 2743         test_clone_func_max_clones = 30; | 
|  | 2744         expected_len = 66; | 
|  | 2745     } | 
|  | 2746     CxList *expected = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), expected_len); | 
|  | 2747     cxListAddArray(expected, sorted ? expected_sorted : expected_unsorted, expected_len); | 
|  | 2748 | 
|  | 2749     int result = cxListDifference(dst, minuend, subtrahend, test_clone_func, &talloc.base, NULL); | 
|  | 2750     if (alloc_fail) { | 
|  | 2751         CX_TEST_ASSERT(result != 0); | 
|  | 2752     } else { | 
|  | 2753         CX_TEST_ASSERT(result == 0); | 
|  | 2754     } | 
|  | 2755     test_clone_func_max_enabled = false; | 
|  | 2756     CX_TEST_ASSERT(expected_len == cxListSize(dst)); | 
|  | 2757     CX_TEST_ASSERT(0 == cxListCompare(dst, expected)); | 
|  | 2758 | 
|  | 2759     cxListFree(dst); | 
|  | 2760     cxListFree(minuend); | 
|  | 2761     cxListFree(subtrahend); | 
|  | 2762     cxListFree(expected); | 
|  | 2763     CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); | 
|  | 2764 } | 
|  | 2765 | 
|  | 2766 CX_TEST(test_list_difference_unsorted) { | 
|  | 2767     CX_TEST_DO { | 
|  | 2768         CX_TEST_CALL_SUBROUTINE(verify_difference, false, false); | 
|  | 2769     } | 
|  | 2770 } | 
|  | 2771 | 
|  | 2772 CX_TEST(test_list_difference_sorted) { | 
|  | 2773     CX_TEST_DO { | 
|  | 2774         CX_TEST_CALL_SUBROUTINE(verify_difference, true, false); | 
|  | 2775     } | 
|  | 2776 } | 
|  | 2777 | 
|  | 2778 CX_TEST(test_list_difference_unsorted_alloc_fail) { | 
|  | 2779     CX_TEST_DO { | 
|  | 2780         CX_TEST_CALL_SUBROUTINE(verify_difference, false, true); | 
|  | 2781     } | 
|  | 2782 } | 
|  | 2783 | 
|  | 2784 CX_TEST(test_list_difference_sorted_alloc_fail) { | 
|  | 2785     CX_TEST_DO { | 
|  | 2786         CX_TEST_CALL_SUBROUTINE(verify_difference, true, true); | 
|  | 2787     } | 
|  | 2788 } | 
| 2679 | 2789 | 
| 2680 CX_TEST(test_list_pointer_list_supports_null) { | 2790 CX_TEST(test_list_pointer_list_supports_null) { | 
| 2681     CxList *list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); | 2791     CxList *list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); | 
| 2682     int x = 47; | 2792     int x = 47; | 
| 2683     int y = 11; | 2793     int y = 11; |