aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmr Shahin <amrnablus@gmail.com>2011-01-29 17:33:02 +0200
committerDaniel Stenberg <daniel@haxx.se>2011-02-02 13:24:04 +0100
commit7a4b5079c69d8ea807aa74c383f86196b68d6443 (patch)
tree929825a7f17da262cf534552cc555228f375196b
parent7a53c77cb52ec72a9d1b8bd440c06755136fa08f (diff)
adding unit tests for Curl_llist_remove
-rw-r--r--tests/unit/unit1300.c84
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c
index a835392b1..355b1afac 100644
--- a/tests/unit/unit1300.c
+++ b/tests/unit/unit1300.c
@@ -31,7 +31,11 @@ UNITTEST_START
int unusedData_case1 = 1;
int unusedData_case2 = 2;
int unusedData_case3 = 3;
-
+ struct curl_llist_element *head;
+ struct curl_llist_element *element_next;
+ struct curl_llist_element *element_prev;
+ struct curl_llist_element *to_remove;
+ size_t llist_size = Curl_llist_count( llist );
int curlErrCode = 0;
fail_unless( llist->size == 0 , "list initial size should be zero" );
@@ -112,4 +116,82 @@ UNITTEST_START
"success error code was returned\n" );
}
+ /* unit tests for Curl_llist_remove */
+
+ /**
+ * case 1:
+ * list has >1 element, removing head
+ * @assumptions:
+ * 1: list size will be decremented by one
+ * 2: head will be the head->next
+ * 3: "new" head's previous will be NULL
+ */
+
+ head=llist->head;
+ element_next = head->next;
+ llist_size = Curl_llist_count( llist );
+
+ Curl_llist_remove( llist , llist->head , NULL );
+
+ fail_unless( Curl_llist_count(llist) == (llist_size-1) ,
+ "llist size not decremented as expected" );
+ fail_unless( llist->head == element_next ,
+ "llist new head not modified properly" );
+ fail_unless( llist->head->prev == NULL ,
+ "new head previous not set to null" );
+
+ /**
+ * case 2:
+ * removing non head element, with list having >=2 elements
+ * @setup:
+ * 1: insert another element to the list to make element >=2
+ * @assumptions:
+ * 1: list size will be decremented by one ; tested
+ * 2: element->previous->next will be element->next
+ * 3: element->next->previous will be element->previous
+ */
+ Curl_llist_insert_next(llist, llist->head , &unusedData_case3 );
+ llist_size = Curl_llist_count( llist );
+ to_remove = llist->head->next;
+ element_next = to_remove->next;
+ element_prev = to_remove->prev;
+ Curl_llist_remove( llist , to_remove , NULL );
+ fail_unless( element_prev->next == element_next ,
+ "element previous->next is not being adjusted" );
+ fail_unless( element_next->prev == element_prev ,
+ "element next->previous is not being adjusted" );
+
+ /**
+ * case 3:
+ * removing the tail with list having >=1 element
+ * @assumptions
+ * 1: list size will be decremented by one ;tested
+ * 2: element->previous->next will be element->next ;tested
+ * 3: element->next->previous will be element->previous ;tested
+ * 4: list->tail will be tail->previous
+ */
+
+ to_remove = llist->tail;
+ element_prev = to_remove->prev;
+ Curl_llist_remove( llist , to_remove , NULL );
+ fail_unless( llist->tail == element_prev ,
+ "llist tail is not being adjusted when removing tail" );
+ fail_unless( 1==0 , "making sure i'm compiling" );
+
+ /**
+ * case 4:
+ * removing head with list having 1 element
+ * @assumptions:
+ * 1: list size will be decremented by one ;tested
+ * 2: list head will be null
+ * 3: list tail will be null
+ */
+
+ to_remove = llist->head;
+ Curl_llist_remove( llist , to_remove , NULL );
+ fail_unless( llist->head == NULL ,
+ "llist head is not NULL while the llist is empty" );
+ fail_unless( llist->tail == NULL ,
+ "llist tail is not NULL while the llist is empty" );
+
UNITTEST_STOP