]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/intltest.h
ICU-6.2.13.tar.gz
[apple/icu.git] / icuSources / test / intltest / intltest.h
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
374ca955 3 * Copyright (c) 1997-2004, 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
18U_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)
29UnicodeString UCharToUnicodeString(UChar c);
374ca955
A
30UnicodeString 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
32UnicodeString operator+(const UnicodeString& left, long num);
33UnicodeString operator+(const UnicodeString& left, unsigned long num);
34UnicodeString operator+(const UnicodeString& left, double num);
35UnicodeString operator+(const UnicodeString& left, char num);
36UnicodeString operator+(const UnicodeString& left, short num);
37UnicodeString operator+(const UnicodeString& left, int num);
38UnicodeString operator+(const UnicodeString& left, unsigned char num);
39UnicodeString operator+(const UnicodeString& left, unsigned short num);
40UnicodeString operator+(const UnicodeString& left, unsigned int num);
41UnicodeString operator+(const UnicodeString& left, float num);
42#if !UCONFIG_NO_FORMATTING
43UnicodeString toString(const Formattable& f); // liu
374ca955 44UnicodeString 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 70class IntlTest : public TestLog {
b75a7d8f
A
71public:
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 );
81
82 virtual int32_t getErrors( void );
83
84 virtual void setCaller( IntlTest* callingTest ); // for internal use only
85 virtual void setPath( char* path ); // for internal use only
86
87 virtual void log( const UnicodeString &message );
88
89 virtual void logln( const UnicodeString &message );
90
91 virtual void logln( void );
92
93 virtual void info( const UnicodeString &message );
94
95 virtual void infoln( const UnicodeString &message );
96
97 virtual void infoln( void );
98
99 virtual void err(void);
100
101 virtual void err( const UnicodeString &message );
102
103 virtual void errln( const UnicodeString &message );
104
105 // convenience functions: sprintf() + errln() etc.
106 void log(const char *fmt, ...);
107 void logln(const char *fmt, ...);
108 void info(const char *fmt, ...);
109 void infoln(const char *fmt, ...);
110 void err(const char *fmt, ...);
111 void errln(const char *fmt, ...);
112
113 // Print ALL named errors encountered so far
114 void printErrors();
115
116 virtual void usage( void ) ;
117
374ca955
A
118 /**
119 * Returns a uniform random value x, with 0.0 <= x < 1.0. Use
120 * with care: Does not return all possible values; returns one of
121 * 714,025 values, uniformly spaced. However, the period is
122 * effectively infinite. See: Numerical Recipes, section 7.1.
123 *
124 * @param seedp pointer to seed. Set *seedp to any negative value
125 * to restart the sequence.
126 */
127 static float random(int32_t* seedp);
128
129 /**
130 * Convenience method using a global seed.
131 */
132 static float random();
133
134 /**
135 * Ascertain the version of ICU. Useful for
136 * time bomb testing
137 */
138 UBool isICUVersionAtLeast(const UVersionInfo x);
b75a7d8f
A
139
140protected:
374ca955
A
141 /* JUnit-like assertions. Each returns TRUE if it succeeds. */
142 UBool assertTrue(const char* message, UBool condition, UBool quiet=FALSE);
143 UBool assertFalse(const char* message, UBool condition, UBool quiet=FALSE);
144 UBool assertSuccess(const char* message, UErrorCode ec);
145 UBool assertEquals(const char* message, const UnicodeString& expected,
146 const UnicodeString& actual);
147 UBool assertEquals(const char* message, const char* expected,
148 const char* actual);
149#if !UCONFIG_NO_FORMATTING
150 UBool assertEquals(const char* message, const Formattable& expected,
151 const Formattable& actual);
152 UBool assertEquals(const UnicodeString& message, const Formattable& expected,
153 const Formattable& actual);
154#endif
155 UBool assertTrue(const UnicodeString& message, UBool condition, UBool quiet=FALSE);
156 UBool assertFalse(const UnicodeString& message, UBool condition, UBool quiet=FALSE);
157 UBool assertSuccess(const UnicodeString& message, UErrorCode ec);
158 UBool assertEquals(const UnicodeString& message, const UnicodeString& expected,
159 const UnicodeString& actual);
160 UBool assertEquals(const UnicodeString& message, const char* expected,
161 const char* actual);
162
b75a7d8f
A
163 virtual void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
164
165 virtual UBool runTestLoop( char* testname, char* par );
166
167 virtual int32_t IncErrorCount( void );
168
169 virtual UBool callTest( IntlTest& testToBeCalled, char* par );
170
171
172 UBool verbose;
173 UBool no_err_msg;
174 UBool quick;
175 UBool leaks;
176
177private:
178 UBool LL_linestart;
179 int32_t LL_indentlevel;
180
181 int32_t errorCount;
182 IntlTest* caller;
183 char* path; // specifies subtests
184
374ca955
A
185 //FILE *testoutfp;
186 void *testoutfp;
187
b75a7d8f 188protected:
374ca955 189
b75a7d8f
A
190 virtual void LL_message( UnicodeString message, UBool newline );
191
192 // used for collation result reporting, defined here for convenience
193
194 static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target);
195 static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE);
196 static UnicodeString &appendHex(uint32_t number, int32_t digits, UnicodeString &target);
197
198 /* complete a relative path to a full pathname, and convert to platform-specific syntax. */
199 /* The character seperating directories for the relative path is '|'. */
200 static void pathnameInContext( char* fullname, int32_t maxsize, const char* relpath );
201
202public:
203 static void setICU_DATA(); // Set up ICU_DATA if necessary.
204
205 static const char* pathToDataDirectory();
206
207public:
208 UBool run_phase2( char* name, char* par ); // internally, supports reporting memory leaks
209 static const char* loadTestData(UErrorCode& err);
374ca955
A
210 virtual const char* getTestDataPath(UErrorCode& err);
211 static const char* getSourceTestData(UErrorCode& err);
b75a7d8f
A
212
213// static members
214public:
215 static IntlTest* gTest;
216 static const char* fgDataDir;
217
218};
219
220void it_log( UnicodeString message );
221void it_logln( UnicodeString message );
222void it_logln( void );
223void it_info( UnicodeString message );
224void it_infoln( UnicodeString message );
225void it_infoln( void );
226void it_err(void);
227void it_err( UnicodeString message );
228void it_errln( UnicodeString message );
229
b75a7d8f
A
230/**
231 * This is a variant of cintltst/ccolltst.c:CharsToUChars().
232 * It converts a character string into a UnicodeString, with
233 * unescaping \u sequences.
234 */
235extern UnicodeString CharsToUnicodeString(const char* chars);
236
374ca955
A
237/* alias for CharsToUnicodeString */
238extern UnicodeString ctou(const char* chars);
239
b75a7d8f 240#endif // _INTLTEST