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