]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/unicode/ctest.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
6 * Copyright (C) 1996-2013, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ********************************************************************************
15 #include "unicode/testtype.h"
16 #include "unicode/utrace.h"
19 /* prototypes *********************************/
22 typedef void (U_CALLCONV
*TestFunctionPtr
)(void);
23 typedef int (U_CALLCONV
*ArgHandlerPtr
)(int arg
, int argc
, const char* const argv
[], void *context
);
24 typedef struct TestNode TestNode
;
28 * This is use to set or get the option value for REPEAT_TESTS.
29 * Use with set/getTestOption().
33 #define REPEAT_TESTS_OPTION 1
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.
38 * Otherwise nonzero to see log_verbose() messages.
39 * Use with set/getTestOption().
43 #define VERBOSITY_OPTION 2
46 * This is use to set or get the option value for ERR_MSG.
47 * Use with set/getTestOption().
51 #define ERR_MSG_OPTION 3
54 * This is use to set or get the option value for QUICK.
55 * When option is zero, disable some of the slower tests.
56 * Otherwise nonzero to run the slower tests.
57 * Use with set/getTestOption().
61 #define QUICK_OPTION 4
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.
67 * Affects the behavior of log_dataerr.
68 * Use with set/getTestOption().
73 #define WARN_ON_MISSING_DATA_OPTION 5
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().
82 #define ICU_TRACE_OPTION 6
85 * Maximum amount of memory uprv_malloc should allocate before returning NULL.
89 extern T_CTEST_EXPORT_API
size_t MAX_MEMORY_ALLOCATION
;
92 * If memory tracing was enabled, contains the number of unfreed allocations.
96 extern T_CTEST_EXPORT_API
int32_t ALLOCATION_COUNT
;
99 * Pass to setTestOption to decrement the test option value.
103 #define DECREMENT_OPTION_VALUE -99
106 * Gets the test option set on commandline.
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
112 T_CTEST_API
int32_t T_CTEST_EXPORT2
113 getTestOption ( int32_t testOption
);
116 * Sets the test option with value given on commandline.
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
122 T_CTEST_API
void T_CTEST_EXPORT2
123 setTestOption ( int32_t testOption
, int32_t value
);
126 * Show the names of all nodes.
128 * @param root Subtree of tests.
129 * @internal Internal APIs for testing purpose only
131 T_CTEST_API
void T_CTEST_EXPORT2
132 showTests ( const TestNode
*root
);
135 * Run a subtree of tests.
137 * @param root Subtree of tests.
138 * @internal Internal APIs for testing purpose only
140 T_CTEST_API
void T_CTEST_EXPORT2
141 runTests ( const TestNode
* root
);
144 * Add a test to the subtree.
147 * TestNode* root=NULL;
148 * addTest(&root, &mytest, "/a/b/mytest" );
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
155 T_CTEST_API
void T_CTEST_EXPORT2
156 addTest(TestNode
** root
,
157 TestFunctionPtr test
,
161 * Clean up any allocated memory.
162 * Conditions for calling this function are the same as u_cleanup().
164 * @internal Internal APIs for testing purpose only
166 T_CTEST_API
void T_CTEST_EXPORT2
167 cleanUpTestTree(TestNode
*tn
);
170 * Retreive a specific subtest. (subtree).
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
177 T_CTEST_API
const TestNode
* T_CTEST_EXPORT2
178 getTest(const TestNode
* root
,
183 * Log an error message. (printf style)
184 * @param pattern printf-style format string
185 * @internal Internal APIs for testing purpose only
187 T_CTEST_API
void T_CTEST_EXPORT2
188 log_err(const char* pattern
, ...);
190 T_CTEST_API
void T_CTEST_EXPORT2
191 log_err_status(UErrorCode status
, const char* pattern
, ...);
193 * Log an informational message. (printf style)
194 * @param pattern printf-style format string
195 * @internal Internal APIs for testing purpose only
197 T_CTEST_API
void T_CTEST_EXPORT2
198 log_info(const char* pattern
, ...);
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
207 T_CTEST_API
void T_CTEST_EXPORT2
208 vlog_info(const char *prefix
, const char *pattern
, va_list ap
);
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
216 T_CTEST_API
void T_CTEST_EXPORT2
217 log_verbose(const char* pattern
, ...);
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
226 T_CTEST_API
void T_CTEST_EXPORT2
227 log_data_err(const char *pattern
, ...);
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
237 log_knownIssue(const char *ticket
, const char *fmt
, ...);
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.
244 T_CTEST_API
int T_CTEST_EXPORT2
245 initArgs( int argc
, const char* const argv
[], ArgHandlerPtr argHandler
, void *context
);
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
260 T_CTEST_API
int T_CTEST_EXPORT2
261 runTestRequest(const TestNode
* root
,
263 const char* const argv
[]);
266 T_CTEST_API
const char* T_CTEST_EXPORT2
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.
274 T_CTEST_API
void T_CTEST_EXPORT2
275 str_timeDelta(char *str
, UDate delta
);
278 /* ======== XML (JUnit output) ========= */
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.
285 T_CTEST_API
int32_t T_CTEST_EXPORT2
286 ctest_xml_setFileName(const char *fileName
);
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.
294 T_CTEST_API
int32_t T_CTEST_EXPORT2
295 ctest_xml_init(const char *rootName
);
299 * Set the filename for the XML output. Caller must retain storage.
300 * @return 0 on success, 1 on failure.
302 T_CTEST_API
int32_t T_CTEST_EXPORT2
303 ctest_xml_fini(void);
308 * @return 0 on success, 1 on failure.
312 ctest_xml_testcase(const char *classname
, const char *name
, const char *time
, const char *failMsg
);