iscsi, nfs, opt, tap: use config.h instead of defining _GNU_SOURCE.
[ccan] / ccan / opt / test / run-iter.c
1 #include <ccan/tap/tap.h>
2 #include <stdarg.h>
3 #include <setjmp.h>
4 #include <stdlib.h>
5 #include <stdarg.h>
6 #include "utils.h"
7 #include <ccan/opt/opt.c>
8 #include <ccan/opt/usage.c>
9 #include <ccan/opt/helpers.c>
10 #include <ccan/opt/parse.c>
11
12 static void reset_options(void)
13 {
14         free(opt_table);
15         opt_table = NULL;
16         opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0;
17 }
18
19 /* Test iterators. */
20 int main(int argc, char *argv[])
21 {
22         unsigned j, i, len = 0;
23         const char *p;
24
25         plan_tests(37 * 2);
26         for (j = 0; j < 2; j ++) {
27                 reset_options();
28                 /* Giving subtable a title makes an extra entry! */
29                 opt_register_table(subtables, j == 0 ? NULL : "subtable");
30
31                 p = first_lopt(&i, &len);
32                 ok1(i == j + 0);
33                 ok1(len == 3);
34                 ok1(strncmp(p, "jjj", len) == 0);
35                 p = next_lopt(p, &i, &len);
36                 ok1(i == j + 0);
37                 ok1(len == 3);
38                 ok1(strncmp(p, "lll", len) == 0);
39                 p = next_lopt(p, &i, &len);
40                 ok1(i == j + 1);
41                 ok1(len == 3);
42                 ok1(strncmp(p, "mmm", len) == 0);
43                 p = next_lopt(p, &i, &len);
44                 ok1(i == j + 5);
45                 ok1(len == 3);
46                 ok1(strncmp(p, "ddd", len) == 0);
47                 p = next_lopt(p, &i, &len);
48                 ok1(i == j + 6);
49                 ok1(len == 3);
50                 ok1(strncmp(p, "eee", len) == 0);
51                 p = next_lopt(p, &i, &len);
52                 ok1(i == j + 7);
53                 ok1(len == 3);
54                 ok1(strncmp(p, "ggg", len) == 0);
55                 p = next_lopt(p, &i, &len);
56                 ok1(i == j + 8);
57                 ok1(len == 3);
58                 ok1(strncmp(p, "hhh", len) == 0);
59                 p = next_lopt(p, &i, &len);
60                 ok1(!p);
61
62                 p = first_sopt(&i);
63                 ok1(i == j + 0);
64                 ok1(*p == 'j');
65                 p = next_sopt(p, &i);
66                 ok1(i == j + 0);
67                 ok1(*p == 'l');
68                 p = next_sopt(p, &i);
69                 ok1(i == j + 1);
70                 ok1(*p == 'm');
71                 p = next_sopt(p, &i);
72                 ok1(i == j + 2);
73                 ok1(*p == 'a');
74                 p = next_sopt(p, &i);
75                 ok1(i == j + 3);
76                 ok1(*p == 'b');
77                 p = next_sopt(p, &i);
78                 ok1(i == j + 7);
79                 ok1(*p == 'g');
80                 p = next_sopt(p, &i);
81                 ok1(i == j + 8);
82                 ok1(*p == 'h');
83                 p = next_sopt(p, &i);
84                 ok1(!p);
85         }
86
87         return exit_status();
88 }