Commit c9f16e67 authored by Amr Shahin's avatar Amr Shahin Committed by Daniel Stenberg
Browse files

unitteset: Curl_llist_move

adding unit test for Curl_llist_move, documenting unit-tested functions
in llist.c, changing unit-test to unittest, replacing assert calls with
abort_unless calls
parent f851f768
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@
/* this must be the last include file */
#include "memdebug.h"

/*
 * @unittest: 1300
 */
static void
llist_init(struct curl_llist *l, curl_llist_dtor dtor)
{
@@ -106,7 +109,8 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e,
/*
 * @unittest: 1300
 */
int Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
int
Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
                  void *user)
{
  if(e == NULL || list->size == 0)
@@ -153,6 +157,9 @@ Curl_llist_count(struct curl_llist *list)
  return list->size;
}

/*
 * @unittest: 1300
 */
int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
                    struct curl_llist *to_list,
                    struct curl_llist_element *to_e)
+73 −1
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@

static struct curl_llist *llist;

static struct curl_llist *llist_destination;

static void test_curl_llist_dtor(void *key, void *value)
{
  /* used by the llist API, does nothing here */
@@ -37,12 +39,17 @@ static CURLcode unit_setup(void)
  llist = Curl_llist_alloc(test_curl_llist_dtor);
  if(!llist)
    return CURLE_OUT_OF_MEMORY;
  llist_destination = Curl_llist_alloc(test_curl_llist_dtor);
  if(!llist_destination)
      return CURLE_OUT_OF_MEMORY;

  return CURLE_OK;
}

static void unit_stop(void)
{
  Curl_llist_destroy(llist, NULL);
  Curl_llist_destroy(llist_destination, NULL);
}

UNITTEST_START
@@ -56,6 +63,17 @@ UNITTEST_START
  size_t llist_size = Curl_llist_count(llist);
  int curlErrCode = 0;

  /**
   * testing llist_init
   * case 1:
   * list initiation
   * @assumptions:
   * 1: list size will be 0
   * 2: list head will be NULL
   * 3: list tail will be NULL
   * 4: list dtor will be NULL
  */

  fail_unless(llist->size == 0, "list initial size should be zero");
  fail_unless(llist->head == NULL, "list head should initiate to NULL");
  fail_unless(llist->tail == NULL, "list tail should intiate to NULL");
@@ -215,4 +233,58 @@ UNITTEST_START
  fail_unless(llist->tail == NULL,
              "llist tail is not NULL while the llist is empty");

  /* @testing Curl_llist_move(struct curl_llist *,
   * struct curl_llist_element *, struct curl_llist *,
   * struct curl_llist_element *);
  */

  /**
   * @case 1:
   * moving head from an llist containg one element to an empty llist
   * @assumptions:
   * 1: llist size will be 0
   * 2: llist_destination size will be 1
   * 3: llist head will be NULL
   * 4: llist_destination head == llist_destination tail != NULL
   */

  /*
  * @setup
  * add one element to the list
  */

  curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
  /* necessary assertions */

  abort_unless(curlErrCode == 1,
  "Curl_llist_insert_next returned an error, Can't move on with test");
  abort_unless(Curl_llist_count(llist) == 1,
  "Number of list elements is not as expected, Aborting");
  abort_unless(Curl_llist_count(llist_destination) == 0,
  "Number of list elements is not as expected, Aborting");

  /*actual testing code*/
  curlErrCode = Curl_llist_move(llist, llist->head, llist_destination, NULL);
  abort_unless(curlErrCode == 1,
  "Curl_llist_move returned an error, Can't move on with test");
  fail_unless(Curl_llist_count(llist) == 0,
      "moving element from llist didn't decrement the size");

  fail_unless(Curl_llist_count(llist_destination) == 1,
        "moving element to llist_destination didn't increment the size");

  fail_unless(llist->head == NULL,
      "llist head not set to null after moving the head");

  fail_unless(llist_destination->head != NULL,
        "llist_destination head set to null after moving an element");

  fail_unless(llist_destination->tail != NULL,
          "llist_destination tail set to null after moving an element");

  fail_unless(llist_destination->tail == llist_destination->tail,
            "llist_destination tail doesn't equal llist_destination head");



UNITTEST_STOP