test/test_list.c

changeset 422
afd87df80b13
parent 413
0f4aa9fc75d9
child 435
0fe204d50f54
equal deleted inserted replaced
421:aa465fac4ef6 422:afd87df80b13
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "cx/linked_list.h" 29 #include "cx/linked_list.h"
30 #include "test_config.h" 30 #include "test_config.h"
31 #include "util_allocator.h"
31 32
32 int cmp_int(int const *l, int const *r) { 33 int cmp_int(int const *l, int const *r) {
33 int left = *l, right = *r; 34 int left = *l, right = *r;
34 return left == right ? 0 : (left < right ? -1 : 1); 35 return left == right ? 0 : (left < right ? -1 : 1);
35 } 36 }
36 37
37 void test_linked_list_create() { 38 void test_linked_list_create() {
38 CxList list = cxLinkedListCreate(cxDefaultAllocator, (CxListComparator) cmp_int, sizeof(int)); 39 cxTestingAllocatorReset();
40
41 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
39 42
40 CU_ASSERT_EQUAL(list->data.size, 0) 43 CU_ASSERT_EQUAL(list->data.size, 0)
41 CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1) 44 CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1)
42 CU_ASSERT_PTR_EQUAL(list->data.allocator, cxDefaultAllocator) 45 CU_ASSERT_PTR_EQUAL(list->data.allocator, cxTestingAllocator)
43 CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int)) 46 CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int))
44 CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int) 47 CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int)
45 48
46 struct node { 49 struct node {
47 void* begin; void* end; ptrdiff_t ploc; ptrdiff_t nloc; 50 void *begin;
51 void *end;
52 ptrdiff_t ploc;
53 ptrdiff_t nloc;
48 }; 54 };
49 55
50 struct node* actual = (struct node*) list->data.listdata; 56 struct node *actual = (struct node *) list->data.listdata;
51 CU_ASSERT_PTR_NULL(actual->begin) 57 CU_ASSERT_PTR_NULL(actual->begin)
52 CU_ASSERT_PTR_NULL(actual->end) 58 CU_ASSERT_PTR_NULL(actual->end)
53 CU_ASSERT_EQUAL(0, actual->ploc) 59 CU_ASSERT_EQUAL(0, actual->ploc)
54 CU_ASSERT_EQUAL(sizeof(void*), actual->nloc) 60 CU_ASSERT_EQUAL(sizeof(void *), actual->nloc)
55 61
56 cxLinkedListDestroy(list); 62 cxLinkedListDestroy(list);
57 63
58 // TODO: use allocator that keeps track of the freed memory 64 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
59 } 65 }
60 66
61 int main() { 67 int main() {
62 CU_pSuite suite = NULL; 68 CU_pSuite suite = NULL;
63 69

mercurial