]> git.ozlabs.org Git - ccan/blob - ccan/structeq/test/run-with-padding.c
ccan/structeq: make it safe when there's padding.
[ccan] / ccan / structeq / test / run-with-padding.c
1 #include <ccan/structeq/structeq.h>
2 #include <ccan/tap/tap.h>
3
4 /* In theory, this could be generated without padding, if alignof(int) were 0,
5  * and test would fail.  Call me when that happens. */
6 struct mydata {
7         char start;
8         int end;
9 };
10
11 STRUCTEQ_DEF(mydata, sizeof(int) - sizeof(char), start, end);
12
13 int main(void)
14 {
15         struct mydata a, b;
16
17         /* This is how many tests you plan to run */
18         plan_tests(3);
19
20         a.start = 0;
21         a.end = 100;
22         ok1(mydata_eq(&a, &a));
23
24         b = a;
25         ok1(mydata_eq(&a, &b));
26
27         b.end++;
28         ok1(!mydata_eq(&a, &b));
29
30         /* This exits depending on whether all tests passed */
31         return exit_status();
32 }