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