X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fforeach%2Ftest%2Frun-nested.c;h=0bb21c980057d29af5ac34680a15ca1cbf39f83d;hp=b54fbbe07bcd1b17f658aa76845850d298657f3b;hb=6e86fffc5e5780c209f52986be4f150b16b96d29;hpb=5b115ea9392ca30ce5f0bbeb18389ea9aaea7421 diff --git a/ccan/foreach/test/run-nested.c b/ccan/foreach/test/run-nested.c index b54fbbe0..0bb21c98 100644 --- a/ccan/foreach/test/run-nested.c +++ b/ccan/foreach/test/run-nested.c @@ -44,10 +44,10 @@ static int count_iters(void) int main(void) { - int i, j, sum; + int i, j, sum, max_iters = 0 /* keep gcc happy */; const char *istr, *jstr; - plan_tests(12); + plan_tests(13); 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,24 @@ 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); + + sum = test_ptr_recursion("0"); + diag("sum = %i\n", sum); + diag("iters = %i\n", count_iters()); + ok1(sum == 160); + if (i == 0) + max_iters = count_iters(); + else + ok1(count_iters() <= max_iters); + } return exit_status(); }