X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fforeach%2Ftest%2Frun-nested.c;fp=ccan%2Fforeach%2Ftest%2Frun-nested.c;h=17fa2f16667c5cc881b00aa21f7c8dbf2b478e00;hp=b54fbbe07bcd1b17f658aa76845850d298657f3b;hb=83bba283bd7c94f083ea19df78e1e921b30d97b6;hpb=a8446c3ef94ae0d5f273656da12aa9a8b3abf658 diff --git a/ccan/foreach/test/run-nested.c b/ccan/foreach/test/run-nested.c index b54fbbe0..17fa2f16 100644 --- a/ccan/foreach/test/run-nested.c +++ b/ccan/foreach/test/run-nested.c @@ -47,7 +47,7 @@ int main(void) int i, j, sum; const char *istr, *jstr; - plan_tests(12); + plan_tests(16); sum = 0; foreach_int(i, 0, 1, 2, 3, 4) @@ -68,12 +68,6 @@ int main(void) ok1(sum == 100); ok1(count_iters() <= 2); - sum = test_int_recursion(0); - diag("sum = %i\n", sum); - diag("iters = %i\n", count_iters()); - ok1(sum == 160); - ok1(count_iters() <= 2 + 5); /* 5 is max depth of recursion. */ - sum = 0; foreach_ptr(istr, "0", "1", "2", "3", "4") foreach_ptr(jstr, "0", "1", "2", "3", "4") @@ -81,7 +75,7 @@ int main(void) diag("sum = %i\n", sum); diag("iters = %i\n", count_iters()); ok1(sum == 100); - ok1(count_iters() <= 2 + 5 + 2); + ok1(count_iters() <= 2 + 2); /* Same again... reusing iterators. */ sum = 0; @@ -91,13 +85,22 @@ int main(void) diag("sum = %i\n", sum); diag("iters = %i\n", count_iters()); ok1(sum == 100); - ok1(count_iters() <= 2 + 5 + 2); + ok1(count_iters() <= 2 + 2); - sum = test_ptr_recursion("0"); - diag("sum = %i\n", sum); - diag("iters = %i\n", count_iters()); - ok1(sum == 160); - ok1(count_iters() <= 2 + 5 + 2); + /* Do this twice, second time shouldn't increase iterators. */ + for (i = 0; i < 2; i++) { + sum = test_int_recursion(0); + diag("sum = %i\n", sum); + diag("iters = %i\n", count_iters()); + ok1(sum == 160); + ok1(count_iters() <= 2 + 2 + 5); /* 5 is max depth of recursion. */ + + sum = test_ptr_recursion("0"); + diag("sum = %i\n", sum); + diag("iters = %i\n", count_iters()); + ok1(sum == 160); + ok1(count_iters() <= 2 + 2 + 5); + } return exit_status(); }