Hello Curlers, this is a patch that contains a unit test for Curl_llist_move function.
It also adds the @unit-test: <unit-test-id> to the .c file to mention that this function is unit-tested. *-Amr*
From 7b5a149840a14257e6c12508e8fbbd370be867b0 Mon Sep 17 00:00:00 2001 From: Amr Shahin <[email protected]> Date: Sun, 12 Jun 2011 14:04:31 +0300 Subject: [PATCH] adding unit test for Curl_llist_move and documenting unit-tested functions in llist.c --- lib/llist.c | 13 +++++++-- tests/unit/unit1300.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/lib/llist.c b/lib/llist.c index 9478a70..0d270de 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -31,6 +31,9 @@ /* this must be the last include file */ #include "memdebug.h" +/* + * @unit-test: 1300 + */ static void llist_init(struct curl_llist *l, curl_llist_dtor dtor) { @@ -104,10 +107,11 @@ Curl_llist_insert_next(struct curl_llist *list, struct curl_llist_element *e, } /* - * @unittest: 1300 + * @unit-test: 1300 */ -int Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, - void *user) +int +Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e, + void *user) { if(e == NULL || list->size == 0) return 1; @@ -153,6 +157,9 @@ Curl_llist_count(struct curl_llist *list) return list->size; } +/* + * @unit-test: 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) diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c index 792bfa1..95fa1e2 100644 --- a/tests/unit/unit1300.c +++ b/tests/unit/unit1300.c @@ -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 */ @@ -35,14 +37,19 @@ static void test_curl_llist_dtor(void *key, void *value) static CURLcode unit_setup(void) { llist = Curl_llist_alloc(test_curl_llist_dtor); - if (!llist) + if(!llist) return CURLE_OUT_OF_MEMORY; + llist_destination = Curl_llist_alloc(test_curl_llist_dtor); + if(!llist) + 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,54 @@ 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 */ + + assert(curlErrCode == 1); + assert(Curl_llist_count(llist) == 1); + assert(Curl_llist_count(llist_destination) == 0); + + /*actual testing code*/ + curlErrCode = Curl_llist_move(llist, llist->head, llist_destination, NULL); + assert(curlErrCode == 1); + 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 -- 1.7.5.2
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
