Tue, 28 Sep 2021 18:05:52 +0200
remove error handling from tests
390 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
29 | #include "cx/linked_list.h" |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
30 | #include "test_config.h" |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
31 | #include "util_allocator.h" |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
32 | |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
33 | int cmp_int(int const *l, int const *r) { |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
34 | int left = *l, right = *r; |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
35 | return left == right ? 0 : (left < right ? -1 : 1); |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
36 | } |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
37 | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
38 | void test_linked_list_create(void) { |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
39 | cxTestingAllocatorReset(); |
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
40 | |
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
41 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
42 | |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
43 | CU_ASSERT_EQUAL(list->size, 0) |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
44 | CU_ASSERT_EQUAL(list->capacity, (size_t) -1) |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
45 | CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
46 | CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
47 | CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
48 | |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
49 | // assume this structure for a linked list |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
50 | struct ll_check { |
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
51 | cx_list_s base; |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
52 | void *begin; |
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
53 | void *end; |
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
54 | ptrdiff_t ploc; |
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
55 | ptrdiff_t nloc; |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
56 | }; |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
57 | |
435
0fe204d50f54
change inheritance model for lists
Mike Becker <universe@uap-core.de>
parents:
422
diff
changeset
|
58 | struct ll_check *actual = (struct ll_check *) list; |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
59 | CU_ASSERT_PTR_NULL(actual->begin) |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
60 | CU_ASSERT_PTR_NULL(actual->end) |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
61 | CU_ASSERT_EQUAL(0, actual->ploc) |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
62 | CU_ASSERT_EQUAL(sizeof(void *), actual->nloc) |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
63 | |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
64 | cxLinkedListDestroy(list); |
413
0f4aa9fc75d9
perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents:
412
diff
changeset
|
65 | |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
66 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
67 | } |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
68 | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
69 | void test_linked_list_at(void) { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
70 | struct node { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
71 | void *next; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
72 | void *prev; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
73 | }; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
74 | const ptrdiff_t loc_prev = offsetof(struct node, prev); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
75 | const ptrdiff_t loc_next = offsetof(struct node, next); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
76 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
77 | struct node a, b, c, d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
78 | a.prev = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
79 | a.next = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
80 | b.prev = &a; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
81 | b.next = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
82 | c.prev = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
83 | c.next = &d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
84 | d.prev = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
85 | d.next = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
86 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
87 | CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&a, 0, loc_next, 0)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
88 | CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&a, 0, loc_next, 1)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
89 | CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&a, 0, loc_next, 2)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
90 | CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&a, 0, loc_next, 3)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
91 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
92 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
93 | CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&b, 1, loc_prev, 0)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
94 | CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&b, 1, loc_next, 1)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
95 | CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&b, 1, loc_next, 2)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
96 | CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&b, 1, loc_next, 3)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
97 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
98 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
99 | CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&d, 3, loc_prev, 0)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
100 | CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&d, 3, loc_prev, 1)); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
101 | } |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
102 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
103 | void test_cx_linked_list_add(void) { |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
104 | struct node { |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
105 | void *prev; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
106 | void *next; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
107 | int value; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
108 | }; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
109 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
110 | struct node nodes[4]; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
111 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
112 | // test with begin, end / prev, next |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
113 | memset(nodes, 0, 4*sizeof(struct node)); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
114 | void *begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
115 | void *end = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
116 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
117 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
118 | ptrdiff_t loc_next = offsetof(struct node, next); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
119 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
120 | int ret; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
121 | ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
122 | CU_ASSERT_EQUAL(ret, 0); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
123 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
124 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
125 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
126 | CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
127 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
128 | ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
129 | CU_ASSERT_EQUAL(ret, 0); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
130 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
131 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
132 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
133 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
134 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
135 | // test with begin only / prev, next |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
136 | memset(nodes, 0, 4*sizeof(struct node)); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
137 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
138 | end = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
139 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
140 | ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
141 | CU_ASSERT_EQUAL(ret, 0); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
142 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
143 | ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
144 | CU_ASSERT_EQUAL(ret, 0); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
145 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
146 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
147 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
148 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
149 | ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
150 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
151 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
152 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
153 | // test with begin, end / next |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
154 | memset(nodes, 0, 4*sizeof(struct node)); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
155 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
156 | end = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
157 | |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
158 | ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
159 | CU_ASSERT_EQUAL(ret, 0); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
160 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
161 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
162 | ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
163 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
164 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
165 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, NULL); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
166 | } |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
167 | |
390 | 168 | int main() { |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
169 | CU_pSuite suite = NULL; |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
170 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
171 | if (CUE_SUCCESS != CU_initialize_registry()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
172 | return CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
173 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
174 | |
413
0f4aa9fc75d9
perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents:
412
diff
changeset
|
175 | suite = CU_add_suite("linked list suite", NULL, NULL); |
443
d6d8712e15bc
remove error handling from tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
442
diff
changeset
|
176 | |
d6d8712e15bc
remove error handling from tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
442
diff
changeset
|
177 | CU_add_test(suite, "linked list: create and destroy", test_linked_list_create); |
d6d8712e15bc
remove error handling from tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
442
diff
changeset
|
178 | CU_add_test(suite, "linked list: get node at index", test_linked_list_at); |
d6d8712e15bc
remove error handling from tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
442
diff
changeset
|
179 | CU_add_test(suite, "linked list: add", test_cx_linked_list_add); |
413
0f4aa9fc75d9
perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents:
412
diff
changeset
|
180 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
181 | CU_basic_set_mode(UCX_CU_BRM); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
182 | |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
183 | int exitcode; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
184 | if (CU_basic_run_tests()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
185 | exitcode = CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
186 | } else { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
187 | exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
188 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
189 | CU_cleanup_registry(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
190 | return exitcode; |
390 | 191 | } |