X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftcon%2Ftest%2Fcompile_ok-value.c;fp=ccan%2Ftcon%2Ftest%2Fcompile_ok-value.c;h=d9c911e6d0dba5d0c2e6af802bcc322aa0a2c0ae;hb=fd48aee6393bda1e4eda9f9e52e6d9f818b77211;hp=0000000000000000000000000000000000000000;hpb=cc3db07ecc15f3e1e556387d82318697956e8e0c;p=ccan diff --git a/ccan/tcon/test/compile_ok-value.c b/ccan/tcon/test/compile_ok-value.c new file mode 100644 index 00000000..d9c911e6 --- /dev/null +++ b/ccan/tcon/test/compile_ok-value.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +struct container { + void *p; +}; + +struct val_container { + struct container raw; + TCON(TCON_VALUE(fixed_val, 17)); +}; + +struct other_struct { + char junk1; + int x1; + long junk2; + char *x2; + short junk3; +}; + +struct offs_container { + struct container raw; + TCON(TCON_VALUE(off1, offsetof(struct other_struct, x1)); + TCON_VALUE(off2, offsetof(struct other_struct, x2))); +}; + +int main(int argc, char *argv[]) +{ + struct val_container valcon; + struct offs_container offscon; + TCON_WRAP(struct container, TCON_VALUE(fixed_val, 17)) valconw; + TCON_WRAP(struct container, + TCON_VALUE(off1, offsetof(struct other_struct, x1)); + TCON_VALUE(off2, offsetof(struct other_struct, x2))) offsconw; + + BUILD_ASSERT(tcon_value(&valcon, fixed_val) == 17); + BUILD_ASSERT(tcon_value(&valconw, fixed_val) == 17); + + BUILD_ASSERT(tcon_value(&offscon, off1) + == offsetof(struct other_struct, x1)); + BUILD_ASSERT(tcon_value(&offscon, off2) + == offsetof(struct other_struct, x2)); + BUILD_ASSERT(tcon_value(&offsconw, off1) + == offsetof(struct other_struct, x1)); + BUILD_ASSERT(tcon_value(&offsconw, off2) + == offsetof(struct other_struct, x2)); + + return 0; +}