unit1300.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "curlcheck.h"
23 
24 #include "llist.h"
25 
26 static struct curl_llist llist;
27 
29 
30 static void test_curl_llist_dtor(void *key, void *value)
31 {
32  /* used by the llist API, does nothing here */
33  (void)key;
34  (void)value;
35 }
36 
37 static CURLcode unit_setup(void)
38 {
41  return CURLE_OK;
42 }
43 
44 static void unit_stop(void)
45 {
46  Curl_llist_destroy(&llist, NULL);
48 }
49 
51 {
52  int unusedData_case1 = 1;
65 
77  fail_unless(llist.size == 0, "list initial size should be zero");
78  fail_unless(llist.head == NULL, "list head should initiate to NULL");
79  fail_unless(llist.tail == NULL, "list tail should intiate to NULL");
81  "list dtor shold initiate to test_curl_llist_dtor");
82 
93  Curl_llist_insert_next(&llist, llist.head, &unusedData_case1, &case1_list);
94 
96  "List size should be 1 after adding a new element");
97  /*test that the list head data holds my unusedData */
98  fail_unless(llist.head->ptr == &unusedData_case1,
99  "head ptr should be first entry");
100  /*same goes for the list tail */
102  "tail and head should be the same");
103 
114  &unusedData_case3, &case3_list);
115  fail_unless(llist.head->next->ptr == &unusedData_case3,
116  "the node next to head is not getting set correctly");
117  fail_unless(llist.tail->ptr == &unusedData_case3,
118  "the list tail is not getting set correctly");
119 
130  &unusedData_case2, &case2_list);
131  fail_unless(llist.head->next->ptr == &unusedData_case2,
132  "the node next to head is not getting set correctly");
133  /* better safe than sorry, check that the tail isn't corrupted */
134  fail_unless(llist.tail->ptr != &unusedData_case2,
135  "the list tail is not getting set correctly");
136 
137  /* unit tests for Curl_llist_remove */
138 
148  head = llist.head;
149  abort_unless(head, "llist.head is NULL");
150  element_next = head->next;
151  llist_size = Curl_llist_count(&llist);
152 
154 
155  fail_unless(Curl_llist_count(&llist) == (llist_size-1),
156  "llist size not decremented as expected");
157  fail_unless(llist.head == element_next,
158  "llist new head not modified properly");
159  abort_unless(llist.head, "llist.head is NULL");
160  fail_unless(llist.head->prev == NULL,
161  "new head previous not set to null");
162 
173  Curl_llist_insert_next(&llist, llist.head, &unusedData_case3,
174  &case4_list);
175  llist_size = Curl_llist_count(&llist);
176  fail_unless(llist_size == 3, "should be 3 list members");
177 
178  to_remove = llist.head->next;
179  abort_unless(to_remove, "to_remove is NULL");
180  element_next = to_remove->next;
181  element_prev = to_remove->prev;
182  Curl_llist_remove(&llist, to_remove, NULL);
183  fail_unless(element_prev->next == element_next,
184  "element previous->next is not being adjusted");
185  abort_unless(element_next, "element_next is NULL");
186  fail_unless(element_next->prev == element_prev,
187  "element next->previous is not being adjusted");
188 
199  to_remove = llist.tail;
200  element_prev = to_remove->prev;
201  Curl_llist_remove(&llist, to_remove, NULL);
202  fail_unless(llist.tail == element_prev,
203  "llist tail is not being adjusted when removing tail");
204 
214  to_remove = llist.head;
215  Curl_llist_remove(&llist, to_remove, NULL);
216  fail_unless(llist.head == NULL,
217  "llist head is not NULL while the llist is empty");
218  fail_unless(llist.tail == NULL,
219  "llist tail is not NULL while the llist is empty");
220 
221  /* @testing Curl_llist_move(struct curl_llist *,
222  * struct curl_llist_element *, struct curl_llist *,
223  * struct curl_llist_element *);
224  */
225 
236  /*
237  * @setup
238  * add one element to the list
239  */
240 
241  Curl_llist_insert_next(&llist, llist.head, &unusedData_case1,
242  &case5_list);
243  /* necessary assertions */
244 
246  "Number of list elements is not as expected, Aborting");
248  "Number of list elements is not as expected, Aborting");
249 
250  /*actual testing code*/
253  "moving element from llist didn't decrement the size");
254 
256  "moving element to llist_destination didn't increment the size");
257 
258  fail_unless(llist.head == NULL,
259  "llist head not set to null after moving the head");
260 
262  "llist_destination head set to null after moving an element");
263 
265  "llist_destination tail set to null after moving an element");
266 
268  "llist_destination tail doesn't equal llist_destination head");
269 }
struct curl_llist_element case2_list
Definition: unit1300.c:56
struct curl_llist_element case4_list
Definition: unit1300.c:58
static CURLcode unit_setup(void)
Definition: unit1300.c:37
fail_unless(llist.size==0,"list initial size should be zero")
testing llist_init case 1: list initiation : 1: list size will be 0 2: list head will be NULL 3: list...
struct curl_llist_element * tail
Definition: llist.h:38
CURLcode
Definition: curl.h:454
struct curl_llist_element case5_list
Definition: unit1300.c:59
size_t llist_size
Definition: unit1300.c:64
void Curl_llist_init(struct curl_llist *l, curl_llist_dtor dtor)
Definition: llist.c:37
void Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e, struct curl_llist *to_list, struct curl_llist_element *to_e)
Definition: llist.c:147
curl_llist_dtor dtor
Definition: llist.h:39
int unusedData_case2
Definition: unit1300.c:53
struct curl_llist_element * element_prev
Definition: unit1300.c:62
size_t size
Definition: llist.h:40
size_t Curl_llist_count(struct curl_llist *list)
Definition: llist.c:139
void * ptr
Definition: llist.h:31
static void test_curl_llist_dtor(void *key, void *value)
Definition: unit1300.c:30
static struct curl_llist llist_destination
Definition: unit1300.c:28
static void unit_stop(void)
Definition: unit1300.c:44
struct curl_llist_element * to_remove
case 3: removing the tail with list having >=1 element 1: list size will be decremented by one ;test...
Definition: unit1300.c:63
Definition: curl.h:455
struct curl_llist_element * head
Definition: llist.h:37
#define UNITTEST_STOP
Definition: curlcheck.h:95
struct curl_llist_element * element_next
Definition: unit1300.c:61
void Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, void *user)
Definition: llist.c:93
struct curl_llist_element case3_list
Definition: unit1300.c:57
void Curl_llist_destroy(struct curl_llist *list, void *user)
Definition: llist.c:130
static struct curl_llist llist
testing Curl_llist_insert_next case 1: list is empty : 1: list size will be 1 2: list head will hold ...
Definition: unit1300.c:26
UNITTEST_START
Definition: unit1300.c:51
UNITTEST_START int * value
Definition: unit1602.c:51
struct curl_llist_element case1_list
Definition: unit1300.c:55
void Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, const void *p, struct curl_llist_element *ne)
Definition: llist.c:57
struct curl_llist_element * prev
Definition: llist.h:32
abort_unless(head,"llist.head is NULL")
int unusedData_case3
Definition: unit1300.c:54
int key
Definition: unit1602.c:56
struct curl_llist_element * next
Definition: llist.h:33
struct curl_llist_element * head
case 1: list has >1 element, removing head : 1: list size will be decremented by one 2: head will be ...
Definition: unit1300.c:60


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16