1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /******************************************************************** 4 * COPYRIGHT: 5 * Copyright (c) 1997-2013, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ********************************************************************/ 8 /******************************************************************************** 9 * 10 * File CINTLTST.H 11 * 12 * Madhu Katragadda Creation 13 * Modification History: 14 * Date Name Description 15 * 07/13/99 helena HPUX 11 CC port. 16 ********************************************************************************* 17 18 The main root for C API tests 19 */ 20 21 #ifndef _CINTLTST 22 #define _CINTLTST 23 24 #include "unicode/utypes.h" 25 #include "unicode/putil.h" 26 #include "unicode/ctest.h" 27 28 #include <stdlib.h> 29 30 #ifndef U_USE_DEPRECATED_API 31 #define U_USE_DEPRECATED_API 1 32 #endif 33 34 U_CFUNC void addAllTests(TestNode** root); 35 36 /** 37 * Return the path to the icu/source/data/out directory 38 */ 39 U_CFUNC const char* ctest_dataOutDir(void); 40 41 /** 42 * Return the path to the icu/source/data/ directory 43 * for out of source builds too returns the source directory 44 */ 45 U_CFUNC const char* ctest_dataSrcDir(void); 46 47 /** 48 * Convert a char string into a UChar string, with unescaping 49 * The result buffer has been malloc()'ed (not ctst_malloc) and needs to be free()'ed by the caller. 50 */ 51 U_CFUNC UChar* CharsToUChars(const char* chars); 52 53 /** 54 * Convert a const UChar* into a char* 55 * Result is allocated with ctst_malloc and will be freed at the end of the test. 56 * @param unichars UChars (null terminated) to be converted 57 * @return new char* to the unichars in host format 58 */ 59 60 U_CFUNC char *austrdup(const UChar* unichars); 61 62 /** 63 * Convert a const UChar* into an escaped char* 64 * Result is allocated with ctst_malloc and will be freed at the end of the test. 65 * @param unichars UChars to be converted 66 * @param length length of chars 67 * @return new char* to the unichars in host format 68 */ 69 U_CFUNC char *aescstrdup(const UChar* unichars, int32_t length); 70 71 /** 72 * Special memory allocation function for test use. At the end of cintltst, 73 * or every few thousand allocations, memory allocated by this function will be freed. 74 * Do not manually free memory returned by this function, and do not retain a pointer 75 * outside of a single instruction scope (i.e. long enough to display the value). 76 * @see #ctst_freeAll 77 */ 78 U_CFUNC void *ctst_malloc(size_t size); 79 80 /** 81 * Return the path to cintltst's data ( icu/source/data/testdata ) directory. 82 * The path may be in the out/ directory. 83 * Return value is allocated by ctst_malloc and should not be deleted. 84 */ 85 U_CFUNC const char* loadTestData(UErrorCode* err); 86 87 /* 88 * Returns the path to the icu/source/test/testdata directory. 89 * The path is always the source directory. 90 * Return value is static and should not be deleted. 91 */ 92 U_CFUNC const char* loadSourceTestData(UErrorCode* err); 93 94 /** 95 * function used to specify the error 96 * converts the errorcode to an error descriptive string(const char*) 97 * @param status the error code 98 */ 99 #define myErrorName(errorCode) u_errorName(errorCode) 100 101 102 /** 103 * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value. 104 * @param optionalTimeZone Set this to a requested timezone. 105 * Set to NULL to use the standard test timezone (Pacific Time) 106 */ 107 U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status); 108 /** 109 * Call this once get back the original timezone 110 */ 111 U_CFUNC void ctest_resetTimeZone(void); 112 113 /** 114 * Call this once get ICU back to its original state with test arguments. 115 * This function calls u_cleanup. 116 */ 117 U_CFUNC UBool ctest_resetICU(void); 118 119 /** 120 * Assert that the given UErrorCode succeeds, and return true if it does. 121 */ 122 U_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec); 123 124 /** 125 * Assert that the given UErrorCode succeeds, and return true if it does. 126 * Give data error if UErrorCode fails and possibleDataError is true. 127 */ 128 U_CFUNC UBool assertSuccessCheck(const char* msg, UErrorCode* ec, UBool possibleDataError); 129 130 /** 131 * Assert that the UBool is true, and return true if it does. 132 * 133 * NOTE: Use 'int condition' rather than 'UBool condition' so the 134 * compiler doesn't complain about integral conversion of expressions 135 * like 'p != 0'. 136 */ 137 U_CFUNC UBool assertTrue(const char* msg, int condition); 138 139 /** 140 * Assert that the actualString equals the expectedString, and return 141 * true if it does. 142 */ 143 U_CFUNC UBool assertEquals(const char* msg, const char* expectedString, 144 const char* actualString); 145 146 /** 147 * Assert that the actualString equals the expectedString, and return 148 * true if it does. 149 */ 150 U_CFUNC UBool assertUEquals(const char* msg, const UChar* expectedString, 151 const UChar* actualString); 152 153 /** 154 * Assert that two 64-bit integers are equal, returning true if they are. 155 */ 156 U_CFUNC UBool assertIntEquals(const char* msg, int64_t expected, int64_t actual); 157 158 /** 159 * Assert that the addresses of the two pointers are the same, returning 160 * true if they are equal. 161 */ 162 U_CFUNC UBool assertPtrEquals(const char* msg, const void* expected, const void* actual); 163 164 /** 165 * Assert that two doubles are equal, returning true if they are. 166 */ 167 U_CFUNC UBool assertDoubleEquals(const char *msg, double expected, double actual); 168 169 /* 170 * note - isICUVersionBefore and isICUVersionAtLeast have been removed. 171 * use log_knownIssue() instead. 172 */ 173 174 #endif 175