1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/tools/ctestfw/unicode/ctest.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,312 @@ 1.4 +/* 1.5 + ******************************************************************************** 1.6 + * 1.7 + * Copyright (C) 1996-2013, International Business Machines 1.8 + * Corporation and others. All Rights Reserved. 1.9 + * 1.10 + ******************************************************************************** 1.11 + */ 1.12 + 1.13 +#ifndef CTEST_H 1.14 +#define CTEST_H 1.15 + 1.16 +#include "unicode/testtype.h" 1.17 +#include "unicode/utrace.h" 1.18 + 1.19 + 1.20 +/* prototypes *********************************/ 1.21 + 1.22 +U_CDECL_BEGIN 1.23 +typedef void (U_CALLCONV *TestFunctionPtr)(void); 1.24 +typedef int (U_CALLCONV *ArgHandlerPtr)(int arg, int argc, const char* const argv[], void *context); 1.25 +typedef struct TestNode TestNode; 1.26 +U_CDECL_END 1.27 + 1.28 +/** 1.29 + * This is use to set or get the option value for REPEAT_TESTS. 1.30 + * Use with set/getTestOption(). 1.31 + * 1.32 + * @internal 1.33 + */ 1.34 +#define REPEAT_TESTS_OPTION 1 1.35 + 1.36 +/** 1.37 + * This is use to set or get the option value for VERBOSITY. 1.38 + * When option is set to zero to disable log_verbose() messages. 1.39 + * Otherwise nonzero to see log_verbose() messages. 1.40 + * Use with set/getTestOption(). 1.41 + * 1.42 + * @internal 1.43 + */ 1.44 +#define VERBOSITY_OPTION 2 1.45 + 1.46 +/** 1.47 + * This is use to set or get the option value for ERR_MSG. 1.48 + * Use with set/getTestOption(). 1.49 + * 1.50 + * @internal 1.51 + */ 1.52 +#define ERR_MSG_OPTION 3 1.53 + 1.54 +/** 1.55 + * This is use to set or get the option value for QUICK. 1.56 + * When option is zero, disable some of the slower tests. 1.57 + * Otherwise nonzero to run the slower tests. 1.58 + * Use with set/getTestOption(). 1.59 + * 1.60 + * @internal 1.61 + */ 1.62 +#define QUICK_OPTION 4 1.63 + 1.64 +/** 1.65 + * This is use to set or get the option value for WARN_ON_MISSING_DATA. 1.66 + * When option is nonzero, warn on missing data. 1.67 + * Otherwise, errors are propagated when data is not available. 1.68 + * Affects the behavior of log_dataerr. 1.69 + * Use with set/getTestOption(). 1.70 + * 1.71 + * @see log_data_err 1.72 + * @internal 1.73 + */ 1.74 +#define WARN_ON_MISSING_DATA_OPTION 5 1.75 + 1.76 +/** 1.77 + * This is use to set or get the option value for ICU_TRACE. 1.78 + * ICU tracing level, is set by command line option. 1.79 + * Use with set/getTestOption(). 1.80 + * 1.81 + * @internal 1.82 + */ 1.83 +#define ICU_TRACE_OPTION 6 1.84 + 1.85 +/** 1.86 + * Maximum amount of memory uprv_malloc should allocate before returning NULL. 1.87 + * 1.88 + * @internal 1.89 + */ 1.90 +extern T_CTEST_EXPORT_API size_t MAX_MEMORY_ALLOCATION; 1.91 + 1.92 +/** 1.93 + * If memory tracing was enabled, contains the number of unfreed allocations. 1.94 + * 1.95 + * @internal 1.96 + */ 1.97 +extern T_CTEST_EXPORT_API int32_t ALLOCATION_COUNT; 1.98 + 1.99 +/** 1.100 + * Pass to setTestOption to decrement the test option value. 1.101 + * 1.102 + * @internal 1.103 + */ 1.104 +#define DECREMENT_OPTION_VALUE -99 1.105 + 1.106 +/** 1.107 + * Gets the test option set on commandline. 1.108 + * 1.109 + * @param testOption macro definition for the individual test option 1.110 + * @return value of test option, zero if option is not set or off 1.111 + * @internal Internal APIs for testing purpose only 1.112 + */ 1.113 +T_CTEST_API int32_t T_CTEST_EXPORT2 1.114 +getTestOption ( int32_t testOption ); 1.115 + 1.116 +/** 1.117 + * Sets the test option with value given on commandline. 1.118 + * 1.119 + * @param testOption macro definition for the individual test option 1.120 + * @param value to set the test option to 1.121 + * @internal Internal APIs for testing purpose only 1.122 + */ 1.123 +T_CTEST_API void T_CTEST_EXPORT2 1.124 +setTestOption ( int32_t testOption, int32_t value); 1.125 + 1.126 +/** 1.127 + * Show the names of all nodes. 1.128 + * 1.129 + * @param root Subtree of tests. 1.130 + * @internal Internal APIs for testing purpose only 1.131 + */ 1.132 +T_CTEST_API void T_CTEST_EXPORT2 1.133 +showTests ( const TestNode *root); 1.134 + 1.135 +/** 1.136 + * Run a subtree of tests. 1.137 + * 1.138 + * @param root Subtree of tests. 1.139 + * @internal Internal APIs for testing purpose only 1.140 + */ 1.141 +T_CTEST_API void T_CTEST_EXPORT2 1.142 +runTests ( const TestNode* root); 1.143 + 1.144 +/** 1.145 + * Add a test to the subtree. 1.146 + * Example usage: 1.147 + * <PRE> 1.148 + * TestNode* root=NULL; 1.149 + * addTest(&root, &mytest, "/a/b/mytest" ); 1.150 + * </PRE> 1.151 + * @param root Pointer to the root pointer. 1.152 + * @param test Pointer to 'void function(void)' for actual test. 1.153 + * @param path Path from root under which test will be placed. Ex. '/a/b/mytest' 1.154 + * @internal Internal APIs for testing purpose only 1.155 + */ 1.156 +T_CTEST_API void T_CTEST_EXPORT2 1.157 +addTest(TestNode** root, 1.158 + TestFunctionPtr test, 1.159 + const char *path); 1.160 + 1.161 +/** 1.162 + * Clean up any allocated memory. 1.163 + * Conditions for calling this function are the same as u_cleanup(). 1.164 + * @see u_cleanup 1.165 + * @internal Internal APIs for testing purpose only 1.166 + */ 1.167 +T_CTEST_API void T_CTEST_EXPORT2 1.168 +cleanUpTestTree(TestNode *tn); 1.169 + 1.170 +/** 1.171 + * Retreive a specific subtest. (subtree). 1.172 + * 1.173 + * @param root Pointer to the root. 1.174 + * @param path Path relative to the root, Ex. '/a/b' 1.175 + * @return The subtest, or NULL on failure. 1.176 + * @internal Internal APIs for testing purpose only 1.177 + */ 1.178 +T_CTEST_API const TestNode* T_CTEST_EXPORT2 1.179 +getTest(const TestNode* root, 1.180 + const char *path); 1.181 + 1.182 + 1.183 +/** 1.184 + * Log an error message. (printf style) 1.185 + * @param pattern printf-style format string 1.186 + * @internal Internal APIs for testing purpose only 1.187 + */ 1.188 +T_CTEST_API void T_CTEST_EXPORT2 1.189 +log_err(const char* pattern, ...); 1.190 + 1.191 +T_CTEST_API void T_CTEST_EXPORT2 1.192 +log_err_status(UErrorCode status, const char* pattern, ...); 1.193 +/** 1.194 + * Log an informational message. (printf style) 1.195 + * @param pattern printf-style format string 1.196 + * @internal Internal APIs for testing purpose only 1.197 + */ 1.198 +T_CTEST_API void T_CTEST_EXPORT2 1.199 +log_info(const char* pattern, ...); 1.200 + 1.201 +/** 1.202 + * Log an informational message. (vprintf style) 1.203 + * @param prefix a string that is output before the pattern and without formatting 1.204 + * @param pattern printf-style format string 1.205 + * @param ap variable-arguments list 1.206 + * @internal Internal APIs for testing purpose only 1.207 + */ 1.208 +T_CTEST_API void T_CTEST_EXPORT2 1.209 +vlog_info(const char *prefix, const char *pattern, va_list ap); 1.210 + 1.211 +/** 1.212 + * Log a verbose informational message. (printf style) 1.213 + * This message will only appear if the global VERBOSITY is nonzero 1.214 + * @param pattern printf-style format string 1.215 + * @internal Internal APIs for testing purpose only 1.216 + */ 1.217 +T_CTEST_API void T_CTEST_EXPORT2 1.218 +log_verbose(const char* pattern, ...); 1.219 + 1.220 +/** 1.221 + * Log an error message concerning missing data. (printf style) 1.222 + * If WARN_ON_MISSING_DATA is nonzero, this will case a log_info (warning) to be 1.223 + * printed, but if it is zero this will produce an error (log_err). 1.224 + * @param pattern printf-style format string 1.225 + * @internal Internal APIs for testing purpose only 1.226 + */ 1.227 +T_CTEST_API void T_CTEST_EXPORT2 1.228 +log_data_err(const char *pattern, ...); 1.229 + 1.230 +/** 1.231 + * Log a known issue. 1.232 + * @param ticket ticket number such as "12345" for ICU tickets or "cldrbug:6636" for CLDR tickets. 1.233 + * @param fmt ... sprintf-style format, optional message. can be NULL. 1.234 + * @return TRUE if known issue test should be skipped, FALSE if it should be run 1.235 + */ 1.236 +T_CTEST_API UBool 1.237 +T_CTEST_EXPORT2 1.238 +log_knownIssue(const char *ticket, const char *fmt, ...); 1.239 + 1.240 +/** 1.241 + * Initialize the variables above. This allows the test to set up accordingly 1.242 + * before running the tests. 1.243 + * This must be called before runTests. 1.244 + */ 1.245 +T_CTEST_API int T_CTEST_EXPORT2 1.246 +initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context); 1.247 + 1.248 +/** 1.249 + * Processes the command line arguments. 1.250 + * This is a sample implementation 1.251 + * <PRE>Usage: %s [ -l ] [ -v ] [ -? ] [ /path/to/test ] 1.252 + * -l List only, do not run\ 1.253 + * -v turn OFF verbosity 1.254 + * -? print this message</PRE> 1.255 + * @param root Testnode root with tests already attached to it 1.256 + * @param argv argument list from main (stdio.h) 1.257 + * @param argc argument list count from main (stdio.h) 1.258 + * @return positive for error count, 0 for success, negative for illegal argument 1.259 + * @internal Internal APIs for testing purpose only 1.260 + */ 1.261 +T_CTEST_API int T_CTEST_EXPORT2 1.262 +runTestRequest(const TestNode* root, 1.263 + int argc, 1.264 + const char* const argv[]); 1.265 + 1.266 + 1.267 +T_CTEST_API const char* T_CTEST_EXPORT2 1.268 +getTestName(void); 1.269 + 1.270 +/** 1.271 + * Append a time delta to str if it is significant (>5 ms) otherwise no change 1.272 + * @param delta a delta in millis 1.273 + * @param str a string to append to. 1.274 + */ 1.275 +T_CTEST_API void T_CTEST_EXPORT2 1.276 +str_timeDelta(char *str, UDate delta); 1.277 + 1.278 + 1.279 +/* ======== XML (JUnit output) ========= */ 1.280 + 1.281 +/** 1.282 + * Set the filename for the XML output. 1.283 + * @param fileName file name. Caller must retain storage. 1.284 + * @return 0 on success, 1 on failure. 1.285 + */ 1.286 +T_CTEST_API int32_t T_CTEST_EXPORT2 1.287 +ctest_xml_setFileName(const char *fileName); 1.288 + 1.289 + 1.290 +/** 1.291 + * Init XML subsystem. Call ctest_xml_setFileName first 1.292 + * @param rootName the test root name to be written 1.293 + * @return 0 on success, 1 on failure. 1.294 + */ 1.295 +T_CTEST_API int32_t T_CTEST_EXPORT2 1.296 +ctest_xml_init(const char *rootName); 1.297 + 1.298 + 1.299 +/** 1.300 + * Set the filename for the XML output. Caller must retain storage. 1.301 + * @return 0 on success, 1 on failure. 1.302 + */ 1.303 +T_CTEST_API int32_t T_CTEST_EXPORT2 1.304 +ctest_xml_fini(void); 1.305 + 1.306 + 1.307 +/** 1.308 + * report a test case 1.309 + * @return 0 on success, 1 on failure. 1.310 + */ 1.311 +T_CTEST_API int32_t 1.312 +T_CTEST_EXPORT2 1.313 +ctest_xml_testcase(const char *classname, const char *name, const char *time, const char *failMsg); 1.314 + 1.315 +#endif