argcheck: a module to check argument ranges
[ccan] / ccan / argcheck / test / run.c
1 #include <ccan/tap/tap.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4
5 #include <ccan/argcheck/argcheck.h>
6
7 int main(void)
8 {
9         int a = 0;
10         const int flag = 0x1;
11         const int invalid_flag = 0x0;
12         int *ptr = NULL,
13             *ptr_not_null = &a;
14
15         const char *str = "hello",
16                    *str_zero = "\0",
17                    *str_null = NULL;
18
19         plan_tests(60);
20
21         ok1(!argcheck_int_eq(a, 1));
22         ok1(argcheck_int_eq(a, 0));
23
24         ok1(!argcheck_int_ne(a, 0));
25         ok1(argcheck_int_ne(a, 10));
26
27         ok1(!argcheck_int_ge(a, 1));
28         ok1(argcheck_int_ge(a, 0));
29         ok1(argcheck_int_ge(a, -1));
30
31         ok1(!argcheck_int_gt(a, 1));
32         ok1(!argcheck_int_gt(a, 0));
33         ok1(argcheck_int_gt(a, -1));
34
35         ok1(!argcheck_int_le(a, -1));
36         ok1(argcheck_int_le(a, 0));
37         ok1(argcheck_int_le(a, 1));
38
39         ok1(!argcheck_int_lt(a, -1));
40         ok1(!argcheck_int_lt(a, 0));
41         ok1(argcheck_int_lt(a, 1));
42
43         ok1(!argcheck_int_range(a, 0, -1));
44         ok1(!argcheck_int_range(a, -3, -1));
45         ok1(argcheck_int_range(a, 0, 1));
46         ok1(argcheck_int_range(a, -1, 0));
47
48         ok1(!argcheck_flag_set(a, invalid_flag));
49         ok1(!argcheck_flag_set(a, flag));
50         ok1(argcheck_flag_set(a | flag, flag));
51
52         ok1(!argcheck_flag_unset(a, invalid_flag));
53         ok1(!argcheck_flag_unset(a | flag, flag));
54         ok1(argcheck_flag_unset(a, flag));
55
56         ok1(argcheck_ptr_null(ptr));
57         ok1(!argcheck_ptr_not_null(ptr));
58         ok1(!argcheck_ptr_null(ptr_not_null));
59         ok1(argcheck_ptr_not_null(ptr_not_null));
60
61         ok1(argcheck_str_null(str_null));
62         ok1(!argcheck_str_not_null(str_null));
63         ok1(!argcheck_str_null(str));
64         ok1(argcheck_str_not_null(str));
65         ok1(!argcheck_str_null(str_zero));
66         ok1(argcheck_str_not_null(str_zero));
67
68         ok1(!argcheck_str_zero_len(str_null));
69         ok1(argcheck_str_zero_len(str_zero));
70         ok1(!argcheck_str_zero_len(str));
71
72         ok1(!argcheck_str_not_zero_len(str_null));
73         ok1(!argcheck_str_not_zero_len(str_zero));
74         ok1(argcheck_str_not_zero_len(str));
75
76         ok1(!argcheck_str_min_len(str_null, 1));
77         ok1(!argcheck_str_min_len(str_zero, 1));
78         ok1(argcheck_str_min_len(str, 1));
79
80         ok1(!argcheck_str_max_len(str_null, 1));
81         ok1(argcheck_str_max_len(str_zero, 1));
82         ok1(!argcheck_str_max_len(str, 1));
83
84         ok1(argcheck_str_null_or_zero_len(str_null));
85         ok1(argcheck_str_null_or_zero_len(str_zero));
86         ok1(!argcheck_str_null_or_zero_len(str));
87
88         ok1(argcheck_str_null_or_not_zero_len(str_null));
89         ok1(!argcheck_str_null_or_not_zero_len(str_zero));
90         ok1(argcheck_str_null_or_not_zero_len(str));
91
92         ok1(argcheck_str_null_or_min_len(str_null, 1));
93         ok1(!argcheck_str_null_or_min_len(str_zero, 1));
94         ok1(argcheck_str_null_or_min_len(str, 1));
95
96         ok1(argcheck_str_null_or_max_len(str_null, 1));
97         ok1(argcheck_str_null_or_max_len(str_zero, 1));
98         ok1(!argcheck_str_null_or_max_len(str, 1));
99
100         return exit_status();
101 }