Commit | Line | Data |
---|---|---|
39550fe8 MJ |
1 | /* |
2 | * SPDX-License-Identifier: LGPL-2.1-or-later | |
3 | * | |
4 | * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com> | |
5 | */ | |
6 | ||
7 | #include "tap.h" | |
8 | ||
62eb004c | 9 | #define NUM_TESTS 94 |
39550fe8 MJ |
10 | |
11 | static | |
12 | void test_ust_stringify(void) | |
13 | { | |
14 | ok(strcmp(lttng_ust_stringify(1), "1") == 0, "lttng_ust_stringify - literal integer"); | |
15 | ok(strcmp(lttng_ust_stringify(random_identifier), "random_identifier") == 0, "lttng_ust_stringify - identifier"); | |
16 | } | |
17 | ||
18 | #define ok_is_signed(_type) \ | |
19 | ok(lttng_ust_is_signed_type(_type) == true, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is signed") | |
20 | ||
21 | #define ok_is_unsigned(_type) \ | |
22 | ok(lttng_ust_is_signed_type(_type) == false, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is unsigned") | |
23 | ||
24 | static | |
25 | void test_ust_is_signed(void) | |
26 | { | |
27 | /* | |
28 | * Signed types | |
29 | */ | |
30 | ||
31 | ok_is_signed(signed char); | |
32 | ok_is_signed(short); | |
33 | ok_is_signed(int); | |
34 | ok_is_signed(long); | |
35 | ok_is_signed(long long); | |
36 | ok_is_signed(float); | |
37 | ok_is_signed(double); | |
38 | ok_is_signed(long double); | |
39 | ||
40 | ok_is_signed(int8_t); | |
41 | ok_is_signed(int16_t); | |
42 | ok_is_signed(int32_t); | |
43 | ok_is_signed(int64_t); | |
44 | ok_is_signed(intmax_t); | |
45 | ||
46 | ok_is_signed(ssize_t); | |
47 | ok_is_signed(ptrdiff_t); | |
48 | ok_is_signed(intptr_t); | |
49 | ||
50 | /* | |
51 | * Unsigned types | |
52 | */ | |
53 | ||
54 | ok_is_unsigned(unsigned char); | |
55 | ok_is_unsigned(unsigned short); | |
56 | ok_is_unsigned(unsigned int); | |
57 | ok_is_unsigned(unsigned long); | |
58 | ok_is_unsigned(unsigned long long); | |
59 | ||
60 | ok_is_unsigned(uint8_t); | |
61 | ok_is_unsigned(uint16_t); | |
62 | ok_is_unsigned(uint32_t); | |
63 | ok_is_unsigned(uint64_t); | |
64 | ok_is_unsigned(uintmax_t); | |
65 | ||
66 | ok_is_unsigned(bool); | |
67 | ok_is_unsigned(size_t); | |
68 | ||
69 | ok_is_unsigned(void *); | |
70 | } | |
71 | ||
72 | ||
73 | #define ok_is_integer_type(_type) \ | |
74 | ok(lttng_ust_is_integer_type(_type) == true, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is an integer") | |
75 | ||
76 | #define ok_is_not_integer_type(_type) \ | |
77 | ok(lttng_ust_is_integer_type(_type) == false, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is not an integer") | |
78 | ||
79 | static | |
80 | void test_ust_is_integer_type(void) | |
81 | { | |
82 | ok_is_integer_type(char); | |
83 | ok_is_integer_type(short); | |
84 | ok_is_integer_type(int); | |
85 | ok_is_integer_type(long); | |
86 | ok_is_integer_type(long long); | |
87 | ||
88 | ok_is_integer_type(signed char); | |
89 | ok_is_integer_type(signed short); | |
90 | ok_is_integer_type(signed int); | |
91 | ok_is_integer_type(signed long); | |
92 | ok_is_integer_type(signed long long); | |
93 | ||
94 | ok_is_integer_type(unsigned char); | |
95 | ok_is_integer_type(unsigned short); | |
96 | ok_is_integer_type(unsigned int); | |
97 | ok_is_integer_type(unsigned long); | |
98 | ok_is_integer_type(unsigned long long); | |
99 | ||
100 | ok_is_integer_type(int8_t); | |
101 | ok_is_integer_type(int16_t); | |
102 | ok_is_integer_type(int32_t); | |
103 | ok_is_integer_type(int64_t); | |
104 | ok_is_integer_type(intmax_t); | |
105 | ||
106 | ok_is_integer_type(uint8_t); | |
107 | ok_is_integer_type(uint16_t); | |
108 | ok_is_integer_type(uint32_t); | |
109 | ok_is_integer_type(uint64_t); | |
110 | ok_is_integer_type(uintmax_t); | |
111 | ||
112 | ok_is_not_integer_type(float); | |
113 | ok_is_not_integer_type(double); | |
114 | ok_is_not_integer_type(long double); | |
115 | ||
116 | ok_is_not_integer_type(void *); | |
117 | } | |
118 | ||
62eb004c MD |
119 | #define ok_is_pointer_type(_type) \ |
120 | ok(lttng_ust_is_pointer_type(_type) == true, "lttng_ust_is_pointer_type - '" lttng_ust_stringify(_type) "' is a pointer") | |
121 | ||
122 | #define ok_is_not_pointer_type(_type) \ | |
123 | ok(lttng_ust_is_pointer_type(_type) == false, "lttng_ust_is_pointer_type - '" lttng_ust_stringify(_type) "' is not a pointer") | |
124 | ||
125 | struct dummy { | |
126 | int a; | |
127 | }; | |
128 | ||
129 | static | |
130 | void test_ust_is_pointer_type(void) | |
131 | { | |
132 | ok_is_not_pointer_type(char); | |
133 | ok_is_not_pointer_type(short); | |
134 | ok_is_not_pointer_type(int); | |
135 | ok_is_not_pointer_type(long); | |
136 | ok_is_not_pointer_type(long long); | |
137 | ||
138 | ok_is_not_pointer_type(signed char); | |
139 | ok_is_not_pointer_type(signed short); | |
140 | ok_is_not_pointer_type(signed int); | |
141 | ok_is_not_pointer_type(signed long); | |
142 | ok_is_not_pointer_type(signed long long); | |
143 | ||
144 | ok_is_not_pointer_type(unsigned char); | |
145 | ok_is_not_pointer_type(unsigned short); | |
146 | ok_is_not_pointer_type(unsigned int); | |
147 | ok_is_not_pointer_type(unsigned long); | |
148 | ok_is_not_pointer_type(unsigned long long); | |
149 | ||
150 | ok_is_not_pointer_type(int8_t); | |
151 | ok_is_not_pointer_type(int16_t); | |
152 | ok_is_not_pointer_type(int32_t); | |
153 | ok_is_not_pointer_type(int64_t); | |
154 | ok_is_not_pointer_type(intmax_t); | |
155 | ||
156 | ok_is_not_pointer_type(uint8_t); | |
157 | ok_is_not_pointer_type(uint16_t); | |
158 | ok_is_not_pointer_type(uint32_t); | |
159 | ok_is_not_pointer_type(uint64_t); | |
160 | ok_is_not_pointer_type(uintmax_t); | |
161 | ||
162 | ok_is_not_pointer_type(float); | |
163 | ok_is_not_pointer_type(double); | |
164 | ok_is_not_pointer_type(long double); | |
165 | ||
166 | ok_is_pointer_type(void *); | |
167 | ok_is_pointer_type(void **); | |
168 | ok_is_pointer_type(struct dummy *); | |
169 | ok_is_pointer_type(int *); | |
170 | ok_is_pointer_type(float *); | |
171 | ok_is_pointer_type(double *); | |
172 | } | |
173 | ||
39550fe8 MJ |
174 | int main(void) |
175 | { | |
176 | plan_tests(NUM_TESTS); | |
177 | ||
178 | test_ust_stringify(); | |
179 | test_ust_is_signed(); | |
180 | test_ust_is_integer_type(); | |
62eb004c | 181 | test_ust_is_pointer_type(); |
39550fe8 MJ |
182 | |
183 | return exit_status(); | |
184 | } |