summaryrefslogtreecommitdiffstats
path: root/op-flasher/pflash/ccan/container_of/test/run.c
diff options
context:
space:
mode:
Diffstat (limited to 'op-flasher/pflash/ccan/container_of/test/run.c')
-rw-r--r--op-flasher/pflash/ccan/container_of/test/run.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/op-flasher/pflash/ccan/container_of/test/run.c b/op-flasher/pflash/ccan/container_of/test/run.c
new file mode 100644
index 0000000..bc87789
--- /dev/null
+++ b/op-flasher/pflash/ccan/container_of/test/run.c
@@ -0,0 +1,24 @@
+#include <ccan/container_of/container_of.h>
+#include <ccan/tap/tap.h>
+
+struct foo {
+ int a;
+ char b;
+};
+
+int main(int argc, char *argv[])
+{
+ struct foo foo = { .a = 1, .b = 2 };
+ int *intp = &foo.a;
+ char *charp = &foo.b;
+
+ plan_tests(6);
+ ok1(container_of(intp, struct foo, a) == &foo);
+ ok1(container_of(charp, struct foo, b) == &foo);
+ ok1(container_of_var(intp, &foo, a) == &foo);
+ ok1(container_of_var(charp, &foo, b) == &foo);
+
+ ok1(container_off(struct foo, a) == 0);
+ ok1(container_off(struct foo, b) == offsetof(struct foo, b));
+ return exit_status();
+}
OpenPOWER on IntegriCloud