summaryrefslogtreecommitdiff
path: root/ccan/ptrint/test/run.c
blob: 7d6f934b42367f60ac824e9903fdd9106aabd538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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();
}