| 489 CX_TEST_DO { |
489 CX_TEST_DO { |
| 490 size_t i = 10; |
490 size_t i = 10; |
| 491 int s; |
491 int s; |
| 492 s = 2; |
492 s = 2; |
| 493 node *n = list; |
493 node *n = list; |
| 494 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == n); |
494 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == n); |
| 495 CX_TEST_ASSERT(i == 0); |
495 CX_TEST_ASSERT(i == 0); |
| 496 n = n->next; |
496 n = n->next; |
| 497 s = 4; |
497 s = 4; |
| 498 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == n); |
498 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == n); |
| 499 CX_TEST_ASSERT(i == 1); |
499 CX_TEST_ASSERT(i == 1); |
| 500 n = n->next; |
500 n = n->next; |
| 501 s = 6; |
501 s = 6; |
| 502 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == n); |
502 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == n); |
| 503 CX_TEST_ASSERT(i == 2); |
503 CX_TEST_ASSERT(i == 2); |
| 504 n = n->next; |
504 n = n->next; |
| 505 s = 8; |
505 s = 8; |
| 506 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == n); |
506 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == n); |
| 507 CX_TEST_ASSERT(i == 3); |
507 CX_TEST_ASSERT(i == 3); |
| 508 s = 10; |
508 s = 10; |
| 509 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == NULL); |
509 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == NULL); |
| 510 s = -2; |
510 s = -2; |
| 511 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, cx_cmp_int, &s, &i) == NULL); |
511 CX_TEST_ASSERT(cx_linked_list_find(list, loc_next, loc_data, &s, &i, cx_cmp_int) == NULL); |
| 512 } |
512 } |
| 513 destroy_nodes_test_data(list); |
513 destroy_nodes_test_data(list); |
| 514 } |
514 } |
| 515 |
515 |
| 516 CX_TEST(test_linked_list_compare) { |
516 CX_TEST(test_linked_list_compare) { |
| 1286 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1286 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1287 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1287 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1288 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1288 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1289 CX_TEST_ASSERT(cxListSize(list) == 0); |
1289 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1290 CX_TEST_ASSERT(list->collection.allocator == alloc); |
1290 CX_TEST_ASSERT(list->collection.allocator == alloc); |
| 1291 CX_TEST_ASSERT(list->collection.cmpfunc == cx_cmp_int); |
1291 CX_TEST_ASSERT(list->collection.simple_cmp == cx_cmp_int); |
| |
1292 CX_TEST_ASSERT(list->collection.advanced_cmp == NULL); |
| 1292 CX_TEST_ASSERT(!list->collection.store_pointer); |
1293 CX_TEST_ASSERT(!list->collection.store_pointer); |
| 1293 cxListFree(list); |
1294 cxListFree(list); |
| 1294 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1295 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 1295 } |
1296 } |
| 1296 cx_testing_allocator_destroy(&talloc); |
1297 cx_testing_allocator_destroy(&talloc); |
| 1304 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1305 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1305 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1306 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1306 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1307 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1307 CX_TEST_ASSERT(cxListSize(list) == 0); |
1308 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1308 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
1309 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
| 1309 CX_TEST_ASSERT(list->collection.cmpfunc == NULL); |
1310 CX_TEST_ASSERT(list->collection.simple_cmp == NULL); |
| |
1311 CX_TEST_ASSERT(list->collection.advanced_cmp == cx_acmp_memcmp); |
| |
1312 CX_TEST_ASSERT(list->collection.cmp_data == &list->collection.elem_size); |
| 1310 CX_TEST_ASSERT(!list->collection.store_pointer); |
1313 CX_TEST_ASSERT(!list->collection.store_pointer); |
| 1311 } |
1314 } |
| 1312 cxListFree(list); |
1315 cxListFree(list); |
| 1313 } |
1316 } |
| 1314 |
1317 |
| 1320 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1323 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1321 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1324 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1322 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1325 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1323 CX_TEST_ASSERT(cxListSize(list) == 0); |
1326 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1324 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
1327 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
| 1325 CX_TEST_ASSERT(list->collection.cmpfunc == cx_cmp_ptr); |
1328 CX_TEST_ASSERT(list->collection.simple_cmp == cx_cmp_ptr); |
| |
1329 CX_TEST_ASSERT(list->collection.advanced_cmp == NULL); |
| 1326 CX_TEST_ASSERT(list->collection.store_pointer); |
1330 CX_TEST_ASSERT(list->collection.store_pointer); |
| 1327 } |
1331 } |
| 1328 cxListFree(list); |
1332 cxListFree(list); |
| 1329 } |
1333 } |
| 1330 |
1334 |
| 1340 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1344 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1341 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1345 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1342 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1346 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1343 CX_TEST_ASSERT(cxListSize(list) == 0); |
1347 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1344 CX_TEST_ASSERT(list->collection.allocator == alloc); |
1348 CX_TEST_ASSERT(list->collection.allocator == alloc); |
| 1345 CX_TEST_ASSERT(list->collection.cmpfunc == cx_cmp_int); |
1349 CX_TEST_ASSERT(list->collection.simple_cmp == cx_cmp_int); |
| |
1350 CX_TEST_ASSERT(list->collection.advanced_cmp == NULL); |
| 1346 CX_TEST_ASSERT(!list->collection.store_pointer); |
1351 CX_TEST_ASSERT(!list->collection.store_pointer); |
| 1347 cxListFree(list); |
1352 cxListFree(list); |
| 1348 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1353 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 1349 } |
1354 } |
| 1350 cx_testing_allocator_destroy(&talloc); |
1355 cx_testing_allocator_destroy(&talloc); |
| 1358 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1363 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1359 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1364 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1360 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1365 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1361 CX_TEST_ASSERT(cxListSize(list) == 0); |
1366 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1362 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
1367 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
| 1363 CX_TEST_ASSERT(list->collection.cmpfunc == NULL); |
1368 CX_TEST_ASSERT(list->collection.simple_cmp == NULL); |
| |
1369 CX_TEST_ASSERT(list->collection.advanced_cmp == cx_acmp_memcmp); |
| |
1370 CX_TEST_ASSERT(list->collection.cmp_data == &list->collection.elem_size); |
| 1364 CX_TEST_ASSERT(!list->collection.store_pointer); |
1371 CX_TEST_ASSERT(!list->collection.store_pointer); |
| 1365 } |
1372 } |
| 1366 cxListFree(list); |
1373 cxListFree(list); |
| 1367 } |
1374 } |
| 1368 |
1375 |
| 1374 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
1381 CX_TEST_ASSERT(list->collection.simple_destructor == NULL); |
| 1375 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
1382 CX_TEST_ASSERT(list->collection.advanced_destructor == NULL); |
| 1376 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
1383 CX_TEST_ASSERT(list->collection.destructor_data == NULL); |
| 1377 CX_TEST_ASSERT(cxListSize(list) == 0); |
1384 CX_TEST_ASSERT(cxListSize(list) == 0); |
| 1378 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
1385 CX_TEST_ASSERT(list->collection.allocator == cxDefaultAllocator); |
| 1379 CX_TEST_ASSERT(list->collection.cmpfunc == cx_cmp_ptr); |
1386 CX_TEST_ASSERT(list->collection.simple_cmp == cx_cmp_ptr); |
| |
1387 CX_TEST_ASSERT(list->collection.advanced_cmp == NULL); |
| 1380 CX_TEST_ASSERT(list->collection.store_pointer); |
1388 CX_TEST_ASSERT(list->collection.store_pointer); |
| 1381 } |
1389 } |
| 1382 cxListFree(list); |
1390 cxListFree(list); |
| 1383 } |
1391 } |
| 1384 |
1392 |
| 1541 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
1549 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ |
| 1542 cx_attr_unused bool isptrlist) body \ |
1550 cx_attr_unused bool isptrlist) body \ |
| 1543 roll_out_test_invokers(name) |
1551 roll_out_test_invokers(name) |
| 1544 |
1552 |
| 1545 static void set_default_class_funcs(CxList *list, cx_list_class *defaulted_cl) { |
1553 static void set_default_class_funcs(CxList *list, cx_list_class *defaulted_cl) { |
| 1546 const cx_list_class *cl = list->climpl == NULL ? list->cl : list->climpl; |
1554 memcpy(defaulted_cl, list->cl, sizeof(cx_list_class)); |
| 1547 memcpy(defaulted_cl, cl, sizeof(cx_list_class)); |
|
| 1548 defaulted_cl->insert_array = cx_list_default_insert_array; |
1555 defaulted_cl->insert_array = cx_list_default_insert_array; |
| 1549 defaulted_cl->insert_unique = cx_list_default_insert_unique; |
1556 defaulted_cl->insert_unique = cx_list_default_insert_unique; |
| 1550 defaulted_cl->insert_sorted = cx_list_default_insert_sorted; |
1557 defaulted_cl->insert_sorted = cx_list_default_insert_sorted; |
| 1551 defaulted_cl->sort = cx_list_default_sort; |
1558 defaulted_cl->sort = cx_list_default_sort; |
| 1552 defaulted_cl->swap = cx_list_default_swap; |
1559 defaulted_cl->swap = cx_list_default_swap; |
| 1553 defaulted_cl->compare = NULL; |
1560 defaulted_cl->compare = NULL; |
| 1554 if (list->climpl == NULL) { |
1561 list->cl = defaulted_cl; |
| 1555 list->cl = defaulted_cl; |
|
| 1556 } else { |
|
| 1557 list->climpl = defaulted_cl; |
|
| 1558 } |
|
| 1559 } |
1562 } |
| 1560 |
1563 |
| 1561 #define do_set_default_class_funcs(list) \ |
1564 #define do_set_default_class_funcs(list) \ |
| 1562 cx_list_class defaulted_cl; \ |
1565 cx_list_class defaulted_cl; \ |
| 1563 set_default_class_funcs(list, &defaulted_cl) |
1566 set_default_class_funcs(list, &defaulted_cl) |