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