]> granicus.if.org Git - libevent/commitdiff
Improvements to tinytest_macros.h
authorNick Mathewson <nickm@torproject.org>
Tue, 19 Oct 2010 16:33:50 +0000 (12:33 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 19 Oct 2010 16:33:50 +0000 (12:33 -0400)
First, handle cases where we have %s in a tt_want or tt_assert.

Second, add tt_want_*_op that do a tt_*_op test, but do not exit the
test on failure.

We should push these upstream to tinytest some time.

test/tinytest_macros.h

index a7fa64a824531d9d041df7bf1fe11d3a7602508a..032393ccf762500228c6f9647e123cf8a7cec0fa 100644 (file)
        TT_STMT_BEGIN                                   \
        if (!(b)) {                                     \
                _tinytest_set_test_failed();            \
-               TT_GRIPE((msg));                        \
+               TT_GRIPE(("%s",msg));                   \
                fail;                                   \
        } else {                                        \
-               TT_BLATHER((msg));                      \
+               TT_BLATHER(("%s",msg));                 \
        }                                               \
        TT_STMT_END
 
 #define tt_assert(b) tt_assert_msg((b), "assert("#b")")
 
 #define tt_assert_test_fmt_type(a,b,str_test,type,test,printf_type,printf_fmt, \
-                               setup_block,cleanup_block)              \
+    setup_block,cleanup_block,die_on_fail)                             \
        TT_STMT_BEGIN                                                   \
        type _val1 = (type)(a);                                         \
        type _val2 = (type)(b);                                         \
                cleanup_block;                                          \
                if (!_tt_status) {                                      \
                        _tinytest_set_test_failed();                    \
-                       TT_EXIT_TEST_FUNCTION;                          \
+                       die_on_fail ;                                   \
                }                                                       \
        }                                                               \
        TT_STMT_END
 
-#define tt_assert_test_type(a,b,str_test,type,test,fmt)                        \
+#define tt_assert_test_type(a,b,str_test,type,test,fmt,die_on_fail)    \
        tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt,        \
-                               {_print=_value;},{})
+           {_print=_value;},{},die_on_fail)
 
 /* Helper: assert that a op b, when cast to type.  Format the values with
  * printf format fmt on failure. */
 #define tt_assert_op_type(a,op,b,type,fmt)                             \
-       tt_assert_test_type(a,b,#a" "#op" "#b,type,(_val1 op _val2),fmt)
+       tt_assert_test_type(a,b,#a" "#op" "#b,type,(_val1 op _val2),fmt, \
+           TT_EXIT_TEST_FUNCTION)
 
 #define tt_int_op(a,op,b)                      \
-       tt_assert_test_type(a,b,#a" "#op" "#b,long,(_val1 op _val2),"%ld")
+       tt_assert_test_type(a,b,#a" "#op" "#b,long,(_val1 op _val2), \
+           "%ld",TT_EXIT_TEST_FUNCTION)
 
 #define tt_uint_op(a,op,b)                                             \
        tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long,            \
-                           (_val1 op _val2),"%lu")
+           (_val1 op _val2),"%lu",TT_EXIT_TEST_FUNCTION)
 
 #define tt_ptr_op(a,op,b)                                              \
        tt_assert_test_type(a,b,#a" "#op" "#b,void*,                    \
-                           (_val1 op _val2),"%p")
+           (_val1 op _val2),"%p",TT_EXIT_TEST_FUNCTION)
 
 #define tt_str_op(a,op,b)                                              \
        tt_assert_test_type(a,b,#a" "#op" "#b,const char *,             \
-                           (strcmp(_val1,_val2) op 0),"<%s>")
+           (strcmp(_val1,_val2) op 0),"<%s>",TT_EXIT_TEST_FUNCTION)
+
+#define tt_want_int_op(a,op,b)                                         \
+       tt_assert_test_type(a,b,#a" "#op" "#b,long,(_val1 op _val2),"%ld",(void)0)
+
+#define tt_want_uint_op(a,op,b)                                                \
+       tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long,            \
+           (_val1 op _val2),"%lu",(void)0)
+
+#define tt_want_ptr_op(a,op,b)                                         \
+       tt_assert_test_type(a,b,#a" "#op" "#b,void*,                    \
+           (_val1 op _val2),"%p",(void)0)
+
+#define tt_want_str_op(a,op,b)                                         \
+       tt_assert_test_type(a,b,#a" "#op" "#b,const char *,             \
+           (strcmp(_val1,_val2) op 0),"<%s>",(void)0)
 
 #endif