]> git.ozlabs.org Git - ccan/blob - ccan/autodata/test/run.c
autodata: stash pointers in a binary.
[ccan] / ccan / autodata / test / run.c
1 #include <ccan/autodata/autodata.h>
2 /* Include the C files directly. */
3 #include <ccan/autodata/autodata.c>
4 #include <ccan/tap/tap.h>
5
6 AUTODATA_TYPE(autostrings, char);
7
8 AUTODATA(autostrings, "hello");
9 AUTODATA(autostrings, "world");
10
11 int main(void)
12 {
13         char **table;
14         size_t num;
15         int i, hello = -1, world = -1, helper = -1;
16
17         /* This is how many tests you plan to run */
18         plan_tests(4);
19
20         table = autodata_get(autostrings, &num);
21         ok1(num == 3);
22
23         for (i = 0; i < num; i++) {
24                 if (strcmp(table[i], "hello") == 0)
25                         hello = i;
26                 else if (strcmp(table[i], "world") == 0)
27                         world = i;
28                 else if (strcmp(table[i], "helper") == 0)
29                         helper = i;
30                 else
31                         fail("Unknown entry %s", table[i]);
32         }
33         ok1(hello != -1);
34         ok1(world != -1);
35         ok1(helper != -1);
36
37         autodata_free(table);
38
39         /* This exits depending on whether all tests passed */
40         return exit_status();
41 }