]> git.ozlabs.org Git - ccan/blob - ccan/autodata/test/run-fools.c
check_type: fix incorrect documentation.
[ccan] / ccan / autodata / test / run-fools.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, "genuine");
9
10 #if !HAVE_SECTION_START_STOP
11 /* These are all fake, to test the various failure paths. */
12 /* Hopefully fake_alpha or fake_omega will test run-past-end. */
13 static const void *NEEDED fake_alpha[] = { (void *)AUTODATA_MAGIC };
14
15 /* Wrong magic in the middle. */
16 static const void *NEEDED fake1[] = { (void *)(AUTODATA_MAGIC ^ 0x10000),
17                                       (void *)&fake1,
18                                       "fake1",
19                                       (void *)"autostrings" };
20
21 /* Wrong self pointer. */
22 static const void *NEEDED fake2[] = { (void *)AUTODATA_MAGIC,
23                                       (void *)&fake1,
24                                       "fake2",
25                                       (void *)"autostrings" };
26
27 /* Wrong name. */
28 static const void *NEEDED fake3[] = { (void *)AUTODATA_MAGIC,
29                                       (void *)&fake3,
30                                       "fake3",
31                                       (void *)"autostrings2" };
32
33 /* Invalid self-pointer. */
34 static const void *NEEDED fake4[] = { (void *)AUTODATA_MAGIC,
35                                       (void *)1UL,
36                                       "fake4",
37                                       (void *)"autostrings" };
38
39 /* Invalid name pointer */
40 static const void *NEEDED fake5[] = { (void *)AUTODATA_MAGIC,
41                                       (void *)&fake5,
42                                       "fake5",
43                                       (void *)1UL };
44
45 /* Invalid contents pointer */
46 static const void *NEEDED fake6[] = { (void *)AUTODATA_MAGIC,
47                                       (void *)&fake6,
48                                       (char *)1UL,
49                                       (void *)"autostrings" };
50
51 static const void *NEEDED fake_omega[] = { (void *)AUTODATA_MAGIC };
52 #endif
53
54 int main(void)
55 {
56         char **table;
57         size_t num;
58
59         /* This is how many tests you plan to run */
60         plan_tests(2);
61
62         table = autodata_get(autostrings, &num);
63         ok1(num == 2);
64         ok1((!strcmp(table[0], "genuine") && !strcmp(table[1], "helper"))
65             || (!strcmp(table[1], "genuine") && !strcmp(table[0], "helper")));
66
67         autodata_free(table);
68
69         /* This exits depending on whether all tests passed */
70         return exit_status();
71 }