|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "curlcheck.h" |
|
|
|
|
|
#include "llist.h" |
|
|
|
|
|
static struct Curl_llist llist; |
|
|
|
|
|
static struct Curl_llist llist_destination; |
|
|
|
|
|
static void test_Curl_llist_dtor(void *key, void *value) |
|
|
{ |
|
|
|
|
|
(void)key; |
|
|
(void)value; |
|
|
} |
|
|
|
|
|
static CURLcode unit_setup(void) |
|
|
{ |
|
|
Curl_llist_init(&llist, test_Curl_llist_dtor); |
|
|
Curl_llist_init(&llist_destination, test_Curl_llist_dtor); |
|
|
return CURLE_OK; |
|
|
} |
|
|
|
|
|
static void unit_stop(void) |
|
|
{ |
|
|
} |
|
|
|
|
|
UNITTEST_START |
|
|
{ |
|
|
int unusedData_case1 = 1; |
|
|
int unusedData_case2 = 2; |
|
|
int unusedData_case3 = 3; |
|
|
struct Curl_llist_node case1_list; |
|
|
struct Curl_llist_node case2_list; |
|
|
struct Curl_llist_node case3_list; |
|
|
struct Curl_llist_node case4_list; |
|
|
struct Curl_llist_node *head; |
|
|
struct Curl_llist_node *element_next; |
|
|
struct Curl_llist_node *element_prev; |
|
|
struct Curl_llist_node *to_remove; |
|
|
size_t llist_size = Curl_llist_count(&llist); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fail_unless(Curl_llist_count(&llist) == 0, |
|
|
"list initial size should be zero"); |
|
|
fail_unless(Curl_llist_head(&llist) == NULL, |
|
|
"list head should initiate to NULL"); |
|
|
fail_unless(Curl_llist_tail(&llist) == NULL, |
|
|
"list tail should initiate to NULL"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case1, |
|
|
&case1_list); |
|
|
|
|
|
fail_unless(Curl_llist_count(&llist) == 1, |
|
|
"List size should be 1 after adding a new element"); |
|
|
|
|
|
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1, |
|
|
"head ptr should be first entry"); |
|
|
|
|
|
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist), |
|
|
"tail and head should be the same"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), |
|
|
&unusedData_case3, &case3_list); |
|
|
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == |
|
|
&unusedData_case3, |
|
|
"the node next to head is not getting set correctly"); |
|
|
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3, |
|
|
"the list tail is not getting set correctly"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), |
|
|
&unusedData_case2, &case2_list); |
|
|
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == |
|
|
&unusedData_case2, |
|
|
"the node next to head is not getting set correctly"); |
|
|
|
|
|
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) != &unusedData_case2, |
|
|
"the list tail is not getting set correctly"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head = Curl_llist_head(&llist); |
|
|
abort_unless(head, "llist.head is NULL"); |
|
|
element_next = Curl_node_next(head); |
|
|
llist_size = Curl_llist_count(&llist); |
|
|
|
|
|
Curl_node_remove(Curl_llist_head(&llist)); |
|
|
|
|
|
fail_unless(Curl_llist_count(&llist) == (llist_size-1), |
|
|
"llist size not decremented as expected"); |
|
|
fail_unless(Curl_llist_head(&llist) == element_next, |
|
|
"llist new head not modified properly"); |
|
|
abort_unless(Curl_llist_head(&llist), "llist.head is NULL"); |
|
|
fail_unless(Curl_node_prev(Curl_llist_head(&llist)) == NULL, |
|
|
"new head previous not set to null"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case3, |
|
|
&case4_list); |
|
|
llist_size = Curl_llist_count(&llist); |
|
|
fail_unless(llist_size == 3, "should be 3 list members"); |
|
|
|
|
|
to_remove = Curl_node_next(Curl_llist_head(&llist)); |
|
|
abort_unless(to_remove, "to_remove is NULL"); |
|
|
element_next = Curl_node_next(to_remove); |
|
|
element_prev = Curl_node_prev(to_remove); |
|
|
Curl_node_uremove(to_remove, NULL); |
|
|
fail_unless(Curl_node_next(element_prev) == element_next, |
|
|
"element previous->next is not being adjusted"); |
|
|
abort_unless(element_next, "element_next is NULL"); |
|
|
fail_unless(Curl_node_prev(element_next) == element_prev, |
|
|
"element next->previous is not being adjusted"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
to_remove = Curl_llist_tail(&llist); |
|
|
element_prev = Curl_node_prev(to_remove); |
|
|
Curl_node_remove(to_remove); |
|
|
fail_unless(Curl_llist_tail(&llist) == element_prev, |
|
|
"llist tail is not being adjusted when removing tail"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
to_remove = Curl_llist_head(&llist); |
|
|
Curl_node_remove(to_remove); |
|
|
fail_unless(Curl_llist_head(&llist) == NULL, |
|
|
"llist head is not NULL while the llist is empty"); |
|
|
fail_unless(Curl_llist_tail(&llist) == NULL, |
|
|
"llist tail is not NULL while the llist is empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_append(&llist, &unusedData_case1, &case1_list); |
|
|
fail_unless(Curl_llist_count(&llist) == 1, |
|
|
"List size should be 1 after appending a new element"); |
|
|
|
|
|
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1, |
|
|
"head ptr should be first entry"); |
|
|
|
|
|
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist), |
|
|
"tail and head should be the same"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_append(&llist, &unusedData_case2, &case2_list); |
|
|
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == |
|
|
&unusedData_case2, |
|
|
"the node next to head is not getting set correctly"); |
|
|
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case2, |
|
|
"the list tail is not getting set correctly"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Curl_llist_append(&llist, &unusedData_case3, &case3_list); |
|
|
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) == |
|
|
&unusedData_case2, |
|
|
"the node next to head did not stay the same"); |
|
|
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3, |
|
|
"the list tail is not getting set correctly"); |
|
|
|
|
|
Curl_llist_destroy(&llist, NULL); |
|
|
Curl_llist_destroy(&llist_destination, NULL); |
|
|
} |
|
|
UNITTEST_STOP |
|
|
|