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 | /**
|
---|
56 | * Creates a test instance.
|
---|
57 | *
|
---|
58 | * @returns IPRT status code.
|
---|
59 | * @param pszTest The test name.
|
---|
60 | * @param phTest Where to store the test instance handle.
|
---|
61 | */
|
---|
62 | RTR3DECL(int) RTTestCreate(const char *pszTest, PRTTEST phTest);
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Destroys a test instance previously created by RTTestCreate.
|
---|
66 | *
|
---|
67 | * @returns IPRT status code.
|
---|
68 | * @param hTest The test handle. NIL_RTTEST is ignored.
|
---|
69 | */
|
---|
70 | RTR3DECL(int) RTTestDestroy(RTTEST hTest);
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Allocate a block of guarded memory.
|
---|
74 | *
|
---|
75 | * @returns IPRT status code.
|
---|
76 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
77 | * associated with the calling thread.
|
---|
78 | * @param cb The amount of memory to allocate.
|
---|
79 | * @param cbAlign The alignment of the returned block.
|
---|
80 | * @param fHead Head or tail optimized guard.
|
---|
81 | * @param ppvUser Where to return the pointer to the block.
|
---|
82 | */
|
---|
83 | RTR3DECL(int) RTTestGuardedAlloc(RTTEST hTest, size_t cb, uint32_t cbAlign, bool fHead, void **ppvUser);
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Allocates a block of guarded memory where the guarded is immediately after
|
---|
87 | * the user memory.
|
---|
88 | *
|
---|
89 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
90 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
91 | * associated with the calling thread.
|
---|
92 | * @param cb The amount of memory to allocate.
|
---|
93 | */
|
---|
94 | RTR3DECL(void *) RTTestGuardedAllocTail(RTTEST hTest, size_t cb);
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Allocates a block of guarded memory where the guarded is right in front of
|
---|
98 | * the user memory.
|
---|
99 | *
|
---|
100 | * @returns Pointer to the allocated memory. NULL on failure.
|
---|
101 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
102 | * associated with the calling thread.
|
---|
103 | * @param cb The amount of memory to allocate.
|
---|
104 | */
|
---|
105 | RTR3DECL(void *) RTTestGuardedAllocHead(RTTEST hTest, size_t cb);
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Frees a block of guarded memory.
|
---|
109 | *
|
---|
110 | * @returns IPRT status code.
|
---|
111 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
112 | * associated with the calling thread.
|
---|
113 | * @param pv The memory. NULL is ignored.
|
---|
114 | */
|
---|
115 | RTR3DECL(int) RTTestGuardedFree(RTTEST hTest, void *pv);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Test vprintf making sure the output starts on a new line.
|
---|
119 | *
|
---|
120 | * @returns Number of chars printed.
|
---|
121 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
122 | * associated with the calling thread.
|
---|
123 | * @param pszFormat The message.
|
---|
124 | * @param va Arguments.
|
---|
125 | */
|
---|
126 | RTR3DECL(int) RTTestPrintfNlV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Test printf making sure the output starts on a new line.
|
---|
130 | *
|
---|
131 | * @returns Number of chars printed.
|
---|
132 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
133 | * associated with the calling thread.
|
---|
134 | * @param pszFormat The message.
|
---|
135 | * @param ... Arguments.
|
---|
136 | */
|
---|
137 | RTR3DECL(int) RTTestPrintfNl(RTTEST hTest, const char *pszFormat, ...);
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Test vprintf, makes sure lines are prefixed and so forth.
|
---|
141 | *
|
---|
142 | * @returns Number of chars printed.
|
---|
143 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
144 | * associated with the calling thread.
|
---|
145 | * @param pszFormat The message.
|
---|
146 | * @param va Arguments.
|
---|
147 | */
|
---|
148 | RTR3DECL(int) RTTestPrintfV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Test printf, makes sure lines are prefixed and so forth.
|
---|
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 pszFormat The message.
|
---|
157 | * @param ... Arguments.
|
---|
158 | */
|
---|
159 | RTR3DECL(int) RTTestPrintf(RTTEST hTest, const char *pszFormat, ...);
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Prints the test banner.
|
---|
163 | *
|
---|
164 | * @returns Number of chars printed.
|
---|
165 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
166 | * associated with the calling thread.
|
---|
167 | */
|
---|
168 | RTR3DECL(int) RTTestBanner(RTTEST hTest);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Summaries the test, destroys the test instance and return an exit code.
|
---|
172 | *
|
---|
173 | * @returns Test program exit code.
|
---|
174 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
175 | * associated with the calling thread.
|
---|
176 | */
|
---|
177 | RTR3DECL(int) RTTestSummaryAndDestroy(RTTEST hTest);
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Increments the error counter.
|
---|
181 | *
|
---|
182 | * @returns IPRT status code.
|
---|
183 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
184 | * associated with the calling thread.
|
---|
185 | */
|
---|
186 | RTR3DECL(int) RTTestErrorInc(RTTEST hTest);
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Increments the error counter and prints a failure message.
|
---|
190 | *
|
---|
191 | * @returns IPRT status code.
|
---|
192 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
193 | * associated with the calling thread.
|
---|
194 | * @param pszFormat The message. No trailing newline.
|
---|
195 | * @param va The arguments.
|
---|
196 | */
|
---|
197 | RTR3DECL(int) RTTestFailedV(RTTEST hTest, const char *pszFormat, va_list va);
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Increments the error counter and prints a failure message.
|
---|
201 | *
|
---|
202 | * @returns IPRT status code.
|
---|
203 | * @param hTest The test handle. If NIL_RTTEST we'll use the one
|
---|
204 | * associated with the calling thread.
|
---|
205 | * @param pszFormat The message. No trailing newline.
|
---|
206 | * @param ... The arguments.
|
---|
207 | */
|
---|
208 | RTR3DECL(int) RTTestFailed(RTTEST hTest, const char *pszFormat, ...);
|
---|
209 |
|
---|
210 |
|
---|
211 | /** @def RTTEST_CHECK
|
---|
212 | * Check whether a boolean expression holds true.
|
---|
213 | *
|
---|
214 | * If the expression is false, call RTTestFailed giving the line number and expression.
|
---|
215 | *
|
---|
216 | * @param hTest The test handle.
|
---|
217 | * @param expr The expression to evaluate.
|
---|
218 | */
|
---|
219 | #define RTTEST_CHECK(hTest, expr) \
|
---|
220 | do { if (!(expr)) { RTTestFailed((hTest), "line %u: %s", __LINE__, #expr); } } while (0)
|
---|
221 |
|
---|
222 |
|
---|
223 | /** @} */
|
---|
224 |
|
---|
225 | __END_DECLS
|
---|
226 |
|
---|
227 | #endif
|
---|
228 |
|
---|