tests/test_list.c

changeset 807
c8d692131b1e
parent 804
5136f2fc32ec
child 818
2be8fe3d5a2d
equal deleted inserted replaced
806:e06249e09f99 807:c8d692131b1e
865 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));\ 865 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));\
866 } \ 866 } \
867 cx_testing_allocator_destroy(&talloc); 867 cx_testing_allocator_destroy(&talloc);
868 #define roll_out_test_combos(name, body) \ 868 #define roll_out_test_combos(name, body) \
869 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ 869 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \
870 __attribute__((__unused__)) bool isptrlist, \ 870 __attribute__((__unused__)) bool isptrlist) body \
871 __attribute__((__unused__)) bool islinkedlist) body \
872 CX_TEST(test_list_ll_##name) { \ 871 CX_TEST(test_list_ll_##name) { \
873 set_up_combo \ 872 set_up_combo \
874 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \ 873 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \
875 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, true); \ 874 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \
876 tear_down_combo \ 875 tear_down_combo \
877 } \ 876 } \
878 CX_TEST(test_list_arl_##name) { \ 877 CX_TEST(test_list_arl_##name) { \
879 set_up_combo \ 878 set_up_combo \
880 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \ 879 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \
881 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, false); \ 880 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \
882 tear_down_combo \ 881 tear_down_combo \
883 } \ 882 } \
884 CX_TEST(test_list_pll_##name) { \ 883 CX_TEST(test_list_pll_##name) { \
885 set_up_combo \ 884 set_up_combo \
886 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \ 885 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \
887 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, true); \ 886 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \
888 tear_down_combo \ 887 tear_down_combo \
889 } \ 888 } \
890 CX_TEST(test_list_parl_##name) { \ 889 CX_TEST(test_list_parl_##name) { \
891 set_up_combo \ 890 set_up_combo \
892 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \ 891 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \
893 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, false); \ 892 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \
894 tear_down_combo \ 893 tear_down_combo \
895 } 894 }
896 #define array_init(...) {__VA_ARGS__} 895 #define array_init(...) {__VA_ARGS__}
897 896
898 static inline int *int_test_data_added_to_list(CxList *list, bool isptrlist, size_t len) { 897 static inline int *int_test_data_added_to_list(CxList *list, bool isptrlist, size_t len) {
1078 cx_foreach(int*, e, iter) { 1077 cx_foreach(int*, e, iter) {
1079 CX_TEST_ASSERT(*e == swapped[iter.index]); 1078 CX_TEST_ASSERT(*e == swapped[iter.index]);
1080 } 1079 }
1081 }) 1080 })
1082 1081
1083 roll_out_test_combos(swap_no_sbo, { 1082 CX_TEST(test_list_ll_swap_no_sbo) {
1084 if (islinkedlist) { 1083 set_up_combo
1085 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; 1084 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, 2*cx_linked_list_swap_sbo_size);
1086 CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true); 1085 CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, false);
1087 CX_DISABLE_LINKED_LIST_SWAP_SBO = false; 1086 tear_down_combo
1088 } else { 1087 }
1089 CX_DISABLE_ARRAY_LIST_SWAP_SBO = true; 1088 CX_TEST(test_list_arl_swap_no_sbo) {
1090 CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, false); 1089 set_up_combo
1091 CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; 1090 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, 2*cx_array_swap_sbo_size, 8);
1092 } 1091 CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, false);
1093 }) 1092 tear_down_combo
1093 }
1094 1094
1095 roll_out_test_combos(find, { 1095 roll_out_test_combos(find, {
1096 const size_t testdata_len = 500; 1096 const size_t testdata_len = 500;
1097 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len); 1097 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1098 1098
1366 cx_test_register(suite, test_list_arl_at); 1366 cx_test_register(suite, test_list_arl_at);
1367 cx_test_register(suite, test_list_parl_at); 1367 cx_test_register(suite, test_list_parl_at);
1368 cx_test_register(suite, test_list_arl_swap); 1368 cx_test_register(suite, test_list_arl_swap);
1369 cx_test_register(suite, test_list_parl_swap); 1369 cx_test_register(suite, test_list_parl_swap);
1370 cx_test_register(suite, test_list_arl_swap_no_sbo); 1370 cx_test_register(suite, test_list_arl_swap_no_sbo);
1371 cx_test_register(suite, test_list_parl_swap_no_sbo);
1372 cx_test_register(suite, test_list_arl_find); 1371 cx_test_register(suite, test_list_arl_find);
1373 cx_test_register(suite, test_list_parl_find); 1372 cx_test_register(suite, test_list_parl_find);
1374 cx_test_register(suite, test_list_arl_sort); 1373 cx_test_register(suite, test_list_arl_sort);
1375 cx_test_register(suite, test_list_parl_sort); 1374 cx_test_register(suite, test_list_parl_sort);
1376 cx_test_register(suite, test_list_arl_reverse); 1375 cx_test_register(suite, test_list_arl_reverse);
1438 cx_test_register(suite, test_list_ll_at); 1437 cx_test_register(suite, test_list_ll_at);
1439 cx_test_register(suite, test_list_pll_at); 1438 cx_test_register(suite, test_list_pll_at);
1440 cx_test_register(suite, test_list_ll_swap); 1439 cx_test_register(suite, test_list_ll_swap);
1441 cx_test_register(suite, test_list_pll_swap); 1440 cx_test_register(suite, test_list_pll_swap);
1442 cx_test_register(suite, test_list_ll_swap_no_sbo); 1441 cx_test_register(suite, test_list_ll_swap_no_sbo);
1443 cx_test_register(suite, test_list_pll_swap_no_sbo);
1444 cx_test_register(suite, test_list_ll_find); 1442 cx_test_register(suite, test_list_ll_find);
1445 cx_test_register(suite, test_list_pll_find); 1443 cx_test_register(suite, test_list_pll_find);
1446 cx_test_register(suite, test_list_ll_sort); 1444 cx_test_register(suite, test_list_ll_sort);
1447 cx_test_register(suite, test_list_pll_sort); 1445 cx_test_register(suite, test_list_pll_sort);
1448 cx_test_register(suite, test_list_ll_reverse); 1446 cx_test_register(suite, test_list_ll_reverse);

mercurial