tests/test_list.c

changeset 800
1274e46b3013
parent 799
a2a757d225b4
child 801
04aa3913c0e3
equal deleted inserted replaced
799:a2a757d225b4 800:1274e46b3013
553 } 553 }
554 destroy_nodes_test_data(begin); 554 destroy_nodes_test_data(begin);
555 destroy_nodes_test_data(expected); 555 destroy_nodes_test_data(expected);
556 } 556 }
557 557
558
559 CX_TEST(test_empty_list_size) {
560 CX_TEST_DO {
561 CX_TEST_ASSERT(cxEmptyList->size == 0);
562 CX_TEST_ASSERT(cxListSize(cxEmptyList) == 0);
563 }
564 }
565
566 CX_TEST(test_empty_list_iterator) {
567 CxList *list = cxEmptyList;
568
569 CxIterator it1 = cxListIterator(list);
570 CxIterator it2 = cxListBackwardsIterator(list);
571 CxMutIterator it3 = cxListMutIterator(list);
572 CxMutIterator it4 = cxListMutBackwardsIterator(list);
573
574 CX_TEST_DO {
575 CX_TEST_ASSERT(!cxIteratorValid(it1));
576 CX_TEST_ASSERT(!cxIteratorValid(it2));
577 CX_TEST_ASSERT(!cxIteratorValid(it3));
578 CX_TEST_ASSERT(!cxIteratorValid(it4));
579
580 int c = 0;
581 cx_foreach(void*, data, it1) c++;
582 cx_foreach(void*, data, it2) c++;
583 cx_foreach(void*, data, it3) c++;
584 cx_foreach(void*, data, it4) c++;
585 CX_TEST_ASSERT(c == 0);
586 }
587 }
588
589 CX_TEST(test_empty_list_noops) {
590 CX_TEST_DO {
591 CxList copy = *cxEmptyList;
592 cxListSort(cxEmptyList);
593 cxListClear(cxEmptyList);
594 cxListDestroy(cxEmptyList);
595 CX_TEST_ASSERT(0 == memcmp(&copy, cxEmptyList, sizeof(CxList))); // NOLINT(*-suspicious-memory-comparison)
596 }
597 }
598
599 CX_TEST(test_empty_list_at) {
600 CX_TEST_DO {
601 CX_TEST_ASSERT(cxListAt(cxEmptyList, 0) == NULL);
602 CX_TEST_ASSERT(cxListAt(cxEmptyList, 1) == NULL);
603 }
604 }
605
606 CX_TEST(test_empty_list_find) {
607 int x = 42, y = 1337;
608 CX_TEST_DO {
609 CX_TEST_ASSERT(cxListFind(cxEmptyList, &x) < 0);
610 CX_TEST_ASSERT(cxListFind(cxEmptyList, &y) < 0);
611 }
612 }
613
614 CX_TEST(test_empty_list_compare) {
615 CxList *empty = cxEmptyList;
616 CxList *ll = cxLinkedListCreateSimple(sizeof(int));
617 CxList *al = cxArrayListCreateSimple(sizeof(int), 8);
618 int x = 5;
619 CX_TEST_DO {
620 CX_TEST_ASSERT(0 == cxListCompare(empty, cxEmptyList));
621 CX_TEST_ASSERT(0 == cxListCompare(ll, cxEmptyList));
622 CX_TEST_ASSERT(0 == cxListCompare(al, cxEmptyList));
623 CX_TEST_ASSERT(0 == cxListCompare(cxEmptyList, ll));
624 CX_TEST_ASSERT(0 == cxListCompare(cxEmptyList, al));
625
626 cxListAdd(ll, &x);
627 cxListAdd(al, &x);
628
629 CX_TEST_ASSERT(0 < cxListCompare(ll, cxEmptyList));
630 CX_TEST_ASSERT(0 < cxListCompare(al, cxEmptyList));
631 CX_TEST_ASSERT(0 > cxListCompare(cxEmptyList, ll));
632 CX_TEST_ASSERT(0 > cxListCompare(cxEmptyList, al));
633 }
634 cxListDestroy(ll);
635 cxListDestroy(al);
636 }
637
558 CxTestSuite *cx_test_suite_array_list(void) { 638 CxTestSuite *cx_test_suite_array_list(void) {
559 CxTestSuite *suite = cx_test_suite_new("array_list"); 639 CxTestSuite *suite = cx_test_suite_new("array_list");
560 640
561 return suite; 641 return suite;
562 } 642 }
582 cx_test_register(suite, test_linked_list_reverse); 662 cx_test_register(suite, test_linked_list_reverse);
583 663
584 return suite; 664 return suite;
585 } 665 }
586 666
667 CxTestSuite *cx_test_suite_empty_list(void) {
668 CxTestSuite *suite = cx_test_suite_new("empty list dummy");
669
670 cx_test_register(suite, test_empty_list_size);
671 cx_test_register(suite, test_empty_list_iterator);
672 cx_test_register(suite, test_empty_list_noops);
673 cx_test_register(suite, test_empty_list_at);
674 cx_test_register(suite, test_empty_list_find);
675 cx_test_register(suite, test_empty_list_compare);
676
677 return suite;
678 }

mercurial