aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorAmr Shahin <amrnablus@gmail.com>2011-01-19 00:39:47 +0200
committerDaniel Stenberg <daniel@haxx.se>2011-01-20 23:16:30 +0100
commit77f0fcae0e345c1a0cd069784e176881346e0001 (patch)
treea2f455b058590c5200e04e3f7971375223d7f85b /tests/unit
parent03be2c99ba7ce0b00988667061087e3bfc2cd62b (diff)
unittest: add 3 tests to test1300
Testing Curl_llist_insert_next
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unit1300.c80
1 files changed, 79 insertions, 1 deletions
diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c
index 093ef850a..3aa351a3a 100644
--- a/tests/unit/unit1300.c
+++ b/tests/unit/unit1300.c
@@ -28,10 +28,88 @@ static void unit_stop( void )
}
UNITTEST_START
+ int unusedData_case1 = 1;
+ int unusedData_case2 = 2;
+ int unusedData_case3 = 3;
+
+ int curlErrCode = 0;
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" );
- fail_unless( llist->dtor == test_curl_llist_dtor , "list dtor shold initiate to test_curl_llist_dtor" );
+ fail_unless( llist->dtor == test_curl_llist_dtor ,
+ "list dtor shold initiate to test_curl_llist_dtor" );
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 1:
+ * list is empty
+ * @assumptions:
+ * 1: list size will be 1
+ * 2: list head will hold the data "unusedData_case1"
+ * 3: list tail will be the same as list head
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
+ if( curlErrCode == 1 ) {
+ fail_unless( Curl_llist_count( llist ) == 1 ,
+ "List size should be 1 after adding a new element" );
+ /*test that the list head data holds my unusedData */
+ fail_unless( llist->head->ptr == &unusedData_case1 ,
+ "List size should be 1 after adding a new element" );
+ /*same goes for the list tail */
+ fail_unless( llist->tail == llist->head ,
+ "List size should be 1 after adding a new element" );
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 2:
+ * list has 1 element, adding one element after the head
+ * @assumptions:
+ * 1: the element next to head should be our newly created element
+ * 2: the list tail should be our newly created element
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head ,
+ &unusedData_case3 );
+ if( curlErrCode == 1 ) {
+ fail_unless(llist->head->next->ptr == &unusedData_case3 ,
+ "the node next to head is not getting set correctly" );
+ fail_unless(llist->tail->ptr == &unusedData_case3,
+ "the list tail is not getting set correctly");
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n" );
+ }
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 3:
+ * list has >1 element, adding one element after "NULL"
+ * @assumptions:
+ * 1: the element next to head should be our newly created element
+ * 2: the list tail should different from newly created element
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head,
+ &unusedData_case2);
+ if( curlErrCode == 1 ) {
+ fail_unless(llist->head->next->ptr == &unusedData_case2,
+ "the node next to head is not getting set correctly" );
+ //better safe than sorry, check that the tail isn't corrupted
+ fail_unless(llist->tail->ptr != &unusedData_case2,
+ "the list tail is not getting set correctly" );
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n" );
+ }
+
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n" );
+ }
UNITTEST_STOP