diff options
author | Amr Shahin <amrnablus@gmail.com> | 2011-06-19 03:27:22 +0300 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-06-19 22:22:49 +0200 |
commit | c9f16e67eff98c8c6a3e6ff32927af8c002ac2d8 (patch) | |
tree | bd8fab4287ee6436826a31100d9649a4c54f775b | |
parent | f851f768578dc096c561d57ba07ffd1004d504c0 (diff) |
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
-rw-r--r-- | lib/llist.c | 11 | ||||
-rw-r--r-- | tests/unit/unit1300.c | 74 |
2 files changed, 82 insertions, 3 deletions
diff --git a/lib/llist.c b/lib/llist.c index 9478a708d..8b4bc7f20 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -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,8 +109,9 @@ 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, - 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; } +/* + * @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) diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c index 792bfa1e6..199cf2c9e 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_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 |