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 | __BEGIN_DECLS
|
---|
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 | * Destroys a test instance previously created by RTTestCreate.
|
---|
87 | *
|
---|
88 | * @returns IPRT status code.
|
---|
89 | * @param hTest The test handle. NIL_RTTEST is ignored.
|
---|
90 | */
|
---|
91 | RTR3DECL(int) RTTestDestroy(RTTEST hTest);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Allocate a block of guarded memory.
|
---|
95 | *
|
---|
96 | * @returns IPRT status code.
|
---|
97 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
98 | * associated with the calling thread.
|
---|
99 | * @param cb The amount of memory to allocate.
|
---|
100 | * @param cbAlign The alignment of the returned block.
|
---|
101 | * @param fHead Head or tail optimized guard.
|
---|
102 | * @param ppvUser Where to return the pointer to the block.
|
---|
103 | */
|
---|
104 | RTR3DECL(int) RTTestGuardedAlloc(RTTEST hTest, size_t cb, uint32_t cbAlign, bool fHead, void **ppvUser);
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Allocates a block of guarded memory where the guarded is immediately after
|
---|
108 | * the user memory.
|
---|
109 | *
|
---|
110 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
111 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
112 | * associated with the calling thread.
|
---|
113 | * @param cb The amount of memory to allocate.
|
---|
114 | */
|
---|
115 | RTR3DECL(void *) RTTestGuardedAllocTail(RTTEST hTest, size_t cb);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Allocates a block of guarded memory where the guarded is right in front of
|
---|
119 | * the user memory.
|
---|
120 | *
|
---|
121 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
122 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
123 | * associated with the calling thread.
|
---|
124 | * @param cb The amount of memory to allocate.
|
---|
125 | */
|
---|
126 | RTR3DECL(void *) RTTestGuardedAllocHead(RTTEST hTest, size_t cb);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Frees a block of guarded memory.
|
---|
130 | *
|
---|
131 | * @returns IPRT status code.
|
---|
132 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
133 | * associated with the calling thread.
|
---|
134 | * @param pv The memory. NULL is ignored.
|
---|
135 | */
|
---|
136 | RTR3DECL(int) RTTestGuardedFree(RTTEST hTest, void *pv);
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Test vprintf making sure the output starts on a new line.
|
---|
140 | *
|
---|
141 | * @returns Number of chars printed.
|
---|
142 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
143 | * associated with the calling thread.
|
---|
144 | * @param enmLevel Message importance level.
|
---|
145 | * @param pszFormat The message.
|
---|
146 | * @param va Arguments.
|
---|
147 | */
|
---|
148 | RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Test printf making sure the output starts on a new line.
|
---|
152 | *
|
---|
153 | * @returns Number of chars printed.
|
---|
154 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
155 | * associated with the calling thread.
|
---|
156 | * @param enmLevel Message importance level.
|
---|
157 | * @param pszFormat The message.
|
---|
158 | * @param ... Arguments.
|
---|
159 | */
|
---|
160 | RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Test vprintf, makes sure lines are prefixed and so forth.
|
---|
164 | *
|
---|
165 | * @returns Number of chars printed.
|
---|
166 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
167 | * associated with the calling thread.
|
---|
168 | * @param enmLevel Message importance level.
|
---|
169 | * @param pszFormat The message.
|
---|
170 | * @param va Arguments.
|
---|
171 | */
|
---|
172 | RTR3DECL(int) RTTestPrintfV(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Test printf, makes sure lines are prefixed and so forth.
|
---|
176 | *
|
---|
177 | * @returns Number of chars printed.
|
---|
178 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
179 | * associated with the calling thread.
|
---|
180 | * @param enmLevel Message importance level.
|
---|
181 | * @param pszFormat The message.
|
---|
182 | * @param ... Arguments.
|
---|
183 | */
|
---|
184 | RTR3DECL(int) RTTestPrintf(RTTEST hTest, RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Prints the test banner.
|
---|
188 | *
|
---|
189 | * @returns Number of chars printed.
|
---|
190 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
191 | * associated with the calling thread.
|
---|
192 | */
|
---|
193 | RTR3DECL(int) RTTestBanner(RTTEST hTest);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Summaries the test, destroys the test instance and return an exit code.
|
---|
197 | *
|
---|
198 | * @returns Test program exit code.
|
---|
199 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
200 | * associated with the calling thread.
|
---|
201 | */
|
---|
202 | RTR3DECL(int) RTTestSummaryAndDestroy(RTTEST hTest);
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Starts a sub-test.
|
---|
206 | *
|
---|
207 | * This will perform an implicit RTTestSubDone() call if that has not been done
|
---|
208 | * since the last RTTestSub call.
|
---|
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 pszSubTest The sub-test name.
|
---|
214 | */
|
---|
215 | RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest);
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Format string version of RTTestSub.
|
---|
219 | *
|
---|
220 | * See RTTestSub for details.
|
---|
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 | * @param pszSubTestFmt The sub-test name format string.
|
---|
226 | * @param ... Arguments.
|
---|
227 | */
|
---|
228 | RTR3DECL(int) RTTestSubF(RTTEST hTest, const char *pszSubTestFmt, ...);
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Format string version of RTTestSub.
|
---|
232 | *
|
---|
233 | * See RTTestSub for details.
|
---|
234 | *
|
---|
235 | * @returns Number of chars printed.
|
---|
236 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
237 | * associated with the calling thread.
|
---|
238 | * @param pszSubTestFmt The sub-test name format string.
|
---|
239 | * @param ... Arguments.
|
---|
240 | */
|
---|
241 | RTR3DECL(int) RTTestSubV(RTTEST hTest, const char *pszSubTestFmt, va_list va);
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Completes a sub-test.
|
---|
245 | *
|
---|
246 | * @returns Number of chars printed.
|
---|
247 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
248 | * associated with the calling thread.
|
---|
249 | */
|
---|
250 | RTR3DECL(int) RTTestSubDone(RTTEST hTest);
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Prints an extended PASSED message, optional.
|
---|
254 | *
|
---|
255 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
256 | * of a sub-sub-to-the-power-of-N-test.
|
---|
257 | *
|
---|
258 | * @returns IPRT status code.
|
---|
259 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
260 | * associated with the calling thread.
|
---|
261 | * @param pszFormat The message. No trailing newline.
|
---|
262 | * @param va The arguments.
|
---|
263 | */
|
---|
264 | RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Prints an extended PASSED message, optional.
|
---|
268 | *
|
---|
269 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
270 | * of a sub-sub-to-the-power-of-N-test.
|
---|
271 | *
|
---|
272 | * @returns IPRT status code.
|
---|
273 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
274 | * associated with the calling thread.
|
---|
275 | * @param pszFormat The message. No trailing newline.
|
---|
276 | * @param ... The arguments.
|
---|
277 | */
|
---|
278 | RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...);
|
---|
279 |
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Increments the error counter.
|
---|
283 | *
|
---|
284 | * @returns IPRT status code.
|
---|
285 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
286 | * associated with the calling thread.
|
---|
287 | */
|
---|
288 | RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Increments the error counter and prints a failure message.
|
---|
292 | *
|
---|
293 | * @returns IPRT status code.
|
---|
294 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
295 | * associated with the calling thread.
|
---|
296 | * @param pszFormat The message. No trailing newline.
|
---|
297 | * @param va The arguments.
|
---|
298 | */
|
---|
299 | RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Increments the error counter and prints a failure message.
|
---|
303 | *
|
---|
304 | * @returns IPRT status code.
|
---|
305 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
306 | * associated with the calling thread.
|
---|
307 | * @param pszFormat The message. No trailing newline.
|
---|
308 | * @param ... The arguments.
|
---|
309 | */
|
---|
310 | RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...);
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Same as RTTestPrintfV with RTTESTLVL_FAILURE.
|
---|
314 | *
|
---|
315 | * @returns Number of chars printed.
|
---|
316 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
317 | * associated with the calling thread.
|
---|
318 | * @param enmLevel Message importance level.
|
---|
319 | * @param pszFormat The message.
|
---|
320 | * @param va Arguments.
|
---|
321 | */
|
---|
322 | RTR3DECL(int) RTTestFailureDetailsV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Same as RTTestPrintf with RTTESTLVL_FAILURE.
|
---|
326 | *
|
---|
327 | * @returns Number of chars printed.
|
---|
328 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
329 | * associated with the calling thread.
|
---|
330 | * @param enmLevel Message importance level.
|
---|
331 | * @param pszFormat The message.
|
---|
332 | * @param ... Arguments.
|
---|
333 | */
|
---|
334 | RTR3DECL(int) RTTestFailureDetails(RTTEST hTest, const char *pszFormat, ...);
|
---|
335 |
|
---|
336 |
|
---|
337 | /** @def RTTEST_CHECK
|
---|
338 | * Check whether a boolean expression holds true.
|
---|
339 | *
|
---|
340 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
341 | *
|
---|
342 | * @param hTest The test handle.
|
---|
343 | * @param expr The expression to evaluate.
|
---|
344 | */
|
---|
345 | #define RTTEST_CHECK(hTest, expr) \
|
---|
346 | do { if (!(expr)) { \
|
---|
347 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
348 | } \
|
---|
349 | } while (0)
|
---|
350 | /** @def RTTEST_CHECK_RET
|
---|
351 | * Check whether a boolean expression holds true, returns on false.
|
---|
352 | *
|
---|
353 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
354 | *
|
---|
355 | * @param hTest The test handle.
|
---|
356 | * @param expr The expression to evaluate.
|
---|
357 | * @param rcRet What to return on failure.
|
---|
358 | */
|
---|
359 | #define RTTEST_CHECK_RET(hTest, expr, rcRet) \
|
---|
360 | do { if (!(expr)) { \
|
---|
361 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
362 | return (rcRet); \
|
---|
363 | } \
|
---|
364 | } while (0)
|
---|
365 | /** @def RTTEST_CHECK_RETV
|
---|
366 | * Check whether a boolean expression holds true, returns void on false.
|
---|
367 | *
|
---|
368 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
369 | *
|
---|
370 | * @param hTest The test handle.
|
---|
371 | * @param expr The expression to evaluate.
|
---|
372 | */
|
---|
373 | #define RTTEST_CHECK_RETV(hTest, expr) \
|
---|
374 | do { if (!(expr)) { \
|
---|
375 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
376 | return; \
|
---|
377 | } \
|
---|
378 | } while (0)
|
---|
379 |
|
---|
380 |
|
---|
381 | /** @def RTTEST_CHECK_MSG
|
---|
382 | * Check whether a boolean expression holds true.
|
---|
383 | *
|
---|
384 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
385 | *
|
---|
386 | * @param hTest The test handle.
|
---|
387 | * @param expr The expression to evaluate.
|
---|
388 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
389 | * parenthesis.
|
---|
390 | */
|
---|
391 | #define RTTEST_CHECK_MSG(hTest, expr, DetailsArgs) \
|
---|
392 | do { if (!(expr)) { \
|
---|
393 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
394 | RTTestFailureDetails DetailsArgs; \
|
---|
395 | } \
|
---|
396 | } while (0)
|
---|
397 | /** @def RTTEST_CHECK_MSG_RET
|
---|
398 | * Check whether a boolean expression holds true, returns on false.
|
---|
399 | *
|
---|
400 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
401 | *
|
---|
402 | * @param hTest The test handle.
|
---|
403 | * @param expr The expression to evaluate.
|
---|
404 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
405 | * parenthesis.
|
---|
406 | * @param rcRet What to return on failure.
|
---|
407 | */
|
---|
408 | #define RTTEST_CHECK_MSG_RET(hTest, expr, DetailsArgs, rcRet) \
|
---|
409 | do { if (!(expr)) { \
|
---|
410 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
411 | RTTestFailureDetails DetailsArgs; \
|
---|
412 | return (rcRet); \
|
---|
413 | } \
|
---|
414 | } while (0)
|
---|
415 | /** @def RTTEST_CHECK_MSG_RET
|
---|
416 | * Check whether a boolean expression holds true, returns void on false.
|
---|
417 | *
|
---|
418 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
419 | *
|
---|
420 | * @param hTest The test handle.
|
---|
421 | * @param expr The expression to evaluate.
|
---|
422 | * @param DetailsArgs Argument list for RTTestFailureDetails, including
|
---|
423 | * parenthesis.
|
---|
424 | */
|
---|
425 | #define RTTEST_CHECK_MSG_RETV(hTest, expr, DetailsArgs) \
|
---|
426 | do { if (!(expr)) { \
|
---|
427 | RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
|
---|
428 | RTTestFailureDetails DetailsArgs; \
|
---|
429 | return; \
|
---|
430 | } \
|
---|
431 | } while (0)
|
---|
432 |
|
---|
433 |
|
---|
434 | /** @def RTTEST_CHECK_RC
|
---|
435 | * Check whether an expression returns a specific IPRT style status code.
|
---|
436 | *
|
---|
437 | * If a different status code is return, call RTTestFailed giving the line
|
---|
438 | * number, expression, actual and expected status codes.
|
---|
439 | *
|
---|
440 | * @param hTest The test handle.
|
---|
441 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
442 | * @param rcExpect The expected return code. This may be referenced
|
---|
443 | * more than once by the macro.
|
---|
444 | */
|
---|
445 | #define RTTEST_CHECK_RC(hTest, rcExpr, rcExpect) \
|
---|
446 | do { \
|
---|
447 | int rcCheck = (rcExpr); \
|
---|
448 | if (rcCheck != (rcExpect)) { \
|
---|
449 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
450 | } \
|
---|
451 | } while (0)
|
---|
452 | /** @def RTTEST_CHECK_RC_RET
|
---|
453 | * Check whether an expression returns a specific IPRT style status code.
|
---|
454 | *
|
---|
455 | * If a different status code is return, call RTTestFailed giving the line
|
---|
456 | * number, expression, actual and expected status codes, then return.
|
---|
457 | *
|
---|
458 | * @param hTest The test handle.
|
---|
459 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
460 | * @param rcExpect The expected return code. This may be referenced
|
---|
461 | * more than once by the macro.
|
---|
462 | * @param rcRet The return code.
|
---|
463 | */
|
---|
464 | #define RTTEST_CHECK_RC_RET(hTest, rcExpr, rcExpect, rcRet) \
|
---|
465 | do { \
|
---|
466 | int rcCheck = (rcExpr); \
|
---|
467 | if (rcCheck != (rcExpect)) { \
|
---|
468 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
469 | return (rcRet); \
|
---|
470 | } \
|
---|
471 | } while (0)
|
---|
472 | /** @def RTTEST_CHECK_RC_RETV
|
---|
473 | * Check whether an expression returns a specific IPRT style status code.
|
---|
474 | *
|
---|
475 | * If a different status code is return, call RTTestFailed giving the line
|
---|
476 | * number, expression, actual and expected status codes, then return.
|
---|
477 | *
|
---|
478 | * @param hTest The test handle.
|
---|
479 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
480 | * @param rcExpect The expected return code. This may be referenced
|
---|
481 | * more than once by the macro.
|
---|
482 | */
|
---|
483 | #define RTTEST_CHECK_RC_RETV(hTest, rcExpr, rcExpect) \
|
---|
484 | do { \
|
---|
485 | int rcCheck = (rcExpr); \
|
---|
486 | if (rcCheck != (rcExpect)) { \
|
---|
487 | RTTestFailed((hTest), "line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
488 | return; \
|
---|
489 | } \
|
---|
490 | } while (0)
|
---|
491 |
|
---|
492 |
|
---|
493 | /** @def RTTEST_CHECK_RC_OK
|
---|
494 | * Check whether a IPRT style status code indicates success.
|
---|
495 | *
|
---|
496 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
497 | * expression and status code.
|
---|
498 | *
|
---|
499 | * @param hTest The test handle.
|
---|
500 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
501 | */
|
---|
502 | #define RTTEST_CHECK_RC_OK(hTest, rcExpr) \
|
---|
503 | do { \
|
---|
504 | int rcCheck = (rcExpr); \
|
---|
505 | if (RT_FAILURE(rcCheck)) { \
|
---|
506 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rc); \
|
---|
507 | } \
|
---|
508 | } while (0)
|
---|
509 | /** @def RTTEST_CHECK_RC_OK_RET
|
---|
510 | * Check whether a IPRT style status code indicates success.
|
---|
511 | *
|
---|
512 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
513 | * expression and status code, then return with the specified value.
|
---|
514 | *
|
---|
515 | * @param hTest The test handle.
|
---|
516 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
517 | * @param rcRet The return code.
|
---|
518 | */
|
---|
519 | #define RTTEST_CHECK_RC_OK_RET(hTest, rcExpr, rcRet) \
|
---|
520 | do { \
|
---|
521 | int rcCheck = (rcExpr); \
|
---|
522 | if (RT_FAILURE(rcCheck)) { \
|
---|
523 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rc); \
|
---|
524 | return (rcRet); \
|
---|
525 | } \
|
---|
526 | } while (0)
|
---|
527 | /** @def RTTEST_CHECK_RC_OK_RETV
|
---|
528 | * Check whether a IPRT style status code indicates success.
|
---|
529 | *
|
---|
530 | * If the status indicates failure, call RTTestFailed giving the line number,
|
---|
531 | * expression and status code, then return.
|
---|
532 | *
|
---|
533 | * @param hTest The test handle.
|
---|
534 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
535 | */
|
---|
536 | #define RTTEST_CHECK_RC_OK_RETV(hTest, rcExpr) \
|
---|
537 | do { \
|
---|
538 | int rcCheck = (rcExpr); \
|
---|
539 | if (RT_FAILURE(rcCheck)) { \
|
---|
540 | RTTestFailed((hTest), "line %u: %s: %Rrc", __LINE__, #rcExpr, rc); \
|
---|
541 | return; \
|
---|
542 | } \
|
---|
543 | } while (0)
|
---|
544 |
|
---|
545 |
|
---|
546 |
|
---|
547 |
|
---|
548 | /** @name Implicit Test Handle API Variation
|
---|
549 | * The test handle is retrieved from the test TLS entry of the calling thread.
|
---|
550 | * @{
|
---|
551 | */
|
---|
552 |
|
---|
553 | /**
|
---|
554 | * Test vprintf, makes sure lines are prefixed and so forth.
|
---|
555 | *
|
---|
556 | * @returns Number of chars printed.
|
---|
557 | * @param enmLevel Message importance level.
|
---|
558 | * @param pszFormat The message.
|
---|
559 | * @param va Arguments.
|
---|
560 | */
|
---|
561 | RTR3DECL(int) RTTestIPrintfV(RTTESTLVL enmLevel, const char *pszFormat, va_list va);
|
---|
562 |
|
---|
563 | /**
|
---|
564 | * Test printf, makes sure lines are prefixed and so forth.
|
---|
565 | *
|
---|
566 | * @returns Number of chars printed.
|
---|
567 | * @param enmLevel Message importance level.
|
---|
568 | * @param pszFormat The message.
|
---|
569 | * @param ... Arguments.
|
---|
570 | */
|
---|
571 | RTR3DECL(int) RTTestIPrintf(RTTESTLVL enmLevel, const char *pszFormat, ...);
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Starts a sub-test.
|
---|
575 | *
|
---|
576 | * This will perform an implicit RTTestSubDone() call if that has not been done
|
---|
577 | * since the last RTTestSub call.
|
---|
578 | *
|
---|
579 | * @returns Number of chars printed.
|
---|
580 | * @param pszSubTest The sub-test name.
|
---|
581 | */
|
---|
582 | RTR3DECL(int) RTTestISub(const char *pszSubTest);
|
---|
583 |
|
---|
584 | /**
|
---|
585 | * Format string version of RTTestSub.
|
---|
586 | *
|
---|
587 | * See RTTestSub for details.
|
---|
588 | *
|
---|
589 | * @returns Number of chars printed.
|
---|
590 | * @param pszSubTestFmt The sub-test name format string.
|
---|
591 | * @param ... Arguments.
|
---|
592 | */
|
---|
593 | RTR3DECL(int) RTTestISubF(const char *pszSubTestFmt, ...);
|
---|
594 |
|
---|
595 | /**
|
---|
596 | * Format string version of RTTestSub.
|
---|
597 | *
|
---|
598 | * See RTTestSub for details.
|
---|
599 | *
|
---|
600 | * @returns Number of chars printed.
|
---|
601 | * @param pszSubTestFmt The sub-test name format string.
|
---|
602 | * @param ... Arguments.
|
---|
603 | */
|
---|
604 | RTR3DECL(int) RTTestISubV(const char *pszSubTestFmt, va_list va);
|
---|
605 |
|
---|
606 | /**
|
---|
607 | * Completes a sub-test.
|
---|
608 | *
|
---|
609 | * @returns Number of chars printed.
|
---|
610 | */
|
---|
611 | RTR3DECL(int) RTTestISubDone(void);
|
---|
612 |
|
---|
613 | /**
|
---|
614 | * Prints an extended PASSED message, optional.
|
---|
615 | *
|
---|
616 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
617 | * of a sub-sub-to-the-power-of-N-test.
|
---|
618 | *
|
---|
619 | * @returns IPRT status code.
|
---|
620 | * @param pszFormat The message. No trailing newline.
|
---|
621 | * @param va The arguments.
|
---|
622 | */
|
---|
623 | RTR3DECL(int) RTTestIPassedV(const char *pszFormat, va_list va);
|
---|
624 |
|
---|
625 | /**
|
---|
626 | * Prints an extended PASSED message, optional.
|
---|
627 | *
|
---|
628 | * This does not conclude the sub-test, it could be used to report the passing
|
---|
629 | * of a sub-sub-to-the-power-of-N-test.
|
---|
630 | *
|
---|
631 | * @returns IPRT status code.
|
---|
632 | * @param pszFormat The message. No trailing newline.
|
---|
633 | * @param ... The arguments.
|
---|
634 | */
|
---|
635 | RTR3DECL(int) RTTestIPassed(const char *pszFormat, ...);
|
---|
636 |
|
---|
637 | /**
|
---|
638 | * Increments the error counter.
|
---|
639 | *
|
---|
640 | * @returns IPRT status code.
|
---|
641 | */
|
---|
642 | RTR3DECL(int) RTTestIErrorInc(void);
|
---|
643 |
|
---|
644 | /**
|
---|
645 | * Increments the error counter and prints a failure message.
|
---|
646 | *
|
---|
647 | * @returns IPRT status code.
|
---|
648 | * @param pszFormat The message. No trailing newline.
|
---|
649 | * @param va The arguments.
|
---|
650 | */
|
---|
651 | RTR3DECL(int) RTTestIFailedV(const char *pszFormat, va_list va);
|
---|
652 |
|
---|
653 | /**
|
---|
654 | * Increments the error counter and prints a failure message.
|
---|
655 | *
|
---|
656 | * @returns IPRT status code.
|
---|
657 | * @param pszFormat The message. No trailing newline.
|
---|
658 | * @param ... The arguments.
|
---|
659 | */
|
---|
660 | RTR3DECL(int) RTTestIFailed(const char *pszFormat, ...);
|
---|
661 |
|
---|
662 | /**
|
---|
663 | * Same as RTTestIPrintfV with RTTESTLVL_FAILURE.
|
---|
664 | *
|
---|
665 | * @returns Number of chars printed.
|
---|
666 | * @param pszFormat The message.
|
---|
667 | * @param va Arguments.
|
---|
668 | */
|
---|
669 | RTR3DECL(int) RTTestIFailureDetailsV(const char *pszFormat, va_list va);
|
---|
670 |
|
---|
671 | /**
|
---|
672 | * Same as RTTestIPrintf with RTTESTLVL_FAILURE.
|
---|
673 | *
|
---|
674 | * @returns Number of chars printed.
|
---|
675 | * @param pszFormat The message.
|
---|
676 | * @param ... Arguments.
|
---|
677 | */
|
---|
678 | RTR3DECL(int) RTTestIFailureDetails(const char *pszFormat, ...);
|
---|
679 |
|
---|
680 |
|
---|
681 | /** @def RTTESTI_CHECK
|
---|
682 | * Check whether a boolean expression holds true.
|
---|
683 | *
|
---|
684 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
685 | * expression.
|
---|
686 | *
|
---|
687 | * @param expr The expression to evaluate.
|
---|
688 | */
|
---|
689 | #define RTTESTI_CHECK(expr) \
|
---|
690 | do { if (!(expr)) { \
|
---|
691 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
692 | } \
|
---|
693 | } while (0)
|
---|
694 | /** @def RTTESTI_CHECK_RET
|
---|
695 | * Check whether a boolean expression holds true, returns on false.
|
---|
696 | *
|
---|
697 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
698 | * expression.
|
---|
699 | *
|
---|
700 | * @param expr The expression to evaluate.
|
---|
701 | * @param rcRet What to return on failure.
|
---|
702 | */
|
---|
703 | #define RTTESTI_CHECK_RET(expr, rcRet) \
|
---|
704 | do { if (!(expr)) { \
|
---|
705 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
706 | return (rcRet); \
|
---|
707 | } \
|
---|
708 | } while (0)
|
---|
709 | /** @def RTTESTI_CHECK_RETV
|
---|
710 | * Check whether a boolean expression holds true, returns void on false.
|
---|
711 | *
|
---|
712 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
713 | * expression.
|
---|
714 | *
|
---|
715 | * @param expr The expression to evaluate.
|
---|
716 | */
|
---|
717 | #define RTTESTI_CHECK_RETV(expr) \
|
---|
718 | do { if (!(expr)) { \
|
---|
719 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
720 | return; \
|
---|
721 | } \
|
---|
722 | } while (0)
|
---|
723 |
|
---|
724 |
|
---|
725 | /** @def RTTESTI_CHECK_MSG
|
---|
726 | * Check whether a boolean expression holds true.
|
---|
727 | *
|
---|
728 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
729 | * expression.
|
---|
730 | *
|
---|
731 | * @param expr The expression to evaluate.
|
---|
732 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
733 | * parenthesis.
|
---|
734 | */
|
---|
735 | #define RTTESTI_CHECK_MSG(expr, DetailsArgs) \
|
---|
736 | do { if (!(expr)) { \
|
---|
737 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
738 | RTTestIFailureDetails DetailsArgs; \
|
---|
739 | } \
|
---|
740 | } while (0)
|
---|
741 | /** @def RTTESTI_CHECK_MSG_RET
|
---|
742 | * Check whether a boolean expression holds true, returns on false.
|
---|
743 | *
|
---|
744 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
745 | * expression.
|
---|
746 | *
|
---|
747 | * @param expr The expression to evaluate.
|
---|
748 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
749 | * parenthesis.
|
---|
750 | * @param rcRet What to return on failure.
|
---|
751 | */
|
---|
752 | #define RTTESTI_CHECK_MSG_RET(expr, DetailsArgs, rcRet) \
|
---|
753 | do { if (!(expr)) { \
|
---|
754 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
755 | RTTestIFailureDetails DetailsArgs; \
|
---|
756 | return (rcRet); \
|
---|
757 | } \
|
---|
758 | } while (0)
|
---|
759 | /** @def RTTESTI_CHECK_MSG_RET
|
---|
760 | * Check whether a boolean expression holds true, returns void on false.
|
---|
761 | *
|
---|
762 | * If the expression is false, call RTTestIFailed giving the line number and
|
---|
763 | * expression.
|
---|
764 | *
|
---|
765 | * @param expr The expression to evaluate.
|
---|
766 | * @param DetailsArgs Argument list for RTTestIFailureDetails, including
|
---|
767 | * parenthesis.
|
---|
768 | */
|
---|
769 | #define RTTESTI_CHECK_MSG_RETV(expr, DetailsArgs) \
|
---|
770 | do { if (!(expr)) { \
|
---|
771 | RTTestIFailed("line %u: %s", __LINE__, #expr); \
|
---|
772 | RTTestIFailureDetails DetailsArgs; \
|
---|
773 | return; \
|
---|
774 | } \
|
---|
775 | } while (0)
|
---|
776 |
|
---|
777 |
|
---|
778 | /** @def RTTESTI_CHECK_RC
|
---|
779 | * Check whether an expression returns a specific IPRT style status code.
|
---|
780 | *
|
---|
781 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
782 | * number, expression, actual and expected status codes.
|
---|
783 | *
|
---|
784 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
785 | * @param rcExpect The expected return code. This may be referenced
|
---|
786 | * more than once by the macro.
|
---|
787 | */
|
---|
788 | #define RTTESTI_CHECK_RC(rcExpr, rcExpect) \
|
---|
789 | do { \
|
---|
790 | int rcCheck = (rcExpr); \
|
---|
791 | if (rcCheck != (rcExpect)) { \
|
---|
792 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
793 | } \
|
---|
794 | } while (0)
|
---|
795 | /** @def RTTESTI_CHECK_RC_RET
|
---|
796 | * Check whether an expression returns a specific IPRT style status code.
|
---|
797 | *
|
---|
798 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
799 | * number, expression, actual and expected status codes, then return.
|
---|
800 | *
|
---|
801 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
802 | * @param rcExpect The expected return code. This may be referenced
|
---|
803 | * more than once by the macro.
|
---|
804 | * @param rcRet The return code.
|
---|
805 | */
|
---|
806 | #define RTTESTI_CHECK_RC_RET(rcExpr, rcExpect, rcRet) \
|
---|
807 | do { \
|
---|
808 | int rcCheck = (rcExpr); \
|
---|
809 | if (rcCheck != (rcExpect)) { \
|
---|
810 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
811 | return (rcRet); \
|
---|
812 | } \
|
---|
813 | } while (0)
|
---|
814 | /** @def RTTESTI_CHECK_RC_RETV
|
---|
815 | * Check whether an expression returns a specific IPRT style status code.
|
---|
816 | *
|
---|
817 | * If a different status code is return, call RTTestIFailed giving the line
|
---|
818 | * number, expression, actual and expected status codes, then return.
|
---|
819 | *
|
---|
820 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
821 | * @param rcExpect The expected return code. This may be referenced
|
---|
822 | * more than once by the macro.
|
---|
823 | */
|
---|
824 | #define RTTESTI_CHECK_RC_RETV(rcExpr, rcExpect) \
|
---|
825 | do { \
|
---|
826 | int rcCheck = (rcExpr); \
|
---|
827 | if (rcCheck != (rcExpect)) { \
|
---|
828 | RTTestIFailed("line %u: %s: expected %Rrc, got %Rrc", __LINE__, #rcExpr, (rcExpect), rcCheck); \
|
---|
829 | return; \
|
---|
830 | } \
|
---|
831 | } while (0)
|
---|
832 |
|
---|
833 |
|
---|
834 | /** @def RTTESTI_CHECK_RC_OK
|
---|
835 | * Check whether a IPRT style status code indicates success.
|
---|
836 | *
|
---|
837 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
838 | * expression and status code.
|
---|
839 | *
|
---|
840 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
841 | */
|
---|
842 | #define RTTESTI_CHECK_RC_OK(rcExpr) \
|
---|
843 | do { \
|
---|
844 | int rcCheck = (rcExpr); \
|
---|
845 | if (RT_FAILURE(rcCheck)) { \
|
---|
846 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
847 | } \
|
---|
848 | } while (0)
|
---|
849 | /** @def RTTESTI_CHECK_RC_OK_RET
|
---|
850 | * Check whether a IPRT style status code indicates success.
|
---|
851 | *
|
---|
852 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
853 | * expression and status code, then return with the specified value.
|
---|
854 | *
|
---|
855 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
856 | * @param rcRet The return code.
|
---|
857 | */
|
---|
858 | #define RTTESTI_CHECK_RC_OK_RET(rcExpr, rcRet) \
|
---|
859 | do { \
|
---|
860 | int rcCheck = (rcExpr); \
|
---|
861 | if (RT_FAILURE(rcCheck)) { \
|
---|
862 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
863 | return (rcRet); \
|
---|
864 | } \
|
---|
865 | } while (0)
|
---|
866 | /** @def RTTESTI_CHECK_RC_OK_RETV
|
---|
867 | * Check whether a IPRT style status code indicates success.
|
---|
868 | *
|
---|
869 | * If the status indicates failure, call RTTestIFailed giving the line number,
|
---|
870 | * expression and status code, then return.
|
---|
871 | *
|
---|
872 | * @param rcExpr The expression resulting an IPRT status code.
|
---|
873 | */
|
---|
874 | #define RTTESTI_CHECK_RC_OK_RETV(rcExpr) \
|
---|
875 | do { \
|
---|
876 | int rcCheck = (rcExpr); \
|
---|
877 | if (RT_FAILURE(rcCheck)) { \
|
---|
878 | RTTestIFailed("line %u: %s: %Rrc", __LINE__, #rcExpr, rcCheck); \
|
---|
879 | return; \
|
---|
880 | } \
|
---|
881 | } while (0)
|
---|
882 |
|
---|
883 | /** @} */
|
---|
884 |
|
---|
885 |
|
---|
886 | /** @} */
|
---|
887 |
|
---|
888 | __END_DECLS
|
---|
889 |
|
---|
890 | #endif
|
---|
891 |
|
---|