]> granicus.if.org Git - check/commitdiff
Applied varargs patch (#933411) and added test cases.
authorhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 17 Aug 2004 09:50:36 +0000 (09:50 +0000)
committerhugo303 <hugo303@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 17 Aug 2004 09:50:36 +0000 (09:50 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@180 64e312b2-a51f-0410-8e61-82d0ca0eb02a

check/ChangeLog
check/src/check.c
check/src/check.h.in
check/tests/check_check_master.c
check/tests/check_check_sub.c

index c2d8634394ba93829287ebcb599c373ce4be86a9..61f9fcac1bbdcccd468be95a090117d8318efd02 100644 (file)
@@ -1,5 +1,8 @@
 2004-08-17 hugo303
 
+       * src/check.c, src/check.h.in, tests/check_check_master.c,
+       tests/check_check_sub.c, ChangeLog
+       Applied varargs patch (#933411) and added test cases.
        * src/check.h.in tests/check_check_master.c tests/check_check_sub.c:
        Applied fail_if (#709167) patch.
 
index 42ab77c2498c8655e5401ac87ab98f8aeae7af4b..2a3cf5d0c3742e5843a6f31043fdf3efd7a9a83c 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 
 #include "check.h"
 #include "check_error.h"
@@ -168,14 +169,21 @@ void _mark_point (const char *file, int line)
   send_loc_info (get_send_key(), file, line);
 }
 
-void _fail_unless (int result, const char *file, int line, const char * msg)
+void _fail_unless (int result, const char *file,
+                   int line, const char * msg, ...)
 {
   if (msg == NULL)
     eprintf ("_fail_unless() called with NULL msg",__FILE__,__LINE__);
 
   send_loc_info (get_send_key(), file, line);
   if (!result) {
-    send_failure_info (get_send_key(), msg);
+    va_list ap;
+    char buf[BUFSIZ];
+
+    va_start(ap,msg);
+    vsnprintf(buf, BUFSIZ, msg, ap);
+    va_end(ap);
+    send_failure_info (get_send_key(), buf);
     if (cur_fork_status() == CK_FORK)
       exit(1);
   }
index bf77b524b7eaac75915c3ec025c26255cbc86258..746fee59aad156691712d38d9c28752bc22106f6 100644 (file)
@@ -155,18 +155,21 @@ static void __testname (void)\
 
 
 /* Fail the test case unless expr is true */
-#define fail_unless(expr,msg)\
- _fail_unless(expr,__FILE__,__LINE__, msg ? msg : "Assertion '"#expr"' failed")
+#define fail_unless(expr, msg, args...)\
+        _fail_unless(expr, __FILE__, __LINE__,\
+        msg ? msg : "Assertion '"#expr"' failed", ##args)
 
 /* Fail the test case if expr is true */
-#define fail_if(expr, msg)\
- _fail_unless(!(expr),__FILE__,__LINE__,msg ?msg :"Assertion '"#expr"' failed")
-
-/* Non macro version of #fail_unless, with more complicated interface */
-void _fail_unless (int result, const char *file, int line, const char *msg);
+#define fail_if(expr, msg, args...)\
+        _fail_unless(!(expr), __FILE__, __LINE__,\
+        msg ?msg :"Assertion '"#expr"' failed", ##args)
 
 /* Always fail */
-#define fail(msg) _fail_unless(0,__FILE__,__LINE__,msg)
+#define fail(msg, args...) _fail_unless(0, __FILE__, __LINE__, msg, ##args)
+
+/* Non macro version of #fail_unless, with more complicated interface */
+void _fail_unless (int result, const char *file,
+                   int line, const char *msg, ...);
 
 /* Mark the last point reached in a unit test
    
index 5b962342c31a5ea7a045529da78ea6241e9e6290..ab65326286f60d7059fa2a30ba57476f3e157af1 100644 (file)
@@ -14,13 +14,15 @@ TestResult **tr_all_array;
 
 START_TEST(test_check_nfailures)
 {
-  fail_unless (sub_nfailed == 12, "Unexpected number of failures received");
+  fail_unless (sub_nfailed == 16,
+               "Unexpected number of failures received, %d.", sub_nfailed);
 }
 END_TEST
 
 START_TEST(test_check_ntests_run)
 {
-  fail_unless (sub_ntests == 14, "Unexpected number of tests run");
+  fail_unless (sub_ntests == 18,
+               "Unexpected number of tests run, %d.", sub_ntests);
 }
 END_TEST
 
@@ -34,7 +36,11 @@ START_TEST(test_check_failure_msgs)
     "This test should fail",
     /*    "Test passed", */
     "This test should fail",
-    "Assertion '2==3' failed",
+    "Assertion '2 == 3' failed",
+    "Assertion '2 != 3' failed",
+    "3 != 4",
+    "5 != 6",
+    "7 == 7",
     "Received signal 11",
     "Received signal 8",
     "Received signal 8",
@@ -71,6 +77,10 @@ START_TEST(test_check_failure_lnos)
     -1,
     -1,
     -1,
+    -1,
+    -1,
+    -1,
+    -1,
     -1};
   
   for (i = 0; i < sub_nfailed; i++) {
@@ -95,6 +105,10 @@ START_TEST(test_check_failure_ftypes)
     CK_FAILURE,
     CK_FAILURE,
     CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
     CK_ERROR,
     CK_ERROR,
     CK_ERROR,
@@ -132,6 +146,10 @@ START_TEST(test_check_failure_tcnames)
     "Simple Tests",
     "Simple Tests",
     "Simple Tests",
+    "Simple Tests",
+    "Simple Tests",
+    "Simple Tests",
+    "Simple Tests",
     "Signal Tests",
     "Signal Tests",
     "Signal Tests",
@@ -164,7 +182,11 @@ START_TEST(test_check_all_msgs)
     "This test should fail",
     "Passed",
     "This test should fail",
-    "Assertion '2==3' failed",
+    "Assertion '2 == 3' failed",
+    "Assertion '2 != 3' failed",
+    "3 != 4",
+    "5 != 6",
+    "7 == 7",
     "Received signal 11",
     "Received signal 8",
     "Received signal 8",
@@ -197,6 +219,10 @@ START_TEST(test_check_all_ftypes)
     CK_PASS,
     CK_FAILURE,
     CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
+    CK_FAILURE,
     CK_ERROR,
     CK_ERROR,
     CK_ERROR,
index b0625769fab30839ce5c542bed03a36a885b1d79..8c82e7df7310012e64c4c8183e5b026d9961985f 100644 (file)
@@ -18,33 +18,63 @@ END_TEST
 
 START_TEST(test_pass)
 {
-  fail_unless (1==1, "This test should pass");
-  fail_unless (9999, "This test should pass");
+  fail_unless(1 == 1, "This test should pass");
+  fail_unless(9999, "This test should pass");
 }
 END_TEST
 
 START_TEST(test_fail)
 {
-  fail_unless (1==2, "This test should fail");
+  fail_unless(1 == 2, "This test should fail");
+}
+END_TEST
+
+START_TEST(test_fail_if_pass)
+{
+  fail_if(1 == 2, "This test should pass");
+  fail_if(0, "This test should pass");
+}
+END_TEST
+
+START_TEST(test_fail_if_fail)
+{
+  fail_if(1 == 1, "This test should fail");
 }
 END_TEST
 
 START_TEST(test_fail_null_msg)
 {
-  fail_unless (2==3, NULL);
+  fail_unless(2 == 3, NULL);
 }
 END_TEST
 
-START_TEST(test_fail_if_pass)
+START_TEST(test_fail_if_null_msg)
 {
-  fail_if(1==2, "This test should pass");
-  fail_if(0, "This test should pass");
+  fail_if(2 != 3, NULL);
 }
 END_TEST
 
-START_TEST(test_fail_if_fail)
+START_TEST(test_fail_vararg_msg_1)
+{
+  int x = 3;
+  int y = 4;
+  fail_unless(x == y, "%d != %d", x, y);
+}
+END_TEST
+
+START_TEST(test_fail_vararg_msg_2)
+{
+  int x = 5;
+  int y = 6;
+  fail_if(x != y, "%d != %d", x, y);
+}
+END_TEST
+
+START_TEST(test_fail_vararg_msg_3)
 {
-  fail_if(1==1, "This test should fail");
+  int x = 7;
+  int y = 7;
+  fail("%d == %d", x, y);
 }
 END_TEST
 
@@ -140,6 +170,10 @@ Suite *make_sub_suite(void)
   tcase_add_test (tc_simple, test_fail_if_pass);
   tcase_add_test (tc_simple, test_fail_if_fail);
   tcase_add_test (tc_simple, test_fail_null_msg);
+  tcase_add_test (tc_simple, test_fail_if_null_msg);
+  tcase_add_test (tc_simple, test_fail_vararg_msg_1);
+  tcase_add_test (tc_simple, test_fail_vararg_msg_2);
+  tcase_add_test (tc_simple, test_fail_vararg_msg_3);
   tcase_add_test (tc_signal, test_segv);
   tcase_add_test (tc_signal, test_fpe);
   tcase_add_test (tc_signal, test_mark_point);