RTEMS
t-test-checks.c
1 /*
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (C) 2018 embedded brains GmbH
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <rtems/test.h>
29 
30 #include <inttypes.h>
31 
32 void
33 T_check_eq_ptr(const T_check_context_msg *t, const void *a, const void *e)
34 {
35  T_check(&t->base, a == e, "%s", t->msg);
36 }
37 
38 void
39 T_check_ne_ptr(const T_check_context_msg *t, const void *a, const void *e)
40 {
41  T_check(&t->base, a != e, "%s", t->msg);
42 }
43 
44 void
45 T_check_null(const T_check_context_msg *t, const void *a)
46 {
47  T_check(&t->base, a == NULL, "%s == NULL", t->msg);
48 }
49 
50 void
51 T_check_not_null(const T_check_context_msg *t, const void *a)
52 {
53  T_check(&t->base, a != NULL, "%s != NULL", t->msg);
54 }
55 
56 void
57 T_check_eq_mem(const T_check_context_msg *t, const void *a, const void *e,
58  size_t n)
59 {
60  T_check(&t->base, memcmp(a, e, n) == 0, "%s", t->msg);
61 }
62 
63 void
64 T_check_ne_mem(const T_check_context_msg *t, const void *a, const void *e,
65  size_t n)
66 {
67  T_check(&t->base, memcmp(a, e, n) != 0, "%s", t->msg);
68 }
69 
70 void
71 T_check_eq_str(const T_check_context *t, const char *a, const char *e)
72 {
73  T_check(t, strcmp(a, e) == 0, "\"%s\" == \"%s\"", a, e);
74 }
75 
76 void
77 T_check_ne_str(const T_check_context *t, const char *a, const char *e)
78 {
79  T_check(t, strcmp(a, e) != 0, "\"%s\" != \"%s\"", a, e);
80 }
81 
82 void
83 T_check_eq_nstr(const T_check_context *t, const char *a, const char *e, size_t n)
84 {
85  T_check(t, strncmp(a, e, n) == 0, "\"%.*s\" == \"%.*s\"", (int)n, a,
86  (int)n, e);
87 }
88 
89 void
90 T_check_ne_nstr(const T_check_context *t, const char *a, const char *e, size_t n)
91 {
92  T_check(t, strncmp(a, e, n) != 0, "\"%.*s\" != \"%.*s\"", (int)n, a,
93  (int)n, e);
94 }
95 
96 void
97 T_check_eq_char(const T_check_context *t, char a, char e)
98 {
99  T_check(t, a == e, "'%c' == '%c'", a, e);
100 }
101 
102 void
103 T_check_ne_char(const T_check_context *t, char a, char e)
104 {
105  T_check(t, a != e, "'%c' != '%c'", a, e);
106 }
107 
108 void
109 T_check_eq_int(const T_check_context *t, int a, int e)
110 {
111  T_check(t, a == e, "%i == %i", a, e);
112 }
113 
114 void
115 T_check_ne_int(const T_check_context *t, int a, int e)
116 {
117  T_check(t, a != e, "%i != %i", a, e);
118 }
119 
120 void
121 T_check_ge_int(const T_check_context *t, int a, int e)
122 {
123  T_check(t, a >= e, "%i >= %i", a, e);
124 }
125 
126 void
127 T_check_gt_int(const T_check_context *t, int a, int e)
128 {
129  T_check(t, a > e, "%i > %i", a, e);
130 }
131 
132 void
133 T_check_le_int(const T_check_context *t, int a, int e)
134 {
135  T_check(t, a <= e, "%i <= %i", a, e);
136 }
137 
138 void
139 T_check_lt_int(const T_check_context *t, int a, int e)
140 {
141  T_check(t, a < e, "%i < %i", a, e);
142 }
143 
144 void
145 T_check_eq_uint(const T_check_context *t, unsigned int a, unsigned int e)
146 {
147  T_check(t, a == e, "%u == %u", a, e);
148 }
149 
150 void
151 T_check_ne_uint(const T_check_context *t, unsigned int a, unsigned int e)
152 {
153  T_check(t, a != e, "%u != %u", a, e);
154 }
155 
156 void
157 T_check_ge_uint(const T_check_context *t, unsigned int a, unsigned int e)
158 {
159  T_check(t, a >= e, "%u >= %u", a, e);
160 }
161 
162 void
163 T_check_gt_uint(const T_check_context *t, unsigned int a, unsigned int e)
164 {
165  T_check(t, a > e, "%u > %u", a, e);
166 }
167 
168 void
169 T_check_le_uint(const T_check_context *t, unsigned int a, unsigned int e)
170 {
171  T_check(t, a <= e, "%u <= %u", a, e);
172 }
173 
174 void
175 T_check_lt_uint(const T_check_context *t, unsigned int a, unsigned int e)
176 {
177  T_check(t, a < e, "%u < %u", a, e);
178 }
179 
180 void
181 T_check_eq_long(const T_check_context *t, long a, long e)
182 {
183  T_check(t, a == e, "%li == %li", a, e);
184 }
185 
186 void
187 T_check_ne_long(const T_check_context *t, long a, long e)
188 {
189  T_check(t, a != e, "%li != %li", a, e);
190 }
191 
192 void
193 T_check_ge_long(const T_check_context *t, long a, long e)
194 {
195  T_check(t, a >= e, "%li >= %li", a, e);
196 }
197 
198 void
199 T_check_gt_long(const T_check_context *t, long a, long e)
200 {
201  T_check(t, a > e, "%li > %li", a, e);
202 }
203 
204 void
205 T_check_le_long(const T_check_context *t, long a, long e)
206 {
207  T_check(t, a <= e, "%li <= %li", a, e);
208 }
209 
210 void
211 T_check_lt_long(const T_check_context *t, long a, long e)
212 {
213  T_check(t, a < e, "%li < %li", a, e);
214 }
215 
216 void
217 T_check_eq_ulong(const T_check_context *t, unsigned long a, unsigned long e)
218 {
219  T_check(t, a == e, "%lu == %lu", a, e);
220 }
221 
222 void
223 T_check_ne_ulong(const T_check_context *t, unsigned long a, unsigned long e)
224 {
225  T_check(t, a != e, "%lu != %lu", a, e);
226 }
227 
228 void
229 T_check_ge_ulong(const T_check_context *t, unsigned long a, unsigned long e)
230 {
231  T_check(t, a >= e, "%lu >= %lu", a, e);
232 }
233 
234 void
235 T_check_gt_ulong(const T_check_context *t, unsigned long a, unsigned long e)
236 {
237  T_check(t, a > e, "%lu > %lu", a, e);
238 }
239 
240 void
241 T_check_le_ulong(const T_check_context *t, unsigned long a, unsigned long e)
242 {
243  T_check(t, a <= e, "%lu <= %lu", a, e);
244 }
245 
246 void
247 T_check_lt_ulong(const T_check_context *t, unsigned long a, unsigned long e)
248 {
249  T_check(t, a < e, "%lu < %lu", a, e);
250 }
251 
252 void
253 T_check_eq_ll(const T_check_context *t, long long a, long long e)
254 {
255  T_check(t, a == e, "%lli == %lli", a, e);
256 }
257 
258 void
259 T_check_ne_ll(const T_check_context *t, long long a, long long e)
260 {
261  T_check(t, a != e, "%lli != %lli", a, e);
262 }
263 
264 void
265 T_check_ge_ll(const T_check_context *t, long long a, long long e)
266 {
267  T_check(t, a >= e, "%lli >= %lli", a, e);
268 }
269 
270 void
271 T_check_gt_ll(const T_check_context *t, long long a, long long e)
272 {
273  T_check(t, a > e, "%lli > %lli", a, e);
274 }
275 
276 void
277 T_check_le_ll(const T_check_context *t, long long a, long long e)
278 {
279  T_check(t, a <= e, "%lli <= %lli", a, e);
280 }
281 
282 void
283 T_check_lt_ll(const T_check_context *t, long long a, long long e)
284 {
285  T_check(t, a < e, "%lli < %lli", a, e);
286 }
287 
288 void
289 T_check_eq_ull(const T_check_context *t, unsigned long long a,
290  unsigned long long e)
291 {
292  T_check(t, a == e, "%llu == %llu", a, e);
293 }
294 
295 void
296 T_check_ne_ull(const T_check_context *t, unsigned long long a,
297  unsigned long long e)
298 {
299  T_check(t, a != e, "%llu != %llu", a, e);
300 }
301 
302 void
303 T_check_ge_ull(const T_check_context *t, unsigned long long a,
304  unsigned long long e)
305 {
306  T_check(t, a >= e, "%llu >= %llu", a, e);
307 }
308 
309 void
310 T_check_gt_ull(const T_check_context *t, unsigned long long a,
311  unsigned long long e)
312 {
313  T_check(t, a > e, "%llu > %llu", a, e);
314 }
315 
316 void
317 T_check_le_ull(const T_check_context *t, unsigned long long a,
318  unsigned long long e)
319 {
320  T_check(t, a <= e, "%llu <= %llu", a, e);
321 }
322 
323 void
324 T_check_lt_ull(const T_check_context *t, unsigned long long a,
325  unsigned long long e)
326 {
327  T_check(t, a < e, "%llu < %llu", a, e);
328 }