1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/test/tinytest_macros.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,184 @@ 1.4 +/* tinytest_macros.h -- Copyright 2009-2012 Nick Mathewson 1.5 + * 1.6 + * Redistribution and use in source and binary forms, with or without 1.7 + * modification, are permitted provided that the following conditions 1.8 + * are met: 1.9 + * 1. Redistributions of source code must retain the above copyright 1.10 + * notice, this list of conditions and the following disclaimer. 1.11 + * 2. Redistributions in binary form must reproduce the above copyright 1.12 + * notice, this list of conditions and the following disclaimer in the 1.13 + * documentation and/or other materials provided with the distribution. 1.14 + * 3. The name of the author may not be used to endorse or promote products 1.15 + * derived from this software without specific prior written permission. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1.18 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1.19 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.20 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1.21 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1.22 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.23 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.24 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1.26 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 + */ 1.28 + 1.29 +#ifndef _TINYTEST_MACROS_H 1.30 +#define _TINYTEST_MACROS_H 1.31 + 1.32 +/* Helpers for defining statement-like macros */ 1.33 +#define TT_STMT_BEGIN do { 1.34 +#define TT_STMT_END } while (0) 1.35 + 1.36 +/* Redefine this if your test functions want to abort with something besides 1.37 + * "goto end;" */ 1.38 +#ifndef TT_EXIT_TEST_FUNCTION 1.39 +#define TT_EXIT_TEST_FUNCTION TT_STMT_BEGIN goto end; TT_STMT_END 1.40 +#endif 1.41 + 1.42 +/* Redefine this if you want to note success/failure in some different way. */ 1.43 +#ifndef TT_DECLARE 1.44 +#define TT_DECLARE(prefix, args) \ 1.45 + TT_STMT_BEGIN \ 1.46 + printf("\n %s %s:%d: ",prefix,__FILE__,__LINE__); \ 1.47 + printf args ; \ 1.48 + TT_STMT_END 1.49 +#endif 1.50 + 1.51 +/* Announce a failure. Args are parenthesized printf args. */ 1.52 +#define TT_GRIPE(args) TT_DECLARE("FAIL", args) 1.53 + 1.54 +/* Announce a non-failure if we're verbose. */ 1.55 +#define TT_BLATHER(args) \ 1.56 + TT_STMT_BEGIN \ 1.57 + if (_tinytest_get_verbosity()>1) TT_DECLARE(" OK", args); \ 1.58 + TT_STMT_END 1.59 + 1.60 +#define TT_DIE(args) \ 1.61 + TT_STMT_BEGIN \ 1.62 + _tinytest_set_test_failed(); \ 1.63 + TT_GRIPE(args); \ 1.64 + TT_EXIT_TEST_FUNCTION; \ 1.65 + TT_STMT_END 1.66 + 1.67 +#define TT_FAIL(args) \ 1.68 + TT_STMT_BEGIN \ 1.69 + _tinytest_set_test_failed(); \ 1.70 + TT_GRIPE(args); \ 1.71 + TT_STMT_END 1.72 + 1.73 +/* Fail and abort the current test for the reason in msg */ 1.74 +#define tt_abort_printf(msg) TT_DIE(msg) 1.75 +#define tt_abort_perror(op) TT_DIE(("%s: %s [%d]",(op),strerror(errno), errno)) 1.76 +#define tt_abort_msg(msg) TT_DIE(("%s", msg)) 1.77 +#define tt_abort() TT_DIE(("%s", "(Failed.)")) 1.78 + 1.79 +/* Fail but do not abort the current test for the reason in msg. */ 1.80 +#define tt_fail_printf(msg) TT_FAIL(msg) 1.81 +#define tt_fail_perror(op) TT_FAIL(("%s: %s [%d]",(op),strerror(errno), errno)) 1.82 +#define tt_fail_msg(msg) TT_FAIL(("%s", msg)) 1.83 +#define tt_fail() TT_FAIL(("%s", "(Failed.)")) 1.84 + 1.85 +/* End the current test, and indicate we are skipping it. */ 1.86 +#define tt_skip() \ 1.87 + TT_STMT_BEGIN \ 1.88 + _tinytest_set_test_skipped(); \ 1.89 + TT_EXIT_TEST_FUNCTION; \ 1.90 + TT_STMT_END 1.91 + 1.92 +#define _tt_want(b, msg, fail) \ 1.93 + TT_STMT_BEGIN \ 1.94 + if (!(b)) { \ 1.95 + _tinytest_set_test_failed(); \ 1.96 + TT_GRIPE(("%s",msg)); \ 1.97 + fail; \ 1.98 + } else { \ 1.99 + TT_BLATHER(("%s",msg)); \ 1.100 + } \ 1.101 + TT_STMT_END 1.102 + 1.103 +/* Assert b, but do not stop the test if b fails. Log msg on failure. */ 1.104 +#define tt_want_msg(b, msg) \ 1.105 + _tt_want(b, msg, ); 1.106 + 1.107 +/* Assert b and stop the test if b fails. Log msg on failure. */ 1.108 +#define tt_assert_msg(b, msg) \ 1.109 + _tt_want(b, msg, TT_EXIT_TEST_FUNCTION); 1.110 + 1.111 +/* Assert b, but do not stop the test if b fails. */ 1.112 +#define tt_want(b) tt_want_msg( (b), "want("#b")") 1.113 +/* Assert b, and stop the test if b fails. */ 1.114 +#define tt_assert(b) tt_assert_msg((b), "assert("#b")") 1.115 + 1.116 +#define tt_assert_test_fmt_type(a,b,str_test,type,test,printf_type,printf_fmt, \ 1.117 + setup_block,cleanup_block,die_on_fail) \ 1.118 + TT_STMT_BEGIN \ 1.119 + type _val1 = (type)(a); \ 1.120 + type _val2 = (type)(b); \ 1.121 + int _tt_status = (test); \ 1.122 + if (!_tt_status || _tinytest_get_verbosity()>1) { \ 1.123 + printf_type _print; \ 1.124 + printf_type _print1; \ 1.125 + printf_type _print2; \ 1.126 + type _value = _val1; \ 1.127 + setup_block; \ 1.128 + _print1 = _print; \ 1.129 + _value = _val2; \ 1.130 + setup_block; \ 1.131 + _print2 = _print; \ 1.132 + TT_DECLARE(_tt_status?" OK":"FAIL", \ 1.133 + ("assert(%s): "printf_fmt" vs "printf_fmt, \ 1.134 + str_test, _print1, _print2)); \ 1.135 + _print = _print1; \ 1.136 + cleanup_block; \ 1.137 + _print = _print2; \ 1.138 + cleanup_block; \ 1.139 + if (!_tt_status) { \ 1.140 + _tinytest_set_test_failed(); \ 1.141 + die_on_fail ; \ 1.142 + } \ 1.143 + } \ 1.144 + TT_STMT_END 1.145 + 1.146 +#define tt_assert_test_type(a,b,str_test,type,test,fmt,die_on_fail) \ 1.147 + tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \ 1.148 + {_print=_value;},{},die_on_fail) 1.149 + 1.150 +/* Helper: assert that a op b, when cast to type. Format the values with 1.151 + * printf format fmt on failure. */ 1.152 +#define tt_assert_op_type(a,op,b,type,fmt) \ 1.153 + tt_assert_test_type(a,b,#a" "#op" "#b,type,(_val1 op _val2),fmt, \ 1.154 + TT_EXIT_TEST_FUNCTION) 1.155 + 1.156 +#define tt_int_op(a,op,b) \ 1.157 + tt_assert_test_type(a,b,#a" "#op" "#b,long,(_val1 op _val2), \ 1.158 + "%ld",TT_EXIT_TEST_FUNCTION) 1.159 + 1.160 +#define tt_uint_op(a,op,b) \ 1.161 + tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long, \ 1.162 + (_val1 op _val2),"%lu",TT_EXIT_TEST_FUNCTION) 1.163 + 1.164 +#define tt_ptr_op(a,op,b) \ 1.165 + tt_assert_test_type(a,b,#a" "#op" "#b,void*, \ 1.166 + (_val1 op _val2),"%p",TT_EXIT_TEST_FUNCTION) 1.167 + 1.168 +#define tt_str_op(a,op,b) \ 1.169 + tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ 1.170 + (strcmp(_val1,_val2) op 0),"<%s>",TT_EXIT_TEST_FUNCTION) 1.171 + 1.172 +#define tt_want_int_op(a,op,b) \ 1.173 + tt_assert_test_type(a,b,#a" "#op" "#b,long,(_val1 op _val2),"%ld",(void)0) 1.174 + 1.175 +#define tt_want_uint_op(a,op,b) \ 1.176 + tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long, \ 1.177 + (_val1 op _val2),"%lu",(void)0) 1.178 + 1.179 +#define tt_want_ptr_op(a,op,b) \ 1.180 + tt_assert_test_type(a,b,#a" "#op" "#b,void*, \ 1.181 + (_val1 op _val2),"%p",(void)0) 1.182 + 1.183 +#define tt_want_str_op(a,op,b) \ 1.184 + tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ 1.185 + (strcmp(_val1,_val2) op 0),"<%s>",(void)0) 1.186 + 1.187 +#endif