test/test_list.c

changeset 422
afd87df80b13
parent 413
0f4aa9fc75d9
child 435
0fe204d50f54
--- a/test/test_list.c	Sun Sep 26 14:34:49 2021 +0200
+++ b/test/test_list.c	Sun Sep 26 14:41:16 2021 +0200
@@ -28,6 +28,7 @@
 
 #include "cx/linked_list.h"
 #include "test_config.h"
+#include "util_allocator.h"
 
 int cmp_int(int const *l, int const *r) {
     int left = *l, right = *r;
@@ -35,27 +36,32 @@
 }
 
 void test_linked_list_create() {
-    CxList list = cxLinkedListCreate(cxDefaultAllocator, (CxListComparator) cmp_int, sizeof(int));
+    cxTestingAllocatorReset();
+
+    CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
 
     CU_ASSERT_EQUAL(list->data.size, 0)
     CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1)
-    CU_ASSERT_PTR_EQUAL(list->data.allocator, cxDefaultAllocator)
+    CU_ASSERT_PTR_EQUAL(list->data.allocator, cxTestingAllocator)
     CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int))
     CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int)
 
     struct node {
-        void* begin; void* end; ptrdiff_t ploc; ptrdiff_t nloc;
+        void *begin;
+        void *end;
+        ptrdiff_t ploc;
+        ptrdiff_t nloc;
     };
 
-    struct node* actual = (struct node*) list->data.listdata;
+    struct node *actual = (struct node *) list->data.listdata;
     CU_ASSERT_PTR_NULL(actual->begin)
     CU_ASSERT_PTR_NULL(actual->end)
     CU_ASSERT_EQUAL(0, actual->ploc)
-    CU_ASSERT_EQUAL(sizeof(void*), actual->nloc)
+    CU_ASSERT_EQUAL(sizeof(void *), actual->nloc)
 
     cxLinkedListDestroy(list);
 
-    // TODO: use allocator that keeps track of the freed memory
+    CU_ASSERT_TRUE(cxTestingAllocatorVerify())
 }
 
 int main() {

mercurial