test/test_list.cpp

changeset 518
74d0372f5c6f
parent 517
b3baaf9b7e3c
child 520
f937c6d11d1f
--- a/test/test_list.cpp	Sat Apr 16 18:02:10 2022 +0200
+++ b/test/test_list.cpp	Sat Apr 16 20:17:01 2022 +0200
@@ -552,13 +552,11 @@
 class HighLevelTest : public ::testing::Test {
     mutable std::unordered_set<CxList *> lists;
 protected:
-    void SetUp() override {
-        cxTestingAllocatorReset();
-    }
+    CxTestingAllocator testingAllocator;
 
     void TearDown() override {
         for (auto &&l: lists) cxListDestroy(l);
-        EXPECT_TRUE(cxTestingAllocatorVerify());
+        EXPECT_TRUE(testingAllocator.verify());
     }
 
     static constexpr size_t testdata_len = 250;
@@ -572,7 +570,7 @@
     auto linkedListFromTestData() const -> CxList * {
         return autofree(
                 cxLinkedListFromArray(
-                        cxTestingAllocator,
+                        &testingAllocator,
                         cmp_int,
                         sizeof(int),
                         testdata_len,
@@ -582,15 +580,15 @@
     }
 
     auto pointerLinkedListFromTestData() const -> CxList * {
-        auto list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
+        auto list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
         cx_for_n(i, testdata_len) cxListAdd(list, &testdata.data[i]);
         return list;
     }
 
-    static void verifyCreate(CxList *list) {
+    void verifyCreate(CxList *list) const {
         EXPECT_EQ(list->size, 0);
         EXPECT_EQ(list->capacity, (size_t) -1);
-        EXPECT_EQ(list->allocator, cxTestingAllocator);
+        EXPECT_EQ(list->allocator, &testingAllocator);
         EXPECT_EQ(list->cmpfunc, cmp_int);
     }
 
@@ -736,41 +734,41 @@
 };
 
 TEST_F(LinkedList, cxLinkedListCreate) {
-    CxList *list = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
+    CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
     EXPECT_EQ(list->itemsize, sizeof(int));
     verifyCreate(list);
 }
 
 TEST_F(PointerLinkedList, cxPointerLinkedListCreate) {
-    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
+    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
     EXPECT_EQ(list->itemsize, sizeof(void *));
     verifyCreate(list);
 }
 
 TEST_F(LinkedList, cxLinkedListFromArray) {
-    CxList *expected = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
+    CxList *expected = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
     cx_for_n (i, testdata_len) cxListAdd(expected, &testdata.data[i]);
-    CxList *list = autofree(cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int),
+    CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int),
                                                   testdata_len, testdata.data.data()));
     EXPECT_EQ(cxListCompare(list, expected), 0);
 }
 
 TEST_F(LinkedList, cxListAdd) {
-    CxList *list = autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int)));
+    CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int)));
     verifyAdd(list, false);
 }
 
 TEST_F(PointerLinkedList, cxListAdd) {
-    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
+    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
     verifyAdd(list, true);
 }
 
 TEST_F(LinkedList, cxListInsert) {
-    verifyInsert(autofree(cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int))));
+    verifyInsert(autofree(cxLinkedListCreate(&testingAllocator, cmp_int, sizeof(int))));
 }
 
 TEST_F(PointerLinkedList, cxListInsert) {
-    verifyInsert(autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int)));
+    verifyInsert(autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int)));
 }
 
 TEST_F(LinkedList, cxListRemove) {
@@ -815,13 +813,13 @@
 
 TEST_F(LinkedList, InsertViaIterator) {
     int fivenums[] = {0, 1, 2, 3, 4, 5};
-    CxList *list = autofree(cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 5, fivenums));
+    CxList *list = autofree(cxLinkedListFromArray(&testingAllocator, cmp_int, sizeof(int), 5, fivenums));
     verifyInsertViaIterator(list);
 }
 
 TEST_F(PointerLinkedList, InsertViaIterator) {
     int fivenums[] = {0, 1, 2, 3, 4, 5};
-    CxList *list = autofree(cxPointerLinkedListCreate(cxTestingAllocator, cmp_int));
+    CxList *list = autofree(cxPointerLinkedListCreate(&testingAllocator, cmp_int));
     cx_for_n (i, 5) cxListAdd(list, &fivenums[i]);
     verifyInsertViaIterator(list);
 }

mercurial