]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
73c04bcf | 3 | * Copyright (c) 1997-2005, International Business Machines Corporation and |
b75a7d8f A |
4 | * others. All Rights Reserved. |
5 | ********************************************************************/ | |
6 | ||
7 | ||
8 | /** | |
9 | * IntlTest is a base class for tests. */ | |
10 | ||
11 | #ifndef _INTLTEST | |
12 | #define _INTLTEST | |
13 | ||
374ca955 | 14 | // The following includes utypes.h, uobject.h and unistr.h |
b75a7d8f | 15 | #include "unicode/fmtable.h" |
374ca955 | 16 | #include "unicode/testlog.h" |
b75a7d8f A |
17 | |
18 | U_NAMESPACE_USE | |
19 | ||
20 | #ifdef OS390 | |
21 | // avoid collision with math.h/log() | |
22 | // this must be after including utypes.h so that OS390 is actually defined | |
23 | #pragma map(IntlTest::log( const UnicodeString &message ),"logos390") | |
24 | #endif | |
25 | ||
b75a7d8f A |
26 | //----------------------------------------------------------------------------- |
27 | //convenience classes to ease porting code that uses the Java | |
28 | //string-concatenation operator (moved from findword test by rtg) | |
29 | UnicodeString UCharToUnicodeString(UChar c); | |
374ca955 A |
30 | UnicodeString Int64ToUnicodeString(int64_t num); |
31 | //UnicodeString operator+(const UnicodeString& left, int64_t num); // Some compilers don't allow this because of the long type. | |
b75a7d8f A |
32 | UnicodeString operator+(const UnicodeString& left, long num); |
33 | UnicodeString operator+(const UnicodeString& left, unsigned long num); | |
34 | UnicodeString operator+(const UnicodeString& left, double num); | |
35 | UnicodeString operator+(const UnicodeString& left, char num); | |
36 | UnicodeString operator+(const UnicodeString& left, short num); | |
37 | UnicodeString operator+(const UnicodeString& left, int num); | |
38 | UnicodeString operator+(const UnicodeString& left, unsigned char num); | |
39 | UnicodeString operator+(const UnicodeString& left, unsigned short num); | |
40 | UnicodeString operator+(const UnicodeString& left, unsigned int num); | |
41 | UnicodeString operator+(const UnicodeString& left, float num); | |
42 | #if !UCONFIG_NO_FORMATTING | |
43 | UnicodeString toString(const Formattable& f); // liu | |
374ca955 | 44 | UnicodeString toString(int32_t n); |
b75a7d8f A |
45 | #endif |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | // Use the TESTCASE macro in subclasses of IntlTest. Define the | |
49 | // runIndexedTest method in this fashion: | |
50 | // | |
51 | //| void MyTest::runIndexedTest(int32_t index, UBool exec, | |
52 | //| const char* &name, char* /*par*/) { | |
53 | //| switch (index) { | |
54 | //| TESTCASE(0,TestSomething); | |
55 | //| TESTCASE(1,TestSomethingElse); | |
56 | //| TESTCASE(2,TestAnotherThing); | |
57 | //| default: name = ""; break; | |
58 | //| } | |
59 | //| } | |
60 | #define TESTCASE(id,test) \ | |
61 | case id: \ | |
62 | name = #test; \ | |
63 | if (exec) { \ | |
64 | logln(#test "---"); \ | |
65 | logln((UnicodeString)""); \ | |
66 | test(); \ | |
67 | } \ | |
68 | break | |
69 | ||
374ca955 | 70 | class IntlTest : public TestLog { |
b75a7d8f A |
71 | public: |
72 | ||
73 | IntlTest(); | |
74 | ||
75 | virtual UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden | |
76 | ||
77 | virtual UBool setVerbose( UBool verbose = TRUE ); | |
78 | virtual UBool setNoErrMsg( UBool no_err_msg = TRUE ); | |
79 | virtual UBool setQuick( UBool quick = TRUE ); | |
80 | virtual UBool setLeaks( UBool leaks = TRUE ); | |
73c04bcf | 81 | virtual UBool setWarnOnMissingData( UBool warn_on_missing_data = TRUE ); |
b75a7d8f A |
82 | |
83 | virtual int32_t getErrors( void ); | |
73c04bcf | 84 | virtual int32_t getDataErrors (void ); |
b75a7d8f A |
85 | |
86 | virtual void setCaller( IntlTest* callingTest ); // for internal use only | |
87 | virtual void setPath( char* path ); // for internal use only | |
88 | ||
89 | virtual void log( const UnicodeString &message ); | |
90 | ||
91 | virtual void logln( const UnicodeString &message ); | |
92 | ||
93 | virtual void logln( void ); | |
94 | ||
95 | virtual void info( const UnicodeString &message ); | |
96 | ||
97 | virtual void infoln( const UnicodeString &message ); | |
98 | ||
99 | virtual void infoln( void ); | |
100 | ||
101 | virtual void err(void); | |
102 | ||
103 | virtual void err( const UnicodeString &message ); | |
104 | ||
105 | virtual void errln( const UnicodeString &message ); | |
106 | ||
73c04bcf A |
107 | virtual void dataerr( const UnicodeString &message ); |
108 | ||
109 | virtual void dataerrln( const UnicodeString &message ); | |
110 | ||
b75a7d8f A |
111 | // convenience functions: sprintf() + errln() etc. |
112 | void log(const char *fmt, ...); | |
113 | void logln(const char *fmt, ...); | |
114 | void info(const char *fmt, ...); | |
115 | void infoln(const char *fmt, ...); | |
116 | void err(const char *fmt, ...); | |
117 | void errln(const char *fmt, ...); | |
73c04bcf A |
118 | void dataerr(const char *fmt, ...); |
119 | void dataerrln(const char *fmt, ...); | |
b75a7d8f A |
120 | |
121 | // Print ALL named errors encountered so far | |
122 | void printErrors(); | |
123 | ||
124 | virtual void usage( void ) ; | |
125 | ||
374ca955 A |
126 | /** |
127 | * Returns a uniform random value x, with 0.0 <= x < 1.0. Use | |
128 | * with care: Does not return all possible values; returns one of | |
129 | * 714,025 values, uniformly spaced. However, the period is | |
130 | * effectively infinite. See: Numerical Recipes, section 7.1. | |
131 | * | |
132 | * @param seedp pointer to seed. Set *seedp to any negative value | |
133 | * to restart the sequence. | |
134 | */ | |
135 | static float random(int32_t* seedp); | |
136 | ||
137 | /** | |
138 | * Convenience method using a global seed. | |
139 | */ | |
140 | static float random(); | |
141 | ||
142 | /** | |
143 | * Ascertain the version of ICU. Useful for | |
144 | * time bomb testing | |
145 | */ | |
146 | UBool isICUVersionAtLeast(const UVersionInfo x); | |
b75a7d8f A |
147 | |
148 | protected: | |
374ca955 A |
149 | /* JUnit-like assertions. Each returns TRUE if it succeeds. */ |
150 | UBool assertTrue(const char* message, UBool condition, UBool quiet=FALSE); | |
151 | UBool assertFalse(const char* message, UBool condition, UBool quiet=FALSE); | |
152 | UBool assertSuccess(const char* message, UErrorCode ec); | |
153 | UBool assertEquals(const char* message, const UnicodeString& expected, | |
154 | const UnicodeString& actual); | |
155 | UBool assertEquals(const char* message, const char* expected, | |
156 | const char* actual); | |
157 | #if !UCONFIG_NO_FORMATTING | |
158 | UBool assertEquals(const char* message, const Formattable& expected, | |
159 | const Formattable& actual); | |
160 | UBool assertEquals(const UnicodeString& message, const Formattable& expected, | |
161 | const Formattable& actual); | |
162 | #endif | |
163 | UBool assertTrue(const UnicodeString& message, UBool condition, UBool quiet=FALSE); | |
164 | UBool assertFalse(const UnicodeString& message, UBool condition, UBool quiet=FALSE); | |
165 | UBool assertSuccess(const UnicodeString& message, UErrorCode ec); | |
166 | UBool assertEquals(const UnicodeString& message, const UnicodeString& expected, | |
167 | const UnicodeString& actual); | |
168 | UBool assertEquals(const UnicodeString& message, const char* expected, | |
169 | const char* actual); | |
170 | ||
b75a7d8f A |
171 | virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide ! |
172 | ||
173 | virtual UBool runTestLoop( char* testname, char* par ); | |
174 | ||
175 | virtual int32_t IncErrorCount( void ); | |
176 | ||
73c04bcf A |
177 | virtual int32_t IncDataErrorCount( void ); |
178 | ||
b75a7d8f A |
179 | virtual UBool callTest( IntlTest& testToBeCalled, char* par ); |
180 | ||
181 | ||
73c04bcf A |
182 | UBool verbose; |
183 | UBool no_err_msg; | |
184 | UBool quick; | |
185 | UBool leaks; | |
186 | UBool warn_on_missing_data; | |
b75a7d8f A |
187 | |
188 | private: | |
73c04bcf | 189 | UBool LL_linestart; |
b75a7d8f A |
190 | int32_t LL_indentlevel; |
191 | ||
192 | int32_t errorCount; | |
73c04bcf | 193 | int32_t dataErrorCount; |
b75a7d8f | 194 | IntlTest* caller; |
73c04bcf | 195 | char* testPath; // specifies subtests |
b75a7d8f | 196 | |
374ca955 A |
197 | //FILE *testoutfp; |
198 | void *testoutfp; | |
199 | ||
b75a7d8f | 200 | protected: |
374ca955 | 201 | |
b75a7d8f A |
202 | virtual void LL_message( UnicodeString message, UBool newline ); |
203 | ||
204 | // used for collation result reporting, defined here for convenience | |
205 | ||
206 | static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target); | |
207 | static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE); | |
208 | static UnicodeString &appendHex(uint32_t number, int32_t digits, UnicodeString &target); | |
209 | ||
b75a7d8f A |
210 | public: |
211 | static void setICU_DATA(); // Set up ICU_DATA if necessary. | |
212 | ||
213 | static const char* pathToDataDirectory(); | |
214 | ||
215 | public: | |
216 | UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks | |
217 | static const char* loadTestData(UErrorCode& err); | |
374ca955 A |
218 | virtual const char* getTestDataPath(UErrorCode& err); |
219 | static const char* getSourceTestData(UErrorCode& err); | |
b75a7d8f A |
220 | |
221 | // static members | |
222 | public: | |
223 | static IntlTest* gTest; | |
224 | static const char* fgDataDir; | |
225 | ||
226 | }; | |
227 | ||
228 | void it_log( UnicodeString message ); | |
229 | void it_logln( UnicodeString message ); | |
230 | void it_logln( void ); | |
231 | void it_info( UnicodeString message ); | |
232 | void it_infoln( UnicodeString message ); | |
233 | void it_infoln( void ); | |
234 | void it_err(void); | |
235 | void it_err( UnicodeString message ); | |
236 | void it_errln( UnicodeString message ); | |
73c04bcf A |
237 | void it_dataerr( UnicodeString message ); |
238 | void it_dataerrln( UnicodeString message ); | |
b75a7d8f | 239 | |
b75a7d8f A |
240 | /** |
241 | * This is a variant of cintltst/ccolltst.c:CharsToUChars(). | |
242 | * It converts a character string into a UnicodeString, with | |
243 | * unescaping \u sequences. | |
244 | */ | |
245 | extern UnicodeString CharsToUnicodeString(const char* chars); | |
246 | ||
374ca955 A |
247 | /* alias for CharsToUnicodeString */ |
248 | extern UnicodeString ctou(const char* chars); | |
249 | ||
b75a7d8f | 250 | #endif // _INTLTEST |