test/test_list.cpp

changeset 630
ac5e7f789048
parent 629
6c81ee4f11ad
child 638
eafb45eefc51
equal deleted inserted replaced
629:6c81ee4f11ad 630:ac5e7f789048
684 cx_for_n (i, testdata_len) ASSERT_EQ(*(int *) cxListAt(list, i), expected[i]); 684 cx_for_n (i, testdata_len) ASSERT_EQ(*(int *) cxListAt(list, i), expected[i]);
685 } 685 }
686 686
687 void verifyIterator(CxList *list) const { 687 void verifyIterator(CxList *list) const {
688 int i = 0; 688 int i = 0;
689 CxIterator iter = cxListBegin(list); 689 auto iter = cxListBeginMut(list);
690 cx_foreach(int*, x, iter) { 690 cx_foreach(int*, x, iter) {
691 ASSERT_EQ(iter.index, (size_t) (i + 1) / 2); 691 ASSERT_EQ(iter.index, (size_t) (i + 1) / 2);
692 ASSERT_EQ(*x, testdata.data[i]); 692 ASSERT_EQ(*x, testdata.data[i]);
693 if (i % 2 == 1) iter.remove = true; 693 if (i % 2 == 1) cxIteratorFlagRemoval(iter);
694 i++; 694 i++;
695 } 695 }
696 auto len = testdata_len; 696 auto len = testdata_len;
697 EXPECT_EQ(i, len); 697 EXPECT_EQ(i, len);
698 ASSERT_EQ(list->size, len / 2); 698 ASSERT_EQ(list->size, len / 2);
700 } 700 }
701 701
702 static void verifyInsertViaIterator(CxList *list) { 702 static void verifyInsertViaIterator(CxList *list) {
703 int newdata[] = {10, 20, 30, 40, 50}; 703 int newdata[] = {10, 20, 30, 40, 50};
704 704
705 CxIterator iter = cxListIterator(list, 2); 705 auto iter = cxListMutIterator(list, 2);
706 EXPECT_TRUE(cxIteratorValid(&iter)); 706 EXPECT_TRUE(cxIteratorValid(iter));
707 EXPECT_EQ(iter.index, 2); 707 EXPECT_EQ(iter.index, 2);
708 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2); 708 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
709 cxListInsertAfter(&iter, &newdata[0]); 709 cxListInsertAfter(&iter, &newdata[0]);
710 EXPECT_TRUE(cxIteratorValid(&iter)); 710 EXPECT_TRUE(cxIteratorValid(iter));
711 EXPECT_EQ(iter.index, 2); 711 EXPECT_EQ(iter.index, 2);
712 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2); 712 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
713 cxListInsertBefore(&iter, &newdata[1]); 713 cxListInsertBefore(&iter, &newdata[1]);
714 EXPECT_TRUE(cxIteratorValid(&iter)); 714 EXPECT_TRUE(cxIteratorValid(iter));
715 EXPECT_EQ(iter.index, 3); 715 EXPECT_EQ(iter.index, 3);
716 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 2); 716 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2);
717 717
718 iter = cxListBegin(list); 718 iter = cxListBeginMut(list);
719 cxListInsertBefore(&iter, &newdata[2]); 719 cxListInsertBefore(&iter, &newdata[2]);
720 EXPECT_TRUE(cxIteratorValid(&iter)); 720 EXPECT_TRUE(cxIteratorValid(iter));
721 EXPECT_EQ(iter.index, 1); 721 EXPECT_EQ(iter.index, 1);
722 EXPECT_EQ(*(int *) cxIteratorCurrent(&iter), 0); 722 EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0);
723 iter = cxListIterator(list, list->size); 723 iter = cxListMutIterator(list, list->size);
724 cxListInsertBefore(&iter, &newdata[3]); 724 cxListInsertBefore(&iter, &newdata[3]);
725 EXPECT_FALSE(cxIteratorValid(&iter)); 725 EXPECT_FALSE(cxIteratorValid(iter));
726 EXPECT_EQ(iter.index, 9); 726 EXPECT_EQ(iter.index, 9);
727 iter = cxListIterator(list, list->size); 727 iter = cxListMutIterator(list, list->size);
728 cxListInsertAfter(&iter, &newdata[4]); 728 cxListInsertAfter(&iter, &newdata[4]);
729 EXPECT_FALSE(cxIteratorValid(&iter)); 729 EXPECT_FALSE(cxIteratorValid(iter));
730 EXPECT_EQ(iter.index, 10); 730 EXPECT_EQ(iter.index, 10);
731 731
732 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50}; 732 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
733 cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]); 733 cx_for_n (j, 10) EXPECT_EQ(*(int *) cxListAt(list, j), expdata[j]);
734 } 734 }

mercurial