1 #include <ccan/failtest/failtest_override.h>
2 #include <ccan/failtest/failtest.h>
3 #include <ccan/deque/deque.h>
4 /* Include the C files directly. */
5 #include <ccan/deque/deque.c>
6 #include <ccan/tap/tap.h>
8 int main(int argc, char *argv[])
10 failtest_init(argc, argv);
14 ok1(deq_new(a, 2, DEQ_SHRINK_IF_EMPTY) == 0); // two mallocs
15 ok1(a && deq_push(a, 'a') == 1);
16 ok1(a && deq_push(a, 'b') == 1);
17 ok1(a && deq_push(a, 'c') == 1); // malloc to grow
20 ok1(a && deq_pop(a, &t) == 1);
21 ok1(a && deq_pop(a, &t) == 1);
22 ok1(a && deq_pop(a, &t) == 1); // malloc to shrink
27 ok1(deq_new(b, 5, DEQ_SHRINK_AT_20PCT) == 0); // two mallocs
29 for (i = 0; b && i < 6; i++)
30 ok1(deq_push(b, i + 'A') == 1); // last iteration mallocs to grow
31 for (; b && i > 2; i--)
32 ok1(deq_pop(b, &t) == 1); // last iteration mallocs to shrink
36 failtest_exit(exit_status());