]> git.ozlabs.org Git - ccan/blobdiff - ccan/ptrint/test/run.c
ptrint: Module for encoding integers into void * pointers
[ccan] / ccan / ptrint / test / run.c
diff --git a/ccan/ptrint/test/run.c b/ccan/ptrint/test/run.c
new file mode 100644 (file)
index 0000000..7d6f934
--- /dev/null
@@ -0,0 +1,29 @@
+#include <limits.h>
+
+#include <ccan/array_size/array_size.h>
+
+#include <ccan/ptrint/ptrint.h>
+#include <ccan/tap/tap.h>
+
+static ptrdiff_t testvals[] = {
+       -INT_MAX, -1, 0, 1, 2, 17, INT_MAX,
+};
+
+int main(void)
+{
+       int i;
+
+       /* This is how many tests you plan to run */
+       plan_tests(2 * ARRAY_SIZE(testvals));
+
+       for (i = 0; i < ARRAY_SIZE(testvals); i++) {
+               ptrdiff_t val = testvals[i];
+               void *ptr = int2ptr(val);
+
+               ok1(ptr2int(ptr) == val);
+               ok1(!val == !ptr);
+       }
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}