tests/test_list.c

changeset 855
35bcb3216c0d
parent 854
fe0d69d72bcd
child 856
6bbbf219251d
equal deleted inserted replaced
854:fe0d69d72bcd 855:35bcb3216c0d
704 cx_testing_allocator_init(&talloc); 704 cx_testing_allocator_init(&talloc);
705 CxAllocator *alloc = &talloc.base; 705 CxAllocator *alloc = &talloc.base;
706 CX_TEST_DO { 706 CX_TEST_DO {
707 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); 707 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int));
708 CX_TEST_ASSERT(list != NULL); 708 CX_TEST_ASSERT(list != NULL);
709 CX_TEST_ASSERT(list->base.item_size == sizeof(int)); 709 CX_TEST_ASSERT(list->base.elem_size == sizeof(int));
710 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 710 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
711 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 711 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
712 CX_TEST_ASSERT(list->base.destructor_data == NULL); 712 CX_TEST_ASSERT(list->base.destructor_data == NULL);
713 CX_TEST_ASSERT(cxListSize(list) == 0); 713 CX_TEST_ASSERT(cxListSize(list) == 0);
714 CX_TEST_ASSERT(list->base.allocator == alloc); 714 CX_TEST_ASSERT(list->base.allocator == alloc);
722 722
723 CX_TEST(test_list_ll_create_simple) { 723 CX_TEST(test_list_ll_create_simple) {
724 CxList *list = cxLinkedListCreateSimple(sizeof(int)); 724 CxList *list = cxLinkedListCreateSimple(sizeof(int));
725 CX_TEST_DO { 725 CX_TEST_DO {
726 CX_TEST_ASSERT(list != NULL); 726 CX_TEST_ASSERT(list != NULL);
727 CX_TEST_ASSERT(list->base.item_size == sizeof(int)); 727 CX_TEST_ASSERT(list->base.elem_size == sizeof(int));
728 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 728 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
729 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 729 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
730 CX_TEST_ASSERT(list->base.destructor_data == NULL); 730 CX_TEST_ASSERT(list->base.destructor_data == NULL);
731 CX_TEST_ASSERT(cxListSize(list) == 0); 731 CX_TEST_ASSERT(cxListSize(list) == 0);
732 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator); 732 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator);
739 CX_TEST(test_list_ll_store_pointers) { 739 CX_TEST(test_list_ll_store_pointers) {
740 CxList *list = cxLinkedListCreateSimple(47); 740 CxList *list = cxLinkedListCreateSimple(47);
741 CX_TEST_DO { 741 CX_TEST_DO {
742 CX_TEST_ASSERT(!cxListIsStoringPointers(list)); 742 CX_TEST_ASSERT(!cxListIsStoringPointers(list));
743 cxListStorePointers(list); 743 cxListStorePointers(list);
744 CX_TEST_ASSERT(list->base.item_size == sizeof(void *)); 744 CX_TEST_ASSERT(list->base.elem_size == sizeof(void *));
745 CX_TEST_ASSERT(list->cl != NULL); 745 CX_TEST_ASSERT(list->cl != NULL);
746 CX_TEST_ASSERT(list->climpl != NULL); 746 CX_TEST_ASSERT(list->climpl != NULL);
747 CX_TEST_ASSERT(cxListIsStoringPointers(list)); 747 CX_TEST_ASSERT(cxListIsStoringPointers(list));
748 cxListStoreObjects(list); 748 cxListStoreObjects(list);
749 CX_TEST_ASSERT(list->cl != NULL); 749 CX_TEST_ASSERT(list->cl != NULL);
755 755
756 CX_TEST(test_list_ll_create_simple_for_pointers) { 756 CX_TEST(test_list_ll_create_simple_for_pointers) {
757 CxList *list = cxLinkedListCreateSimple(CX_STORE_POINTERS); 757 CxList *list = cxLinkedListCreateSimple(CX_STORE_POINTERS);
758 CX_TEST_DO { 758 CX_TEST_DO {
759 CX_TEST_ASSERT(list != NULL); 759 CX_TEST_ASSERT(list != NULL);
760 CX_TEST_ASSERT(list->base.item_size == sizeof(void*)); 760 CX_TEST_ASSERT(list->base.elem_size == sizeof(void*));
761 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 761 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
762 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 762 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
763 CX_TEST_ASSERT(list->base.destructor_data == NULL); 763 CX_TEST_ASSERT(list->base.destructor_data == NULL);
764 CX_TEST_ASSERT(cxListSize(list) == 0); 764 CX_TEST_ASSERT(cxListSize(list) == 0);
765 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator); 765 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator);
774 cx_testing_allocator_init(&talloc); 774 cx_testing_allocator_init(&talloc);
775 CxAllocator *alloc = &talloc.base; 775 CxAllocator *alloc = &talloc.base;
776 CX_TEST_DO { 776 CX_TEST_DO {
777 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); 777 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8);
778 CX_TEST_ASSERT(list != NULL); 778 CX_TEST_ASSERT(list != NULL);
779 CX_TEST_ASSERT(list->base.item_size == sizeof(int)); 779 CX_TEST_ASSERT(list->base.elem_size == sizeof(int));
780 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 780 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
781 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 781 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
782 CX_TEST_ASSERT(list->base.destructor_data == NULL); 782 CX_TEST_ASSERT(list->base.destructor_data == NULL);
783 CX_TEST_ASSERT(cxListSize(list) == 0); 783 CX_TEST_ASSERT(cxListSize(list) == 0);
784 CX_TEST_ASSERT(list->base.allocator == alloc); 784 CX_TEST_ASSERT(list->base.allocator == alloc);
792 792
793 CX_TEST(test_list_arl_create_simple) { 793 CX_TEST(test_list_arl_create_simple) {
794 CxList *list = cxArrayListCreateSimple(sizeof(int), 8); 794 CxList *list = cxArrayListCreateSimple(sizeof(int), 8);
795 CX_TEST_DO { 795 CX_TEST_DO {
796 CX_TEST_ASSERT(list != NULL); 796 CX_TEST_ASSERT(list != NULL);
797 CX_TEST_ASSERT(list->base.item_size == sizeof(int)); 797 CX_TEST_ASSERT(list->base.elem_size == sizeof(int));
798 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 798 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
799 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 799 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
800 CX_TEST_ASSERT(list->base.destructor_data == NULL); 800 CX_TEST_ASSERT(list->base.destructor_data == NULL);
801 CX_TEST_ASSERT(cxListSize(list) == 0); 801 CX_TEST_ASSERT(cxListSize(list) == 0);
802 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator); 802 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator);
808 808
809 CX_TEST(test_list_arl_create_simple_for_pointers) { 809 CX_TEST(test_list_arl_create_simple_for_pointers) {
810 CxList *list = cxArrayListCreateSimple(CX_STORE_POINTERS, 8); 810 CxList *list = cxArrayListCreateSimple(CX_STORE_POINTERS, 8);
811 CX_TEST_DO { 811 CX_TEST_DO {
812 CX_TEST_ASSERT(list != NULL); 812 CX_TEST_ASSERT(list != NULL);
813 CX_TEST_ASSERT(list->base.item_size == sizeof(void*)); 813 CX_TEST_ASSERT(list->base.elem_size == sizeof(void*));
814 CX_TEST_ASSERT(list->base.simple_destructor == NULL); 814 CX_TEST_ASSERT(list->base.simple_destructor == NULL);
815 CX_TEST_ASSERT(list->base.advanced_destructor == NULL); 815 CX_TEST_ASSERT(list->base.advanced_destructor == NULL);
816 CX_TEST_ASSERT(list->base.destructor_data == NULL); 816 CX_TEST_ASSERT(list->base.destructor_data == NULL);
817 CX_TEST_ASSERT(cxListSize(list) == 0); 817 CX_TEST_ASSERT(cxListSize(list) == 0);
818 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator); 818 CX_TEST_ASSERT(list->base.allocator == cxDefaultAllocator);
1205 roll_out_test_combos(iterator, { 1205 roll_out_test_combos(iterator, {
1206 const size_t len = 50; 1206 const size_t len = 50;
1207 int *testdata = int_test_data_added_to_list(list, isptrlist, len); 1207 int *testdata = int_test_data_added_to_list(list, isptrlist, len);
1208 1208
1209 CxIterator iter = cxListIterator(list); 1209 CxIterator iter = cxListIterator(list);
1210 CX_TEST_ASSERT(iter.elem_size == list->base.item_size); 1210 CX_TEST_ASSERT(iter.elem_size == list->base.elem_size);
1211 CX_TEST_ASSERT(iter.elem_count == list->base.size); 1211 CX_TEST_ASSERT(iter.elem_count == list->base.size);
1212 size_t i = 0; 1212 size_t i = 0;
1213 cx_foreach(int*, x, iter) { 1213 cx_foreach(int*, x, iter) {
1214 CX_TEST_ASSERT(i == iter.index); 1214 CX_TEST_ASSERT(i == iter.index);
1215 CX_TEST_ASSERT(*x == testdata[iter.index]); 1215 CX_TEST_ASSERT(*x == testdata[iter.index]);
1223 i--; 1223 i--;
1224 } 1224 }
1225 CX_TEST_ASSERT(i == 0); 1225 CX_TEST_ASSERT(i == 0);
1226 i = len / 2; 1226 i = len / 2;
1227 CxIterator mut_iter = cxListMutIteratorAt(list, i); 1227 CxIterator mut_iter = cxListMutIteratorAt(list, i);
1228 CX_TEST_ASSERT(mut_iter.elem_size == list->base.item_size); 1228 CX_TEST_ASSERT(mut_iter.elem_size == list->base.elem_size);
1229 CX_TEST_ASSERT(mut_iter.elem_count == list->base.size); 1229 CX_TEST_ASSERT(mut_iter.elem_count == list->base.size);
1230 size_t j = 0; 1230 size_t j = 0;
1231 cx_foreach(int*, x, mut_iter) { 1231 cx_foreach(int*, x, mut_iter) {
1232 CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2); 1232 CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2);
1233 CX_TEST_ASSERT(*x == testdata[i]); 1233 CX_TEST_ASSERT(*x == testdata[i]);

mercurial