1 | /** @file
|
---|
2 | * IPRT - Testcase Framework.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_test_h
|
---|
27 | #define ___iprt_test_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/stdarg.h>
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_test RTTest - Testcase Framework.
|
---|
36 | * @ingroup grp_rt
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /** A test handle. */
|
---|
41 | typedef struct RTTESTINT *RTTEST;
|
---|
42 | /** A pointer to a test handle. */
|
---|
43 | typedef RTTEST *PRTTEST;
|
---|
44 | /** A const pointer to a test handle. */
|
---|
45 | typedef RTTEST const *PCRTTEST;
|
---|
46 |
|
---|
47 | /** A NIL Test handle. */
|
---|
48 | #define NIL_RTTEST ((RTTEST)0)
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Test message importance level.
|
---|
52 | */
|
---|
53 | typedef enum RTTESTLVL
|
---|
54 | {
|
---|
55 | /** Invalid 0. */
|
---|
56 | RTTESTLVL_INVALID = 0,
|
---|
57 | /** Message should always be printed. */
|
---|
58 | RTTESTLVL_ALWAYS,
|
---|
59 | /** Failure message. */
|
---|
60 | RTTESTLVL_FAILURE,
|
---|
61 | /** Sub-test banner. */
|
---|
62 | RTTESTLVL_SUB_TEST,
|
---|
63 | /** Info message. */
|
---|
64 | RTTESTLVL_INFO,
|
---|
65 | /** Debug message. */
|
---|
66 | RTTESTLVL_DEBUG,
|
---|
67 | /** The last (invalid). */
|
---|
68 | RTTESTLVL_END
|
---|
69 | } RTTESTLVL;
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Creates a test instance.
|
---|
74 | *
|
---|
75 | * @returns IPRT status code.
|
---|
76 | * @param pszTest The test name.
|
---|
77 | * @param phTest Where to store the test instance handle.
|
---|
78 | */
|
---|
79 | RTR3DECL(int) RTTestCreate(const char *pszTest, PRTTEST phTest);
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Initializes IPRT and creates a test instance.
|
---|
83 | *
|
---|
84 | * Typical usage is:
|
---|
85 | * @code
|
---|
86 | int main(int argc, char **argv)
|
---|
87 | {
|
---|
88 | RTTEST hTest;
|
---|
89 | int rc = RTTestInitAndCreate("tstSomething", &hTest);
|
---|
90 | if (rc)
|
---|
91 | return rc;
|
---|
92 | ...
|
---|
93 | }
|
---|
94 | @endcode
|
---|
95 | *
|
---|
96 | * @returns RTEXITCODE_SUCCESS on success. On failure an error message is
|
---|
97 | * printed and a suitable exit code is return.
|
---|
98 | *
|
---|
99 | * @param pszTest The test name.
|
---|
100 | * @param phTest Where to store the test instance handle.
|
---|
101 | */
|
---|
102 | RTR3DECL(RTEXITCODE) RTTestInitAndCreate(const char *pszTest, PRTTEST phTest);
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Destroys a test instance previously created by RTTestCreate.
|
---|
106 | *
|
---|
107 | * @returns IPRT status code.
|
---|
108 | * @param hTest The test handle. NIL_RTTEST is ignored.
|
---|
109 | */
|
---|
110 | RTR3DECL(int) RTTestDestroy(RTTEST hTest);
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Changes the default test instance for the calling thread.
|
---|
114 | *
|
---|
115 | * @returns IPRT status code.
|
---|
116 | *
|
---|
117 | * @param hNewDefaultTest The new default test. NIL_RTTEST is fine.
|
---|
118 | * @param phOldTest Where to store the old test handle. Optional.
|
---|
119 | */
|
---|
120 | RTR3DECL(int) RTTestSetDefault(RTTEST hNewDefaultTest, PRTTEST phOldTest);
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Allocate a block of guarded memory.
|
---|
124 | *
|
---|
125 | * @returns IPRT status code.
|
---|
126 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
127 | * associated with the calling thread.
|
---|
128 | * @param cb The amount of memory to allocate.
|
---|
129 | * @param cbAlign The alignment of the returned block.
|
---|
130 | * @param fHead Head or tail optimized guard.
|
---|
131 | * @param ppvUser Where to return the pointer to the block.
|
---|
132 | */
|
---|
133 | RTR3DECL(int) RTTestGuardedAlloc(RTTEST hTest, size_t cb, uint32_t cbAlign, bool fHead, void **ppvUser);
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Allocates a block of guarded memory where the guarded is immediately after
|
---|
137 | * the user memory.
|
---|
138 | *
|
---|
139 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
140 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
141 | * associated with the calling thread.
|
---|
142 | * @param cb The amount of memory to allocate.
|
---|
143 | */
|
---|
144 | RTR3DECL(void *) RTTestGuardedAllocTail(RTTEST hTest, size_t cb);
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Allocates a block of guarded memory where the guarded is right in front of
|
---|
148 | * the user memory.
|
---|
149 | *
|
---|
150 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
151 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
152 | * associated with the calling thread.
|
---|
153 | * @param cb The amount of memory to allocate.
|
---|
154 | */
|
---|
155 | RTR3DECL(void *) RTTestGuardedAllocHead(RTTEST hTest, size_t cb);
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Frees a block of guarded memory.
|
---|
159 | *
|
---|
160 | * @returns IPRT status code.
|
---|
161 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
162 | * associated with the calling thread.
|
---|
163 | * @param pv The memory. NULL is ignored.
|
---|
164 | */
|
---|
165 | RTR3DECL(int) RTTestGuardedFree(RTTEST hTest, void *pv);
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Test vprintf making sure the output starts on a new line.
|
---|
169 | *
|
---|
170 | * @returns Number of chars printed.
|
---|
171 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
172 | * associated with the calling thread.
|
---|
173 | * @param enmLevel Message importance level.
|
---|
174 | * @param pszFormat The message.
|
---|
175 | * @param va Arguments.
|
---|
176 | */
|
---|
177 | RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Test printf making sure the output starts on a new line.
|
---|
181 | *
|
---|
182 | * @returns Number of chars printed.
|
---|
183 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
184 | * associated with the calling thread.
|
---|
185 | * @param enmLevel Message importance level.
|
---|
186 | * @param pszFormat The message.
|
---|
187 | * @param ... Arguments.
|
---|
188 | */
|
---|
189 | RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Test vprintf, makes sure lines are prefixed and so forth.
|
---|
193 | *
|
---|
194 | * @returns Number of chars printed.
|
---|
195 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
196 | * associated with the calling thread.
|
---|
197 | * @param enmLevel Message importance level.
|
---|
198 | * @param pszFormat The message.
|
---|
199 | * @param va Arguments.
|
---|
200 | */
|
---|
201 | RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Test printf, makes sure lines are prefixed and so forth.
|
---|
205 | *
|
---|
206 | * @returns Number of chars printed.
|
---|
207 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
208 | * associated with the calling thread.
|
---|
209 | * @param enmLevel Message importance level.
|
---|
210 | * @param pszFormat The message.
|
---|
211 | * @param ... Arguments.
|
---|
212 | */
|
---|
213 | RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Prints the test banner.
|
---|
217 | *
|
---|
218 | * @returns Number of chars printed.
|
---|
219 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
220 | * associated with the calling thread.
|
---|
221 | */
|
---|
222 | RTR3DECL(int) RTTestBanner(RTTEST hTest);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Summaries the test, destroys the test instance and return an exit code.
|
---|
226 | *
|
---|
227 | * @returns Test program exit code.
|
---|
228 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
229 | * associated with the calling thread.
|
---|
230 | */
|
---|
231 | RTR3DECL(RTEXITCODE) RTTestSummaryAndDestroy(RTTEST hTest);
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Skips the test, destroys the test instance and return an exit code.
|
---|
235 | *
|
---|
236 | * @returns Test program exit code.
|
---|
237 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
238 | * associated with the calling thread.
|
---|
239 | * @param pszReasonFmt Text explaining why, optional (NULL).
|
---|
240 | * @param va Arguments for the reason format string.
|
---|
241 | */
|
---|
242 | RTR3DECL(RTEXITCODE) RTTestSkipAndDestroyV(RTTEST hTest, const char *pszReasonFmt, va_list va);
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Skips the test, destroys the test instance and return an exit code.
|
---|
246 | *
|
---|
247 | * @returns Test program exit code.
|
---|
248 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
249 | * associated with the calling thread.
|
---|
250 | * @param pszReasonFmt Text explaining why, optional (NULL).
|
---|
251 | * @param ... Arguments for the reason format string.
|
---|
252 | */
|
---|
253 | RTR3DECL(RTEXITCODE) RTTestSkipAndDestroy(RTTEST hTest, const char *pszReasonFmt, ...);
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Starts a sub-test.
|
---|
257 | *
|
---|
258 | * This will perform an implicit RTTestSubDone() call if that has not been done
|
---|
259 | * since the last RTTestSub call.
|
---|
260 | *
|
---|
261 | * @returns Number of chars printed.
|
---|
262 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
263 | * associated with the calling thread.
|
---|
264 | * @param pszSubTest The sub-test name.
|
---|
265 | */
|
---|
266 | RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest);
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Format string version of RTTestSub.
|
---|
270 | *
|
---|
271 | * See RTTestSub for details.
|
---|
272 | *
|
---|
273 | * @returns Number of chars printed.
|
---|
274 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
275 | * associated with the calling thread.
|
---|
276 | * @param pszSubTestFmt The sub-test name format string.
|
---|
277 | * @param ... Arguments.
|
---|
278 | */
|
---|
279 | RTR3DECL(int) RTTestSubF(RTTEST hTest, const char *pszSubTestFmt, ...);
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Format string version of RTTestSub.
|
---|
283 | *
|
---|
284 | * See RTTestSub for details.
|
---|
285 | *
|
---|
286 | * @returns Number of chars printed.
|
---|
287 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
288 | * associated with the calling thread.
|
---|
289 | * @param pszSubTestFmt The sub-test name format string.
|
---|
290 | * @param va Arguments.
|
---|
291 | */
|
---|
292 | RTR3DECL(int) RTTestSubV(RTTEST hTest, const char *pszSubTestFmt, va_list va);
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Completes a sub-test.
|
---|
296 | *
|
---|
297 | * @returns Number of chars printed.
|
---|
298 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
299 | * associated with the calling thread.
|
---|
300 | */
|
---|
301 | RTR3DECL(int) RTTestSubDone(RTTEST hTest);
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Prints an extended PASSED message, optional.
|
---|
305 | *
|
---|
306 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
307 | * of a sub-sub-to-the-power-of-N-test.
|
---|
308 | *
|
---|
309 | * @returns IPRT status code.
|
---|
310 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
311 | * associated with the calling thread.
|
---|
312 | * @param pszFormat The message. No trailing newline.
|
---|
313 | * @param va The arguments.
|
---|
314 | */
|
---|
315 | RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Prints an extended PASSED message, optional.
|
---|
319 | *
|
---|
320 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
321 | * of a sub-sub-to-the-power-of-N-test.
|
---|
322 | *
|
---|
323 | * @returns IPRT status code.
|
---|
324 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
325 | * associated with the calling thread.
|
---|
326 | * @param pszFormat The message. No trailing newline.
|
---|
327 | * @param ... The arguments.
|
---|
328 | */
|
---|
329 | RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...);
|
---|
330 |
|
---|
331 | /**
|
---|
332 | * Value units.
|
---|
333 | */
|
---|
334 | typedef enum RTTESTUNIT
|
---|
335 | {
|
---|
336 | /** The usual invalid value. */
|
---|
337 | RTTESTUNIT_INVALID = 0,
|
---|
338 | /** Percentage. */
|
---|
339 | RTTESTUNIT_PCT,
|
---|
340 | /** Bytes. */
|
---|
341 | RTTESTUNIT_BYTES,
|
---|
342 | /** Bytes per second. */
|
---|
343 | RTTESTUNIT_BYTES_PER_SEC,
|
---|
344 | /** Kilobytes. */
|
---|
345 | RTTESTUNIT_KILOBYTES,
|
---|
346 | /** Kilobytes per second. */
|
---|
347 | RTTESTUNIT_KILOBYTES_PER_SEC,
|
---|
348 | /** Megabytes. */
|
---|
349 | RTTESTUNIT_MEGABYTES,
|
---|
350 | /** Megabytes per second. */
|
---|
351 | RTTESTUNIT_MEGABYTES_PER_SEC,
|
---|
352 | /** Packets. */
|
---|
353 | RTTESTUNIT_PACKETS,
|
---|
354 | /** Packets per second. */
|
---|
355 | RTTESTUNIT_PACKETS_PER_SEC,
|
---|
356 | /** Frames. */
|
---|
357 | RTTESTUNIT_FRAMES,
|
---|
358 | /** Frames per second. */
|
---|
359 | RTTESTUNIT_FRAMES_PER_SEC,
|
---|
360 | /** Occurrences. */
|
---|
361 | RTTESTUNIT_OCCURRENCES,
|
---|
362 | /** Occurrences per second. */
|
---|
363 | RTTESTUNIT_OCCURRENCES_PER_SEC,
|
---|
364 | /** Calls. */
|
---|
365 | RTTESTUNIT_CALLS,
|
---|
366 | /** Calls per second. */
|
---|
367 | RTTESTUNIT_CALLS_PER_SEC,
|
---|
368 | /** Round trips. */
|
---|
369 | RTTESTUNIT_ROUND_TRIP,
|
---|
370 | /** Seconds. */
|
---|
371 | RTTESTUNIT_SECS,
|
---|
372 | /** Milliseconds. */
|
---|
373 | RTTESTUNIT_MS,
|
---|
374 | /** Nanoseconds. */
|
---|
375 | RTTESTUNIT_NS,
|
---|
376 | /** Nanoseconds per call. */
|
---|
377 | RTTESTUNIT_NS_PER_CALL,
|
---|
378 | /** Nanoseconds per frame. */
|
---|
379 | RTTESTUNIT_NS_PER_FRAME,
|
---|
380 | /** Nanoseconds per occurrence. */
|
---|
381 | RTTESTUNIT_NS_PER_OCCURRENCE,
|
---|
382 | /** Nanoseconds per frame. */
|
---|
383 | RTTESTUNIT_NS_PER_PACKET,
|
---|
384 | /** Nanoseconds per round trip. */
|
---|
385 | RTTESTUNIT_NS_PER_ROUND_TRIP,
|
---|
386 | /** The end of valid units. */
|
---|
387 | RTTESTUNIT_END
|
---|
388 | } RTTESTUNIT;
|
---|
389 |
|
---|
390 | /**
|
---|
391 | * Report a named test result value.
|
---|
392 | *
|
---|
393 | * This is typically used for benchmarking but can be used for other purposes
|
---|
394 | * like reporting limits of some implementation. The value gets associated with
|
---|
395 | * the current sub test, the name must be unique within the sub test.
|
---|
396 | *
|
---|
397 | * @returns IPRT status code.
|
---|
398 | *
|
---|
399 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
400 | * associated with the calling thread.
|
---|
401 | * @param pszName The value name.
|
---|
402 | * @param u64Value The value.
|
---|
403 | * @param enmUnit The value unit.
|
---|
404 | */
|
---|
405 | RTR3DECL(int) RTTestValue(RTTEST hTest, const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
|
---|
406 |
|
---|
407 | /**
|
---|
408 | * Same as RTTestValue, except that the name is now a format string.
|
---|
409 | *
|
---|
410 | * @returns IPRT status code.
|
---|
411 | *
|
---|
412 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
413 | * associated with the calling thread.
|
---|
414 | * @param u64Value The value.
|
---|
415 | * @param enmUnit The value unit.
|
---|
416 | * @param pszNameFmt The value name format string.
|
---|
417 | * @param ... String arguments.
|
---|
418 | */
|
---|
419 | RTR3DECL(int) RTTestValueF(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...);
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Same as RTTestValue, except that the name is now a format string.
|
---|
423 | *
|
---|
424 | * @returns IPRT status code.
|
---|
425 | *
|
---|
426 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
427 | * associated with the calling thread.
|
---|
428 | * @param u64Value The value.
|
---|
429 | * @param enmUnit The value unit.
|
---|
430 | * @param pszNameFmt The value name format string.
|
---|
431 | * @param va_list String arguments.
|
---|
432 | */
|
---|
433 | RTR3DECL(int) RTTestValueV(RTTEST hTest, uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va);
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * Increments the error counter.
|
---|
437 | *
|
---|
438 | * @returns IPRT status code.
|
---|
439 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
440 | * associated with the calling thread.
|
---|
441 | */
|
---|
442 | RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
|
---|
443 |
|
---|
444 | /**
|
---|
445 | * Get the current error count.
|
---|
446 | *
|
---|
447 | * @returns The error counter, UINT32_MAX if no valid test handle.
|
---|
448 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
449 | * associated with the calling thread.
|
---|
450 | */
|
---|
451 | RTR3DECL(uint32_t) RTTestErrorCount(RTTEST hTest);
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * Increments the error counter and prints a failure message.
|
---|
455 | *
|
---|
456 | * @returns IPRT status code.
|
---|
457 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
458 | * associated with the calling thread.
|
---|
459 | * @param pszFormat The message. No trailing newline.
|
---|
460 | * @param va The arguments.
|
---|
461 | */
|
---|
462 | RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
463 |
|
---|
464 | /**
|
---|
465 | * Increments the error counter and prints a failure message.
|
---|
466 | *
|
---|
467 | * @returns IPRT status code.
|
---|
468 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
469 | * associated with the calling thread.
|
---|
470 | * @param pszFormat The message. No trailing newline.
|
---|
471 | * @param ... The arguments.
|
---|
472 | */
|
---|
473 | RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...);
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
|
---|
477 | *
|
---|
478 | * @returns Number of chars printed.
|
---|
479 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
480 | * associated with the calling thread.
|
---|
481 | * @param pszFormat The message.
|
---|
482 | * @param va Arguments.
|
---|
483 | */
|
---|
484 | RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * Same as RTTestPrintf with RTTESTLVL_FAILURE.
|
---|
488 | *
|
---|
489 | * @returns Number of chars printed.
|
---|
490 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
491 | * associated with the calling thread.
|
---|
492 | * @param pszFormat The message.
|
---|
493 | * @param ... Arguments.
|
---|
494 | */
|
---|
495 | RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...);
|
---|
496 |
|
---|
497 |
|
---|
498 | /** @def RTTEST_CHECK
|
---|
499 | * Check whether a boolean expression holds true.
|
---|
500 | *
|
---|
501 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
502 | *
|
---|
503 | * @param hTest The test handle.
|
---|
504 | * @param expr The expression to evaluate.
|
---|
505 | */
|
---|
506 | #define RTTEST_CHECK(hTest, expr) \
|
---|
507 | do { if (!(expr)) { \
|
---|
508 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
509 | } \
|
---|
510 | } while (0)
|
---|
511 | /** @def RTTEST_CHECK_RET
|
---|
512 | * Check whether a boolean expression holds true, returns on false.
|
---|
513 | *
|
---|
514 | * If the expression is false, call RTTestFailed giving the line number and
|
---|
515 | * expression, then return @a rcRet.
|
---|
516 | *
|
---|
517 | * @param hTest The test handle.
|
---|
518 | * @param expr The expression to evaluate.
|
---|
519 | * @param rcRet What to return on failure.
|
---|
520 | */
|
---|
521 | #define RTTEST_CHECK_RET(hTest, expr, rcRet) \
|
---|
522 | do { if (!(expr)) { \
|
---|
523 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
524 | return (rcRet); \
|
---|
525 | } \
|
---|
526 | } while (0)
|
---|
527 | /** @def RTTEST_CHECK_RETV
|
---|
528 | * Check whether a boolean expression holds true, returns void on false.
|
---|
529 | *
|
---|
530 | * If the expression is false, call RTTestFailed giving the line number and
|
---|
531 | * expression, then return void.
|
---|
532 | *
|
---|
533 | * @param hTest The test handle.
|
---|
534 | * @param expr The expression to evaluate.
|
---|
535 | */
|
---|
536 | #define RTTEST_CHECK_RETV(hTest, expr) \
|
---|
537 | do { if (!(expr)) { \
|
---|
538 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
539 | return; \
|
---|
540 | } \
|
---|
541 | } while (0)
|
---|
542 | /** @def RTTEST_CHECK_BREAK
|
---|
543 | * Check whether a boolean expression holds true.
|
---|
544 | *
|
---|
545 | * If the expression is false, call RTTestFailed giving the line number and
|
---|
546 | * expression, then break.
|
---|
547 | *
|
---|
548 | * @param hTest The test handle.
|
---|
549 | * @param expr The expression to evaluate.
|
---|
550 | */
|
---|
551 | #define RTTEST_CHECK_BREAK(hTest, expr) \
|
---|
552 | if (!(expr)) { \
|
---|
553 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
554 | break; \
|
---|
555 | } else do {} while (0)
|
---|
556 |
|
---|
557 |
|
---|
558 | /** @def RTTEST_CHECK_MSG
|
---|
559 | * Check whether a boolean expression holds true.
|
---|
560 | *
|
---|
561 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
562 | *
|
---|
563 | * @param hTest The test handle.
|
---|
564 | * @param expr The expression to evaluate.
|
---|
565 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
566 | * parenthesis.
|
---|
567 | */
|
---|
568 | #define RTTEST_CHECK_MSG(hTest, expr, DetailsArgs) \
|
---|
569 | do { if (!(expr)) { \
|
---|
570 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
571 | RTTestFailureDetails DetailsArgs; \
|
---|
572 | } \
|
---|
573 | } while (0)
|
---|
574 | /** @def RTTEST_CHECK_MSG_RET
|
---|
575 | * Check whether a boolean expression holds true, returns on false.
|
---|
576 | *
|
---|
577 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
578 | *
|
---|
579 | * @param hTest The test handle.
|
---|
580 | * @param expr The expression to evaluate.
|
---|
581 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
582 | * parenthesis.
|
---|
583 | * @param rcRet What to return on failure.
|
---|
584 | */
|
---|
585 | #define RTTEST_CHECK_MSG_RET(hTest, expr, DetailsArgs, rcRet) \
|
---|
586 | do { if (!(expr)) { \
|
---|
587 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
588 | RTTestFailureDetails DetailsArgs; \
|
---|
589 | return (rcRet); \
|
---|
590 | } \
|
---|
591 | } while (0)
|
---|
592 | /** @def RTTEST_CHECK_MSG_RET
|
---|
593 | * Check whether a boolean expression holds true, returns void on false.
|
---|
594 | *
|
---|
595 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
596 | *
|
---|
597 | * @param hTest The test handle.
|
---|
598 | * @param expr The expression to evaluate.
|
---|
599 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
600 | * parenthesis.
|
---|
601 | */
|
---|
602 | #define RTTEST_CHECK_MSG_RETV(hTest, expr, DetailsArgs) \
|
---|
603 | do { if (!(expr)) { \
|
---|
604 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
605 | RTTestFailureDetails DetailsArgs; \
|
---|
606 | return; \
|
---|
607 | } \
|
---|
608 | } while (0)
|
---|
609 |
|
---|
610 |
|
---|
611 | /** @def RTTEST_CHECK_RC
|
---|
612 | * Check whether an expression returns a specific IPRT style status code.
|
---|
613 | *
|
---|
614 | * If a different status code is return, call RTTestFailed giving the line
|
---|
615 | * number, expression, actual and expected status codes.
|
---|
616 | *
|
---|
617 | * @param hTest The test handle.
|
---|
618 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
619 | * @param rcExpect The expected return code. This may be referenced
|
---|
620 | * more than once by the macro.
|
---|
621 | */
|
---|
622 | #define RTTEST_CHECK_RC(hTest, rcExpr, rcExpect) \
|
---|
623 | do { \
|
---|
624 | int rcCheck = (rcExpr); \
|
---|
625 | if (rcCheck != (rcExpect)) { \
|
---|
626 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
627 | } \
|
---|
628 | } while (0)
|
---|
629 | /** @def RTTEST_CHECK_RC_RET
|
---|
630 | * Check whether an expression returns a specific IPRT style status code.
|
---|
631 | *
|
---|
632 | * If a different status code is return, call RTTestFailed giving the line
|
---|
633 | * number, expression, actual and expected status codes, then return.
|
---|
634 | *
|
---|
635 | * @param hTest The test handle.
|
---|
636 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
637 | * This will be assigned to a local rcCheck variable
|
---|
638 | * that can be used as return value.
|
---|
639 | * @param rcExpect The expected return code. This may be referenced
|
---|
640 | * more than once by the macro.
|
---|
641 | * @param rcRet The return code.
|
---|
642 | */
|
---|
643 | #define RTTEST_CHECK_RC_RET(hTest, rcExpr, rcExpect, rcRet) \
|
---|
644 | do { \
|
---|
645 | int rcCheck = (rcExpr); \
|
---|
646 | if (rcCheck != (rcExpect)) { \
|
---|
647 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
648 | return (rcRet); \
|
---|
649 | } \
|
---|
650 | } while (0)
|
---|
651 | /** @def RTTEST_CHECK_RC_RETV
|
---|
652 | * Check whether an expression returns a specific IPRT style status code.
|
---|
653 | *
|
---|
654 | * If a different status code is return, call RTTestFailed giving the line
|
---|
655 | * number, expression, actual and expected status codes, then return.
|
---|
656 | *
|
---|
657 | * @param hTest The test handle.
|
---|
658 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
659 | * @param rcExpect The expected return code. This may be referenced
|
---|
660 | * more than once by the macro.
|
---|
661 | */
|
---|
662 | #define RTTEST_CHECK_RC_RETV(hTest, rcExpr, rcExpect) \
|
---|
663 | do { \
|
---|
664 | int rcCheck = (rcExpr); \
|
---|
665 | if (rcCheck != (rcExpect)) { \
|
---|
666 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
667 | return; \
|
---|
668 | } \
|
---|
669 | } while (0)
|
---|
670 | /** @def RTTEST_CHECK_RC_BREAK
|
---|
671 | * Check whether an expression returns a specific IPRT style status code.
|
---|
672 | *
|
---|
673 | * If a different status code is return, call RTTestFailed giving the line
|
---|
674 | * number, expression, actual and expected status codes, then break.
|
---|
675 | *
|
---|
676 | * @param hTest The test handle.
|
---|
677 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
678 | * @param rcExpect The expected return code. This may be referenced
|
---|
679 | * more than once by the macro.
|
---|
680 | */
|
---|
681 | #define RTTEST_CHECK_RC_BREAK(hTest, rcExpr, rcExpect) \
|
---|
682 | if (1) { \
|
---|
683 | int rcCheck = (rcExpr); \
|
---|
684 | if (rcCheck != (rcExpect)) { \
|
---|
685 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
686 | break; \
|
---|
687 | } \
|
---|
688 | } else do {} while (0)
|
---|
689 |
|
---|
690 |
|
---|
691 | /** @def RTTEST_CHECK_RC_OK
|
---|
692 | * Check whether a IPRT style status code indicates success.
|
---|
693 | *
|
---|
694 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
695 | * expression and status code.
|
---|
696 | *
|
---|
697 | * @param hTest The test handle.
|
---|
698 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
699 | */
|
---|
700 | #define RTTEST_CHECK_RC_OK(hTest, rcExpr) \
|
---|
701 | do { \
|
---|
702 | int rcCheck = (rcExpr); \
|
---|
703 | if (RT_FAILURE(rcCheck)) { \
|
---|
704 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
705 | } \
|
---|
706 | } while (0)
|
---|
707 | /** @def RTTEST_CHECK_RC_OK_RET
|
---|
708 | * Check whether a IPRT style status code indicates success.
|
---|
709 | *
|
---|
710 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
711 | * expression and status code, then return with the specified value.
|
---|
712 | *
|
---|
713 | * @param hTest The test handle.
|
---|
714 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
715 | * This will be assigned to a local rcCheck variable
|
---|
716 | * that can be used as return value.
|
---|
717 | * @param rcRet The return code.
|
---|
718 | */
|
---|
719 | #define RTTEST_CHECK_RC_OK_RET(hTest, rcExpr, rcRet) \
|
---|
720 | do { \
|
---|
721 | int rcCheck = (rcExpr); \
|
---|
722 | if (RT_FAILURE(rcCheck)) { \
|
---|
723 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
724 | return (rcRet); \
|
---|
725 | } \
|
---|
726 | } while (0)
|
---|
727 | /** @def RTTEST_CHECK_RC_OK_RETV
|
---|
728 | * Check whether a IPRT style status code indicates success.
|
---|
729 | *
|
---|
730 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
731 | * expression and status code, then return.
|
---|
732 | *
|
---|
733 | * @param hTest The test handle.
|
---|
734 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
735 | */
|
---|
736 | #define RTTEST_CHECK_RC_OK_RETV(hTest, rcExpr) \
|
---|
737 | do { \
|
---|
738 | int rcCheck = (rcExpr); \
|
---|
739 | if (RT_FAILURE(rcCheck)) { \
|
---|
740 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
741 | return; \
|
---|
742 | } \
|
---|
743 | } while (0)
|
---|
744 |
|
---|
745 |
|
---|
746 |
|
---|
747 |
|
---|
748 | /** @name Implicit Test Handle API Variation
|
---|
749 | * The test handle is retrieved from the test TLS entry of the calling thread.
|
---|
750 | * @{
|
---|
751 | */
|
---|
752 |
|
---|
753 | /**
|
---|
754 | * Test vprintf, makes sure lines are prefixed and so forth.
|
---|
755 | *
|
---|
756 | * @returns Number of chars printed.
|
---|
757 | * @param enmLevel Message importance level.
|
---|
758 | * @param pszFormat The message.
|
---|
759 | * @param va Arguments.
|
---|
760 | */
|
---|
761 | RTR3DECL(int) RTTestIPrintfV(RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
762 |
|
---|
763 | /**
|
---|
764 | * Test printf, makes sure lines are prefixed and so forth.
|
---|
765 | *
|
---|
766 | * @returns Number of chars printed.
|
---|
767 | * @param enmLevel Message importance level.
|
---|
768 | * @param pszFormat The message.
|
---|
769 | * @param ... Arguments.
|
---|
770 | */
|
---|
771 | RTR3DECL(int) RTTestIPrintf(RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
772 |
|
---|
773 | /**
|
---|
774 | * Starts a sub-test.
|
---|
775 | *
|
---|
776 | * This will perform an implicit RTTestSubDone() call if that has not been done
|
---|
777 | * since the last RTTestSub call.
|
---|
778 | *
|
---|
779 | * @returns Number of chars printed.
|
---|
780 | * @param pszSubTest The sub-test name.
|
---|
781 | */
|
---|
782 | RTR3DECL(int) RTTestISub(const char *pszSubTest);
|
---|
783 |
|
---|
784 | /**
|
---|
785 | * Format string version of RTTestSub.
|
---|
786 | *
|
---|
787 | * See RTTestSub for details.
|
---|
788 | *
|
---|
789 | * @returns Number of chars printed.
|
---|
790 | * @param pszSubTestFmt The sub-test name format string.
|
---|
791 | * @param ... Arguments.
|
---|
792 | */
|
---|
793 | RTR3DECL(int) RTTestISubF(const char *pszSubTestFmt, ...);
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * Format string version of RTTestSub.
|
---|
797 | *
|
---|
798 | * See RTTestSub for details.
|
---|
799 | *
|
---|
800 | * @returns Number of chars printed.
|
---|
801 | * @param pszSubTestFmt The sub-test name format string.
|
---|
802 | * @param va Arguments.
|
---|
803 | */
|
---|
804 | RTR3DECL(int) RTTestISubV(const char *pszSubTestFmt, va_list va);
|
---|
805 |
|
---|
806 | /**
|
---|
807 | * Completes a sub-test.
|
---|
808 | *
|
---|
809 | * @returns Number of chars printed.
|
---|
810 | */
|
---|
811 | RTR3DECL(int) RTTestISubDone(void);
|
---|
812 |
|
---|
813 | /**
|
---|
814 | * Prints an extended PASSED message, optional.
|
---|
815 | *
|
---|
816 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
817 | * of a sub-sub-to-the-power-of-N-test.
|
---|
818 | *
|
---|
819 | * @returns IPRT status code.
|
---|
820 | * @param pszFormat The message. No trailing newline.
|
---|
821 | * @param va The arguments.
|
---|
822 | */
|
---|
823 | RTR3DECL(int) RTTestIPassedV(const char *pszFormat, va_list va);
|
---|
824 |
|
---|
825 | /**
|
---|
826 | * Prints an extended PASSED message, optional.
|
---|
827 | *
|
---|
828 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
829 | * of a sub-sub-to-the-power-of-N-test.
|
---|
830 | *
|
---|
831 | * @returns IPRT status code.
|
---|
832 | * @param pszFormat The message. No trailing newline.
|
---|
833 | * @param ... The arguments.
|
---|
834 | */
|
---|
835 | RTR3DECL(int) RTTestIPassed(const char *pszFormat, ...);
|
---|
836 |
|
---|
837 | /**
|
---|
838 | * Report a named test result value.
|
---|
839 | *
|
---|
840 | * This is typically used for benchmarking but can be used for other purposes
|
---|
841 | * like reporting limits of some implementation. The value gets associated with
|
---|
842 | * the current sub test, the name must be unique within the sub test.
|
---|
843 | *
|
---|
844 | * @returns IPRT status code.
|
---|
845 | *
|
---|
846 | * @param pszName The value name.
|
---|
847 | * @param u64Value The value.
|
---|
848 | * @param enmUnit The value unit.
|
---|
849 | */
|
---|
850 | RTR3DECL(int) RTTestIValue(const char *pszName, uint64_t u64Value, RTTESTUNIT enmUnit);
|
---|
851 |
|
---|
852 | /**
|
---|
853 | * Same as RTTestValue, except that the name is now a format string.
|
---|
854 | *
|
---|
855 | * @returns IPRT status code.
|
---|
856 | *
|
---|
857 | * @param u64Value The value.
|
---|
858 | * @param enmUnit The value unit.
|
---|
859 | * @param pszNameFmt The value name format string.
|
---|
860 | * @param ... String arguments.
|
---|
861 | */
|
---|
862 | RTR3DECL(int) RTTestIValueF(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, ...);
|
---|
863 |
|
---|
864 | /**
|
---|
865 | * Same as RTTestValue, except that the name is now a format string.
|
---|
866 | *
|
---|
867 | * @returns IPRT status code.
|
---|
868 | *
|
---|
869 | * @param u64Value The value.
|
---|
870 | * @param enmUnit The value unit.
|
---|
871 | * @param pszNameFmt The value name format string.
|
---|
872 | * @param va_list String arguments.
|
---|
873 | */
|
---|
874 | RTR3DECL(int) RTTestIValueV(uint64_t u64Value, RTTESTUNIT enmUnit, const char *pszNameFmt, va_list va);
|
---|
875 |
|
---|
876 | /**
|
---|
877 | * Increments the error counter.
|
---|
878 | *
|
---|
879 | * @returns IPRT status code.
|
---|
880 | */
|
---|
881 | RTR3DECL(int) RTTestIErrorInc(void);
|
---|
882 |
|
---|
883 | /**
|
---|
884 | * Get the current error count.
|
---|
885 | *
|
---|
886 | * @returns The error counter, UINT32_MAX if no valid test handle.
|
---|
887 | */
|
---|
888 | RTR3DECL(uint32_t) RTTestIErrorCount(void);
|
---|
889 |
|
---|
890 | /**
|
---|
891 | * Increments the error counter and prints a failure message.
|
---|
892 | *
|
---|
893 | * @returns IPRT status code.
|
---|
894 | * @param pszFormat The message. No trailing newline.
|
---|
895 | * @param va The arguments.
|
---|
896 | */
|
---|
897 | RTR3DECL(int) RTTestIFailedV(const char *pszFormat, va_list va);
|
---|
898 |
|
---|
899 | /**
|
---|
900 | * Increments the error counter and prints a failure message.
|
---|
901 | *
|
---|
902 | * @returns IPRT status code.
|
---|
903 | * @param pszFormat The message. No trailing newline.
|
---|
904 | * @param ... The arguments.
|
---|
905 | */
|
---|
906 | RTR3DECL(int) RTTestIFailed(const char *pszFormat, ...);
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Increments the error counter, prints a failure message and returns the
|
---|
910 | * specified status code.
|
---|
911 | *
|
---|
912 | * This is mainly a convenience method for saving vertical space in the source
|
---|
913 | * code.
|
---|
914 | *
|
---|
915 | * @returns @a rcRet
|
---|
916 | * @param rcRet The IPRT status code to return.
|
---|
917 | * @param pszFormat The message. No trailing newline.
|
---|
918 | * @param va The arguments.
|
---|
919 | */
|
---|
920 | RTR3DECL(int) RTTestIFailedRcV(int rcRet, const char *pszFormat, va_list va);
|
---|
921 |
|
---|
922 | /**
|
---|
923 | * Increments the error counter, prints a failure message and returns the
|
---|
924 | * specified status code.
|
---|
925 | *
|
---|
926 | * This is mainly a convenience method for saving vertical space in the source
|
---|
927 | * code.
|
---|
928 | *
|
---|
929 | * @returns @a rcRet
|
---|
930 | * @param rcRet The IPRT status code to return.
|
---|
931 | * @param pszFormat The message. No trailing newline.
|
---|
932 | * @param ... The arguments.
|
---|
933 | */
|
---|
934 | RTR3DECL(int) RTTestIFailedRc(int rcRet, const char *pszFormat, ...);
|
---|
935 |
|
---|
936 | /**
|
---|
937 | * Same as RTTestIPrintfV with RTTESTLVL_FAILURE.
|
---|
938 | *
|
---|
939 | * @returns Number of chars printed.
|
---|
940 | * @param pszFormat The message.
|
---|
941 | * @param va Arguments.
|
---|
942 | */
|
---|
943 | RTR3DECL(int) RTTestIFailureDetailsV(const char *pszFormat, va_list va);
|
---|
944 |
|
---|
945 | /**
|
---|
946 | * Same as RTTestIPrintf with RTTESTLVL_FAILURE.
|
---|
947 | *
|
---|
948 | * @returns Number of chars printed.
|
---|
949 | * @param pszFormat The message.
|
---|
950 | * @param ... Arguments.
|
---|
951 | */
|
---|
952 | RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...);
|
---|
953 |
|
---|
954 |
|
---|
955 | /** @def RTTESTI_CHECK
|
---|
956 | * Check whether a boolean expression holds true.
|
---|
957 | *
|
---|
958 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
959 | * expression.
|
---|
960 | *
|
---|
961 | * @param expr The expression to evaluate.
|
---|
962 | */
|
---|
963 | #define RTTESTI_CHECK(expr) \
|
---|
964 | do { if (!(expr)) { \
|
---|
965 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
966 | } \
|
---|
967 | } while (0)
|
---|
968 | /** @def RTTESTI_CHECK_RET
|
---|
969 | * Check whether a boolean expression holds true, returns on false.
|
---|
970 | *
|
---|
971 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
972 | * expression, then return @a rcRet.
|
---|
973 | *
|
---|
974 | * @param expr The expression to evaluate.
|
---|
975 | * @param rcRet What to return on failure.
|
---|
976 | */
|
---|
977 | #define RTTESTI_CHECK_RET(expr, rcRet) \
|
---|
978 | do { if (!(expr)) { \
|
---|
979 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
980 | return (rcRet); \
|
---|
981 | } \
|
---|
982 | } while (0)
|
---|
983 | /** @def RTTESTI_CHECK_RETV
|
---|
984 | * Check whether a boolean expression holds true, returns void on false.
|
---|
985 | *
|
---|
986 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
987 | * expression, then return void.
|
---|
988 | *
|
---|
989 | * @param expr The expression to evaluate.
|
---|
990 | */
|
---|
991 | #define RTTESTI_CHECK_RETV(expr) \
|
---|
992 | do { if (!(expr)) { \
|
---|
993 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
994 | return; \
|
---|
995 | } \
|
---|
996 | } while (0)
|
---|
997 | /** @def RTTESTI_CHECK_RETV
|
---|
998 | * Check whether a boolean expression holds true, returns void on false.
|
---|
999 | *
|
---|
1000 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
1001 | * expression, then break.
|
---|
1002 | *
|
---|
1003 | * @param expr The expression to evaluate.
|
---|
1004 | */
|
---|
1005 | #define RTTESTI_CHECK_BREAK(expr) \
|
---|
1006 | if (!(expr)) { \
|
---|
1007 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
1008 | break; \
|
---|
1009 | } do {} while (0)
|
---|
1010 |
|
---|
1011 |
|
---|
1012 | /** @def RTTESTI_CHECK_MSG
|
---|
1013 | * Check whether a boolean expression holds true.
|
---|
1014 | *
|
---|
1015 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
1016 | * expression.
|
---|
1017 | *
|
---|
1018 | * @param expr The expression to evaluate.
|
---|
1019 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
1020 | * parenthesis.
|
---|
1021 | */
|
---|
1022 | #define RTTESTI_CHECK_MSG(expr, DetailsArgs) \
|
---|
1023 | do { if (!(expr)) { \
|
---|
1024 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
1025 | RTTestIFailureDetails DetailsArgs; \
|
---|
1026 | } \
|
---|
1027 | } while (0)
|
---|
1028 | /** @def RTTESTI_CHECK_MSG_RET
|
---|
1029 | * Check whether a boolean expression holds true, returns on false.
|
---|
1030 | *
|
---|
1031 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
1032 | * expression.
|
---|
1033 | *
|
---|
1034 | * @param expr The expression to evaluate.
|
---|
1035 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
1036 | * parenthesis.
|
---|
1037 | * @param rcRet What to return on failure.
|
---|
1038 | */
|
---|
1039 | #define RTTESTI_CHECK_MSG_RET(expr, DetailsArgs, rcRet) \
|
---|
1040 | do { if (!(expr)) { \
|
---|
1041 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
1042 | RTTestIFailureDetails DetailsArgs; \
|
---|
1043 | return (rcRet); \
|
---|
1044 | } \
|
---|
1045 | } while (0)
|
---|
1046 | /** @def RTTESTI_CHECK_MSG_RET
|
---|
1047 | * Check whether a boolean expression holds true, returns void on false.
|
---|
1048 | *
|
---|
1049 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
1050 | * expression.
|
---|
1051 | *
|
---|
1052 | * @param expr The expression to evaluate.
|
---|
1053 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
1054 | * parenthesis.
|
---|
1055 | */
|
---|
1056 | #define RTTESTI_CHECK_MSG_RETV(expr, DetailsArgs) \
|
---|
1057 | do { if (!(expr)) { \
|
---|
1058 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
1059 | RTTestIFailureDetails DetailsArgs; \
|
---|
1060 | return; \
|
---|
1061 | } \
|
---|
1062 | } while (0)
|
---|
1063 |
|
---|
1064 |
|
---|
1065 | /** @def RTTESTI_CHECK_RC
|
---|
1066 | * Check whether an expression returns a specific IPRT style status code.
|
---|
1067 | *
|
---|
1068 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
1069 | * number, expression, actual and expected status codes.
|
---|
1070 | *
|
---|
1071 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1072 | * @param rcExpect The expected return code. This may be referenced
|
---|
1073 | * more than once by the macro.
|
---|
1074 | */
|
---|
1075 | #define RTTESTI_CHECK_RC(rcExpr, rcExpect) \
|
---|
1076 | do { \
|
---|
1077 | int rcCheck = (rcExpr); \
|
---|
1078 | if (rcCheck != (rcExpect)) { \
|
---|
1079 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
1080 | } \
|
---|
1081 | } while (0)
|
---|
1082 | /** @def RTTESTI_CHECK_RC_RET
|
---|
1083 | * Check whether an expression returns a specific IPRT style status code.
|
---|
1084 | *
|
---|
1085 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
1086 | * number, expression, actual and expected status codes, then return.
|
---|
1087 | *
|
---|
1088 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1089 | * This will be assigned to a local rcCheck variable
|
---|
1090 | * that can be used as return value.
|
---|
1091 | * @param rcExpect The expected return code. This may be referenced
|
---|
1092 | * more than once by the macro.
|
---|
1093 | * @param rcRet The return code.
|
---|
1094 | */
|
---|
1095 | #define RTTESTI_CHECK_RC_RET(rcExpr, rcExpect, rcRet) \
|
---|
1096 | do { \
|
---|
1097 | int rcCheck = (rcExpr); \
|
---|
1098 | if (rcCheck != (rcExpect)) { \
|
---|
1099 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
1100 | return (rcRet); \
|
---|
1101 | } \
|
---|
1102 | } while (0)
|
---|
1103 | /** @def RTTESTI_CHECK_RC_RETV
|
---|
1104 | * Check whether an expression returns a specific IPRT style status code.
|
---|
1105 | *
|
---|
1106 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
1107 | * number, expression, actual and expected status codes, then return.
|
---|
1108 | *
|
---|
1109 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1110 | * @param rcExpect The expected return code. This may be referenced
|
---|
1111 | * more than once by the macro.
|
---|
1112 | */
|
---|
1113 | #define RTTESTI_CHECK_RC_RETV(rcExpr, rcExpect) \
|
---|
1114 | do { \
|
---|
1115 | int rcCheck = (rcExpr); \
|
---|
1116 | if (rcCheck != (rcExpect)) { \
|
---|
1117 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
1118 | return; \
|
---|
1119 | } \
|
---|
1120 | } while (0)
|
---|
1121 | /** @def RTTESTI_CHECK_RC_BREAK
|
---|
1122 | * Check whether an expression returns a specific IPRT style status code.
|
---|
1123 | *
|
---|
1124 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
1125 | * number, expression, actual and expected status codes, then break.
|
---|
1126 | *
|
---|
1127 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1128 | * @param rcExpect The expected return code. This may be referenced
|
---|
1129 | * more than once by the macro.
|
---|
1130 | */
|
---|
1131 | #define RTTESTI_CHECK_RC_BREAK(rcExpr, rcExpect) \
|
---|
1132 | if (1) { \
|
---|
1133 | int rcCheck = (rcExpr); \
|
---|
1134 | if (rcCheck != (rcExpect)) { \
|
---|
1135 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
1136 | break; \
|
---|
1137 | } \
|
---|
1138 | } else do {} while (0)
|
---|
1139 |
|
---|
1140 |
|
---|
1141 | /** @def RTTESTI_CHECK_RC_OK
|
---|
1142 | * Check whether a IPRT style status code indicates success.
|
---|
1143 | *
|
---|
1144 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
1145 | * expression and status code.
|
---|
1146 | *
|
---|
1147 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1148 | */
|
---|
1149 | #define RTTESTI_CHECK_RC_OK(rcExpr) \
|
---|
1150 | do { \
|
---|
1151 | int rcCheck = (rcExpr); \
|
---|
1152 | if (RT_FAILURE(rcCheck)) { \
|
---|
1153 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
1154 | } \
|
---|
1155 | } while (0)
|
---|
1156 | /** @def RTTESTI_CHECK_RC_OK_RET
|
---|
1157 | * Check whether a IPRT style status code indicates success.
|
---|
1158 | *
|
---|
1159 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
1160 | * expression and status code, then return with the specified value.
|
---|
1161 | *
|
---|
1162 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1163 | * This will be assigned to a local rcCheck variable
|
---|
1164 | * that can be used as return value.
|
---|
1165 | * @param rcRet The return code.
|
---|
1166 | */
|
---|
1167 | #define RTTESTI_CHECK_RC_OK_RET(rcExpr, rcRet) \
|
---|
1168 | do { \
|
---|
1169 | int rcCheck = (rcExpr); \
|
---|
1170 | if (RT_FAILURE(rcCheck)) { \
|
---|
1171 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
1172 | return (rcRet); \
|
---|
1173 | } \
|
---|
1174 | } while (0)
|
---|
1175 | /** @def RTTESTI_CHECK_RC_OK_RETV
|
---|
1176 | * Check whether a IPRT style status code indicates success.
|
---|
1177 | *
|
---|
1178 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
1179 | * expression and status code, then return.
|
---|
1180 | *
|
---|
1181 | * @param rcExpr The expression resulting in an IPRT status code.
|
---|
1182 | */
|
---|
1183 | #define RTTESTI_CHECK_RC_OK_RETV(rcExpr) \
|
---|
1184 | do { \
|
---|
1185 | int rcCheck = (rcExpr); \
|
---|
1186 | if (RT_FAILURE(rcCheck)) { \
|
---|
1187 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
1188 | return; \
|
---|
1189 | } \
|
---|
1190 | } while (0)
|
---|
1191 |
|
---|
1192 | /** @} */
|
---|
1193 |
|
---|
1194 |
|
---|
1195 | /** @} */
|
---|
1196 |
|
---|
1197 | RT_C_DECLS_END
|
---|
1198 |
|
---|
1199 | #endif
|
---|
1200 |
|
---|