]> git.ozlabs.org Git - ccan/blob - ccan/lstack/test/run.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / lstack / test / run.c
1 #include "config.h"
2
3 #include <ccan/lstack/lstack.h>
4 #include <ccan/tap/tap.h>
5
6 struct stacker {
7         const char *name;
8         struct lstack_link sl;
9 };
10
11 int main(void)
12 {
13         LSTACK(struct stacker, sl) s = LSTACK_INIT;
14         struct stacker a = { "Alice" };
15         struct stacker b = { "Bob" };
16         struct stacker c = { "Carol" };
17         struct stacker *stacker;
18
19         /* This is how many tests you plan to run */
20         plan_tests(18);
21
22         ok1(lstack_empty(&s));
23         diag("top = %p\n", lstack_top(&s));
24         ok1(lstack_top(&s) == NULL);
25
26         lstack_push(&s, &a);
27
28         ok1(!lstack_empty(&s));
29         ok1(lstack_top(&s) == &a);
30
31         lstack_push(&s, &b);
32
33         ok1(!lstack_empty(&s));
34         ok1(lstack_top(&s) == &b);
35
36         lstack_push(&s, &c);
37
38         ok1(!lstack_empty(&s));
39         ok1(lstack_top(&s) == &c);
40
41         stacker = lstack_pop(&s);
42         ok1(stacker == &c);
43
44         ok1(!lstack_empty(&s));
45         ok1(lstack_top(&s) == &b);
46
47         stacker = lstack_pop(&s);
48         ok1(stacker == &b);
49
50         ok1(!lstack_empty(&s));
51         ok1(lstack_top(&s) == &a);
52
53         stacker = lstack_pop(&s);
54         ok1(stacker == &a);
55
56         ok1(lstack_empty(&s));
57         ok1(lstack_top(&s) == NULL);
58
59         ok1(lstack_pop(&s) == NULL);
60
61         /* This exits depending on whether all tests passed */
62         return exit_status();
63 }