unit1300.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #include "llist.h"
00025 
00026 static struct curl_llist *llist;
00027 
00028 static struct curl_llist *llist_destination;
00029 
00030 static void test_curl_llist_dtor(void *key, void *value)
00031 {
00032   /* used by the llist API, does nothing here */
00033   (void)key;
00034   (void)value;
00035 }
00036 
00037 static CURLcode unit_setup(void)
00038 {
00039   llist = Curl_llist_alloc(test_curl_llist_dtor);
00040   if(!llist)
00041     return CURLE_OUT_OF_MEMORY;
00042   llist_destination = Curl_llist_alloc(test_curl_llist_dtor);
00043   if(!llist_destination) {
00044     Curl_llist_destroy(llist, NULL);
00045     return CURLE_OUT_OF_MEMORY;
00046   }
00047 
00048   return CURLE_OK;
00049 }
00050 
00051 static void unit_stop(void)
00052 {
00053   Curl_llist_destroy(llist, NULL);
00054   Curl_llist_destroy(llist_destination, NULL);
00055 }
00056 
00057 UNITTEST_START
00058   int unusedData_case1 = 1;
00059   int unusedData_case2 = 2;
00060   int unusedData_case3 = 3;
00061   struct curl_llist_element *head;
00062   struct curl_llist_element *element_next;
00063   struct curl_llist_element *element_prev;
00064   struct curl_llist_element *to_remove;
00065   size_t llist_size = Curl_llist_count(llist);
00066   int curlErrCode = 0;
00067 
00079   fail_unless(llist->size == 0, "list initial size should be zero");
00080   fail_unless(llist->head == NULL, "list head should initiate to NULL");
00081   fail_unless(llist->tail == NULL, "list tail should intiate to NULL");
00082   fail_unless(llist->dtor == test_curl_llist_dtor,
00083                "list dtor shold initiate to test_curl_llist_dtor");
00084 
00095   curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
00096   if(curlErrCode == 1) {
00097     fail_unless(Curl_llist_count(llist) == 1,
00098                  "List size should be 1 after adding a new element");
00099     /*test that the list head data holds my unusedData */
00100     fail_unless(llist->head->ptr == &unusedData_case1,
00101                  "List size should be 1 after adding a new element");
00102     /*same goes for the list tail */
00103     fail_unless(llist->tail == llist->head,
00104                  "List size should be 1 after adding a new element");
00105 
00115     curlErrCode = Curl_llist_insert_next(llist, llist->head,
00116                                          &unusedData_case3);
00117     if(curlErrCode == 1) {
00118       fail_unless(llist->head->next->ptr == &unusedData_case3,
00119                   "the node next to head is not getting set correctly");
00120       fail_unless(llist->tail->ptr == &unusedData_case3,
00121                   "the list tail is not getting set correctly");
00122     }
00123     else {
00124       printf("skipping Curl_llist_insert_next as a non "
00125              "success error code was returned\n");
00126     }
00127 
00137     curlErrCode = Curl_llist_insert_next(llist, llist->head,
00138                                          &unusedData_case2);
00139     if(curlErrCode == 1) {
00140       fail_unless(llist->head->next->ptr == &unusedData_case2,
00141                   "the node next to head is not getting set correctly");
00142       /* better safe than sorry, check that the tail isn't corrupted */
00143       fail_unless(llist->tail->ptr != &unusedData_case2,
00144                   "the list tail is not getting set correctly");
00145     }
00146     else {
00147       printf("skipping Curl_llist_insert_next as a non "
00148              "success error code was returned\n");
00149     }
00150 
00151   }
00152   else {
00153     printf("skipping Curl_llist_insert_next as a non "
00154            "success error code was returned\n");
00155   }
00156 
00157   /* unit tests for Curl_llist_remove */
00158 
00168   head=llist->head;
00169   abort_unless(head, "llist->head is NULL");
00170   element_next = head->next;
00171   llist_size = Curl_llist_count(llist);
00172 
00173   Curl_llist_remove(llist, llist->head, NULL);
00174 
00175   fail_unless(Curl_llist_count(llist) ==  (llist_size-1),
00176                "llist size not decremented as expected");
00177   fail_unless(llist->head == element_next,
00178                "llist new head not modified properly");
00179   abort_unless(llist->head, "llist->head is NULL");
00180   fail_unless(llist->head->prev == NULL,
00181               "new head previous not set to null");
00182 
00193   Curl_llist_insert_next(llist, llist->head, &unusedData_case3);
00194   llist_size = Curl_llist_count(llist);
00195   to_remove = llist->head->next;
00196   abort_unless(to_remove, "to_remove is NULL");
00197   element_next = to_remove->next;
00198   element_prev = to_remove->prev;
00199   Curl_llist_remove(llist, to_remove, NULL);
00200   fail_unless(element_prev->next == element_next,
00201               "element previous->next is not being adjusted");
00202   abort_unless(element_next, "element_next is NULL");
00203   fail_unless(element_next->prev == element_prev,
00204               "element next->previous is not being adjusted");
00205 
00216   to_remove = llist->tail;
00217   element_prev = to_remove->prev;
00218   Curl_llist_remove(llist, to_remove, NULL);
00219   fail_unless(llist->tail == element_prev,
00220               "llist tail is not being adjusted when removing tail");
00221 
00231   to_remove = llist->head;
00232   Curl_llist_remove(llist, to_remove, NULL);
00233   fail_unless(llist->head == NULL,
00234               "llist head is not NULL while the llist is empty");
00235   fail_unless(llist->tail == NULL,
00236               "llist tail is not NULL while the llist is empty");
00237 
00238   /* @testing Curl_llist_move(struct curl_llist *,
00239    * struct curl_llist_element *, struct curl_llist *,
00240    * struct curl_llist_element *);
00241   */
00242 
00253   /*
00254   * @setup
00255   * add one element to the list
00256   */
00257 
00258   curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
00259   /* necessary assertions */
00260 
00261   abort_unless(curlErrCode == 1,
00262   "Curl_llist_insert_next returned an error, Can't move on with test");
00263   abort_unless(Curl_llist_count(llist) == 1,
00264   "Number of list elements is not as expected, Aborting");
00265   abort_unless(Curl_llist_count(llist_destination) == 0,
00266   "Number of list elements is not as expected, Aborting");
00267 
00268   /*actual testing code*/
00269   curlErrCode = Curl_llist_move(llist, llist->head, llist_destination, NULL);
00270   abort_unless(curlErrCode == 1,
00271   "Curl_llist_move returned an error, Can't move on with test");
00272   fail_unless(Curl_llist_count(llist) == 0,
00273       "moving element from llist didn't decrement the size");
00274 
00275   fail_unless(Curl_llist_count(llist_destination) == 1,
00276         "moving element to llist_destination didn't increment the size");
00277 
00278   fail_unless(llist->head == NULL,
00279       "llist head not set to null after moving the head");
00280 
00281   fail_unless(llist_destination->head != NULL,
00282         "llist_destination head set to null after moving an element");
00283 
00284   fail_unless(llist_destination->tail != NULL,
00285           "llist_destination tail set to null after moving an element");
00286 
00287   fail_unless(llist_destination->tail == llist_destination->tail,
00288             "llist_destination tail doesn't equal llist_destination head");
00289 
00290 
00291 
00292 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07