1 #include <ccan/container_of/container_of.h>
2 #include <ccan/tap/tap.h>
11 struct foo foo = { .a = 1, .b = 2 };
16 ok1(container_of(intp, struct foo, a) == &foo);
17 ok1(container_of(charp, struct foo, b) == &foo);
18 ok1(container_of_or_null(intp, struct foo, a) == &foo);
19 ok1(container_of_or_null(charp, struct foo, b) == &foo);
20 ok1(container_of_or_null((int *)NULL, struct foo, a) == NULL);
21 ok1(container_of_or_null((char *)NULL, struct foo, b) == NULL);
22 ok1(container_of_var(intp, &foo, a) == &foo);
23 ok1(container_of_var(charp, &foo, b) == &foo);
25 ok1(container_off(struct foo, a) == 0);
26 ok1(container_off(struct foo, b) == offsetof(struct foo, b));
27 ok1(container_off_var(&foo, a) == 0);
28 ok1(container_off_var(&foo, b) == offsetof(struct foo, b));