]>
Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | /* |
46f4442e A |
2 | ******************************************************************************** |
3 | * | |
57a6839d | 4 | * Copyright (C) 1996-2013, International Business Machines |
46f4442e A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ******************************************************************************** | |
8 | */ | |
b75a7d8f | 9 | |
b75a7d8f A |
10 | #ifndef CTEST_H |
11 | #define CTEST_H | |
12 | ||
374ca955 A |
13 | #include "unicode/testtype.h" |
14 | #include "unicode/utrace.h" | |
b75a7d8f A |
15 | |
16 | ||
17 | /* prototypes *********************************/ | |
18 | ||
374ca955 A |
19 | U_CDECL_BEGIN |
20 | typedef void (U_CALLCONV *TestFunctionPtr)(void); | |
46f4442e | 21 | typedef int (U_CALLCONV *ArgHandlerPtr)(int arg, int argc, const char* const argv[], void *context); |
b75a7d8f | 22 | typedef struct TestNode TestNode; |
374ca955 | 23 | U_CDECL_END |
b75a7d8f A |
24 | |
25 | /** | |
729e4ab9 A |
26 | * This is use to set or get the option value for REPEAT_TESTS. |
27 | * Use with set/getTestOption(). | |
b75a7d8f | 28 | * |
729e4ab9 | 29 | * @internal |
b75a7d8f | 30 | */ |
729e4ab9 | 31 | #define REPEAT_TESTS_OPTION 1 |
b75a7d8f A |
32 | |
33 | /** | |
729e4ab9 A |
34 | * This is use to set or get the option value for VERBOSITY. |
35 | * When option is set to zero to disable log_verbose() messages. | |
b75a7d8f | 36 | * Otherwise nonzero to see log_verbose() messages. |
729e4ab9 | 37 | * Use with set/getTestOption(). |
b75a7d8f | 38 | * |
729e4ab9 | 39 | * @internal |
b75a7d8f | 40 | */ |
729e4ab9 | 41 | #define VERBOSITY_OPTION 2 |
b75a7d8f A |
42 | |
43 | /** | |
729e4ab9 A |
44 | * This is use to set or get the option value for ERR_MSG. |
45 | * Use with set/getTestOption(). | |
b75a7d8f | 46 | * |
729e4ab9 | 47 | * @internal |
b75a7d8f | 48 | */ |
729e4ab9 | 49 | #define ERR_MSG_OPTION 3 |
b75a7d8f A |
50 | |
51 | /** | |
729e4ab9 A |
52 | * This is use to set or get the option value for QUICK. |
53 | * When option is zero, disable some of the slower tests. | |
b75a7d8f | 54 | * Otherwise nonzero to run the slower tests. |
729e4ab9 | 55 | * Use with set/getTestOption(). |
b75a7d8f | 56 | * |
729e4ab9 | 57 | * @internal |
b75a7d8f | 58 | */ |
729e4ab9 | 59 | #define QUICK_OPTION 4 |
b75a7d8f A |
60 | |
61 | /** | |
729e4ab9 A |
62 | * This is use to set or get the option value for WARN_ON_MISSING_DATA. |
63 | * When option is nonzero, warn on missing data. | |
64 | * Otherwise, errors are propagated when data is not available. | |
b75a7d8f | 65 | * Affects the behavior of log_dataerr. |
729e4ab9 | 66 | * Use with set/getTestOption(). |
b75a7d8f A |
67 | * |
68 | * @see log_data_err | |
729e4ab9 | 69 | * @internal |
b75a7d8f | 70 | */ |
729e4ab9 | 71 | #define WARN_ON_MISSING_DATA_OPTION 5 |
374ca955 A |
72 | |
73 | /** | |
729e4ab9 A |
74 | * This is use to set or get the option value for ICU_TRACE. |
75 | * ICU tracing level, is set by command line option. | |
76 | * Use with set/getTestOption(). | |
374ca955 A |
77 | * |
78 | * @internal | |
79 | */ | |
729e4ab9 | 80 | #define ICU_TRACE_OPTION 6 |
b75a7d8f | 81 | |
46f4442e A |
82 | /** |
83 | * Maximum amount of memory uprv_malloc should allocate before returning NULL. | |
84 | * | |
85 | * @internal | |
86 | */ | |
87 | extern T_CTEST_EXPORT_API size_t MAX_MEMORY_ALLOCATION; | |
88 | ||
89 | /** | |
90 | * If memory tracing was enabled, contains the number of unfreed allocations. | |
91 | * | |
92 | * @internal | |
93 | */ | |
94 | extern T_CTEST_EXPORT_API int32_t ALLOCATION_COUNT; | |
95 | ||
729e4ab9 A |
96 | /** |
97 | * Pass to setTestOption to decrement the test option value. | |
98 | * | |
99 | * @internal | |
100 | */ | |
101 | #define DECREMENT_OPTION_VALUE -99 | |
102 | ||
103 | /** | |
104 | * Gets the test option set on commandline. | |
105 | * | |
106 | * @param testOption macro definition for the individual test option | |
107 | * @return value of test option, zero if option is not set or off | |
108 | * @internal Internal APIs for testing purpose only | |
109 | */ | |
110 | T_CTEST_API int32_t T_CTEST_EXPORT2 | |
111 | getTestOption ( int32_t testOption ); | |
112 | ||
113 | /** | |
114 | * Sets the test option with value given on commandline. | |
115 | * | |
116 | * @param testOption macro definition for the individual test option | |
117 | * @param value to set the test option to | |
118 | * @internal Internal APIs for testing purpose only | |
119 | */ | |
120 | T_CTEST_API void T_CTEST_EXPORT2 | |
121 | setTestOption ( int32_t testOption, int32_t value); | |
46f4442e | 122 | |
b75a7d8f A |
123 | /** |
124 | * Show the names of all nodes. | |
125 | * | |
126 | * @param root Subtree of tests. | |
127 | * @internal Internal APIs for testing purpose only | |
128 | */ | |
374ca955 A |
129 | T_CTEST_API void T_CTEST_EXPORT2 |
130 | showTests ( const TestNode *root); | |
b75a7d8f A |
131 | |
132 | /** | |
133 | * Run a subtree of tests. | |
134 | * | |
135 | * @param root Subtree of tests. | |
136 | * @internal Internal APIs for testing purpose only | |
137 | */ | |
374ca955 A |
138 | T_CTEST_API void T_CTEST_EXPORT2 |
139 | runTests ( const TestNode* root); | |
b75a7d8f A |
140 | |
141 | /** | |
142 | * Add a test to the subtree. | |
143 | * Example usage: | |
144 | * <PRE> | |
145 | * TestNode* root=NULL; | |
146 | * addTest(&root, &mytest, "/a/b/mytest" ); | |
147 | * </PRE> | |
148 | * @param root Pointer to the root pointer. | |
149 | * @param test Pointer to 'void function(void)' for actual test. | |
150 | * @param path Path from root under which test will be placed. Ex. '/a/b/mytest' | |
151 | * @internal Internal APIs for testing purpose only | |
152 | */ | |
374ca955 A |
153 | T_CTEST_API void T_CTEST_EXPORT2 |
154 | addTest(TestNode** root, | |
155 | TestFunctionPtr test, | |
156 | const char *path); | |
b75a7d8f | 157 | |
374ca955 A |
158 | /** |
159 | * Clean up any allocated memory. | |
160 | * Conditions for calling this function are the same as u_cleanup(). | |
161 | * @see u_cleanup | |
162 | * @internal Internal APIs for testing purpose only | |
163 | */ | |
164 | T_CTEST_API void T_CTEST_EXPORT2 | |
165 | cleanUpTestTree(TestNode *tn); | |
b75a7d8f A |
166 | |
167 | /** | |
168 | * Retreive a specific subtest. (subtree). | |
169 | * | |
170 | * @param root Pointer to the root. | |
171 | * @param path Path relative to the root, Ex. '/a/b' | |
172 | * @return The subtest, or NULL on failure. | |
173 | * @internal Internal APIs for testing purpose only | |
174 | */ | |
374ca955 A |
175 | T_CTEST_API const TestNode* T_CTEST_EXPORT2 |
176 | getTest(const TestNode* root, | |
177 | const char *path); | |
b75a7d8f A |
178 | |
179 | ||
180 | /** | |
181 | * Log an error message. (printf style) | |
182 | * @param pattern printf-style format string | |
183 | * @internal Internal APIs for testing purpose only | |
184 | */ | |
374ca955 A |
185 | T_CTEST_API void T_CTEST_EXPORT2 |
186 | log_err(const char* pattern, ...); | |
b75a7d8f | 187 | |
729e4ab9 A |
188 | T_CTEST_API void T_CTEST_EXPORT2 |
189 | log_err_status(UErrorCode status, const char* pattern, ...); | |
b75a7d8f A |
190 | /** |
191 | * Log an informational message. (printf style) | |
192 | * @param pattern printf-style format string | |
193 | * @internal Internal APIs for testing purpose only | |
194 | */ | |
374ca955 A |
195 | T_CTEST_API void T_CTEST_EXPORT2 |
196 | log_info(const char* pattern, ...); | |
197 | ||
198 | /** | |
199 | * Log an informational message. (vprintf style) | |
200 | * @param prefix a string that is output before the pattern and without formatting | |
201 | * @param pattern printf-style format string | |
202 | * @param ap variable-arguments list | |
203 | * @internal Internal APIs for testing purpose only | |
204 | */ | |
205 | T_CTEST_API void T_CTEST_EXPORT2 | |
206 | vlog_info(const char *prefix, const char *pattern, va_list ap); | |
b75a7d8f A |
207 | |
208 | /** | |
209 | * Log a verbose informational message. (printf style) | |
210 | * This message will only appear if the global VERBOSITY is nonzero | |
211 | * @param pattern printf-style format string | |
212 | * @internal Internal APIs for testing purpose only | |
213 | */ | |
374ca955 A |
214 | T_CTEST_API void T_CTEST_EXPORT2 |
215 | log_verbose(const char* pattern, ...); | |
b75a7d8f A |
216 | |
217 | /** | |
218 | * Log an error message concerning missing data. (printf style) | |
219 | * If WARN_ON_MISSING_DATA is nonzero, this will case a log_info (warning) to be | |
220 | * printed, but if it is zero this will produce an error (log_err). | |
221 | * @param pattern printf-style format string | |
222 | * @internal Internal APIs for testing purpose only | |
223 | */ | |
374ca955 A |
224 | T_CTEST_API void T_CTEST_EXPORT2 |
225 | log_data_err(const char *pattern, ...); | |
b75a7d8f | 226 | |
57a6839d A |
227 | /** |
228 | * Log a known issue. | |
229 | * @param ticket ticket number such as "12345" for ICU tickets or "cldrbug:6636" for CLDR tickets. | |
230 | * @param fmt ... sprintf-style format, optional message. can be NULL. | |
231 | * @return TRUE if known issue test should be skipped, FALSE if it should be run | |
232 | */ | |
233 | T_CTEST_API UBool | |
234 | T_CTEST_EXPORT2 | |
235 | log_knownIssue(const char *ticket, const char *fmt, ...); | |
236 | ||
46f4442e A |
237 | /** |
238 | * Initialize the variables above. This allows the test to set up accordingly | |
239 | * before running the tests. | |
240 | * This must be called before runTests. | |
241 | */ | |
242 | T_CTEST_API int T_CTEST_EXPORT2 | |
243 | initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context); | |
244 | ||
b75a7d8f A |
245 | /** |
246 | * Processes the command line arguments. | |
247 | * This is a sample implementation | |
248 | * <PRE>Usage: %s [ -l ] [ -v ] [ -? ] [ /path/to/test ] | |
249 | * -l List only, do not run\ | |
250 | * -v turn OFF verbosity | |
251 | * -? print this message</PRE> | |
252 | * @param root Testnode root with tests already attached to it | |
253 | * @param argv argument list from main (stdio.h) | |
254 | * @param argc argument list count from main (stdio.h) | |
255 | * @return positive for error count, 0 for success, negative for illegal argument | |
256 | * @internal Internal APIs for testing purpose only | |
257 | */ | |
374ca955 | 258 | T_CTEST_API int T_CTEST_EXPORT2 |
46f4442e | 259 | runTestRequest(const TestNode* root, |
374ca955 A |
260 | int argc, |
261 | const char* const argv[]); | |
b75a7d8f A |
262 | |
263 | ||
374ca955 A |
264 | T_CTEST_API const char* T_CTEST_EXPORT2 |
265 | getTestName(void); | |
b75a7d8f | 266 | |
729e4ab9 A |
267 | /** |
268 | * Append a time delta to str if it is significant (>5 ms) otherwise no change | |
269 | * @param delta a delta in millis | |
270 | * @param str a string to append to. | |
271 | */ | |
272 | T_CTEST_API void T_CTEST_EXPORT2 | |
273 | str_timeDelta(char *str, UDate delta); | |
274 | ||
275 | ||
276 | /* ======== XML (JUnit output) ========= */ | |
277 | ||
278 | /** | |
279 | * Set the filename for the XML output. | |
280 | * @param fileName file name. Caller must retain storage. | |
281 | * @return 0 on success, 1 on failure. | |
282 | */ | |
283 | T_CTEST_API int32_t T_CTEST_EXPORT2 | |
284 | ctest_xml_setFileName(const char *fileName); | |
b75a7d8f A |
285 | |
286 | ||
729e4ab9 A |
287 | /** |
288 | * Init XML subsystem. Call ctest_xml_setFileName first | |
289 | * @param rootName the test root name to be written | |
290 | * @return 0 on success, 1 on failure. | |
291 | */ | |
292 | T_CTEST_API int32_t T_CTEST_EXPORT2 | |
293 | ctest_xml_init(const char *rootName); | |
294 | ||
295 | ||
296 | /** | |
297 | * Set the filename for the XML output. Caller must retain storage. | |
298 | * @return 0 on success, 1 on failure. | |
299 | */ | |
300 | T_CTEST_API int32_t T_CTEST_EXPORT2 | |
301 | ctest_xml_fini(void); | |
302 | ||
303 | ||
304 | /** | |
305 | * report a test case | |
306 | * @return 0 on success, 1 on failure. | |
307 | */ | |
308 | T_CTEST_API int32_t | |
309 | T_CTEST_EXPORT2 | |
310 | ctest_xml_testcase(const char *classname, const char *name, const char *time, const char *failMsg); | |
311 | ||
b75a7d8f | 312 | #endif |