Loading changes/bug9004 0 → 100644 +6 −0 Original line number Original line Diff line number Diff line o Minor bugfixes (testing): - Improve the tinytest implementation of string operation tests so that comparisons NULL strings no longer crash the tests; they now just fail, normally. Fixes bug 9004; bugfix on 0.2.2.4-alpha. src/ext/tinytest_macros.h +7 −2 Original line number Original line Diff line number Diff line Loading @@ -144,6 +144,10 @@ tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \ tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \ {print_=value_;},{},die_on_fail) {print_=value_;},{},die_on_fail) #define tt_assert_test_type_opt(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_?value_:"<NULL>";},{},die_on_fail) /* Helper: assert that a op b, when cast to type. Format the values with /* Helper: assert that a op b, when cast to type. Format the values with * printf format fmt on failure. */ * printf format fmt on failure. */ #define tt_assert_op_type(a,op,b,type,fmt) \ #define tt_assert_op_type(a,op,b,type,fmt) \ Loading @@ -163,8 +167,9 @@ (val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION) (val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION) #define tt_str_op(a,op,b) \ #define tt_str_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ tt_assert_test_type_opt(a,b,#a" "#op" "#b,const char *, \ (strcmp(val1_,val2_) op 0),"<%s>",TT_EXIT_TEST_FUNCTION) (val1_ && val2_ && strcmp(val1_,val2_) op 0),"<%s>", \ TT_EXIT_TEST_FUNCTION) #define tt_want_int_op(a,op,b) \ #define tt_want_int_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0) tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0) Loading src/test/test.h +9 −4 Original line number Original line Diff line number Diff line Loading @@ -38,12 +38,17 @@ #define test_mem_op(expr1, op, expr2, len) \ #define test_mem_op(expr1, op, expr2, len) \ tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \ tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \ const char *, \ const char *, \ (memcmp(val1_, val2_, len) op 0), \ (val1_ && val2_ && memcmp(val1_, val2_, len) op 0), \ char *, "%s", \ char *, "%s", \ { size_t printlen = (len)*2+1; \ { size_t printlen = (len)*2+1; \ if (value_) { \ print_ = tor_malloc(printlen); \ print_ = tor_malloc(printlen); \ base16_encode(print_, printlen, value_, \ base16_encode(print_, printlen, value_, \ (len)); }, \ (len)); \ } else { \ print_ = tor_strdup("null"); \ } \ }, \ { tor_free(print_); }, \ { tor_free(print_); }, \ TT_EXIT_TEST_FUNCTION \ TT_EXIT_TEST_FUNCTION \ ); ); Loading Loading
changes/bug9004 0 → 100644 +6 −0 Original line number Original line Diff line number Diff line o Minor bugfixes (testing): - Improve the tinytest implementation of string operation tests so that comparisons NULL strings no longer crash the tests; they now just fail, normally. Fixes bug 9004; bugfix on 0.2.2.4-alpha.
src/ext/tinytest_macros.h +7 −2 Original line number Original line Diff line number Diff line Loading @@ -144,6 +144,10 @@ tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \ tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \ {print_=value_;},{},die_on_fail) {print_=value_;},{},die_on_fail) #define tt_assert_test_type_opt(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_?value_:"<NULL>";},{},die_on_fail) /* Helper: assert that a op b, when cast to type. Format the values with /* Helper: assert that a op b, when cast to type. Format the values with * printf format fmt on failure. */ * printf format fmt on failure. */ #define tt_assert_op_type(a,op,b,type,fmt) \ #define tt_assert_op_type(a,op,b,type,fmt) \ Loading @@ -163,8 +167,9 @@ (val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION) (val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION) #define tt_str_op(a,op,b) \ #define tt_str_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ tt_assert_test_type_opt(a,b,#a" "#op" "#b,const char *, \ (strcmp(val1_,val2_) op 0),"<%s>",TT_EXIT_TEST_FUNCTION) (val1_ && val2_ && strcmp(val1_,val2_) op 0),"<%s>", \ TT_EXIT_TEST_FUNCTION) #define tt_want_int_op(a,op,b) \ #define tt_want_int_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0) tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0) Loading
src/test/test.h +9 −4 Original line number Original line Diff line number Diff line Loading @@ -38,12 +38,17 @@ #define test_mem_op(expr1, op, expr2, len) \ #define test_mem_op(expr1, op, expr2, len) \ tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \ tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \ const char *, \ const char *, \ (memcmp(val1_, val2_, len) op 0), \ (val1_ && val2_ && memcmp(val1_, val2_, len) op 0), \ char *, "%s", \ char *, "%s", \ { size_t printlen = (len)*2+1; \ { size_t printlen = (len)*2+1; \ if (value_) { \ print_ = tor_malloc(printlen); \ print_ = tor_malloc(printlen); \ base16_encode(print_, printlen, value_, \ base16_encode(print_, printlen, value_, \ (len)); }, \ (len)); \ } else { \ print_ = tor_strdup("null"); \ } \ }, \ { tor_free(print_); }, \ { tor_free(print_); }, \ TT_EXIT_TEST_FUNCTION \ TT_EXIT_TEST_FUNCTION \ ); ); Loading