-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemunit_assertions_range.h
More file actions
412 lines (394 loc) · 15.1 KB
/
Copy pathemunit_assertions_range.h
File metadata and controls
412 lines (394 loc) · 15.1 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#ifndef EMUNIT_ASSERTIONS_RANGE_H_INCLUDED
#define EMUNIT_ASSERTIONS_RANGE_H_INCLUDED
/* EMUnit embedded unit test engine - Copyright (C) 2017 Radoslaw Koppel
*
* This program is free software: you can redistribute it and/or modify
* in under the terms of the GNU General Public license (version 3)
* as published by the Free Software Foundation AND MODIFIED BY the
* EMUnit exception.
*
* NOTE: The exception was added to the GPL to ensure
* that you can test any kind of software without being
* obligated to release the whole source code under the terms of GPL.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the EMUnit license exception along with this program.
* If not, it can be viewed in the original EMunit repository:
* <https://github.com/rkel/emunit>.
*/
/**
* @file
* @brief EMUnit header with range assertions
* @author Radosław Koppel <r.koppel\@k-el.com>
* @date 2017
*
* @sa emunit_assertions_range_group
*/
/**
* @addtogroup emunit_assertions_int_group
* @{
*/
/**
* @brief Base range assertion
*
* This assertion is used to build any other type of range assertions.
* @param su Signed or unsigned type (place s or u here).
* @param var_t Variable type - this type of temporary variable would be
* created and would be initialised by input value.
* No casting is used to get compiler warning if data loss
* is possible.
* @param nt Numeric type to be set
* @param min Minimal expected value
* @param max Maximal expected value
* @param actual Actual value
*
* @sa ut_assert_range
*/
#define UT_ASSERT_RANGE_x(su, var_t, nt, min, max, actual) \
do{ \
var_t UT_ASSERT_DELTA_x_min = (min); \
var_t UT_ASSERT_DELTA_x_max = (max); \
var_t UT_ASSERT_DELTA_x_actual = (actual); \
EMUNIT_CALL_ASSERT(nt, ut_assert_range, \
( \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_min}, \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_max}, \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_actual} \
) \
); \
}while(0)
/**
* @brief Base range assertion with message
*
* This is message version of @ref UT_ASSERT_RANGE_x.
* The formated message is processed and displayed if assertion fails.
*
* @copydetails UT_ASSERT_RANGE_x
* @param ... @param ... Format string followed by the format values.
* Standard @c printf format is used.
*/
#define UT_ASSERT_RANGE_MSG_x(su, var_t, nt, min, max, actual, ...) \
do{ \
var_t UT_ASSERT_DELTA_x_min = (min); \
var_t UT_ASSERT_DELTA_x_max = (max); \
var_t UT_ASSERT_DELTA_x_actual = (actual); \
EMUNIT_CALL_ASSERT_MSG(nt, ut_assert_range, \
( \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_min}, \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_max}, \
(emunit_num_t){.su = UT_ASSERT_DELTA_x_actual} \
), \
__VA_ARGS__ \
); \
}while(0)
/** @} <!-- emunit_assertions_int_group --> */
/**
* @defgroup emunit_assertions_range_group <emunit_assertions_range> Range assertions
* @ingroup emunit_assertions_group
* @{
*
* Assertions that checks if assertion is in selected range.
* There are two options:
* 1. If min <= max test is performed if actual value is between min and max (including min/max values).
* 2. If min > max test is performed if actual value is outside min and max (but including min and max into valid values).
*
* This way following code:
*
* @code
* UT_ASSERT_RANGE_INT8(100, 50, val);
* @endcode
*
* Is valid if @c val is between -128 and 50 or between 100 and 127.
*/
/**
* @defgroup emunit_assertions_range_def_group <emunit_assertions_range_def> Default assertions
* @{
*
* Default range assertions.
*/
/**
* @def UT_ASSERT_RANGE(min, max, a)
* @brief Default integer in range assertion
*
* This macro maps directly to @ref UT_ASSERT_RANGE_INT
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
*/
/**
* @def UT_ASSERT_RANGE_INT(min, max, a)
* @brief Default signed integer in range assertion
*
* Macro that checks signed integer value with maximum allowed size.
*
* @sa EMUNIT_CONF_NUMBER_SIZE
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
*/
/**
* @def UT_ASSERT_RANGE_UINT(min, max, a)
* @brief Default unsigned integer in range assertion
*
* Macro that checks unsigned integer value with maximum allowed size.
*
* @sa EMUNIT_CONF_NUMBER_SIZE
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
*/
/**
* @def UT_ASSERT_RANGE_HEX(min, max a)
* @brief Default unsigned integer assertion in range - hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_UINT
*/
#define UT_ASSERT_RANGE(min, max, a) UT_ASSERT_RANGE_INT(min, max, a)
#define UT_ASSERT_RANGE_INT( min, max, a) EMUNIT_CN2(UT_ASSERT_RANGE_INT, EMUNIT_CONF_NUMBER_SIZE)(min, max, a)
#define UT_ASSERT_RANGE_UINT(min, max, a) EMUNIT_CN2(UT_ASSERT_RANGE_UINT, EMUNIT_CONF_NUMBER_SIZE)(min, max, a)
#define UT_ASSERT_RANGE_HEX( min, max, a) EMUNIT_CN2(UT_ASSERT_RANGE_HEX, EMUNIT_CONF_NUMBER_SIZE)(min, max, a)
/**
* @def UT_ASSERT_RANGE_MSG(min, max, a, ...)
* @brief Default integer in range assertion with message
*
* This macro maps directly to @ref UT_ASSERT_RANGE_INT
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
* @param[in] ... Format string followed by the format values.
* Standard @c printf format is used.
*/
/**
* @def UT_ASSERT_RANGE_INT_MSG(min, max, a, ...)
* @brief Default signed integer in range assertion with message
*
* Macro that checks signed integer value with maximum allowed size.
*
* @sa EMUNIT_CONF_NUMBER_SIZE
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
* @param[in] ... Format string followed by the format values.
* Standard @c printf format is used.
*/
/**
* @def UT_ASSERT_RANGE_UINT_MSG(min, max, a, ...)
* @brief Default unsigned integer in range assertion with message
*
* Macro that checks unsigned integer value with maximum allowed size.
*
* @sa EMUNIT_CONF_NUMBER_SIZE
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
* @param[in] ... Format string followed by the format values.
* Standard @c printf format is used.
*/
/**
* @def UT_ASSERT_RANGE_HEX_MSG(min, max a, ...)
* @brief Default unsigned integer assertion in range with message - hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_UINT_MSG
*/
#define UT_ASSERT_RANGE_MSG(min, max, a, ...) UT_ASSERT_RANGE_INT_MSG(min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_INT_MSG( min, max, a, ...) EMUNIT_CN3(UT_ASSERT_RANGE_INT, EMUNIT_CONF_NUMBER_SIZE, _MSG)(min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_UINT_MSG(min, max, a, ...) EMUNIT_CN3(UT_ASSERT_RANGE_UINT, EMUNIT_CONF_NUMBER_SIZE, _MSG)(min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_HEX_MSG( min, max, a, ...) EMUNIT_CN3(UT_ASSERT_RANGE_HEX, EMUNIT_CONF_NUMBER_SIZE, _MSG)(min, max, a, __VA_ARGS__)
/** @} <!-- emunit_assertions_range_def_group --> */
/**
* @def UT_ASSERT_RANGE_INT8(min, max, a)
* @brief Signed 8-bit assertion
*
* Checks if actual value is between min and max.
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
*/
/**
* @def UT_ASSERT_RANGE_INT16(min, max, a)
* @brief Signed 16-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT8
*/
/**
* @def UT_ASSERT_RANGE_INT32(min, max, a)
* @brief Signed 32-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT16
*
* @note This assertion may be disabled.
* See @ref EMUNIT_CONF_NUMBER_SIZE for details.
*/
/**
* @def UT_ASSERT_RANGE_INT64(min, max, a)
* @brief Signed 64-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT32
*/
/**
* @def UT_ASSERT_RANGE_UINT8(min, max, a)
* @brief Unsigned 8-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT8
*/
/**
* @def UT_ASSERT_RANGE_UINT16(min, max, a)
* @brief Unsigned 16-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT16
*/
/**
* @def UT_ASSERT_RANGE_UINT32(min, max, a)
* @brief Unsigned 32-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT32
*/
/**
* @def UT_ASSERT_RANGE_UINT64(min, max, a)
* @brief Unsigned 64-bit assertion
*
* @copydetails UT_ASSERT_RANGE_INT64
*/
/**
* @def UT_ASSERT_RANGE_HEX8(min, max, a)
* @brief Unsigned 8-bit assertion with hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_INT8
*/
/**
* @def UT_ASSERT_RANGE_HEX16(min, max, a)
* @brief Unsigned 16-bit assertion with hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_INT16
*/
/**
* @def UT_ASSERT_RANGE_HEX32(min, max, a)
* @brief Unsigned 32-bit assertion with hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_INT32
*/
/**
* @def UT_ASSERT_RANGE_HEX64(min, max, a)
* @brief Unsigned 64-bit assertion with hexadecimal display
*
* @copydetails UT_ASSERT_RANGE_INT64
*/
#define UT_ASSERT_RANGE_INT8( min, max, a) UT_ASSERT_RANGE_x(s, int8_t, EMUNIT_NUMTYPE_S8, min, max, a)
#define UT_ASSERT_RANGE_INT16( min, max, a) UT_ASSERT_RANGE_x(s, int16_t, EMUNIT_NUMTYPE_S16, min, max, a)
#define UT_ASSERT_RANGE_INT32( min, max, a) UT_ASSERT_RANGE_x(s, int32_t, EMUNIT_NUMTYPE_S32, min, max, a)
#define UT_ASSERT_RANGE_INT64( min, max, a) UT_ASSERT_RANGE_x(s, int64_t, EMUNIT_NUMTYPE_S64, min, max, a)
#define UT_ASSERT_RANGE_UINT8( min, max, a) UT_ASSERT_RANGE_x(u, uint8_t, EMUNIT_NUMTYPE_U8, min, max, a)
#define UT_ASSERT_RANGE_UINT16(min, max, a) UT_ASSERT_RANGE_x(u, uint16_t, EMUNIT_NUMTYPE_U16, min, max, a)
#define UT_ASSERT_RANGE_UINT32(min, max, a) UT_ASSERT_RANGE_x(u, uint32_t, EMUNIT_NUMTYPE_U32, min, max, a)
#define UT_ASSERT_RANGE_UINT64(min, max, a) UT_ASSERT_RANGE_x(u, uint64_t, EMUNIT_NUMTYPE_U64, min, max, a)
#define UT_ASSERT_RANGE_HEX8( min, max, a) UT_ASSERT_RANGE_x(u, uint8_t, EMUNIT_NUMTYPE_X8, min, max, a)
#define UT_ASSERT_RANGE_HEX16( min, max, a) UT_ASSERT_RANGE_x(u, uint16_t, EMUNIT_NUMTYPE_X16, min, max, a)
#define UT_ASSERT_RANGE_HEX32( min, max, a) UT_ASSERT_RANGE_x(u, uint32_t, EMUNIT_NUMTYPE_X32, min, max, a)
#define UT_ASSERT_RANGE_HEX64( min, max, a) UT_ASSERT_RANGE_x(u, uint64_t, EMUNIT_NUMTYPE_X64, min, max, a)
/**
* @def UT_ASSERT_RANGE_INT8_MSG(min, max, a, ...)
* @brief Signed 8-bit assertion, version with message
*
* Checks if actual value is between min and max.
*
* @param[in] min Minimal expected value
* @param[in] max Maximal expected value
* @param[in] a Actual value
* @param[in] ... Format string followed by the format values.
* Standard @c printf format is used.
*/
/**
* @def UT_ASSERT_RANGE_INT16_MSG(min, max, a, ...)
* @brief Signed 16-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT8_MSG
*/
/**
* @def UT_ASSERT_RANGE_INT32_MSG(min, max, a, ...)
* @brief Signed 32-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT16_MSG
*
* @note This assertion may be disabled.
* See @ref EMUNIT_CONF_NUMBER_SIZE for details.
*/
/**
* @def UT_ASSERT_RANGE_INT64_MSG(min, max, a, ...)
* @brief Signed 64-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT32_MSG
*/
/**
* @def UT_ASSERT_RANGE_UINT8_MSG(min, max, a, ...)
* @brief Unsigned 8-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT8_MSG
*/
/**
* @def UT_ASSERT_RANGE_UINT16_MSG(min, max, a, ...)
* @brief Unsigned 16-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT16_MSG
*/
/**
* @def UT_ASSERT_RANGE_UINT32_MSG(min, max, a, ...)
* @brief Unsigned 32-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT32_MSG
*/
/**
* @def UT_ASSERT_RANGE_UINT64_MSG(min, max, a, ...)
* @brief Unsigned 64-bit assertion, version with message
*
* @copydetails UT_ASSERT_RANGE_INT64_MSG
*/
/**
* @def UT_ASSERT_RANGE_HEX8_MSG(min, max, a, ...)
* @brief Unsigned 8-bit assertion with hexadecimal display, version with message
*
* @copydetails UT_ASSERT_RANGE_INT8_MSG
*/
/**
* @def UT_ASSERT_RANGE_HEX16_MSG(min, max, a, ...)
* @brief Unsigned 16-bit assertion with hexadecimal display, version with message
*
* @copydetails UT_ASSERT_RANGE_INT16_MSG
*/
/**
* @def UT_ASSERT_RANGE_HEX32_MSG(min, max, a, ...)
* @brief Unsigned 32-bit assertion with hexadecimal display, version with message
*
* @copydetails UT_ASSERT_RANGE_INT32_MSG
*/
/**
* @def UT_ASSERT_RANGE_HEX64_MSG(min, max, a, ...)
* @brief Unsigned 64-bit assertion with hexadecimal display, version with message
*
* @copydetails UT_ASSERT_RANGE_INT64_MSG
*/
#define UT_ASSERT_RANGE_INT8_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(s, int8_t, EMUNIT_NUMTYPE_S8, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_INT16_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(s, int16_t, EMUNIT_NUMTYPE_S16, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_INT32_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(s, int32_t, EMUNIT_NUMTYPE_S32, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_INT64_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(s, int64_t, EMUNIT_NUMTYPE_S64, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_UINT8_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint8_t, EMUNIT_NUMTYPE_U8, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_UINT16_MSG(min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint16_t, EMUNIT_NUMTYPE_U16, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_UINT32_MSG(min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint32_t, EMUNIT_NUMTYPE_U32, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_UINT64_MSG(min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint64_t, EMUNIT_NUMTYPE_U64, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_HEX8_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint8_t, EMUNIT_NUMTYPE_X8, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_HEX16_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint16_t, EMUNIT_NUMTYPE_X16, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_HEX32_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint32_t, EMUNIT_NUMTYPE_X32, min, max, a, __VA_ARGS__)
#define UT_ASSERT_RANGE_HEX64_MSG( min, max, a, ...) UT_ASSERT_RANGE_MSG_x(u, uint64_t, EMUNIT_NUMTYPE_X64, min, max, a, __VA_ARGS__)
/** @} <!-- emunit_assertions_range_group --> */
#endif /* EMUNIT_ASSERTIONS_RANGE_H_INCLUDED */