Github User Fetcher
1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
theories.h
Go to the documentation of this file.
1
/*
2
* The MIT License (MIT)
3
*
4
* Copyright © 2015-2016 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
/*!
25
* @file
26
* @brief Theory tests
27
*****************************************************************************/
28
#ifndef CRITERION_THEORIES_H_
29
#define CRITERION_THEORIES_H_
30
31
#include "
criterion.h
"
32
33
CR_BEGIN_C_API
34
35
/**
36
* Aborts the current theory iteration.
37
* This function does not return.
38
*/
39
CR_API
void
cr_theory_abort
(
void
);
40
41
CR_END_C_API
42
43
/**
44
* @defgroup TheoryBase Theory and datapoint macros
45
* @{
46
*/
47
48
/**
49
* Defines a new theory test.
50
*
51
* The parameters are selected from a cartesian product defined by a
52
* TheoryDataPoints macro.
53
*
54
* Example:
55
* @code{.c}
56
* Theory((int arg0, double arg1), suite, test) {
57
* // function body
58
* };
59
* @endcode
60
*
61
* @param Params A list of function parameters.
62
* @param Suite The name of the test suite containing this test.
63
* @param Name The name of the test.
64
* @param ... An optional sequence of designated initializer key/value
65
* pairs as described in the `criterion_test_extra_data` structure
66
* (see criterion/types.h).
67
* Example: .exit_code = 1
68
*/
69
#define Theory(Params, Suite, Name, ...) internal
70
71
/**
72
* Defines an array of data points.
73
*
74
* The types of the specified data points *must* match the types of the
75
* associated theory.
76
*
77
* Each entry in the array must be the result of the `DataPoints` macro.
78
*
79
* Example:
80
* @code{.c}
81
* TheoryDataPoints(suite, test) = {
82
* DataPoints(int, 1, 2, 3), // first theory parameter
83
* DataPoints(double, 4.2, 0, -INFINITY), // second theory parameter
84
* };
85
* @endcode
86
*
87
* @param Suite The name of the test suite containing this test.
88
* @param Name The name of the test.
89
*/
90
#define TheoryDataPoints(Suite, Name) CR_TH_INTERNAL_TDPS(Suite, Name)
91
92
/**
93
* Defines a new set of data points.
94
*
95
* @param Type The type of each data point in the set.
96
* @param ... The data points in the set.
97
*/
98
#define DataPoints(Type, ...) CR_EXPAND(CR_TH_INTERNAL_DP(Type, __VA_ARGS__))
99
100
/**@}*/
101
102
/**
103
* @defgroup TheoryInvariants Theory invariants
104
* @{
105
*/
106
107
/**
108
* Assumes `Condition` is true
109
*
110
* Evaluates `Condition` and continues execution if it is true.
111
* Otherwise the current theory iteration aborts without marking the test as
112
* failure.
113
*
114
* @param[in] Condition Condition to test
115
*
116
*****************************************************************************/
117
#define cr_assume(Condition) \
118
do { \
119
if (!(Condition)) \
120
cr_theory_abort(); \
121
} while (0)
122
123
/**
124
* Assumes `Condition` is false
125
*
126
* Evaluates `Condition` and continues execution if it is false.
127
* Otherwise the current theory iteration aborts without marking the test as
128
* failure.
129
*
130
* @param[in] Condition Condition to test
131
*
132
*****************************************************************************/
133
#define cr_assume_not(Condition) cr_assume(!(Condition))
134
135
/**
136
* Assumes `Actual` is equal to `Expected`
137
*
138
* Continues execution if `Actual` is equal to `Expected`.
139
* Otherwise the current theory iteration aborts without marking the test as
140
* failure.
141
*
142
* @param[in] Actual Value to test
143
* @param[in] Expected Expected value
144
*
145
*****************************************************************************/
146
#define cr_assume_eq(Actual, Expected) cr_assume_op_(==, Actual, Expected)
147
148
/**
149
* Assumes `Actual` is not equal to `Unexpected`
150
*
151
* Continues execution if `Actual` is not equal to `Unexpected`.
152
* Otherwise the current theory iteration aborts without marking the test as
153
* failure.
154
*
155
* @param[in] Actual Value to test
156
* @param[in] Unexpected Unexpected value
157
*
158
*****************************************************************************/
159
#define cr_assume_neq(Actual, Unexpected) cr_assume_op_(!=, Actual, Unexpected)
160
161
/**
162
* Assumes `Actual` is greater than `Reference`
163
*
164
* Continues execution if `Actual` is greater than `Reference`.
165
* Otherwise the current theory iteration aborts without marking the test as
166
* failure.
167
*
168
* @param[in] Actual Value to test
169
* @param[in] Reference Reference value
170
*
171
*****************************************************************************/
172
#define cr_assume_gt(Actual, Reference) cr_assume_op_(>, Actual, Reference)
173
174
/**
175
* Assumes `Actual` is greater or equal to `Reference`
176
*
177
* Continues execution if `Actual` is greater or equal to `Reference`.
178
* Otherwise the current theory iteration aborts without marking the test as
179
* failure.
180
*
181
* @param[in] Actual Value to test
182
* @param[in] Reference Reference value
183
*
184
*****************************************************************************/
185
#define cr_assume_geq(Actual, Reference) cr_assume_op_(>=, Actual, Reference)
186
187
/**
188
* Assumes `Actual` is less than `Reference`
189
*
190
* Continues execution if `Actual` is less than `Reference`.
191
* Otherwise the current theory iteration aborts without marking the test as
192
* failure.
193
*
194
* @param[in] Actual Value to test
195
* @param[in] Reference Reference value
196
*
197
*****************************************************************************/
198
#define cr_assume_lt(Actual, Reference) cr_assume_op_(<, Actual, Reference)
199
200
/**
201
* Assumes `Actual` is less or equal to `Reference`
202
*
203
* Continues execution if `Actual` is less or equal to `Reference`.
204
* Otherwise the current theory iteration aborts without marking the test as
205
* failure.
206
*
207
* @param[in] Actual Value to test
208
* @param[in] Reference Reference value
209
*
210
*****************************************************************************/
211
#define cr_assume_leq(Actual, Reference) cr_assume_op_(<=, Actual, Reference)
212
213
/**
214
* Assumes `Value` is NULL.
215
*
216
* Continues execution if `Value` is NULL.
217
* Otherwise the current theory iteration aborts without marking the test as
218
* failure.
219
*
220
* @param[in] Value Value to test
221
*
222
*****************************************************************************/
223
#define cr_assume_null(Value) cr_assume_eq(Value, NULL)
224
225
/**
226
* Assumes `Value` is not NULL.
227
*
228
* Continues execution if `Value` is not NULL.
229
* Otherwise the current theory iteration aborts without marking the test as
230
* failure.
231
*
232
* @param[in] Value Value to test
233
*
234
*****************************************************************************/
235
#define cr_assume_not_null(Value) cr_assume_neq(Value, NULL)
236
237
/**
238
* Assumes `Actual` is equal to `Expected` with a tolerance of `Epsilon`
239
*
240
* Continues execution if `Actual` is equal to `Expected` with a tolerance of Epsilon.
241
* Otherwise the current theory iteration aborts without marking the test as
242
* failure.
243
*
244
* @note Use this to test equality between floats
245
*
246
* @param[in] Actual Value to test
247
* @param[in] Expected Expected value
248
* @param[in] Epsilon Tolerance between Actual and Expected
249
*
250
*****************************************************************************/
251
#define cr_assume_float_eq(Actual, Expected, Epsilon) \
252
cr_assume((Expected) - (Actual) <= (Epsilon) \
253
&& (Actual) - (Expected) <= (Epsilon))
254
255
/**
256
* Assumes `Actual` is not equal to `Expected` with a tolerance of `Epsilon`
257
*
258
* Continues execution if `Actual` is not equal to `Expected` with a tolerance of Epsilon.
259
* Otherwise the current theory iteration aborts without marking the test as
260
* failure.
261
*
262
* @note Use this to test equality between floats
263
*
264
* @param[in] Actual Value to test
265
* @param[in] Expected Expected value
266
* @param[in] Epsilon Tolerance between Actual and Expected
267
*
268
*****************************************************************************/
269
#define cr_assume_float_neq(Actual, Expected, Epsilon) \
270
cr_assume((Expected) - (Actual) > (Epsilon) \
271
|| (Actual) - (Expected) > (Epsilon))
272
273
/**
274
* Assumes `Actual` is lexicographically equal to `Expected`
275
*
276
* Continues execution if `Actual` is lexicographically equal to `Expected`.
277
* Otherwise the current theory iteration aborts without marking the test as
278
* failure.
279
*
280
* @param[in] Actual String to test
281
* @param[in] Expected Expected string
282
*
283
*****************************************************************************/
284
#define cr_assume_str_eq(Actual, Expected) cr_assume_str_op_(==, Actual, Expected)
285
286
/**
287
* Assumes `Actual` is not lexicographically equal to `Unexpected`
288
*
289
* Continues execution if `Actual` is not lexicographically equal to `Unexpected`.
290
* Otherwise the current theory iteration aborts without marking the test as
291
* failure.
292
*
293
* @param[in] Actual String to test
294
* @param[in] Unexpected Unexpected string
295
*
296
*****************************************************************************/
297
#define cr_assume_str_neq(Actual, Unexpected) cr_assume_str_op_(!=, Actual, Unexpected)
298
299
/**
300
* Assumes `Actual` is lexicographically less than `Reference`
301
*
302
* Continues execution if `Actual` is lexicographically less than `Reference`.
303
* Otherwise the current theory iteration aborts without marking the test as
304
* failure.
305
*
306
* @param[in] Actual Value to test
307
* @param[in] Reference Reference value
308
*
309
*****************************************************************************/
310
#define cr_assume_str_lt(Actual, Reference) cr_assume_str_op_(<, Actual, Reference)
311
312
/**
313
* Assumes `Actual` is lexicographically less or equal to `Reference`
314
*
315
* Continues execution if `Actual` is lexicographically less or equal to `Reference`.
316
* Otherwise the current theory iteration aborts without marking the test as
317
* failure.
318
*
319
* @param[in] Actual Value to test
320
* @param[in] Reference Reference value
321
*
322
*****************************************************************************/
323
#define cr_assume_str_leq(Actual, Reference) cr_assume_str_op_(<=, Actual, Reference)
324
325
/**
326
* Assumes `Actual` is lexicographically greater than `Reference`
327
*
328
* Continues execution if `Actual` is lexicographically greater than `Reference`.
329
* Otherwise the current theory iteration aborts without marking the test as
330
* failure.
331
*
332
* @param[in] Actual Value to test
333
* @param[in] Reference Reference value
334
*
335
*****************************************************************************/
336
#define cr_assume_str_gt(Actual, Reference) cr_assume_str_op_(>, Actual, Reference)
337
338
/**
339
* Assumes `Actual` is lexicographically greater or equal to `Reference`
340
*
341
* Continues execution if `Actual` is lexicographically greater or equal to `Reference`.
342
* Otherwise the current theory iteration aborts without marking the test as
343
* failure.
344
*
345
* @param[in] Actual Value to test
346
* @param[in] Reference Reference value
347
*
348
*****************************************************************************/
349
#define cr_assume_str_geq(Actual, Reference) cr_assume_str_op_(>=, Actual, Reference)
350
351
/**
352
* Assumes `Actual` is byte-to-byte equal to `Expected`
353
*
354
* Continues execution if `Actual` is byte-to-byte equal to `Expected`.
355
* Otherwise the current theory iteration aborts without marking the test as
356
* failure.
357
*
358
* @warning This should not be used on struct arrays
359
*
360
* @param[in] Actual Array to test
361
* @param[in] Expected Expected array
362
* @param[in] Size The size of both arrays
363
*
364
*****************************************************************************/
365
#define cr_assume_arr_eq(Actual, Expected, Size) cr_assume(!memcmp((Actual), (Expected), (Size)))
366
/**
367
* Assumes `Actual` is not byte-to-byte equal to `Unexpected`
368
*
369
* Continues execution if `Actual` is not byte-to-byte equal to `Unexpected`.
370
* Otherwise the current theory iteration aborts without marking the test as
371
* failure.
372
*
373
* @warning This should not be used on struct arrays
374
*
375
* @param[in] Actual Array to test
376
* @param[in] Unexpected Unexpected array
377
* @param[in] Size The size of both arrays
378
*
379
*****************************************************************************/
380
#define cr_assume_arr_neq(Actual, Unexpected, Size) cr_assume(memcmp((Actual), (Unexpected), (Size)))
381
382
/**@}*/
383
384
/* Deprecated */
385
386
#ifndef CRITERION_NO_COMPAT
387
# define cr_assume_strings_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_eq, cr_assume_str_eq) cr_assume_str_eq(__VA_ARGS__)
388
# define cr_assume_strings_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_neq, cr_assume_str_neq) cr_assume_str_neq(__VA_ARGS__)
389
# define cr_assume_strings_lt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_lt, cr_assume_str_lt) cr_assume_str_lt(__VA_ARGS__)
390
# define cr_assume_strings_leq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_leq, cr_assume_str_leq) cr_assume_str_leq(__VA_ARGS__)
391
# define cr_assume_strings_gt(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_gt, cr_assume_str_gt) cr_assume_str_gt(__VA_ARGS__)
392
# define cr_assume_strings_geq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_strings_geq, cr_assume_str_geq) cr_assume_str_geq(__VA_ARGS__)
393
394
# define cr_assume_arrays_eq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_eq, cr_assume_arr_eq) cr_assume_arr_eq(__VA_ARGS__)
395
# define cr_assume_arrays_neq(...) CRITERION_ASSERT_DEPRECATED_B(cr_assume_arrays_neq, cr_assume_arr_neq) cr_assume_arr_neq(__VA_ARGS__)
396
#endif
397
398
#include "
internal/theories.h
"
399
400
#endif
/* !CRITERION_THEORIES_H_ */
CR_BEGIN_C_API
#define CR_BEGIN_C_API
Definition
common.h:54
CR_API
#define CR_API
Definition
common.h:128
CR_END_C_API
#define CR_END_C_API
Definition
common.h:55
criterion.h
Include this to use criterion.
theories.h
cr_theory_abort
CR_BEGIN_C_API CR_API void cr_theory_abort(void)
nix
store
2xpcmdrzviw89gzpf8p7l7691wk51i89-criterion-2.4.2-dev
include
criterion
theories.h
Generated by
1.10.0