From: Wouter Wijngaards Date: Tue, 22 Sep 2015 09:52:17 +0000 (+0000) Subject: - testbound selftest also works in non-debug mode. X-Git-Tag: release-1.5.5rc1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66b21d16be7e3a8c77d1df8352ced04817eb0385;p=thirdparty%2Funbound.git - testbound selftest also works in non-debug mode. git-svn-id: file:///svn/unbound/trunk@3490 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 08beef362..6e0f5ef31 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -5,6 +5,7 @@ - Fix #702: New IPs for for h.root-servers.net. - Remove confusion comment from canonical_compare() function. - Fix #705: ub_ctx_set_fwd() return value mishandled on windows. + - testbound selftest also works in non-debug mode. 31 August 2015: Wouter - changed windows setup compression to be more transparent. diff --git a/testcode/replay.c b/testcode/replay.c index 01b17a7f7..8a88814e7 100644 --- a/testcode/replay.c +++ b/testcode/replay.c @@ -909,118 +909,127 @@ macro_assign(rbtree_t* store, char* name, char* value) return x->value != NULL; } +/* testbound assert function for selftest. counts the number of tests */ +#define tb_assert(x) \ + do { if(!(x)) fatal_exit("%s:%d: %s: assertion %s failed", \ + __FILE__, __LINE__, __func__, #x); \ + num_asserts++; \ + } while(0); + void testbound_selftest(void) { /* test the macro store */ rbtree_t* store = macro_store_create(); char* v; int r; - log_assert(store); + int num_asserts = 0; + tb_assert(store); v = macro_lookup(store, "bla"); - log_assert(strcmp(v, "") == 0); + tb_assert(strcmp(v, "") == 0); free(v); v = macro_lookup(store, "vlerk"); - log_assert(strcmp(v, "") == 0); + tb_assert(strcmp(v, "") == 0); free(v); r = macro_assign(store, "bla", "waarde1"); - log_assert(r); + tb_assert(r); v = macro_lookup(store, "vlerk"); - log_assert(strcmp(v, "") == 0); + tb_assert(strcmp(v, "") == 0); free(v); v = macro_lookup(store, "bla"); - log_assert(strcmp(v, "waarde1") == 0); + tb_assert(strcmp(v, "waarde1") == 0); free(v); r = macro_assign(store, "vlerk", "kanteel"); - log_assert(r); + tb_assert(r); v = macro_lookup(store, "bla"); - log_assert(strcmp(v, "waarde1") == 0); + tb_assert(strcmp(v, "waarde1") == 0); free(v); v = macro_lookup(store, "vlerk"); - log_assert(strcmp(v, "kanteel") == 0); + tb_assert(strcmp(v, "kanteel") == 0); free(v); r = macro_assign(store, "bla", "ww"); - log_assert(r); + tb_assert(r); v = macro_lookup(store, "bla"); - log_assert(strcmp(v, "ww") == 0); + tb_assert(strcmp(v, "ww") == 0); free(v); - log_assert( macro_length("}") == 1); - log_assert( macro_length("blabla}") == 7); - log_assert( macro_length("bla${zoink}bla}") == 7+8); - log_assert( macro_length("bla${zoink}${bla}bla}") == 7+8+6); + tb_assert( macro_length("}") == 1); + tb_assert( macro_length("blabla}") == 7); + tb_assert( macro_length("bla${zoink}bla}") == 7+8); + tb_assert( macro_length("bla${zoink}${bla}bla}") == 7+8+6); v = macro_process(store, NULL, ""); - log_assert( v && strcmp(v, "") == 0); + tb_assert( v && strcmp(v, "") == 0); free(v); v = macro_process(store, NULL, "${}"); - log_assert( v && strcmp(v, "") == 0); + tb_assert( v && strcmp(v, "") == 0); free(v); v = macro_process(store, NULL, "blabla ${} dinges"); - log_assert( v && strcmp(v, "blabla dinges") == 0); + tb_assert( v && strcmp(v, "blabla dinges") == 0); free(v); v = macro_process(store, NULL, "1${$bla}2${$bla}3"); - log_assert( v && strcmp(v, "1ww2ww3") == 0); + tb_assert( v && strcmp(v, "1ww2ww3") == 0); free(v); v = macro_process(store, NULL, "it is ${ctime 123456}"); - log_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); + tb_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); free(v); r = macro_assign(store, "t1", "123456"); - log_assert(r); + tb_assert(r); v = macro_process(store, NULL, "it is ${ctime ${$t1}}"); - log_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); + tb_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); free(v); v = macro_process(store, NULL, "it is ${ctime $t1}"); - log_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); + tb_assert( v && strcmp(v, "it is Fri Jan 2 10:17:36 1970") == 0); free(v); r = macro_assign(store, "x", "1"); - log_assert(r); + tb_assert(r); r = macro_assign(store, "y", "2"); - log_assert(r); + tb_assert(r); v = macro_process(store, NULL, "${$x + $x}"); - log_assert( v && strcmp(v, "2") == 0); + tb_assert( v && strcmp(v, "2") == 0); free(v); v = macro_process(store, NULL, "${$x - $x}"); - log_assert( v && strcmp(v, "0") == 0); + tb_assert( v && strcmp(v, "0") == 0); free(v); v = macro_process(store, NULL, "${$y * $y}"); - log_assert( v && strcmp(v, "4") == 0); + tb_assert( v && strcmp(v, "4") == 0); free(v); v = macro_process(store, NULL, "${32 / $y + $x + $y}"); - log_assert( v && strcmp(v, "19") == 0); + tb_assert( v && strcmp(v, "19") == 0); free(v); v = macro_process(store, NULL, "${32 / ${$y+$y} + ${${100*3}/3}}"); - log_assert( v && strcmp(v, "108") == 0); + tb_assert( v && strcmp(v, "108") == 0); free(v); v = macro_process(store, NULL, "${1 2 33 2 1}"); - log_assert( v && strcmp(v, "1 2 33 2 1") == 0); + tb_assert( v && strcmp(v, "1 2 33 2 1") == 0); free(v); v = macro_process(store, NULL, "${123 3 + 5}"); - log_assert( v && strcmp(v, "123 8") == 0); + tb_assert( v && strcmp(v, "123 8") == 0); free(v); v = macro_process(store, NULL, "${123 glug 3 + 5}"); - log_assert( v && strcmp(v, "123 glug 8") == 0); + tb_assert( v && strcmp(v, "123 glug 8") == 0); free(v); macro_store_delete(store); + printf("selftest successful (%d checks).\n", num_asserts); } diff --git a/testcode/testbound.c b/testcode/testbound.c index fa361c4ea..b297f4774 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -284,7 +284,6 @@ main(int argc, char* argv[]) case 's': free(pass_argv[1]); testbound_selftest(); - printf("selftest successful\n"); exit(0); case '2': #if (defined(HAVE_EVP_SHA256) || defined(HAVE_NSS)) && defined(USE_SHA2)