blob: bc8778951bddad9e6069a72b25c4dc5b936e9955 [file] [log] [blame]
Norman James6a58a272015-10-07 14:34:16 -05001#include <ccan/container_of/container_of.h>
2#include <ccan/tap/tap.h>
3
4struct foo {
5 int a;
6 char b;
7};
8
9int main(int argc, char *argv[])
10{
11 struct foo foo = { .a = 1, .b = 2 };
12 int *intp = &foo.a;
13 char *charp = &foo.b;
14
15 plan_tests(6);
16 ok1(container_of(intp, struct foo, a) == &foo);
17 ok1(container_of(charp, struct foo, b) == &foo);
18 ok1(container_of_var(intp, &foo, a) == &foo);
19 ok1(container_of_var(charp, &foo, b) == &foo);
20
21 ok1(container_off(struct foo, a) == 0);
22 ok1(container_off(struct foo, b) == offsetof(struct foo, b));
23 return exit_status();
24}