584 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len)); |
584 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), testdata_len)); |
585 cxListAddArray(list, testdata.data.data(), testdata_len); |
585 cxListAddArray(list, testdata.data.data(), testdata_len); |
586 return list; |
586 return list; |
587 } |
587 } |
588 |
588 |
|
589 auto pointerArrayListFromTestData() const -> CxList * { |
|
590 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 256)); |
|
591 // note: cannot use cxListAddArray() because we don't have a list of pointers |
|
592 cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]); |
|
593 return list; |
|
594 } |
|
595 |
589 void verifyAdd( |
596 void verifyAdd( |
590 CxList *list, |
597 CxList *list, |
591 bool as_pointer |
598 bool as_pointer |
592 ) { |
599 ) { |
593 auto len = testdata_len; |
600 auto len = testdata_len; |
960 }; |
967 }; |
961 |
968 |
962 class ArrayList : public HighLevelTest { |
969 class ArrayList : public HighLevelTest { |
963 }; |
970 }; |
964 |
971 |
|
972 class PointerArrayList : public HighLevelTest { |
|
973 }; |
|
974 |
965 TEST_F(PointerLinkedList, cxListStorePointers) { |
975 TEST_F(PointerLinkedList, cxListStorePointers) { |
966 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47)); |
976 auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47)); |
967 EXPECT_FALSE(cxListIsStoringPointers(list)); |
977 EXPECT_FALSE(cxListIsStoringPointers(list)); |
968 cxListStorePointers(list); |
978 cxListStorePointers(list); |
969 EXPECT_EQ(list->item_size, sizeof(void *)); |
979 EXPECT_EQ(list->item_size, sizeof(void *)); |
1000 EXPECT_EQ(list->destructor_data, nullptr); |
1010 EXPECT_EQ(list->destructor_data, nullptr); |
1001 EXPECT_EQ(cxListSize(list), 0); |
1011 EXPECT_EQ(cxListSize(list), 0); |
1002 EXPECT_FALSE(cxListIsStoringPointers(list)); |
1012 EXPECT_FALSE(cxListIsStoringPointers(list)); |
1003 } |
1013 } |
1004 |
1014 |
1005 TEST_F(LinkedList, cxLinkedListCreateSimpleForPointers) { |
1015 TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) { |
1006 CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS)); |
1016 CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS)); |
1007 ASSERT_NE(list, nullptr); |
1017 ASSERT_NE(list, nullptr); |
1008 EXPECT_EQ(list->item_size, sizeof(void *)); |
1018 EXPECT_EQ(list->item_size, sizeof(void *)); |
1009 EXPECT_EQ(list->cmpfunc, nullptr); |
1019 EXPECT_EQ(list->cmpfunc, nullptr); |
1010 EXPECT_EQ(list->allocator, cxDefaultAllocator); |
1020 EXPECT_EQ(list->allocator, cxDefaultAllocator); |
1039 EXPECT_EQ(list->destructor_data, nullptr); |
1049 EXPECT_EQ(list->destructor_data, nullptr); |
1040 EXPECT_EQ(cxListSize(list), 0); |
1050 EXPECT_EQ(cxListSize(list), 0); |
1041 EXPECT_FALSE(cxListIsStoringPointers(list)); |
1051 EXPECT_FALSE(cxListIsStoringPointers(list)); |
1042 } |
1052 } |
1043 |
1053 |
1044 TEST_F(ArrayList, cxArrayListCreateSimpleForPointers) { |
1054 TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) { |
1045 CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8)); |
1055 CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8)); |
1046 ASSERT_NE(list, nullptr); |
1056 ASSERT_NE(list, nullptr); |
1047 EXPECT_EQ(list->cmpfunc, nullptr); |
1057 EXPECT_EQ(list->cmpfunc, nullptr); |
1048 EXPECT_EQ(list->allocator, cxDefaultAllocator); |
1058 EXPECT_EQ(list->allocator, cxDefaultAllocator); |
1049 EXPECT_EQ(list->item_size, sizeof(void *)); |
1059 EXPECT_EQ(list->item_size, sizeof(void *)); |
1063 TEST_F(ArrayList, cxListAdd) { |
1073 TEST_F(ArrayList, cxListAdd) { |
1064 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); |
1074 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); |
1065 verifyAdd(list, false); |
1075 verifyAdd(list, false); |
1066 } |
1076 } |
1067 |
1077 |
|
1078 TEST_F(PointerArrayList, cxListAdd) { |
|
1079 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 8)); |
|
1080 verifyAdd(list, true); |
|
1081 } |
|
1082 |
1068 TEST_F(LinkedList, cxListInsert) { |
1083 TEST_F(LinkedList, cxListInsert) { |
1069 verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1084 verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1070 } |
1085 } |
1071 |
1086 |
1072 TEST_F(PointerLinkedList, cxListInsert) { |
1087 TEST_F(PointerLinkedList, cxListInsert) { |
1075 |
1090 |
1076 TEST_F(ArrayList, cxListInsert) { |
1091 TEST_F(ArrayList, cxListInsert) { |
1077 verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2))); |
1092 verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 2))); |
1078 } |
1093 } |
1079 |
1094 |
|
1095 TEST_F(PointerArrayList, cxListInsert) { |
|
1096 verifyInsert(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 2))); |
|
1097 } |
|
1098 |
1080 TEST_F(LinkedList, cxListInsertArray) { |
1099 TEST_F(LinkedList, cxListInsertArray) { |
1081 verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1100 verifyInsertArray(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1082 } |
1101 } |
1083 |
1102 |
1084 TEST_F(PointerLinkedList, cxListInsertArray) { |
1103 TEST_F(PointerLinkedList, cxListInsertArray) { |
1087 |
1106 |
1088 TEST_F(ArrayList, cxListInsertArray) { |
1107 TEST_F(ArrayList, cxListInsertArray) { |
1089 verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4))); |
1108 verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4))); |
1090 } |
1109 } |
1091 |
1110 |
|
1111 TEST_F(PointerArrayList, cxListInsertArray) { |
|
1112 verifyInsertArray(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4)), true); |
|
1113 } |
|
1114 |
1092 TEST_F(LinkedList, cxListRemove) { |
1115 TEST_F(LinkedList, cxListRemove) { |
1093 verifyRemove(linkedListFromTestData()); |
1116 verifyRemove(linkedListFromTestData()); |
1094 } |
1117 } |
1095 |
1118 |
1096 TEST_F(PointerLinkedList, cxListRemove) { |
1119 TEST_F(PointerLinkedList, cxListRemove) { |
1099 |
1122 |
1100 TEST_F(ArrayList, cxListRemove) { |
1123 TEST_F(ArrayList, cxListRemove) { |
1101 verifyRemove(arrayListFromTestData()); |
1124 verifyRemove(arrayListFromTestData()); |
1102 } |
1125 } |
1103 |
1126 |
|
1127 TEST_F(PointerArrayList, cxListRemove) { |
|
1128 verifyRemove(pointerArrayListFromTestData()); |
|
1129 } |
|
1130 |
1104 TEST_F(LinkedList, cxListClear) { |
1131 TEST_F(LinkedList, cxListClear) { |
1105 verifyClear(linkedListFromTestData()); |
1132 verifyClear(linkedListFromTestData()); |
1106 } |
1133 } |
1107 |
1134 |
1108 TEST_F(PointerLinkedList, cxListClear) { |
1135 TEST_F(PointerLinkedList, cxListClear) { |
1111 |
1138 |
1112 TEST_F(ArrayList, cxListClear) { |
1139 TEST_F(ArrayList, cxListClear) { |
1113 verifyClear(arrayListFromTestData()); |
1140 verifyClear(arrayListFromTestData()); |
1114 } |
1141 } |
1115 |
1142 |
|
1143 TEST_F(PointerArrayList, cxListClear) { |
|
1144 verifyClear(pointerArrayListFromTestData()); |
|
1145 } |
|
1146 |
1116 TEST_F(LinkedList, cxListSwap) { |
1147 TEST_F(LinkedList, cxListSwap) { |
1117 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1148 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1118 } |
1149 } |
1119 |
1150 |
1120 TEST_F(PointerLinkedList, cxListSwap) { |
1151 TEST_F(PointerLinkedList, cxListSwap) { |
1121 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS))); |
1152 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS))); |
1122 } |
1153 } |
1123 |
1154 |
1124 TEST_F(ArrayList, cxListSwap) { |
1155 TEST_F(ArrayList, cxListSwap) { |
1125 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16))); |
1156 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16))); |
|
1157 } |
|
1158 |
|
1159 TEST_F(PointerArrayList, cxListSwap) { |
|
1160 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 16))); |
1126 } |
1161 } |
1127 |
1162 |
1128 TEST_F(LinkedList, cxListSwapNoSBO) { |
1163 TEST_F(LinkedList, cxListSwapNoSBO) { |
1129 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; |
1164 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; |
1130 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1165 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)))); |
1135 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; |
1170 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; |
1136 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS))); |
1171 verifySwap(autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS))); |
1137 CX_DISABLE_LINKED_LIST_SWAP_SBO = false; |
1172 CX_DISABLE_LINKED_LIST_SWAP_SBO = false; |
1138 } |
1173 } |
1139 |
1174 |
1140 TEST_F(ArrayList, cxListSwapNoSBO) { |
|
1141 CX_DISABLE_LINKED_LIST_SWAP_SBO = true; |
|
1142 verifySwap(autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 16))); |
|
1143 CX_DISABLE_LINKED_LIST_SWAP_SBO = false; |
|
1144 } |
|
1145 |
|
1146 TEST_F(LinkedList, cxListAt) { |
1175 TEST_F(LinkedList, cxListAt) { |
1147 verifyAt(linkedListFromTestData()); |
1176 verifyAt(linkedListFromTestData()); |
1148 } |
1177 } |
1149 |
1178 |
1150 TEST_F(PointerLinkedList, cxListAt) { |
1179 TEST_F(PointerLinkedList, cxListAt) { |
1153 |
1182 |
1154 TEST_F(ArrayList, cxListAt) { |
1183 TEST_F(ArrayList, cxListAt) { |
1155 verifyAt(arrayListFromTestData()); |
1184 verifyAt(arrayListFromTestData()); |
1156 } |
1185 } |
1157 |
1186 |
|
1187 TEST_F(PointerArrayList, cxListAt) { |
|
1188 verifyAt(pointerArrayListFromTestData()); |
|
1189 } |
|
1190 |
1158 TEST_F(LinkedList, cxListFind) { |
1191 TEST_F(LinkedList, cxListFind) { |
1159 verifyFind(linkedListFromTestData()); |
1192 verifyFind(linkedListFromTestData()); |
1160 } |
1193 } |
1161 |
1194 |
1162 TEST_F(PointerLinkedList, cxListFind) { |
1195 TEST_F(PointerLinkedList, cxListFind) { |
1165 |
1198 |
1166 TEST_F(ArrayList, cxListFind) { |
1199 TEST_F(ArrayList, cxListFind) { |
1167 verifyFind(arrayListFromTestData()); |
1200 verifyFind(arrayListFromTestData()); |
1168 } |
1201 } |
1169 |
1202 |
|
1203 TEST_F(PointerArrayList, cxListFind) { |
|
1204 verifyFind(pointerArrayListFromTestData()); |
|
1205 } |
|
1206 |
1170 TEST_F(LinkedList, cxListSort) { |
1207 TEST_F(LinkedList, cxListSort) { |
1171 verifySort(linkedListFromTestData()); |
1208 verifySort(linkedListFromTestData()); |
1172 } |
1209 } |
1173 |
1210 |
1174 TEST_F(PointerLinkedList, cxListSort) { |
1211 TEST_F(PointerLinkedList, cxListSort) { |
1177 |
1214 |
1178 TEST_F(ArrayList, cxListSort) { |
1215 TEST_F(ArrayList, cxListSort) { |
1179 verifySort(arrayListFromTestData()); |
1216 verifySort(arrayListFromTestData()); |
1180 } |
1217 } |
1181 |
1218 |
|
1219 TEST_F(PointerArrayList, cxListSort) { |
|
1220 verifySort(pointerArrayListFromTestData()); |
|
1221 } |
|
1222 |
1182 TEST_F(LinkedList, Iterator) { |
1223 TEST_F(LinkedList, Iterator) { |
1183 verifyIterator(linkedListFromTestData()); |
1224 verifyIterator(linkedListFromTestData()); |
1184 } |
1225 } |
1185 |
1226 |
1186 TEST_F(PointerLinkedList, Iterator) { |
1227 TEST_F(PointerLinkedList, Iterator) { |
1187 verifyIterator(pointerLinkedListFromTestData()); |
1228 verifyIterator(pointerLinkedListFromTestData()); |
1188 } |
1229 } |
1189 |
1230 |
1190 TEST_F(ArrayList, Iterator) { |
1231 TEST_F(ArrayList, Iterator) { |
1191 verifyIterator(arrayListFromTestData()); |
1232 verifyIterator(arrayListFromTestData()); |
|
1233 } |
|
1234 |
|
1235 TEST_F(PointerArrayList, Iterator) { |
|
1236 verifyIterator(pointerArrayListFromTestData()); |
1192 } |
1237 } |
1193 |
1238 |
1194 TEST_F(LinkedList, InsertViaIterator) { |
1239 TEST_F(LinkedList, InsertViaIterator) { |
1195 int fivenums[] = {0, 1, 2, 3, 4, 5}; |
1240 int fivenums[] = {0, 1, 2, 3, 4, 5}; |
1196 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); |
1241 CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); |
1211 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)); |
1256 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 4)); |
1212 cxListAddArray(list, fivenums, 5); |
1257 cxListAddArray(list, fivenums, 5); |
1213 verifyInsertViaIterator(list); |
1258 verifyInsertViaIterator(list); |
1214 } |
1259 } |
1215 |
1260 |
|
1261 TEST_F(PointerArrayList, InsertViaIterator) { |
|
1262 int fivenums[] = {0, 1, 2, 3, 4, 5}; |
|
1263 auto list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, CX_STORE_POINTERS, 4)); |
|
1264 // note: cannot use cxListAddArray() because we don't have a list of pointers |
|
1265 cx_for_n(i, 5) cxListAdd(list, &fivenums[i]); |
|
1266 verifyInsertViaIterator(list); |
|
1267 } |
|
1268 |
1216 TEST_F(LinkedList, cxListReverse) { |
1269 TEST_F(LinkedList, cxListReverse) { |
1217 verifyReverse(linkedListFromTestData()); |
1270 verifyReverse(linkedListFromTestData()); |
1218 } |
1271 } |
1219 |
1272 |
1220 TEST_F(PointerLinkedList, cxListReverse) { |
1273 TEST_F(PointerLinkedList, cxListReverse) { |
1221 verifyReverse(pointerLinkedListFromTestData()); |
1274 verifyReverse(pointerLinkedListFromTestData()); |
1222 } |
1275 } |
1223 |
1276 |
1224 TEST_F(ArrayList, cxListReverse) { |
1277 TEST_F(ArrayList, cxListReverse) { |
1225 verifyReverse(arrayListFromTestData()); |
1278 verifyReverse(arrayListFromTestData()); |
|
1279 } |
|
1280 |
|
1281 TEST_F(PointerArrayList, cxListReverse) { |
|
1282 verifyReverse(pointerArrayListFromTestData()); |
1226 } |
1283 } |
1227 |
1284 |
1228 TEST_F(LinkedList, cxListCompare) { |
1285 TEST_F(LinkedList, cxListCompare) { |
1229 auto left = linkedListFromTestData(); |
1286 auto left = linkedListFromTestData(); |
1230 auto right = linkedListFromTestData(); |
1287 auto right = linkedListFromTestData(); |
1241 auto left = linkedListFromTestData(); |
1298 auto left = linkedListFromTestData(); |
1242 auto right = arrayListFromTestData(); |
1299 auto right = arrayListFromTestData(); |
1243 verifyCompare(left, right); |
1300 verifyCompare(left, right); |
1244 } |
1301 } |
1245 |
1302 |
|
1303 TEST_F(LinkedList, cxListCompareWithPtrArrayList) { |
|
1304 auto left = linkedListFromTestData(); |
|
1305 auto right = pointerArrayListFromTestData(); |
|
1306 verifyCompare(left, right); |
|
1307 } |
|
1308 |
1246 TEST_F(PointerLinkedList, cxListCompare) { |
1309 TEST_F(PointerLinkedList, cxListCompare) { |
1247 auto left = pointerLinkedListFromTestData(); |
1310 auto left = pointerLinkedListFromTestData(); |
1248 auto right = pointerLinkedListFromTestData(); |
1311 auto right = pointerLinkedListFromTestData(); |
1249 verifyCompare(left, right); |
1312 verifyCompare(left, right); |
1250 } |
1313 } |
1259 auto left = pointerLinkedListFromTestData(); |
1322 auto left = pointerLinkedListFromTestData(); |
1260 auto right = arrayListFromTestData(); |
1323 auto right = arrayListFromTestData(); |
1261 verifyCompare(left, right); |
1324 verifyCompare(left, right); |
1262 } |
1325 } |
1263 |
1326 |
|
1327 TEST_F(PointerLinkedList, cxListCompareWithPtrArrayList) { |
|
1328 auto left = pointerLinkedListFromTestData(); |
|
1329 auto right = pointerArrayListFromTestData(); |
|
1330 verifyCompare(left, right); |
|
1331 } |
|
1332 |
1264 TEST_F(ArrayList, cxListCompare) { |
1333 TEST_F(ArrayList, cxListCompare) { |
1265 auto left = arrayListFromTestData(); |
1334 auto left = arrayListFromTestData(); |
1266 auto right = arrayListFromTestData(); |
1335 auto right = arrayListFromTestData(); |
1267 verifyCompare(left, right); |
1336 verifyCompare(left, right); |
1268 } |
1337 } |
1277 auto left = arrayListFromTestData(); |
1346 auto left = arrayListFromTestData(); |
1278 auto right = linkedListFromTestData(); |
1347 auto right = linkedListFromTestData(); |
1279 verifyCompare(left, right); |
1348 verifyCompare(left, right); |
1280 } |
1349 } |
1281 |
1350 |
|
1351 TEST_F(ArrayList, cxListCompareWithPtrArrayList) { |
|
1352 auto left = arrayListFromTestData(); |
|
1353 auto right = pointerArrayListFromTestData(); |
|
1354 verifyCompare(left, right); |
|
1355 } |
|
1356 |
|
1357 TEST_F(PointerArrayList, cxListCompare) { |
|
1358 auto left = pointerArrayListFromTestData(); |
|
1359 auto right = pointerArrayListFromTestData(); |
|
1360 verifyCompare(left, right); |
|
1361 } |
|
1362 |
|
1363 TEST_F(PointerArrayList, cxListCompareWithPtrList) { |
|
1364 auto left = pointerArrayListFromTestData(); |
|
1365 auto right = pointerLinkedListFromTestData(); |
|
1366 verifyCompare(left, right); |
|
1367 } |
|
1368 |
|
1369 TEST_F(PointerArrayList, cxListCompareWithNormalList) { |
|
1370 auto left = pointerArrayListFromTestData(); |
|
1371 auto right = linkedListFromTestData(); |
|
1372 verifyCompare(left, right); |
|
1373 } |
|
1374 |
|
1375 TEST_F(PointerArrayList, cxListCompareWithNormalArrayList) { |
|
1376 auto left = pointerArrayListFromTestData(); |
|
1377 auto right = arrayListFromTestData(); |
|
1378 verifyCompare(left, right); |
|
1379 } |
|
1380 |
1282 TEST_F(LinkedList, SimpleDestructor) { |
1381 TEST_F(LinkedList, SimpleDestructor) { |
1283 verifySimpleDestructor(linkedListFromTestData()); |
1382 verifySimpleDestructor(linkedListFromTestData()); |
1284 } |
1383 } |
1285 |
1384 |
1286 TEST_F(PointerLinkedList, SimpleDestructor) { |
1385 TEST_F(PointerLinkedList, SimpleDestructor) { |
1289 |
1388 |
1290 TEST_F(ArrayList, SimpleDestructor) { |
1389 TEST_F(ArrayList, SimpleDestructor) { |
1291 verifySimpleDestructor(arrayListFromTestData()); |
1390 verifySimpleDestructor(arrayListFromTestData()); |
1292 } |
1391 } |
1293 |
1392 |
|
1393 TEST_F(PointerArrayList, SimpleDestructor) { |
|
1394 verifySimpleDestructor(pointerArrayListFromTestData()); |
|
1395 } |
|
1396 |
1294 TEST_F(LinkedList, AdvancedDestructor) { |
1397 TEST_F(LinkedList, AdvancedDestructor) { |
1295 verifyAdvancedDestructor(linkedListFromTestData()); |
1398 verifyAdvancedDestructor(linkedListFromTestData()); |
1296 } |
1399 } |
1297 |
1400 |
1298 TEST_F(PointerLinkedList, AdvancedDestructor) { |
1401 TEST_F(PointerLinkedList, AdvancedDestructor) { |
1299 verifyAdvancedDestructor(pointerLinkedListFromTestData()); |
1402 verifyAdvancedDestructor(pointerLinkedListFromTestData()); |
1300 } |
1403 } |
1301 |
1404 |
1302 TEST_F(ArrayList, AdvancedDestructor) { |
1405 TEST_F(ArrayList, AdvancedDestructor) { |
1303 verifyAdvancedDestructor(arrayListFromTestData()); |
1406 verifyAdvancedDestructor(arrayListFromTestData()); |
|
1407 } |
|
1408 |
|
1409 TEST_F(PointerArrayList, AdvancedDestructor) { |
|
1410 verifyAdvancedDestructor(pointerArrayListFromTestData()); |
1304 } |
1411 } |
1305 |
1412 |
1306 TEST_F(PointerLinkedList, DestroyNoDestructor) { |
1413 TEST_F(PointerLinkedList, DestroyNoDestructor) { |
1307 void *item = cxMalloc(&testingAllocator, sizeof(int)); |
1414 void *item = cxMalloc(&testingAllocator, sizeof(int)); |
1308 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
1415 auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); |
1331 cxListAdd(list, item); |
1438 cxListAdd(list, item); |
1332 ASSERT_FALSE(testingAllocator.verify()); |
1439 ASSERT_FALSE(testingAllocator.verify()); |
1333 cxListDestroy(list); |
1440 cxListDestroy(list); |
1334 EXPECT_TRUE(testingAllocator.verify()); |
1441 EXPECT_TRUE(testingAllocator.verify()); |
1335 } |
1442 } |
|
1443 |
|
1444 TEST_F(PointerArrayList, DestroyNoDestructor) { |
|
1445 void *item = cxMalloc(&testingAllocator, sizeof(int)); |
|
1446 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
|
1447 cxListAdd(list, item); |
|
1448 ASSERT_FALSE(testingAllocator.verify()); |
|
1449 cxListDestroy(list); |
|
1450 EXPECT_FALSE(testingAllocator.verify()); |
|
1451 cxFree(&testingAllocator, item); |
|
1452 EXPECT_TRUE(testingAllocator.verify()); |
|
1453 } |
|
1454 |
|
1455 TEST_F(PointerArrayList, DestroySimpleDestructor) { |
|
1456 int item = 0; |
|
1457 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
|
1458 list->simple_destructor = [](void *elem) { *(int *) elem = 42; }; |
|
1459 cxListAdd(list, &item); |
|
1460 cxListDestroy(list); |
|
1461 EXPECT_EQ(item, 42); |
|
1462 } |
|
1463 |
|
1464 TEST_F(PointerArrayList, DestroyAdvancedDestructor) { |
|
1465 void *item = cxMalloc(&testingAllocator, sizeof(int)); |
|
1466 auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); |
|
1467 list->destructor_data = &testingAllocator; |
|
1468 list->advanced_destructor = (cx_destructor_func2) cxFree; |
|
1469 cxListAdd(list, item); |
|
1470 ASSERT_FALSE(testingAllocator.verify()); |
|
1471 cxListDestroy(list); |
|
1472 EXPECT_TRUE(testingAllocator.verify()); |
|
1473 } |
|
1474 |