2 ********************************************************************************
4 * Copyright (C) 1996-2008, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
13 #include "unicode/testtype.h"
14 #include "unicode/utrace.h"
17 /* prototypes *********************************/
20 typedef void (U_CALLCONV
*TestFunctionPtr
)(void);
21 typedef int (U_CALLCONV
*ArgHandlerPtr
)(int arg
, int argc
, const char* const argv
[], void *context
);
22 typedef struct TestNode TestNode
;
26 * Set this to zero to disable log_verbose() messages.
27 * Otherwise nonzero to see log_verbose() messages.
29 * @internal Internal APIs for testing purpose only
31 extern T_CTEST_EXPORT_API
int REPEAT_TESTS
;
34 * Set this to zero to disable log_verbose() messages.
35 * Otherwise nonzero to see log_verbose() messages.
37 * @internal Internal APIs for testing purpose only
39 extern T_CTEST_EXPORT_API
int VERBOSITY
;
42 * Set this to zero to disable log_verbose() messages.
43 * Otherwise nonzero to see log_verbose() messages.
45 * @internal Internal APIs for testing purpose only
47 extern T_CTEST_EXPORT_API
int ERR_MSG
;
50 * Set this to zero to disable some of the slower tests.
51 * Otherwise nonzero to run the slower tests.
53 * @internal Internal APIs for testing purpose only
55 extern T_CTEST_EXPORT_API
int QUICK
;
58 * Set this to nonzero to warn (not error) on missing data.
59 * Otherwise, zero will cause an error to be propagated when data is not available.
60 * Affects the behavior of log_dataerr.
63 * @internal Internal APIs for testing purpose only
65 extern T_CTEST_EXPORT_API
int WARN_ON_MISSING_DATA
;
68 * ICU tracing level, is set by command line option
72 extern T_CTEST_EXPORT_API UTraceLevel ICU_TRACE
;
75 * Maximum amount of memory uprv_malloc should allocate before returning NULL.
79 extern T_CTEST_EXPORT_API
size_t MAX_MEMORY_ALLOCATION
;
82 * If memory tracing was enabled, contains the number of unfreed allocations.
86 extern T_CTEST_EXPORT_API
int32_t ALLOCATION_COUNT
;
90 * Show the names of all nodes.
92 * @param root Subtree of tests.
93 * @internal Internal APIs for testing purpose only
95 T_CTEST_API
void T_CTEST_EXPORT2
96 showTests ( const TestNode
*root
);
99 * Run a subtree of tests.
101 * @param root Subtree of tests.
102 * @internal Internal APIs for testing purpose only
104 T_CTEST_API
void T_CTEST_EXPORT2
105 runTests ( const TestNode
* root
);
108 * Add a test to the subtree.
111 * TestNode* root=NULL;
112 * addTest(&root, &mytest, "/a/b/mytest" );
114 * @param root Pointer to the root pointer.
115 * @param test Pointer to 'void function(void)' for actual test.
116 * @param path Path from root under which test will be placed. Ex. '/a/b/mytest'
117 * @internal Internal APIs for testing purpose only
119 T_CTEST_API
void T_CTEST_EXPORT2
120 addTest(TestNode
** root
,
121 TestFunctionPtr test
,
125 * Clean up any allocated memory.
126 * Conditions for calling this function are the same as u_cleanup().
128 * @internal Internal APIs for testing purpose only
130 T_CTEST_API
void T_CTEST_EXPORT2
131 cleanUpTestTree(TestNode
*tn
);
134 * Retreive a specific subtest. (subtree).
136 * @param root Pointer to the root.
137 * @param path Path relative to the root, Ex. '/a/b'
138 * @return The subtest, or NULL on failure.
139 * @internal Internal APIs for testing purpose only
141 T_CTEST_API
const TestNode
* T_CTEST_EXPORT2
142 getTest(const TestNode
* root
,
147 * Log an error message. (printf style)
148 * @param pattern printf-style format string
149 * @internal Internal APIs for testing purpose only
151 T_CTEST_API
void T_CTEST_EXPORT2
152 log_err(const char* pattern
, ...);
155 * Log an informational message. (printf style)
156 * @param pattern printf-style format string
157 * @internal Internal APIs for testing purpose only
159 T_CTEST_API
void T_CTEST_EXPORT2
160 log_info(const char* pattern
, ...);
163 * Log an informational message. (vprintf style)
164 * @param prefix a string that is output before the pattern and without formatting
165 * @param pattern printf-style format string
166 * @param ap variable-arguments list
167 * @internal Internal APIs for testing purpose only
169 T_CTEST_API
void T_CTEST_EXPORT2
170 vlog_info(const char *prefix
, const char *pattern
, va_list ap
);
173 * Log a verbose informational message. (printf style)
174 * This message will only appear if the global VERBOSITY is nonzero
175 * @param pattern printf-style format string
176 * @internal Internal APIs for testing purpose only
178 T_CTEST_API
void T_CTEST_EXPORT2
179 log_verbose(const char* pattern
, ...);
182 * Log an error message concerning missing data. (printf style)
183 * If WARN_ON_MISSING_DATA is nonzero, this will case a log_info (warning) to be
184 * printed, but if it is zero this will produce an error (log_err).
185 * @param pattern printf-style format string
186 * @internal Internal APIs for testing purpose only
188 T_CTEST_API
void T_CTEST_EXPORT2
189 log_data_err(const char *pattern
, ...);
192 * Initialize the variables above. This allows the test to set up accordingly
193 * before running the tests.
194 * This must be called before runTests.
196 T_CTEST_API
int T_CTEST_EXPORT2
197 initArgs( int argc
, const char* const argv
[], ArgHandlerPtr argHandler
, void *context
);
200 * Processes the command line arguments.
201 * This is a sample implementation
202 * <PRE>Usage: %s [ -l ] [ -v ] [ -? ] [ /path/to/test ]
203 * -l List only, do not run\
204 * -v turn OFF verbosity
205 * -? print this message</PRE>
206 * @param root Testnode root with tests already attached to it
207 * @param argv argument list from main (stdio.h)
208 * @param argc argument list count from main (stdio.h)
209 * @return positive for error count, 0 for success, negative for illegal argument
210 * @internal Internal APIs for testing purpose only
212 T_CTEST_API
int T_CTEST_EXPORT2
213 runTestRequest(const TestNode
* root
,
215 const char* const argv
[]);
218 T_CTEST_API
const char* T_CTEST_EXPORT2