]> granicus.if.org Git - check/commitdiff
Added tests for list_add_front.
authorhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Mon, 31 Oct 2005 12:25:59 +0000 (12:25 +0000)
committerhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Mon, 31 Oct 2005 12:25:59 +0000 (12:25 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@255 64e312b2-a51f-0410-8e61-82d0ca0eb02a

check/tests/check_list.c

index 378627d2950023a4ff0ebb9808a3cbc504646f5a..6ad71f4911ecb2d1bc745d7296a9fe96dd5e21c9 100644 (file)
@@ -49,19 +49,22 @@ START_TEST(test_add_end)
               "List should be at end after new insertion");
   fail_unless (strcmp(tval, (char *) list_val (lp)) == 0,
               "List current val should equal newly inserted val");
+  list_free (lp);
 }
 END_TEST
 
-START_TEST(test_add_a_bunch)
+START_TEST(test_add_front)
 {
-  List *lp;
-  int i, j;
-  for (i = 0; i < 3; i++) {
-    lp = check_list_create();
-    for (j = 0; j < 1000; j++)
-      list_add_end (lp, "abc");
-    list_free(lp);
-  }
+  List * lp = check_list_create();
+  const char * tval = "abc";
+  
+  list_add_front (lp, tval);
+  
+  fail_unless (list_val (lp) != NULL,
+              "List current val should not be null after new insertion");
+  fail_unless (strcmp(tval, (char *) list_val (lp)) == 0,
+              "List current val should equal newly inserted val");
+  list_free (lp);
 }
 END_TEST
 
@@ -89,6 +92,44 @@ START_TEST(test_add_end_and_next)
 END_TEST
 
 
+START_TEST(test_add_front_and_next)
+{
+  List * lp = check_list_create();
+  const char *tval1 = "abc";
+  const char *tval2 = "123";
+  
+  list_add_front (lp, tval1);
+  list_add_front (lp, tval2);
+  list_front(lp);
+  fail_unless (strcmp (tval2, list_val (lp)) == 0,
+              "List head val should equal last inserted val");
+  list_advance (lp);
+  fail_unless (!list_at_end (lp),
+              "List should not be at end after two adds and one next");
+  fail_unless (strcmp (tval1, list_val (lp)) == 0,
+              "List val should equal first inserted val");
+  list_advance(lp);
+  fail_unless (list_at_end (lp),
+              "List should be at and after two adds and two nexts");
+  list_free (lp);
+}
+END_TEST
+
+START_TEST(test_add_a_bunch)
+{
+  List *lp;
+  int i, j;
+  for (i = 0; i < 3; i++) {
+    lp = check_list_create();
+    for (j = 0; j < 1000; j++) {
+      list_add_end (lp, "abc");
+      list_add_front (lp, "123");
+    }
+    list_free(lp);
+  }
+}
+END_TEST
+
 
 Suite *make_list_suite (void)
 {
@@ -97,9 +138,11 @@ Suite *make_list_suite (void)
 
   suite_add_tcase (s, tc);
   tcase_add_test (tc, test_create);
+  tcase_add_test (tc, test_free);
   tcase_add_test (tc, test_add_end);
+  tcase_add_test (tc, test_add_front);
   tcase_add_test (tc, test_add_end_and_next);
+  tcase_add_test (tc, test_add_front_and_next);
   tcase_add_test (tc, test_add_a_bunch);
-  tcase_add_test (tc, test_free);
   return s;
 }