2
#include "curl_config.h"
8
struct curl_llist *llist;
10
static void test_curl_llist_dtor(void *key, void *value)
12
/* used by the llist API, does nothing here */
17
static CURLcode unit_setup(void)
19
llist = Curl_llist_alloc(test_curl_llist_dtor);
21
return CURLE_OUT_OF_MEMORY;
25
static void unit_stop(void)
27
Curl_llist_destroy(llist, NULL);
31
int unusedData_case1 = 1;
32
int unusedData_case2 = 2;
33
int unusedData_case3 = 3;
34
struct curl_llist_element *head;
35
struct curl_llist_element *element_next;
36
struct curl_llist_element *element_prev;
37
struct curl_llist_element *to_remove;
38
size_t llist_size = Curl_llist_count(llist);
41
fail_unless(llist->size == 0, "list initial size should be zero");
42
fail_unless(llist->head == NULL, "list head should initiate to NULL");
43
fail_unless(llist->tail == NULL, "list tail should intiate to NULL");
44
fail_unless(llist->dtor == test_curl_llist_dtor,
45
"list dtor shold initiate to test_curl_llist_dtor");
48
* testing Curl_llist_insert_next
52
* 1: list size will be 1
53
* 2: list head will hold the data "unusedData_case1"
54
* 3: list tail will be the same as list head
57
curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
58
if(curlErrCode == 1) {
59
fail_unless(Curl_llist_count(llist) == 1,
60
"List size should be 1 after adding a new element");
61
/*test that the list head data holds my unusedData */
62
fail_unless(llist->head->ptr == &unusedData_case1,
63
"List size should be 1 after adding a new element");
64
/*same goes for the list tail */
65
fail_unless(llist->tail == llist->head,
66
"List size should be 1 after adding a new element");
69
* testing Curl_llist_insert_next
71
* list has 1 element, adding one element after the head
73
* 1: the element next to head should be our newly created element
74
* 2: the list tail should be our newly created element
77
curlErrCode = Curl_llist_insert_next(llist, llist->head,
79
if(curlErrCode == 1) {
80
fail_unless(llist->head->next->ptr == &unusedData_case3,
81
"the node next to head is not getting set correctly");
82
fail_unless(llist->tail->ptr == &unusedData_case3,
83
"the list tail is not getting set correctly");
86
printf("skipping Curl_llist_insert_next as a non "
87
"success error code was returned\n");
91
* testing Curl_llist_insert_next
93
* list has >1 element, adding one element after "NULL"
95
* 1: the element next to head should be our newly created element
96
* 2: the list tail should different from newly created element
99
curlErrCode = Curl_llist_insert_next(llist, llist->head,
101
if(curlErrCode == 1) {
102
fail_unless(llist->head->next->ptr == &unusedData_case2,
103
"the node next to head is not getting set correctly");
104
/* better safe than sorry, check that the tail isn't corrupted */
105
fail_unless(llist->tail->ptr != &unusedData_case2,
106
"the list tail is not getting set correctly");
109
printf("skipping Curl_llist_insert_next as a non "
110
"success error code was returned\n");
115
printf("skipping Curl_llist_insert_next as a non "
116
"success error code was returned\n");
119
/* unit tests for Curl_llist_remove */
123
* list has >1 element, removing head
125
* 1: list size will be decremented by one
126
* 2: head will be the head->next
127
* 3: "new" head's previous will be NULL
131
element_next = head->next;
132
llist_size = Curl_llist_count(llist);
134
Curl_llist_remove(llist, llist->head, NULL);
136
fail_unless(Curl_llist_count(llist) == (llist_size-1),
137
"llist size not decremented as expected");
138
fail_unless(llist->head == element_next,
139
"llist new head not modified properly");
140
fail_unless(llist->head->prev == NULL,
141
"new head previous not set to null");
145
* removing non head element, with list having >=2 elements
147
* 1: insert another element to the list to make element >=2
149
* 1: list size will be decremented by one ; tested
150
* 2: element->previous->next will be element->next
151
* 3: element->next->previous will be element->previous
153
Curl_llist_insert_next(llist, llist->head, &unusedData_case3);
154
llist_size = Curl_llist_count(llist);
155
to_remove = llist->head->next;
156
element_next = to_remove->next;
157
element_prev = to_remove->prev;
158
Curl_llist_remove(llist, to_remove, NULL);
159
fail_unless(element_prev->next == element_next,
160
"element previous->next is not being adjusted");
161
fail_unless(element_next->prev == element_prev,
162
"element next->previous is not being adjusted");
166
* removing the tail with list having >=1 element
168
* 1: list size will be decremented by one ;tested
169
* 2: element->previous->next will be element->next ;tested
170
* 3: element->next->previous will be element->previous ;tested
171
* 4: list->tail will be tail->previous
174
to_remove = llist->tail;
175
element_prev = to_remove->prev;
176
Curl_llist_remove(llist, to_remove, NULL);
177
fail_unless(llist->tail == element_prev,
178
"llist tail is not being adjusted when removing tail");
182
* removing head with list having 1 element
184
* 1: list size will be decremented by one ;tested
185
* 2: list head will be null
186
* 3: list tail will be null
189
to_remove = llist->head;
190
Curl_llist_remove(llist, to_remove, NULL);
191
fail_unless(llist->head == NULL,
192
"llist head is not NULL while the llist is empty");
193
fail_unless(llist->tail == NULL,
194
"llist tail is not NULL while the llist is empty");