test/test_list.cpp

changeset 518
74d0372f5c6f
parent 517
b3baaf9b7e3c
child 520
f937c6d11d1f
     1.1 --- a/test/test_list.cpp	Sat Apr 16 18:02:10 2022 +0200
     1.2 +++ b/test/test_list.cpp	Sat Apr 16 20:17:01 2022 +0200
     1.3 @@ -552,13 +552,11 @@
     1.4  class HighLevelTest : public ::testing::Test {
     1.5      mutable std::unordered_set<CxList *> lists;
     1.6  protected:
     1.7 -    void SetUp() override {
     1.8 -        cxTestingAllocatorReset();
     1.9 -    }
    1.10 +    CxTestingAllocator testingAllocator;
    1.11  
    1.12      void TearDown() override {
    1.13          for (auto &&l: lists) cxListDestroy(l);
    1.14 -        EXPECT_TRUE(cxTestingAllocatorVerify());
    1.15 +        EXPECT_TRUE(testingAllocator.verify());
    1.16      }
    1.17  
    1.18      static constexpr size_t testdata_len = 250;
    1.19 @@ -572,7 +570,7 @@
    1.20      auto linkedListFromTestData() const -> CxList * {
    1.21          return autofree(
    1.22                  cxLinkedListFromArray(
    1.23 -                        cxTestingAllocator,
    1.24 +                        &testingAllocator,
    1.25                          cmp_int,
    1.26                          sizeof(int),
    1.27                          testdata_len,
    1.28 @@ -582,15 +580,15 @@
    1.29      }
    1.30  
    1.31      auto pointerLinkedListFromTestData() const -> CxList * {
    1.32 -        auto list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
    1.33 +        auto list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
    1.34          cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]);
    1.35          return list;
    1.36      }
    1.37  
    1.38 -    static void verifyCreate(CxList *list) {
    1.39 +    void verifyCreate(CxList *list) const {
    1.40          EXPECT_EQ(list->size, 0);
    1.41          EXPECT_EQ(list->capacity, (size_t) -1);
    1.42 -        EXPECT_EQ(list->allocator, cxTestingAllocator);
    1.43 +        EXPECT_EQ(list->allocator, &testingAllocator);
    1.44          EXPECT_EQ(list->cmpfunc, cmp_int);
    1.45      }
    1.46  
    1.47 @@ -736,41 +734,41 @@
    1.48  };
    1.49  
    1.50  TEST_F(LinkedList, cxLinkedListCreate) {
    1.51 -    CxList *list = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
    1.52 +    CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
    1.53      EXPECT_EQ(list->itemsize, sizeof(int));
    1.54      verifyCreate(list);
    1.55  }
    1.56  
    1.57  TEST_F(PointerLinkedList, cxPointerLinkedListCreate) {
    1.58 -    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
    1.59 +    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
    1.60      EXPECT_EQ(list->itemsize, sizeof(void *));
    1.61      verifyCreate(list);
    1.62  }
    1.63  
    1.64  TEST_F(LinkedList, cxLinkedListFromArray) {
    1.65 -    CxList *expected = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
    1.66 +    CxList *expected = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
    1.67      cx_for_n (i, testdata_len) cxListAdd(expected, &testdata.data[i]);
    1.68 -    CxList *list = autofree(cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int),
    1.69 +    CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int),
    1.70                                                    testdata_len, testdata.data.data()));
    1.71      EXPECT_EQ(cxListCompare(list, expected), 0);
    1.72  }
    1.73  
    1.74  TEST_F(LinkedList, cxListAdd) {
    1.75 -    CxList *list = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
    1.76 +    CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
    1.77      verifyAdd(list, false);
    1.78  }
    1.79  
    1.80  TEST_F(PointerLinkedList, cxListAdd) {
    1.81 -    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
    1.82 +    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
    1.83      verifyAdd(list, true);
    1.84  }
    1.85  
    1.86  TEST_F(LinkedList, cxListInsert) {
    1.87 -    verifyInsert(autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int))));
    1.88 +    verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int))));
    1.89  }
    1.90  
    1.91  TEST_F(PointerLinkedList, cxListInsert) {
    1.92 -    verifyInsert(autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int)));
    1.93 +    verifyInsert(autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int)));
    1.94  }
    1.95  
    1.96  TEST_F(LinkedList, cxListRemove) {
    1.97 @@ -815,13 +813,13 @@
    1.98  
    1.99  TEST_F(LinkedList, InsertViaIterator) {
   1.100      int fivenums[] = {0, 1, 2, 3, 4, 5};
   1.101 -    CxList *list = autofree(cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 5, fivenums));
   1.102 +    CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int), 5, fivenums));
   1.103      verifyInsertViaIterator(list);
   1.104  }
   1.105  
   1.106  TEST_F(PointerLinkedList, InsertViaIterator) {
   1.107      int fivenums[] = {0, 1, 2, 3, 4, 5};
   1.108 -    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
   1.109 +    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
   1.110      cx_for_n (i, 5) cxListAdd(list, &fivenums[i]);
   1.111      verifyInsertViaIterator(list);
   1.112  }

mercurial