]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/ctestfw/unicode/ctest.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / tools / ctestfw / unicode / ctest.h
CommitLineData
b75a7d8f 1/*
46f4442e
A
2 ********************************************************************************
3 *
729e4ab9 4 * Copyright (C) 1996-2010, 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
19U_CDECL_BEGIN
20typedef void (U_CALLCONV *TestFunctionPtr)(void);
46f4442e 21typedef int (U_CALLCONV *ArgHandlerPtr)(int arg, int argc, const char* const argv[], void *context);
b75a7d8f 22typedef struct TestNode TestNode;
374ca955 23U_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 */
87extern 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 */
94extern 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 */
110T_CTEST_API int32_t T_CTEST_EXPORT2
111getTestOption ( 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 */
120T_CTEST_API void T_CTEST_EXPORT2
121setTestOption ( 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
129T_CTEST_API void T_CTEST_EXPORT2
130showTests ( 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
138T_CTEST_API void T_CTEST_EXPORT2
139runTests ( 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
153T_CTEST_API void T_CTEST_EXPORT2
154addTest(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 */
164T_CTEST_API void T_CTEST_EXPORT2
165cleanUpTestTree(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
175T_CTEST_API const TestNode* T_CTEST_EXPORT2
176getTest(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
185T_CTEST_API void T_CTEST_EXPORT2
186log_err(const char* pattern, ...);
b75a7d8f 187
729e4ab9
A
188T_CTEST_API void T_CTEST_EXPORT2
189log_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
195T_CTEST_API void T_CTEST_EXPORT2
196log_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 */
205T_CTEST_API void T_CTEST_EXPORT2
206vlog_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
214T_CTEST_API void T_CTEST_EXPORT2
215log_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
224T_CTEST_API void T_CTEST_EXPORT2
225log_data_err(const char *pattern, ...);
b75a7d8f 226
46f4442e
A
227/**
228 * Initialize the variables above. This allows the test to set up accordingly
229 * before running the tests.
230 * This must be called before runTests.
231 */
232T_CTEST_API int T_CTEST_EXPORT2
233initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context);
234
b75a7d8f
A
235/**
236 * Processes the command line arguments.
237 * This is a sample implementation
238 * <PRE>Usage: %s [ -l ] [ -v ] [ -? ] [ /path/to/test ]
239 * -l List only, do not run\
240 * -v turn OFF verbosity
241 * -? print this message</PRE>
242 * @param root Testnode root with tests already attached to it
243 * @param argv argument list from main (stdio.h)
244 * @param argc argument list count from main (stdio.h)
245 * @return positive for error count, 0 for success, negative for illegal argument
246 * @internal Internal APIs for testing purpose only
247 */
374ca955 248T_CTEST_API int T_CTEST_EXPORT2
46f4442e 249runTestRequest(const TestNode* root,
374ca955
A
250 int argc,
251 const char* const argv[]);
b75a7d8f
A
252
253
374ca955
A
254T_CTEST_API const char* T_CTEST_EXPORT2
255getTestName(void);
b75a7d8f 256
729e4ab9
A
257/**
258 * Append a time delta to str if it is significant (>5 ms) otherwise no change
259 * @param delta a delta in millis
260 * @param str a string to append to.
261 */
262T_CTEST_API void T_CTEST_EXPORT2
263str_timeDelta(char *str, UDate delta);
264
265
266/* ======== XML (JUnit output) ========= */
267
268/**
269 * Set the filename for the XML output.
270 * @param fileName file name. Caller must retain storage.
271 * @return 0 on success, 1 on failure.
272 */
273T_CTEST_API int32_t T_CTEST_EXPORT2
274ctest_xml_setFileName(const char *fileName);
b75a7d8f
A
275
276
729e4ab9
A
277/**
278 * Init XML subsystem. Call ctest_xml_setFileName first
279 * @param rootName the test root name to be written
280 * @return 0 on success, 1 on failure.
281 */
282T_CTEST_API int32_t T_CTEST_EXPORT2
283ctest_xml_init(const char *rootName);
284
285
286/**
287 * Set the filename for the XML output. Caller must retain storage.
288 * @return 0 on success, 1 on failure.
289 */
290T_CTEST_API int32_t T_CTEST_EXPORT2
291ctest_xml_fini(void);
292
293
294/**
295 * report a test case
296 * @return 0 on success, 1 on failure.
297 */
298T_CTEST_API int32_t
299T_CTEST_EXPORT2
300ctest_xml_testcase(const char *classname, const char *name, const char *time, const char *failMsg);
301
b75a7d8f 302#endif