VirtualBox

source: vbox/trunk/include/iprt/test.h@ 18569

Last change on this file since 18569 was 18569, checked in by vboxsync, 16 years ago

RTTest: sub tests, more typical reporting of those.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
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. */
45typedef struct RTTESTINT *RTTEST;
46/** A pointer to a test handle. */
47typedef RTTEST *PRTTEST;
48/** A const pointer to a test handle. */
49typedef RTTEST const *PCRTTEST;
50
51/** A NIL Test handle. */
52#define NIL_RTTEST ((RTTEST)0)
53
54/**
55 * Test message importance level.
56 */
57typedef 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 */
83RTR3DECL(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 */
91RTR3DECL(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 */
104RTR3DECL(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 */
115RTR3DECL(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 */
126RTR3DECL(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 */
136RTR3DECL(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 */
148RTR3DECL(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 */
160RTR3DECL(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 */
172RTR3DECL(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 */
184RTR3DECL(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 */
193RTR3DECL(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 */
202RTR3DECL(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 */
215RTR3DECL(int) RTTestSub(RTTEST hTest, const char *pszSubTest);
216
217/**
218 * Completes a sub-test.
219 *
220 * @returns Number of chars printed.
221 * @param hTest The test handle. If NIL_RTTEST we'll use the one
222 * associated with the calling thread.
223 */
224RTR3DECL(int) RTTestSubDone(RTTEST hTest);
225
226/**
227 * Increments the error counter.
228 *
229 * @returns IPRT status code.
230 * @param hTest The test handle. If NIL_RTTEST we'll use the one
231 * associated with the calling thread.
232 */
233RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
234
235/**
236 * Increments the error counter and prints a failure message.
237 *
238 * @returns IPRT status code.
239 * @param hTest The test handle. If NIL_RTTEST we'll use the one
240 * associated with the calling thread.
241 * @param pszFormat The message. No trailing newline.
242 * @param va The arguments.
243 */
244RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va);
245
246/**
247 * Increments the error counter and prints a failure message.
248 *
249 * @returns IPRT status code.
250 * @param hTest The test handle. If NIL_RTTEST we'll use the one
251 * associated with the calling thread.
252 * @param pszFormat The message. No trailing newline.
253 * @param ... The arguments.
254 */
255RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...);
256
257
258/** @def RTTEST_CHECK
259 * Check whether a boolean expression holds true.
260 *
261 * If the expression is false, call RTTestFailed giving the line number and expression.
262 *
263 * @param hTest The test handle.
264 * @param expr The expression to evaluate.
265 */
266#define RTTEST_CHECK(hTest, expr) \
267 do { if (!(expr)) { RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); } } while (0)
268
269/** @def RTTEST_CHECK_MSG
270 * Check whether a boolean expression holds true.
271 *
272 * If the expression is false, call RTTestFailed giving the line number and expression.
273 *
274 * @param hTest The test handle.
275 * @param expr The expression to evaluate.
276 * @param TestPrintfArgs Argument list for RTTestPrintf, including
277 * parenthesis.
278 */
279#define RTTEST_CHECK_MSG(hTest, expr, TestPrintfArgs) \
280 do { if (!(expr)) { \
281 RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); \
282 RTTestPrintf TestPrintfArgs; \
283 } \
284 } while (0)
285
286
287/**
288 * Prints an extended PASSED message, optional.
289 *
290 * This does not conclude the sub-test, it could be used to report the passing
291 * of a sub-sub-to-the-power-of-N-test.
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 */
299RTR3DECL(int) RTTestPassedV(RTTEST hTest, const char *pszFormat, va_list va);
300
301/**
302 * Prints an extended PASSED message, optional.
303 *
304 * This does not conclude the sub-test, it could be used to report the passing
305 * of a sub-sub-to-the-power-of-N-test.
306 *
307 * @returns IPRT status code.
308 * @param hTest The test handle. If NIL_RTTEST we'll use the one
309 * associated with the calling thread.
310 * @param pszFormat The message. No trailing newline.
311 * @param ... The arguments.
312 */
313RTR3DECL(int) RTTestPassed(RTTEST hTest, const char *pszFormat, ...);
314
315
316/** @} */
317
318__END_DECLS
319
320#endif
321
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette