1/* 2 ******************************************************************************** 3 * 4 * Copyright (C) 1996-2009, International Business Machines 5 * Corporation and others. All Rights Reserved. 6 * 7 ******************************************************************************** 8 */ 9 10#ifndef CTEST_H 11#define CTEST_H 12 13#include "unicode/testtype.h" 14#include "unicode/utrace.h" 15 16 17/* prototypes *********************************/ 18 19U_CDECL_BEGIN 20typedef void (U_CALLCONV *TestFunctionPtr)(void); 21typedef int (U_CALLCONV *ArgHandlerPtr)(int arg, int argc, const char* const argv[], void *context); 22typedef struct TestNode TestNode; 23U_CDECL_END 24 25/** 26 * Set this to zero to disable log_verbose() messages. 27 * Otherwise nonzero to see log_verbose() messages. 28 * 29 * @internal Internal APIs for testing purpose only 30 */ 31extern T_CTEST_EXPORT_API int REPEAT_TESTS; 32 33/** 34 * Set this to zero to disable log_verbose() messages. 35 * Otherwise nonzero to see log_verbose() messages. 36 * 37 * @internal Internal APIs for testing purpose only 38 */ 39extern T_CTEST_EXPORT_API int VERBOSITY; 40 41/** 42 * Set this to zero to disable log_verbose() messages. 43 * Otherwise nonzero to see log_verbose() messages. 44 * 45 * @internal Internal APIs for testing purpose only 46 */ 47extern T_CTEST_EXPORT_API int ERR_MSG; 48 49/** 50 * Set this to zero to disable some of the slower tests. 51 * Otherwise nonzero to run the slower tests. 52 * 53 * @internal Internal APIs for testing purpose only 54 */ 55extern T_CTEST_EXPORT_API int QUICK; 56 57/** 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. 61 * 62 * @see log_data_err 63 * @internal Internal APIs for testing purpose only 64 */ 65extern T_CTEST_EXPORT_API int WARN_ON_MISSING_DATA; 66 67/** 68 * ICU tracing level, is set by command line option 69 * 70 * @internal 71 */ 72extern T_CTEST_EXPORT_API UTraceLevel ICU_TRACE; 73 74/** 75 * Maximum amount of memory uprv_malloc should allocate before returning NULL. 76 * 77 * @internal 78 */ 79extern T_CTEST_EXPORT_API size_t MAX_MEMORY_ALLOCATION; 80 81/** 82 * If memory tracing was enabled, contains the number of unfreed allocations. 83 * 84 * @internal 85 */ 86extern T_CTEST_EXPORT_API int32_t ALLOCATION_COUNT; 87 88 89/** 90 * Show the names of all nodes. 91 * 92 * @param root Subtree of tests. 93 * @internal Internal APIs for testing purpose only 94 */ 95T_CTEST_API void T_CTEST_EXPORT2 96showTests ( const TestNode *root); 97 98/** 99 * Run a subtree of tests. 100 * 101 * @param root Subtree of tests. 102 * @internal Internal APIs for testing purpose only 103 */ 104T_CTEST_API void T_CTEST_EXPORT2 105runTests ( const TestNode* root); 106 107/** 108 * Add a test to the subtree. 109 * Example usage: 110 * <PRE> 111 * TestNode* root=NULL; 112 * addTest(&root, &mytest, "/a/b/mytest" ); 113 * </PRE> 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 118 */ 119T_CTEST_API void T_CTEST_EXPORT2 120addTest(TestNode** root, 121 TestFunctionPtr test, 122 const char *path); 123 124/** 125 * Clean up any allocated memory. 126 * Conditions for calling this function are the same as u_cleanup(). 127 * @see u_cleanup 128 * @internal Internal APIs for testing purpose only 129 */ 130T_CTEST_API void T_CTEST_EXPORT2 131cleanUpTestTree(TestNode *tn); 132 133/** 134 * Retreive a specific subtest. (subtree). 135 * 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 140 */ 141T_CTEST_API const TestNode* T_CTEST_EXPORT2 142getTest(const TestNode* root, 143 const char *path); 144 145 146/** 147 * Log an error message. (printf style) 148 * @param pattern printf-style format string 149 * @internal Internal APIs for testing purpose only 150 */ 151T_CTEST_API void T_CTEST_EXPORT2 152log_err(const char* pattern, ...); 153 154T_CTEST_API void T_CTEST_EXPORT2 155log_err_status(UErrorCode status, const char* pattern, ...); 156/** 157 * Log an informational message. (printf style) 158 * @param pattern printf-style format string 159 * @internal Internal APIs for testing purpose only 160 */ 161T_CTEST_API void T_CTEST_EXPORT2 162log_info(const char* pattern, ...); 163 164/** 165 * Log an informational message. (vprintf style) 166 * @param prefix a string that is output before the pattern and without formatting 167 * @param pattern printf-style format string 168 * @param ap variable-arguments list 169 * @internal Internal APIs for testing purpose only 170 */ 171T_CTEST_API void T_CTEST_EXPORT2 172vlog_info(const char *prefix, const char *pattern, va_list ap); 173 174/** 175 * Log a verbose informational message. (printf style) 176 * This message will only appear if the global VERBOSITY is nonzero 177 * @param pattern printf-style format string 178 * @internal Internal APIs for testing purpose only 179 */ 180T_CTEST_API void T_CTEST_EXPORT2 181log_verbose(const char* pattern, ...); 182 183/** 184 * Log an error message concerning missing data. (printf style) 185 * If WARN_ON_MISSING_DATA is nonzero, this will case a log_info (warning) to be 186 * printed, but if it is zero this will produce an error (log_err). 187 * @param pattern printf-style format string 188 * @internal Internal APIs for testing purpose only 189 */ 190T_CTEST_API void T_CTEST_EXPORT2 191log_data_err(const char *pattern, ...); 192 193/** 194 * Initialize the variables above. This allows the test to set up accordingly 195 * before running the tests. 196 * This must be called before runTests. 197 */ 198T_CTEST_API int T_CTEST_EXPORT2 199initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context); 200 201/** 202 * Processes the command line arguments. 203 * This is a sample implementation 204 * <PRE>Usage: %s [ -l ] [ -v ] [ -? ] [ /path/to/test ] 205 * -l List only, do not run\ 206 * -v turn OFF verbosity 207 * -? print this message</PRE> 208 * @param root Testnode root with tests already attached to it 209 * @param argv argument list from main (stdio.h) 210 * @param argc argument list count from main (stdio.h) 211 * @return positive for error count, 0 for success, negative for illegal argument 212 * @internal Internal APIs for testing purpose only 213 */ 214T_CTEST_API int T_CTEST_EXPORT2 215runTestRequest(const TestNode* root, 216 int argc, 217 const char* const argv[]); 218 219 220T_CTEST_API const char* T_CTEST_EXPORT2 221getTestName(void); 222 223 224 225#endif 226