Github User Fetcher
1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
new/assert.h
Go to the documentation of this file.
1
/*
2
* The MIT License (MIT)
3
*
4
* Copyright © 2017 Franklin "Snaipe" Mathieu <http://snai.pe/>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
* THE SOFTWARE.
23
*/
24
#ifndef CRITERION_NEW_ASSERT_H_
25
#define CRITERION_NEW_ASSERT_H_
26
#ifdef CRITERION_DOCGEN
27
28
/**
29
* Assertion API
30
*
31
* @defgroup AssertAPI Assertion API
32
* @{
33
*/
34
35
/**
36
* Mark the test as failed.
37
*
38
* The test is marked as a failure, printing the formatted string if provided,
39
* and the execution continues.
40
*
41
* @param[in] Format (optional) Printf-like format string
42
* @param[in] ... Format string parameters
43
*/
44
#define cr_fail(Format, ...)
45
46
/**
47
* Abort and mark the test as failed.
48
*
49
* The test is marked as a failure, printing the formatted string if provided,
50
* and the execution of the test is aborted.
51
*
52
* @param[in] Format (optional) Printf-like format string
53
* @param[in] ... Format string parameters
54
*/
55
#define cr_fatal(Format, ...)
56
57
/**
58
* Abort and mark the test as skipped.
59
*
60
* The test is marked as skipped, printing the formatted string if provided,
61
* and the execution of the test is aborted.
62
*
63
* @param[in] Format (optional) Printf-like format string
64
* @param[in] ... Format string parameters
65
*/
66
#define cr_skip(Format, ...)
67
68
/**
69
* Assert that a criterion is true and abort if it is not.
70
*
71
* cr_assert evaluates the passed criterion and passes if it has a non-zero
72
* value.
73
*
74
* The criterion may be any C expression of non-void type, in which case the
75
* assertion value will be `!!Criterion`.
76
* Alternatively, the criterion may be any of the valid pseudo-functions
77
* described in the [Criteria list](@ref Criteria).
78
*
79
* If the evaluated criterion is zero, then cr_fatal(Format, ...) is called.
80
*
81
* @param[in] Criterion The Criterion to evaluate
82
* @param[in] Format (optional) Printf-like format string
83
* @param[in] ... Format string parameters
84
*/
85
#define cr_assert(Criterion, Format, ...)
86
87
/**
88
* Expect that a criterion is true and fail if it is not.
89
*
90
* cr_expect evaluates the passed criterion and passes if it has a non-zero
91
* value.
92
*
93
* The criterion may be any C expression of non-void type, in which case the
94
* assertion value will be `!!Criterion`.
95
* Alternatively, the criterion may be any of the valid pseudo-functions
96
* described in the [Criteria list](@ref Criteria).
97
*
98
* If the evaluated criterion is zero, then cr_fail(Format, ...) is called.
99
*
100
* @param[in] Criterion The Criterion to evaluate
101
* @param[in] Format (optional) Printf-like format string
102
* @param[in] ... Format string parameters
103
*/
104
#define cr_expect(Criterion, Format, ...)
105
106
/**
107
* cr_assert_user is an utility macro to help users implement their own
108
* assertions easily.
109
*
110
* Users may pass file and line information. The function behaves like
111
* cr_assert and cr_expect, in that it evaluates the criterion to determine
112
* whether a test fails or not.
113
*
114
* When the criterion evaluates to zero, a failed assertion event is raised
115
* back to the runner, and then FailFunc is called without parameters.
116
*
117
* @param[in] File The file in which the assertion has been
118
* called.
119
* @param[in] Line The line number at which the assertion has been
120
* called.
121
* @param[in] FailFunc The function to call on a failed assertion.
122
* @param[in] Criterion The Criterion to evaluate.
123
* @param[in] Format (optional) Printf-like format string.
124
* @param[in] ... Format string parameters.
125
*/
126
#define cr_assert_user(File, Line, FailFunc, Criterion, Format, ...)
127
128
/**@}*/
129
130
/**
131
* Criteria are pseudo-functions that evaluate to a boolean value.
132
*
133
* Using criteria is recommended over standard C operator as they allow
134
* value pretty printing and other diagnostics on assertion failure.
135
*
136
* @note Criteria are neither symbols or macros, but pseudo-functions. They
137
* are only valid in the context of the assertion API when explicitely
138
* allowed and cannot be called alone.
139
*
140
* @defgroup Criteria Criteria
141
* @{
142
*/
143
144
/**
145
* Evaluates to `!Criterion`.
146
*
147
* @param[in] Criterion The criterion to negate
148
*/
149
#define not(Criterion)
150
151
/**
152
* Evaluates to true if all its arguments are true.
153
*
154
* all() evaluates a sequence of criteria, and combines them into
155
* a single value with the logical and operator (&&).
156
*
157
* @param[in] ... A sequence of criteria to evaluate
158
*/
159
#define all(...)
160
161
/**
162
* Evaluates to true if any of its arguments is true.
163
*
164
* any() evaluates a sequence of criteria, and combines them into
165
* a single value with the logical or operator (||).
166
*
167
* @param[in] ... A sequence of criteria to evaluate
168
*/
169
#define any(...)
170
171
/**
172
* Evaluates to true if none of its arguments is true.
173
*
174
* none() evaluates a sequence of criteria, and combines their negation into
175
* a single value with the logical and operator (&&).
176
*
177
* @param[in] ... A sequence of criteria to evaluate
178
*/
179
#define none(...)
180
181
/**
182
* Tagged Criteria are special criteria that take an optional
183
* type tag as their first argument.
184
*
185
* Unless otherwise specified, all tagged criteria generally support
186
* any of the [supported tags](@ref Tags)
187
*
188
* @defgroup TaggedCriteria Tagged Criteria
189
* @{
190
*/
191
192
/**
193
* Evaluates to `Actual == Expected`.
194
*
195
* While this operator works for `flt`, `dbl`, and `ldbl`, the chance of having
196
* the values being exactly equal to each other is astronomically low due to
197
* round-off errors. Instead, please use as appropriate @ref ieee_ulp_eq and
198
* @ref epsilon_eq
199
*
200
* @param[in] "Tag (optional)" The type tag of the parameters
201
* @param[in] Actual the actual value
202
* @param[in] Expected the expected value
203
*/
204
#define eq(Tag, Actual, Expected)
205
206
/**
207
* Evaluates to `Actual != Unexpected`.
208
*
209
* While this operator works for `flt`, `dbl`, and `ldbl`, the chance of having
210
* the values being exactly equal to each other is astronomically low due to
211
* round-off errors. Instead, please use as appropriate @ref ieee_ulp_ne and
212
* @ref epsilon_ne
213
*
214
* @param[in] "Tag (optional)" The type tag of the parameters
215
* @param[in] Actual the actual value
216
* @param[in] Unexpected the unexpected value
217
*/
218
#define ne(Tag, Actual, Unexpected)
219
220
/**
221
* Evaluates to `Actual < Reference`.
222
*
223
* @param[in] "Tag (optional)" The type tag of the parameters
224
* @param[in] Actual the actual value
225
* @param[in] Reference the reference value
226
*/
227
#define lt(Tag, Actual, Reference)
228
229
/**
230
* Evaluates to `Actual <= Reference`.
231
*
232
* @param[in] "Tag (optional)" The type tag of the parameters
233
* @param[in] Actual the actual value
234
* @param[in] Reference the reference value
235
*/
236
#define le(Tag, Actual, Reference)
237
238
/**
239
* Evaluates to `Actual > Reference`.
240
*
241
* @param[in] "Tag (optional)" The type tag of the parameters
242
* @param[in] Actual the actual value
243
* @param[in] Reference the reference value
244
*/
245
#define gt(Tag, Actual, Reference)
246
247
/**
248
* Evaluates to `Actual >= Reference`.
249
*
250
* @param[in] "Tag (optional)" The type tag of the parameters
251
* @param[in] Actual the actual value
252
* @param[in] Reference the reference value
253
*/
254
#define ge(Tag, Actual, Reference)
255
256
/**
257
* Evaluates to true if `Value` is equal to the "zero value" of its type.
258
*
259
* The zero value for primitive types and pointer types is the constant 0.
260
*
261
* The zero value for c-strings (char *, wchar_t *) is the empty string,
262
* "" and L"" respectively.
263
*
264
* User-defined types may be used, but what a zero value of these types
265
* mean depend on the language used.
266
*
267
* In C, the function `bool cr_user_<type>_zero(const <type> *t)` must be
268
* defined, and will be invoked to check that `t` is a zero value.
269
*
270
* In C++, the type corresponding to the passed tag, or the inferred type of
271
* Value if the tag is unspecified, must be default-constructible. The
272
* zero value of that type is the default construction of that type, and
273
* the value is compared against it with ==.
274
*
275
* @param[in] "Tag (optional)" The type tag of the parameter
276
* @param[in] Value the value to compare for zeroness
277
*/
278
#define zero(Tag, Value)
279
280
/**
281
* Evaluates to true if the IEEE 754 floating point numbers `Actual` and
282
* `Expected` are almost equal, by being within `Ulp` units from each other.
283
*
284
* This method of comparison is more accurate when comparing two IEEE 754
285
* floating point values when `Expected` is non-zero.
286
* When comparing against zero, please use [epsilon_eq](@ref epsilon_eq)
287
* instead.
288
*
289
* This tagged criterion only supports the `flt`, `dbl` and `ldbl` tags.
290
*
291
* A good general-purpose value for Ulp is `4`.
292
*
293
* @param[in] "Tag (optional)" The type tag of the parameters
294
* @param[in] Actual the actual value
295
* @param[in] Expected the reference value
296
* @param[in] Ulp the number of units in the last place used in the comparison
297
*/
298
#define ieee_ulp_eq(Tag, Actual, Expected, Ulp)
299
300
/**
301
* Evaluates to true if the IEEE 754 floating point numbers `Actual` and
302
* `Expected` are different, by not being within `Ulp` units from each other.
303
*
304
* This method of comparison is more accurate when comparing two IEEE 754
305
* floating point values when `Expected` is non-zero.
306
* When comparing against zero, please use [epsilon_ne](@ref epsilon_ne)
307
* instead.
308
*
309
* This tagged criterion only supports the `flt`, `dbl` and `ldbl` tags.
310
*
311
* A good general-purpose value for Ulp is `4`.
312
*
313
* @param[in] "Tag (optional)" The type tag of the parameters
314
* @param[in] Actual the actual value
315
* @param[in] Expected the reference value
316
* @param[in] Ulp the number of units in the last place used in the comparison
317
*/
318
#define ieee_ulp_ne(Tag, Actual, Expected, Ulp)
319
320
/**
321
* Evaluates to true if the floating point numbers `Actual` and `Expected`
322
* are almost equal, by being within an absolute `Epsilon` from each other
323
* (In other words, if `fabs(Actual - Expected) <= Epsilon`).
324
*
325
* This method of comparison is more accurate when comparing two IEEE 754
326
* floating point values that are near zero.
327
* When comparing against values that aren't near zero, please use
328
* [ieee_ulp_eq](@ref ieee_ulp_eq) instead.
329
*
330
* This tagged criterion only supports the `flt`, `dbl` and `ldbl` tags.
331
*
332
* It is recommended to have `Epsilon` be equal to a small multiple of the
333
* type epsilon (`FLT_EPSILON`, `DBL_EPSILON`, `LDBL_EPSILON`) and the
334
* input parameters.
335
*
336
* @param[in] "Tag (optional)" The type tag of the parameters
337
* @param[in] Actual the actual value
338
* @param[in] Expected the reference value
339
* @param[in] Epsilon the epsilon used in the comparison
340
*/
341
#define epsilon_eq(Tag, Actual, Expected, Epsilon)
342
343
/**
344
* Evaluates to true if the floating point numbers `Actual` and `Expected`
345
* are different, by not being within an absolute `Epsilon` from each other
346
* (In other words, if `fabs(Actual - Expected) > Epsilon`).
347
*
348
* This method of comparison is more accurate when comparing two IEEE 754
349
* floating point values that are near zero.
350
* When comparing against values that aren't near zero, please use
351
* [ieee_ulp_eq](@ref ieee_ulp_eq) instead.
352
*
353
* This tagged criterion only supports the `flt`, `dbl` and `ldbl` tags.
354
*
355
* It is recommended to have `Epsilon` be equal to a small multiple of the
356
* type epsilon (`FLT_EPSILON`, `DBL_EPSILON`, `LDBL_EPSILON`) and the
357
* input parameters.
358
*
359
* @param[in] "Tag (optional)" The type tag of the parameters
360
* @param[in] Actual the actual value
361
* @param[in] Expected the reference value
362
* @param[in] Epsilon the epsilon used in the comparison
363
*/
364
#define epsilon_ne(Tag, Actual, Expected, Epsilon)
365
366
/**@}*/
367
/**@}*/
368
369
/**
370
* Tags are special tokens representing a type, that allow Criterion to infer
371
* type information on parameters for better diagnostics on assertion failure.
372
*
373
* Any tag may also use the square-bracket array subscript notation to denote
374
* an array type tag, like `i8[16]` or `type(struct user)[2]`, in which case
375
* the criterion will apply on each element of this array.
376
*
377
* @note A tag is a special, Criterion-specific language token. It it neither
378
* a symbol nor a macro, and cannot be used in any other context than when
379
* explicitely allowed.
380
*
381
* @defgroup Tags
382
* @{
383
*/
384
385
#define i8 int8_t
386
#define i16 int16_t
387
#define i32 int32_t
388
#define i64 int64_t
389
#define u8 uint8_t
390
#define u16 uint16_t
391
#define u32 uint32_t
392
#define u64 uint64_t
393
#define sz size_t
394
#define ptr void *
395
#define iptr intptr_t
396
#define uptr uintptr_t
397
#define chr char
398
#define int int
399
#define uint unsigned int
400
#define long long
401
#define ulong unsigned long
402
#define llong long long
403
#define ullong unsigned long long
404
#define flt float
405
#define dbl double
406
#define ldbl long double
407
#define cx_flt complex float
408
#define cx_dbl complex double
409
#define cx_ldbl complex long double
410
#define mem struct cr_mem
411
#define str const char *
412
#define wcs const wchar_t *
413
#define tcs const TCHAR *
414
415
/**
416
* Represent an user-defined type.
417
*
418
* The user type must be printable, and as such must implement a "to-string"
419
* operation:
420
*
421
* (C only) char *cr_mem_<type>_tostr(const <type> *val);
422
* (C++ only) std::ostream &operator<<(std::ostream &os, const <type> &val);
423
*
424
* Additionally, the user must implement the following functions to use
425
* various general-purpose criteria:
426
*
427
* [eq](@ref eq), [ne](@ref ne), [le](@ref le), [ge](@ref ge):
428
*
429
* (C only) int cr_mem_<type>_eq(const <type> *lhs, const <type> *rhs);
430
* (C++ only) bool operator==(const <type> &lhs, const <type> &rhs);
431
*
432
* [lt](@ref lt), [le](@ref le), [gt](@ref gt), [ge](@ref ge):
433
*
434
* (C only) int cr_mem_<type>_lt(const <type> *lhs, const <type> *rhs);
435
* (C++ only) bool operator<(const <type> &lhs, const <type> &rhs);
436
*
437
* Due to implementation restrictions, UserType must either be a structure,
438
* an union, an enum, or a typedef.
439
*
440
* For instance, these are fine:
441
*
442
* type(foo)
443
* type(struct foo)
444
*
445
* and these are not:
446
*
447
* type(foo *)
448
* type(int (&foo)(void))
449
*
450
* in these cases, use a typedef to alias those types to a single-word token.
451
*
452
*/
453
#define type(UserType) UserType
454
455
/**@}*/
456
457
#endif
/* !CRITERION_DOCGEN */
458
459
#include "
memory.h
"
460
#include "
stream.h
"
461
462
/* Internals */
463
464
#include "
../internal/new_asserts.h
"
465
466
#endif
/* !CRITERION_NEW_ASSERT_H_ */
memory.h
stream.h
new_asserts.h
nix
store
2xpcmdrzviw89gzpf8p7l7691wk51i89-criterion-2.4.2-dev
include
criterion
new
assert.h
Generated by
1.10.0