tests/test_list.c

changeset 799
a2a757d225b4
parent 798
7644da6e2d35
child 800
1274e46b3013
equal deleted inserted replaced
798:7644da6e2d35 799:a2a757d225b4
490 destroy_nodes_test_data(td13); 490 destroy_nodes_test_data(td13);
491 } 491 }
492 492
493 CX_TEST(test_linked_list_sort_empty) { 493 CX_TEST(test_linked_list_sort_empty) {
494 void *begin = NULL; 494 void *begin = NULL;
495 // cannot assert something, we can just test that it does not crash 495 CX_TEST_DO {
496 cx_linked_list_sort(&begin, NULL, loc_prev, loc_next, loc_data, cx_cmp_int); 496 // cannot assert something, we can just test that it does not crash
497 cx_linked_list_sort(&begin, NULL, loc_prev, loc_next, loc_data, cx_cmp_int);
498 CX_TEST_ASSERT(true);
499 }
497 } 500 }
498 501
499 CX_TEST(test_linked_list_sort) { 502 CX_TEST(test_linked_list_sort) {
500 const size_t len = 1500; 503 const size_t len = 1500;
501 int *testdata = int_test_data(len); 504 int *testdata = int_test_data(len);
526 check = check->next; 529 check = check->next;
527 } 530 }
528 CX_TEST_ASSERT(check == NULL); 531 CX_TEST_ASSERT(check == NULL);
529 CX_TEST_ASSERT(end == check_last); 532 CX_TEST_ASSERT(end == check_last);
530 } 533 }
531 free(scrambled); 534 destroy_nodes_test_data(begin);
535 free(sorted);
532 free(testdata); 536 free(testdata);
533 } 537 }
534 538
535 CX_TEST(test_linked_list_reverse) { 539 CX_TEST(test_linked_list_reverse) {
536 void *testdata = create_nodes_test_data(4); 540 void *testdata = create_nodes_test_data(4);
537 void *expected = create_nodes_test_data(4); 541 void *expected = create_nodes_test_data(4);
538 assign_nodes_test_data(testdata, 2, 4, 6, 8); 542 assign_nodes_test_data(testdata, 2, 4, 6, 8);
539 assign_nodes_test_data(expected, 8, 6, 4, 2); 543 assign_nodes_test_data(expected, 8, 6, 4, 2);
540 CX_TEST_DO { 544 void *begin = testdata;
541 void *begin = testdata; 545 CX_TEST_DO {
542 void *end = cx_linked_list_last(begin, loc_next); 546 void *end = cx_linked_list_last(begin, loc_next);
543 void *orig_begin = begin, *orig_end = end; 547 void *orig_begin = begin, *orig_end = end;
544 548
545 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next); 549 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
546 CX_TEST_ASSERT(end == orig_begin); 550 CX_TEST_ASSERT(end == orig_begin);
547 CX_TEST_ASSERT(begin == orig_end); 551 CX_TEST_ASSERT(begin == orig_end);
548 CX_TEST_ASSERT(0 == cx_linked_list_compare(begin, expected, loc_next, loc_data, cx_cmp_int)); 552 CX_TEST_ASSERT(0 == cx_linked_list_compare(begin, expected, loc_next, loc_data, cx_cmp_int));
549 } 553 }
550 destroy_nodes_test_data(testdata); 554 destroy_nodes_test_data(begin);
551 destroy_nodes_test_data(expected); 555 destroy_nodes_test_data(expected);
552 } 556 }
553 557
554 CxTestSuite *cx_test_suite_array_list(void) { 558 CxTestSuite *cx_test_suite_array_list(void) {
555 CxTestSuite *suite = cx_test_suite_new("array_list"); 559 CxTestSuite *suite = cx_test_suite_new("array_list");

mercurial