tests/test_list.c

changeset 803
0711d869ce4d
parent 801
04aa3913c0e3
child 804
5136f2fc32ec
equal deleted inserted replaced
802:30473af255b4 803:0711d869ce4d
27 */ 27 */
28 28
29 #include "cx/test.h" 29 #include "cx/test.h"
30 #include "util_allocator.h" 30 #include "util_allocator.h"
31 #include "cx/compare.h" 31 #include "cx/compare.h"
32 #include "cx/utils.h"
32 33
33 #include "cx/array_list.h" 34 #include "cx/array_list.h"
34 #include "cx/linked_list.h" 35 #include "cx/linked_list.h"
35 36
36 #include <stdarg.h> 37 #include <stdarg.h>
852 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 853 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
853 } 854 }
854 cx_testing_allocator_destroy(&talloc); 855 cx_testing_allocator_destroy(&talloc);
855 } 856 }
856 857
858 #define set_up_combo \
859 CxTestingAllocator talloc; \
860 cx_testing_allocator_init(&talloc); \
861 CxAllocator *alloc = &talloc.base; \
862 CX_TEST_DO {
863 #define tear_down_combo \
864 cxListDestroy(list); \
865 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));\
866 } \
867 cx_testing_allocator_destroy(&talloc);
868 #define roll_out_test_combos(name, body) \
869 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \
870 __attribute__((__unused__)) bool isptrlist, \
871 __attribute__((__unused__)) bool islinkedlist) body \
872 CX_TEST(test_list_ll_##name) { \
873 set_up_combo \
874 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \
875 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, true); \
876 tear_down_combo \
877 } \
878 CX_TEST(test_list_arl_##name) { \
879 set_up_combo \
880 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \
881 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, false); \
882 tear_down_combo \
883 } \
884 CX_TEST(test_list_pll_##name) { \
885 set_up_combo \
886 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \
887 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, true); \
888 tear_down_combo \
889 } \
890 CX_TEST(test_list_parl_##name) { \
891 set_up_combo \
892 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \
893 CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, false); \
894 tear_down_combo \
895 }
896 #define array_init(...) {__VA_ARGS__}
897
898 static inline int *int_test_data_added_to_list(CxList *list, bool isptrlist, size_t len) {
899 int *testdata = int_test_data(len);
900 if (isptrlist) {
901 cx_for_n(i, len) {
902 cxListAdd(list, &testdata[i]);
903 }
904 } else {
905 cxListAddArray(list, testdata, len);
906 }
907 return testdata;
908 }
909
910 roll_out_test_combos(add, {
911 const size_t len = 250;
912 int *testdata = int_test_data(len);
913 cx_for_n (i, len) CX_TEST_ASSERT(cxListAdd(list, &testdata[i]) == 0);
914 CX_TEST_ASSERT(cxListSize(list) == len);
915 cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
916 cx_for_n (i, len) ++testdata[i];
917 if (isptrlist) {
918 cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
919 } else {
920 cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i] - 1);
921 }
922 free(testdata);
923 })
924
925 roll_out_test_combos(insert, {
926 int a = 5;
927 int b = 47;
928 int c = 13;
929 int d = 42;
930 CX_TEST_ASSERT(cxListInsert(list, 1, &a) != 0);
931 CX_TEST_ASSERT(cxListSize(list) == 0);
932 CX_TEST_ASSERT(cxListInsert(list, 0, &a) == 0);
933 CX_TEST_ASSERT(cxListSize(list) == 1);
934 CX_TEST_ASSERT(cxListInsert(list, 0, &b) == 0);
935 CX_TEST_ASSERT(cxListSize(list) == 2);
936 CX_TEST_ASSERT(cxListInsert(list, 1, &c) == 0);
937 CX_TEST_ASSERT(cxListSize(list) == 3);
938 CX_TEST_ASSERT(cxListInsert(list, 3, &d) == 0);
939 CX_TEST_ASSERT(cxListSize(list) == 4);
940 CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 47);
941 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 13);
942 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 5);
943 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 42);
944 })
945
946 roll_out_test_combos(insert_array, {
947 int a[5] = array_init(5, 47, 11, 13, 42);
948 int b[5] = array_init(9, 18, 72, 50, 7);
949 int *aptr[5];
950 int *bptr[5];
951 cx_for_n(i, 5) {
952 aptr[i] = &a[i];
953 bptr[i] = &b[i];
954 }
955
956 size_t inserted;
957
958 if (isptrlist) {
959 inserted = cxListInsertArray(list, 0, aptr, 5);
960 } else {
961 inserted = cxListInsertArray(list, 0, a, 5);
962 }
963 CX_TEST_ASSERT(inserted == 5);
964 CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 5);
965 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 47);
966 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 11);
967 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 13);
968 CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == 42);
969 if (isptrlist) {
970 inserted = cxListInsertArray(list, 3, bptr, 5);
971 } else {
972 inserted = cxListInsertArray(list, 3, b, 5);
973 }
974 CX_TEST_ASSERT(inserted == 5);
975 CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == 5);
976 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == 47);
977 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == 11);
978 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == 9);
979 CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == 18);
980 CX_TEST_ASSERT(*(int *) cxListAt(list, 5) == 72);
981 CX_TEST_ASSERT(*(int *) cxListAt(list, 6) == 50);
982 CX_TEST_ASSERT(*(int *) cxListAt(list, 7) == 7);
983 CX_TEST_ASSERT(*(int *) cxListAt(list, 8) == 13);
984 CX_TEST_ASSERT(*(int *) cxListAt(list, 9) == 42);
985 })
986
987 roll_out_test_combos(remove, {
988 const size_t testdata_len = 32;
989 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
990
991 CX_TEST_ASSERT(cxListRemove(list, 2) == 0);
992 CX_TEST_ASSERT(cxListRemove(list, 4) == 0);
993 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 2);
994 CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == testdata[0]);
995 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == testdata[1]);
996 CX_TEST_ASSERT(*(int *) cxListAt(list, 2) == testdata[3]);
997 CX_TEST_ASSERT(*(int *) cxListAt(list, 3) == testdata[4]);
998 CX_TEST_ASSERT(*(int *) cxListAt(list, 4) == testdata[6]);
999 CX_TEST_ASSERT(cxListRemove(list, 0) == 0);
1000 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 3);
1001 CX_TEST_ASSERT(*(int *) cxListAt(list, 0) == testdata[1]);
1002 CX_TEST_ASSERT(*(int *) cxListAt(list, 1) == testdata[3]);
1003 CX_TEST_ASSERT(cxListRemove(list, testdata_len) != 0);
1004 free(testdata);
1005 })
1006
1007 roll_out_test_combos(find_remove, {
1008 const size_t testdata_len = 250;
1009 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1010
1011 int exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
1012 int val = testdata[exp];
1013 // randomly picked number could occur earlier in list - find first position
1014 for (int i = 0 ; i < exp ; i++) {
1015 if (testdata[i] == val) {
1016 exp = i;
1017 break;
1018 }
1019 }
1020 CX_TEST_ASSERT(cxListSize(list) == testdata_len);
1021 CX_TEST_ASSERT(cxListFind(list, &val) == exp);
1022 CX_TEST_ASSERT(cxListFindRemove(list, &val) == exp);
1023 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
1024 CX_TEST_ASSERT(cxListFind(list, &val) != exp);
1025
1026 int notinlist = -1;
1027 CX_TEST_ASSERT(cxListFindRemove(list, &notinlist) < 0);
1028 CX_TEST_ASSERT(cxListSize(list) == testdata_len - 1);
1029
1030 free(testdata);
1031 })
1032
1033 roll_out_test_combos(clear, {
1034 int *testdata = int_test_data_added_to_list(list, isptrlist, 8);
1035 CX_TEST_ASSERT(cxListSize(list) > 0);
1036 cxListClear(list);
1037 CX_TEST_ASSERT(cxListSize(list) == 0);
1038 free(testdata);
1039 })
1040
1041 roll_out_test_combos(at, {
1042 size_t len = 128;
1043 int *testdata = int_test_data_added_to_list(list, isptrlist, 128);
1044 CX_TEST_ASSERT(cxListSize(list) == len);
1045 cx_for_n (i, len) {
1046 CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]);
1047 }
1048 CX_TEST_ASSERT(cxListAt(list, cxListSize(list)) == NULL);
1049 free(testdata);
1050 })
1051
1052 roll_out_test_combos(swap, {
1053 int original[16] = array_init(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
1054 int swapped[16] = array_init(8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13);
1055
1056 cx_for_n(i, 16) {
1057 cxListAdd(list, &original[i]);
1058 }
1059
1060 CX_TEST_ASSERT(0 == cxListSwap(list, 1, 4));
1061 CX_TEST_ASSERT(0 == cxListSwap(list, 2, 14));
1062 CX_TEST_ASSERT(0 == cxListSwap(list, 9, 6));
1063 CX_TEST_ASSERT(0 == cxListSwap(list, 3, 3));
1064 CX_TEST_ASSERT(0 == cxListSwap(list, 10, 11));
1065 CX_TEST_ASSERT(0 == cxListSwap(list, 8, 0));
1066 CX_TEST_ASSERT(0 == cxListSwap(list, 7, 12));
1067 CX_TEST_ASSERT(0 == cxListSwap(list, 13, 15));
1068
1069 CX_TEST_ASSERT(0 != cxListSwap(list, 5, 16));
1070 CX_TEST_ASSERT(0 != cxListSwap(list, 16, 6));
1071 CX_TEST_ASSERT(0 != cxListSwap(list, 16, 17));
1072
1073 CxIterator iter = cxListIterator(list);
1074 cx_foreach(int*, e, iter) {
1075 CX_TEST_ASSERT(*e == swapped[iter.index]);
1076 }
1077 iter = cxListBackwardsIterator(list);
1078 cx_foreach(int*, e, iter) {
1079 CX_TEST_ASSERT(*e == swapped[iter.index]);
1080 }
1081 })
1082
1083 roll_out_test_combos(swap_no_sbo, {
1084 if (islinkedlist) {
1085 CX_DISABLE_LINKED_LIST_SWAP_SBO = true;
1086 CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true);
1087 CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
1088 } else {
1089 // TODO: currently, SBO for swap operation cannot be disabled for array lists
1090 CX_TEST_ASSERT(true);
1091 }
1092 })
1093
1094 roll_out_test_combos(find, {
1095 const size_t testdata_len = 500;
1096 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1097
1098 cx_for_n (attempt, 25) {
1099 int exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp)
1100 int val = testdata[exp];
1101 // randomly picked number could occur earlier in list - find first position
1102 for (int i = 0 ; i < exp ; i++) {
1103 if (testdata[i] == val) {
1104 exp = i;
1105 break;
1106 }
1107 }
1108 CX_TEST_ASSERT(cxListFind(list, &val) == exp);
1109 }
1110
1111 int notinlist = -1;
1112 CX_TEST_ASSERT(cxListFind(list, &notinlist) < 0);
1113
1114 free(testdata);
1115 })
1116
1117 roll_out_test_combos(sort, {
1118 const size_t testdata_len = 250;
1119 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1120 int *expected = malloc(testdata_len*sizeof(int));
1121 memcpy(expected, testdata, testdata_len*sizeof(int));
1122 qsort(expected, testdata_len, sizeof(int), cx_cmp_int);
1123
1124 cxListSort(list);
1125 cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]);
1126
1127 free(expected);
1128 free(testdata);
1129 })
1130
1131 roll_out_test_combos(reverse, {
1132 const size_t testdata_len = 50;
1133 int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len);
1134 cxListReverse(list);
1135 cx_for_n(i, testdata_len) {
1136 CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[testdata_len - 1 - i]);
1137 }
1138 free(testdata);
1139 })
1140
1141 roll_out_test_combos(iterator, {
1142 const size_t len = 50;
1143 int *testdata = int_test_data_added_to_list(list, isptrlist, len);
1144
1145 CxIterator iter = cxListIterator(list);
1146 size_t i = 0;
1147 cx_foreach(int*, x, iter) {
1148 CX_TEST_ASSERT(i == iter.index);
1149 CX_TEST_ASSERT(*x == testdata[iter.index]);
1150 i++;
1151 }
1152 CX_TEST_ASSERT(i == cxListSize(list));
1153 iter = cxListBackwardsIterator(list);
1154 cx_foreach(int*, x, iter) {
1155 CX_TEST_ASSERT(i - 1 == iter.index);
1156 CX_TEST_ASSERT(*x == testdata[iter.index]);
1157 i--;
1158 }
1159 CX_TEST_ASSERT(i == 0);
1160 i = len / 2;
1161 CxMutIterator mut_iter = cxListMutIteratorAt(list, i);
1162 size_t j = 0;
1163 cx_foreach(int*, x, mut_iter) {
1164 CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
1165 CX_TEST_ASSERT(*x == testdata[i]);
1166 if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter);
1167 i++;
1168 j++;
1169 }
1170 CX_TEST_ASSERT(i == len);
1171 i = len / 2;
1172 j = 0;
1173 mut_iter = cxListMutBackwardsIteratorAt(list, i - 1);
1174 cx_foreach(int*, x, mut_iter) {
1175 CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j);
1176 CX_TEST_ASSERT(*x == testdata[i - 1]);
1177 if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter);
1178 i--;
1179 j++;
1180 }
1181 CX_TEST_ASSERT(i == 0);
1182 CX_TEST_ASSERT(cxListSize(list) == len / 2);
1183 cx_for_n(k, len / 2) CX_TEST_ASSERT(*(int *) cxListAt(list, k) == testdata[k * 2]);
1184
1185 free(testdata);
1186 })
1187
1188 roll_out_test_combos(insert_with_iterator, {
1189 int fivenums[] = array_init(0, 1, 2, 3, 4);
1190 cx_for_n(i, 5) cxListAdd(list, &fivenums[i]);
1191 int newdata[] = array_init(10, 20, 30, 40, 50);
1192
1193 CxMutIterator iter = cxListMutIteratorAt(list, 2);
1194 CX_TEST_ASSERT(cxIteratorValid(iter));
1195 CX_TEST_ASSERT(iter.index == 2);
1196 CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
1197 cxListInsertAfter(&iter, &newdata[0]);
1198 CX_TEST_ASSERT(cxIteratorValid(iter));
1199 CX_TEST_ASSERT(iter.index == 2);
1200 CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
1201 cxListInsertBefore(&iter, &newdata[1]);
1202 CX_TEST_ASSERT(cxIteratorValid(iter));
1203 CX_TEST_ASSERT(iter.index == 3);
1204 CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 2);
1205
1206 iter = cxListMutIterator(list);
1207 cxListInsertBefore(&iter, &newdata[2]);
1208 CX_TEST_ASSERT(cxIteratorValid(iter));
1209 CX_TEST_ASSERT(iter.index == 1);
1210 CX_TEST_ASSERT(*(int *) cxIteratorCurrent(iter) == 0);
1211 iter = cxListMutIteratorAt(list, cxListSize(list));
1212 cxListInsertBefore(&iter, &newdata[3]);
1213 CX_TEST_ASSERT(!cxIteratorValid(iter));
1214 CX_TEST_ASSERT(iter.index == 9);
1215 iter = cxListMutIteratorAt(list, cxListSize(list));
1216 cxListInsertAfter(&iter, &newdata[4]);
1217 CX_TEST_ASSERT(!cxIteratorValid(iter));
1218 CX_TEST_ASSERT(iter.index == 10);
1219
1220 int expdata[] = array_init(30, 0, 1, 20, 2, 10, 3, 4, 40, 50);
1221 cx_for_n (j, 10) CX_TEST_ASSERT(*(int *) cxListAt(list, j) == expdata[j]);
1222 })
1223
1224 static CX_TEST_SUBROUTINE(test_list_verify_compare, CxList *left, CxList *right) {
1225 CX_TEST_ASSERTM(cxListCompare(left, right) == 0, "lists don't start identical");
1226 int x = 42;
1227 cxListAdd(left, &x);
1228 CX_TEST_ASSERT(cxListSize(left) > cxListSize(right));
1229 CX_TEST_ASSERT(cxListCompare(left, right) > 0);
1230 CX_TEST_ASSERT(cxListCompare(right, left) < 0);
1231 cxListAdd(right, &x);
1232 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
1233 CX_TEST_ASSERT(cxListCompare(left, right) == 0);
1234 int a = 5, b = 10;
1235 cxListInsert(left, 15, &a);
1236 cxListInsert(right, 15, &b);
1237 CX_TEST_ASSERT(cxListSize(left) == cxListSize(right));
1238 CX_TEST_ASSERT(cxListCompare(left, right) < 0);
1239 CX_TEST_ASSERT(cxListCompare(right, left) > 0);
1240 *(int *) cxListAt(left, 15) = 10;
1241 CX_TEST_ASSERT(cxListCompare(left, right) == 0);
1242 }
1243
1244 #define roll_out_compare_tests(suffix, otherctr) \
1245 roll_out_test_combos(compare_##suffix, { \
1246 const size_t len = 47; \
1247 int *testdata = int_test_data_added_to_list(list, isptrlist, len); \
1248 CxList *other = otherctr; \
1249 cx_for_n(i, len) cxListAdd(other, &testdata[i]); \
1250 CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \
1251 cxListDestroy(other); \
1252 free(testdata); \
1253 })
1254
1255 roll_out_compare_tests(
1256 ll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int))
1257 )
1258
1259 roll_out_compare_tests(
1260 pll, cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS)
1261 )
1262
1263 roll_out_compare_tests(
1264 arl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50)
1265 )
1266
1267 roll_out_compare_tests(
1268 parl, cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 50)
1269 )
1270
1271 static unsigned destr_test_ctr;
1272 static int destr_last_value;
1273
1274 static void simple_destr_test_fun(void *data) {
1275 int *ptr = data;
1276 destr_last_value = *ptr;
1277 *ptr = destr_last_value + 1;
1278 destr_test_ctr++;
1279 }
1280
1281 static void advanced_destr_test_fun(__attribute__((__unused__)) void *u, void *data) {
1282 simple_destr_test_fun(data);
1283 }
1284
1285 static CX_TEST_SUBROUTINE(test_list_verify_destructor, CxList *list,
1286 int const *testdata, size_t testdata_len) {
1287 destr_test_ctr = 0;
1288
1289 int off = cxListIsStoringPointers(list) ? 1 : 0;
1290
1291 cxListRemove(list, 15);
1292 CX_TEST_ASSERT(1 == destr_test_ctr);
1293 CX_TEST_ASSERT(testdata[15] == destr_last_value + off);
1294 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1295 cxListRemove(list, 47);
1296 CX_TEST_ASSERT(2 == destr_test_ctr);
1297 CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
1298 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1299
1300 CxMutIterator iter = cxListMutIteratorAt(list, 7);
1301 cxIteratorNext(iter);
1302 CX_TEST_ASSERT(2 == destr_test_ctr);
1303 CX_TEST_ASSERT(testdata[48] == destr_last_value + off);
1304 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1305 cxIteratorFlagRemoval(iter);
1306 cxIteratorNext(iter);
1307 CX_TEST_ASSERT(3 == destr_test_ctr);
1308 CX_TEST_ASSERT(testdata[8] == destr_last_value + off);
1309 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1310
1311 iter = cxListMutBackwardsIteratorAt(list, 5);
1312 cxIteratorNext(iter);
1313 CX_TEST_ASSERT(3 == destr_test_ctr);
1314 CX_TEST_ASSERT(testdata[8] == destr_last_value + off);
1315 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1316 cxIteratorFlagRemoval(iter);
1317 cxIteratorNext(iter);
1318 CX_TEST_ASSERT(4 == destr_test_ctr);
1319 CX_TEST_ASSERT(testdata[4] == destr_last_value + off);
1320 CX_TEST_ASSERT(testdata_len - destr_test_ctr == cxListSize(list));
1321
1322 cxListClear(list);
1323 CX_TEST_ASSERT(testdata_len == destr_test_ctr);
1324 CX_TEST_ASSERT(testdata[testdata_len - 1] == destr_last_value + off);
1325 }
1326
1327 roll_out_test_combos(simple_destr, {
1328 const size_t len = 60;
1329 int *testdata = int_test_data_added_to_list(list, isptrlist, len);
1330 list->simple_destructor = simple_destr_test_fun;
1331 CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
1332 free(testdata);
1333 })
1334
1335 roll_out_test_combos(advanced_destr, {
1336 const size_t len = 75;
1337 int *testdata = int_test_data_added_to_list(list, isptrlist, len);
1338 list->advanced_destructor = advanced_destr_test_fun;
1339 CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len);
1340 free(testdata);
1341 })
1342
857 CxTestSuite *cx_test_suite_array_list(void) { 1343 CxTestSuite *cx_test_suite_array_list(void) {
858 CxTestSuite *suite = cx_test_suite_new("array_list"); 1344 CxTestSuite *suite = cx_test_suite_new("array_list");
859 1345
860 cx_test_register(suite, test_list_arl_create); 1346 cx_test_register(suite, test_list_arl_create);
861 cx_test_register(suite, test_list_arl_create_simple); 1347 cx_test_register(suite, test_list_arl_create_simple);
862 cx_test_register(suite, test_list_arl_create_simple_for_pointers); 1348 cx_test_register(suite, test_list_arl_create_simple_for_pointers);
863 cx_test_register(suite, test_list_parl_destroy_no_destr); 1349 cx_test_register(suite, test_list_parl_destroy_no_destr);
864 cx_test_register(suite, test_list_parl_destroy_simple_destr); 1350 cx_test_register(suite, test_list_parl_destroy_simple_destr);
865 cx_test_register(suite, test_list_parl_destroy_adv_destr); 1351 cx_test_register(suite, test_list_parl_destroy_adv_destr);
1352
1353 cx_test_register(suite, test_list_arl_add);
1354 cx_test_register(suite, test_list_parl_add);
1355 cx_test_register(suite, test_list_arl_insert);
1356 cx_test_register(suite, test_list_parl_insert);
1357 cx_test_register(suite, test_list_arl_insert_array);
1358 cx_test_register(suite, test_list_parl_insert_array);
1359 cx_test_register(suite, test_list_arl_remove);
1360 cx_test_register(suite, test_list_parl_remove);
1361 cx_test_register(suite, test_list_arl_find_remove);
1362 cx_test_register(suite, test_list_parl_find_remove);
1363 cx_test_register(suite, test_list_arl_clear);
1364 cx_test_register(suite, test_list_parl_clear);
1365 cx_test_register(suite, test_list_arl_at);
1366 cx_test_register(suite, test_list_parl_at);
1367 cx_test_register(suite, test_list_arl_swap);
1368 cx_test_register(suite, test_list_parl_swap);
1369 cx_test_register(suite, test_list_arl_swap_no_sbo);
1370 cx_test_register(suite, test_list_parl_swap_no_sbo);
1371 cx_test_register(suite, test_list_arl_find);
1372 cx_test_register(suite, test_list_parl_find);
1373 cx_test_register(suite, test_list_arl_sort);
1374 cx_test_register(suite, test_list_parl_sort);
1375 cx_test_register(suite, test_list_arl_reverse);
1376 cx_test_register(suite, test_list_parl_reverse);
1377 cx_test_register(suite, test_list_arl_iterator);
1378 cx_test_register(suite, test_list_parl_iterator);
1379 cx_test_register(suite, test_list_arl_insert_with_iterator);
1380 cx_test_register(suite, test_list_parl_insert_with_iterator);
1381 cx_test_register(suite, test_list_arl_compare_ll);
1382 cx_test_register(suite, test_list_arl_compare_arl);
1383 cx_test_register(suite, test_list_arl_compare_pll);
1384 cx_test_register(suite, test_list_arl_compare_parl);
1385 cx_test_register(suite, test_list_parl_compare_ll);
1386 cx_test_register(suite, test_list_parl_compare_arl);
1387 cx_test_register(suite, test_list_parl_compare_pll);
1388 cx_test_register(suite, test_list_parl_compare_parl);
1389 cx_test_register(suite, test_list_arl_simple_destr);
1390 cx_test_register(suite, test_list_parl_simple_destr);
1391 cx_test_register(suite, test_list_arl_advanced_destr);
1392 cx_test_register(suite, test_list_parl_advanced_destr);
866 1393
867 return suite; 1394 return suite;
868 } 1395 }
869 1396
870 CxTestSuite *cx_test_suite_linked_list(void) { 1397 CxTestSuite *cx_test_suite_linked_list(void) {
893 cx_test_register(suite, test_list_ll_create_simple_for_pointers); 1420 cx_test_register(suite, test_list_ll_create_simple_for_pointers);
894 cx_test_register(suite, test_list_pll_destroy_no_destr); 1421 cx_test_register(suite, test_list_pll_destroy_no_destr);
895 cx_test_register(suite, test_list_pll_destroy_simple_destr); 1422 cx_test_register(suite, test_list_pll_destroy_simple_destr);
896 cx_test_register(suite, test_list_pll_destroy_adv_destr); 1423 cx_test_register(suite, test_list_pll_destroy_adv_destr);
897 1424
1425 cx_test_register(suite, test_list_ll_add);
1426 cx_test_register(suite, test_list_pll_add);
1427 cx_test_register(suite, test_list_ll_insert);
1428 cx_test_register(suite, test_list_pll_insert);
1429 cx_test_register(suite, test_list_ll_insert_array);
1430 cx_test_register(suite, test_list_pll_insert_array);
1431 cx_test_register(suite, test_list_ll_remove);
1432 cx_test_register(suite, test_list_pll_remove);
1433 cx_test_register(suite, test_list_ll_find_remove);
1434 cx_test_register(suite, test_list_pll_find_remove);
1435 cx_test_register(suite, test_list_ll_clear);
1436 cx_test_register(suite, test_list_pll_clear);
1437 cx_test_register(suite, test_list_ll_at);
1438 cx_test_register(suite, test_list_pll_at);
1439 cx_test_register(suite, test_list_ll_swap);
1440 cx_test_register(suite, test_list_pll_swap);
1441 cx_test_register(suite, test_list_ll_swap_no_sbo);
1442 cx_test_register(suite, test_list_pll_swap_no_sbo);
1443 cx_test_register(suite, test_list_ll_find);
1444 cx_test_register(suite, test_list_pll_find);
1445 cx_test_register(suite, test_list_ll_sort);
1446 cx_test_register(suite, test_list_pll_sort);
1447 cx_test_register(suite, test_list_ll_reverse);
1448 cx_test_register(suite, test_list_pll_reverse);
1449 cx_test_register(suite, test_list_ll_iterator);
1450 cx_test_register(suite, test_list_pll_iterator);
1451 cx_test_register(suite, test_list_ll_insert_with_iterator);
1452 cx_test_register(suite, test_list_pll_insert_with_iterator);
1453 cx_test_register(suite, test_list_ll_compare_ll);
1454 cx_test_register(suite, test_list_ll_compare_arl);
1455 cx_test_register(suite, test_list_ll_compare_pll);
1456 cx_test_register(suite, test_list_ll_compare_parl);
1457 cx_test_register(suite, test_list_pll_compare_ll);
1458 cx_test_register(suite, test_list_pll_compare_arl);
1459 cx_test_register(suite, test_list_pll_compare_pll);
1460 cx_test_register(suite, test_list_pll_compare_parl);
1461 cx_test_register(suite, test_list_ll_simple_destr);
1462 cx_test_register(suite, test_list_pll_simple_destr);
1463 cx_test_register(suite, test_list_ll_advanced_destr);
1464 cx_test_register(suite, test_list_pll_advanced_destr);
1465
898 return suite; 1466 return suite;
899 } 1467 }
900 1468
901 CxTestSuite *cx_test_suite_empty_list(void) { 1469 CxTestSuite *cx_test_suite_empty_list(void) {
902 CxTestSuite *suite = cx_test_suite_new("empty list dummy"); 1470 CxTestSuite *suite = cx_test_suite_new("empty list dummy");

mercurial