]> git.ozlabs.org Git - ccan/blobdiff - ccan/tcon/test/compile_ok-sizeof.c
tcon: Add tcon_sizeof() helper
[ccan] / ccan / tcon / test / compile_ok-sizeof.c
diff --git a/ccan/tcon/test/compile_ok-sizeof.c b/ccan/tcon/test/compile_ok-sizeof.c
new file mode 100644 (file)
index 0000000..64ccc13
--- /dev/null
@@ -0,0 +1,35 @@
+#include <ccan/tcon/tcon.h>
+#include <ccan/build_assert/build_assert.h>
+#include <stdlib.h>
+
+struct container {
+       void *p;
+};
+
+struct int_container {
+       struct container raw;
+       TCON(int tc);
+};
+
+struct charp_and_int_container {
+       struct container raw;
+       TCON(int tc1; char *tc2);
+};
+
+int main(int argc, char *argv[])
+{
+       struct int_container icon;
+       struct charp_and_int_container cicon;
+       TCON_WRAP(struct container, int tc) iconw;
+       TCON_WRAP(struct container, int tc1; char *tc2) ciconw;
+
+       BUILD_ASSERT(tcon_sizeof(&icon, tc) == sizeof(int));
+       BUILD_ASSERT(tcon_sizeof(&cicon, tc1) == sizeof(int));
+       BUILD_ASSERT(tcon_sizeof(&cicon, tc2) == sizeof(char *));
+
+       BUILD_ASSERT(tcon_sizeof(&iconw, tc) == sizeof(int));
+       BUILD_ASSERT(tcon_sizeof(&ciconw, tc1) == sizeof(int));
+       BUILD_ASSERT(tcon_sizeof(&ciconw, tc2) == sizeof(char *));
+
+       return 0;
+}