]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 2002-2003, International Business Machines Corporation and | |
4 | * others. All Rights Reserved. | |
5 | ********************************************************************/ | |
6 | ||
7 | #include "uobjtest.h" | |
8 | #include <string.h> | |
9 | ||
10 | /** | |
11 | * | |
12 | * Test for UObject, currently only the classID. | |
13 | * | |
14 | * Usage | |
15 | * TESTCLASSID_ABSTRACT(Bar) | |
16 | * -- Bar is expected to be abstract. Only the static ID will be tested. | |
17 | * | |
18 | * TESTCLASSID_DEFAULT(Foo) | |
19 | * -- Foo will be default-constructed. | |
20 | * | |
21 | * TESTCLASSID_CTOR(Foo, (1, 2, 3, status)) | |
22 | * -- Second argument is (parenthesized) constructor argument. | |
23 | * Will be called as: new Foo ( 1, 2, 3, status) [status is tested] | |
24 | * | |
25 | * TESTCLASSID_FACTORY(Foo, fooCreateFunction(status) ) | |
26 | * -- call fooCreateFunction. 'status' will be tested & reset | |
27 | */ | |
28 | ||
29 | ||
30 | #define TESTCLASSID_FACTORY(c, f) { delete testClass(f, #c, #f, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } | |
31 | #define TESTCLASSID_TRANSLIT(c, t) { delete testClass(Transliterator::createInstance(UnicodeString(t), UTRANS_FORWARD,parseError,status), #c, "Transliterator: " #t, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - Transliterator: " #t " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } | |
32 | #define TESTCLASSID_CTOR(c, x) { delete testClass(new c x, #c, "new " #c #x, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } | |
33 | #define TESTCLASSID_DEFAULT(c) delete testClass(new c, #c, "new " #c , c::getStaticClassID()) | |
34 | #define TESTCLASSID_ABSTRACT(c) testClass(NULL, #c, NULL, c::getStaticClassID()) | |
35 | ||
36 | #define MAX_CLASS_ID 200 | |
37 | ||
38 | UClassID ids[MAX_CLASS_ID]; | |
39 | const char *ids_factory[MAX_CLASS_ID]; | |
40 | const char *ids_class[MAX_CLASS_ID]; | |
41 | uint32_t ids_count = 0; | |
42 | ||
43 | UObject *UObjectTest::testClass(UObject *obj, | |
44 | const char *className, const char *factory, | |
45 | UClassID staticID) | |
46 | { | |
47 | uint32_t i; | |
48 | UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; "; | |
49 | UClassID dynamicID = NULL; | |
50 | ||
51 | if(ids_count >= MAX_CLASS_ID) { | |
52 | char count[100]; | |
53 | sprintf(count, " (currently %d) ", MAX_CLASS_ID); | |
54 | errln("FAIL: Fatal: Ran out of IDs! Increase MAX_CLASS_ID." + UnicodeString(count) + what); | |
55 | return obj; | |
56 | } | |
57 | ||
58 | if(obj) { | |
59 | dynamicID = obj->getDynamicClassID(); | |
60 | } | |
61 | ||
62 | { | |
63 | char tmp[500]; | |
64 | sprintf(tmp, " [static=%p, dynamic=%p] ", staticID, dynamicID); | |
65 | logln(what + tmp); | |
66 | } | |
67 | ||
68 | if(staticID == NULL) { | |
69 | errln( "FAIL: staticID == NULL!" + what); | |
70 | } | |
71 | ||
72 | if(factory != NULL) { /* NULL factory means: abstract */ | |
73 | if(!obj) { | |
74 | errln( "FAIL: ==NULL!" + what); | |
75 | return obj; | |
76 | } | |
77 | ||
78 | if(dynamicID == NULL) { | |
79 | errln("FAIL: dynamicID == NULL!" + what); | |
80 | } | |
81 | ||
82 | if(dynamicID != staticID) { | |
83 | errln("FAIL: dynamicID != staticID!" + what ); | |
84 | } | |
85 | } | |
86 | ||
87 | // Bail out if static ID is null | |
88 | if(staticID == NULL) { | |
89 | return obj; | |
90 | } | |
91 | ||
92 | for(i=0;i<ids_count;i++) { | |
93 | if(staticID == ids[i]) { | |
94 | if(!strcmp(ids_class[i], className)) { | |
95 | logln("OK: ID found is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what); | |
96 | return obj; | |
97 | } else { | |
98 | errln("FAIL: ID is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what); | |
99 | return obj; | |
100 | } | |
101 | } | |
102 | } | |
103 | ||
104 | ids[ids_count] = staticID; | |
105 | ids_factory[ids_count] = factory; | |
106 | ids_class[ids_count] = className; | |
107 | ids_count++; | |
108 | ||
109 | return obj; | |
110 | } | |
111 | ||
112 | ||
113 | // begin actual #includes for things to be tested | |
114 | // | |
115 | // The following script will generate the #includes needed here: | |
116 | // | |
117 | // find common i18n -name '*.h' -print | xargs fgrep ClassID | cut -d: -f1 | cut -d\/ -f2- | sort | uniq | sed -e 's%.*%#include "&"%' | |
118 | ||
119 | ||
120 | #include "unicode/utypes.h" | |
121 | ||
122 | // Things we Patch | |
123 | #define protected public /* to access private factory function */ | |
124 | #include "iculserv.h" | |
125 | #undef protected | |
126 | ||
127 | // Internal Things (woo) | |
128 | #include "cpdtrans.h" | |
129 | #include "rbt.h" | |
130 | #include "rbt_data.h" | |
131 | #include "hextouni.h" | |
132 | #include "unitohex.h" | |
133 | #include "nultrans.h" | |
134 | #include "anytrans.h" | |
135 | #include "digitlst.h" | |
136 | #include "esctrn.h" | |
137 | #include "funcrepl.h" | |
138 | #include "icunotif.h" | |
139 | #include "icuserv.h" | |
140 | #include "name2uni.h" | |
141 | #include "nfsubs.h" | |
142 | #include "nortrans.h" | |
143 | #include "quant.h" | |
144 | #include "remtrans.h" | |
145 | #include "strmatch.h" | |
146 | #include "strrepl.h" | |
147 | #include "titletrn.h" | |
148 | #include "tolowtrn.h" | |
149 | #include "toupptrn.h" | |
150 | #include "unesctrn.h" | |
151 | #include "uni2name.h" | |
152 | #include "uvector.h" | |
153 | ||
154 | // External Things | |
155 | #include "unicode/brkiter.h" | |
156 | #include "unicode/calendar.h" | |
157 | #include "unicode/caniter.h" | |
158 | #include "unicode/chariter.h" | |
159 | #include "unicode/choicfmt.h" | |
160 | #include "unicode/coleitr.h" | |
161 | #include "unicode/coll.h" | |
162 | #include "unicode/datefmt.h" | |
163 | #include "unicode/dbbi.h" | |
164 | #include "unicode/dcfmtsym.h" | |
165 | #include "unicode/decimfmt.h" | |
166 | #include "unicode/dtfmtsym.h" | |
167 | #include "unicode/fieldpos.h" | |
168 | #include "unicode/fmtable.h" | |
169 | #include "unicode/format.h" | |
170 | #include "unicode/gregocal.h" | |
171 | #include "unicode/locid.h" | |
172 | #include "unicode/msgfmt.h" | |
173 | #include "unicode/normlzr.h" | |
174 | #include "unicode/numfmt.h" | |
175 | #include "unicode/parsepos.h" | |
176 | #include "unicode/rbbi.h" | |
177 | #include "unicode/rbnf.h" | |
178 | #include "unicode/regex.h" | |
179 | #include "unicode/resbund.h" | |
180 | #include "unicode/schriter.h" | |
181 | #include "unicode/simpletz.h" | |
182 | #include "unicode/smpdtfmt.h" | |
183 | #include "unicode/sortkey.h" | |
184 | #include "unicode/stsearch.h" | |
185 | #include "unicode/tblcoll.h" | |
186 | #include "unicode/timezone.h" | |
187 | #include "unicode/translit.h" | |
188 | #include "unicode/uchriter.h" | |
189 | #include "unicode/unifilt.h" | |
190 | #include "unicode/unifunct.h" | |
191 | #include "unicode/uniset.h" | |
192 | #include "unicode/unistr.h" | |
193 | #include "unicode/uobject.h" | |
194 | #include "unicode/usetiter.h" | |
195 | //#include "unicode/bidi.h" | |
196 | //#include "unicode/convert.h" | |
197 | ||
198 | // END includes ============================================================= | |
199 | ||
200 | #define UOBJTEST_TEST_INTERNALS 0 /* do NOT test Internal things - their functions aren't exported on Win32 */ | |
201 | ||
202 | void UObjectTest::testIDs() | |
203 | { | |
204 | ids_count = 0; | |
205 | ||
206 | #if !UCONFIG_NO_TRANSLITERATION | |
207 | UParseError parseError; | |
208 | #endif | |
209 | UErrorCode status = U_ZERO_ERROR; | |
210 | ||
211 | ||
212 | ||
213 | //TESTCLASSID_DEFAULT(AbbreviatedUnicodeSetIterator); | |
214 | //TESTCLASSID_DEFAULT(AnonymousStringFactory); | |
215 | ||
216 | ||
217 | #if !UCONFIG_NO_NORMALIZATION | |
218 | TESTCLASSID_FACTORY(CanonicalIterator, new CanonicalIterator(UnicodeString("abc"), status)); | |
219 | #endif | |
220 | //TESTCLASSID_DEFAULT(CollationElementIterator); | |
221 | #if !UCONFIG_NO_COLLATION | |
222 | TESTCLASSID_DEFAULT(CollationKey); | |
223 | #endif | |
224 | //TESTCLASSID_FACTORY(CompoundTransliterator, Transliterator::createInstance(UnicodeString("Any-Jex;Hangul-Jamo"), UTRANS_FORWARD, parseError, status)); | |
225 | ||
226 | #if !UCONFIG_NO_FORMATTING | |
227 | /* TESTCLASSID_FACTORY(NFSubstitution, NFSubstitution::makeSubstitution(8, */ | |
228 | /* TESTCLASSID_DEFAULT(DigitList); UMemory but not UObject*/ | |
229 | TESTCLASSID_ABSTRACT(NumberFormat); | |
230 | TESTCLASSID_CTOR(DateFormatSymbols, (status)); | |
231 | TESTCLASSID_CTOR(DecimalFormatSymbols, (status)); | |
232 | #if UOBJTEST_TEST_INTERNALS | |
233 | TESTCLASSID_CTOR(FunctionReplacer, (NULL,NULL) ); /* don't care */ | |
234 | #endif | |
235 | TESTCLASSID_DEFAULT(FieldPosition); | |
236 | TESTCLASSID_DEFAULT(Formattable); | |
237 | TESTCLASSID_CTOR(GregorianCalendar, (status)); | |
238 | #endif | |
239 | ||
240 | #if !UCONFIG_NO_BREAK_ITERATION | |
241 | /* TESTCLASSID_ABSTRACT(BreakIterator); No staticID! */ | |
242 | TESTCLASSID_FACTORY(RuleBasedBreakIterator, BreakIterator::createLineInstance("mt",status)); | |
243 | TESTCLASSID_FACTORY(DictionaryBasedBreakIterator, BreakIterator::createLineInstance("th",status)); | |
244 | #endif | |
245 | ||
246 | //TESTCLASSID_DEFAULT(EscapeTransliterator); | |
247 | ||
248 | //TESTCLASSID_DEFAULT(GregorianCalendar); | |
249 | ||
250 | #if !UCONFIG_NO_TRANSLITERATION | |
251 | ||
252 | ||
253 | TESTCLASSID_DEFAULT(HexToUnicodeTransliterator); | |
254 | TESTCLASSID_DEFAULT(UnicodeToHexTransliterator); | |
255 | TESTCLASSID_TRANSLIT(AnyTransliterator, "Any-Latin"); | |
256 | TESTCLASSID_TRANSLIT(CompoundTransliterator, "Latin-Greek"); | |
257 | TESTCLASSID_TRANSLIT(EscapeTransliterator, "Any-Hex"); | |
258 | TESTCLASSID_TRANSLIT(LowercaseTransliterator, "Lower"); | |
259 | TESTCLASSID_TRANSLIT(NameUnicodeTransliterator, "Name-Any"); | |
260 | TESTCLASSID_TRANSLIT(NormalizationTransliterator, "NFD"); | |
261 | TESTCLASSID_TRANSLIT(NullTransliterator, "Null"); | |
262 | TESTCLASSID_TRANSLIT(RemoveTransliterator, "Remove"); | |
263 | TESTCLASSID_CTOR(RuleBasedTransliterator, (UnicodeString("abcd"), UnicodeString("a>b;"), status)); | |
264 | TESTCLASSID_TRANSLIT(TitlecaseTransliterator, "Title"); | |
265 | TESTCLASSID_TRANSLIT(UnescapeTransliterator, "Hex-Any"); | |
266 | TESTCLASSID_TRANSLIT(UnicodeNameTransliterator, "Any-Name"); | |
267 | TESTCLASSID_TRANSLIT(UppercaseTransliterator, "Upper"); | |
268 | #endif | |
269 | ||
270 | TESTCLASSID_FACTORY(Locale, new Locale("123")); | |
271 | ||
272 | //TESTCLASSID_DEFAULT(Normalizer); | |
273 | ||
274 | //TESTCLASSID_DEFAULT(NumeratorSubstitution); | |
275 | ||
276 | #if !UCONFIG_NO_TRANSLITERATION | |
277 | TESTCLASSID_DEFAULT(ParsePosition); | |
278 | //TESTCLASSID_DEFAULT(Quantifier); | |
279 | #endif | |
280 | ||
281 | ||
282 | // NO_REG_EX | |
283 | //TESTCLASSID_DEFAULT(RegexCompile); | |
284 | //TESTCLASSID_DEFAULT(RegexMatcher); | |
285 | //TESTCLASSID_DEFAULT(RegexPattern); | |
286 | ||
287 | //TESTCLASSID_DEFAULT(ReplaceableGlue); | |
288 | TESTCLASSID_FACTORY(ResourceBundle, new ResourceBundle(UnicodeString(), status) ); | |
289 | //TESTCLASSID_DEFAULT(RuleBasedTransliterator); | |
290 | ||
291 | //TESTCLASSID_DEFAULT(SimpleFwdCharIterator); | |
292 | //TESTCLASSID_DEFAULT(StringReplacer); | |
293 | //TESTCLASSID_DEFAULT(StringSearch); | |
294 | ||
295 | //TESTCLASSID_DEFAULT(TempSearch); | |
296 | //TESTCLASSID_DEFAULT(TestMultipleKeyStringFactory); | |
297 | //TESTCLASSID_DEFAULT(TestReplaceable); | |
298 | #if !UCONFIG_NO_FORMATTING | |
299 | TESTCLASSID_ABSTRACT(TimeZone); | |
300 | #endif | |
301 | ||
302 | #if !UCONFIG_NO_TRANSLITERATION | |
303 | TESTCLASSID_FACTORY(TitlecaseTransliterator, Transliterator::createInstance(UnicodeString("Any-Title"), UTRANS_FORWARD, parseError, status)); | |
304 | TESTCLASSID_ABSTRACT(Transliterator); | |
305 | ||
306 | #if UOBJTEST_TEST_INTERNALS | |
307 | TESTCLASSID_CTOR(StringMatcher, (UnicodeString("x"), 0,0,0,TransliterationRuleData(status))); | |
308 | TESTCLASSID_CTOR(StringReplacer,(UnicodeString(),new TransliterationRuleData(status))); | |
309 | #endif | |
310 | #endif | |
311 | ||
312 | TESTCLASSID_DEFAULT(UnicodeString); | |
313 | TESTCLASSID_CTOR(UnicodeSet, (0, 1)); | |
314 | TESTCLASSID_ABSTRACT(UnicodeFilter); | |
315 | TESTCLASSID_ABSTRACT(UnicodeFunctor); | |
316 | TESTCLASSID_CTOR(UnicodeSetIterator,(UnicodeSet(0,1))); | |
317 | TESTCLASSID_CTOR(UStack, (status)); | |
318 | TESTCLASSID_CTOR(UVector, (status)); | |
319 | ||
320 | #if !UCONFIG_NO_SERVICE | |
321 | TESTCLASSID_CTOR(SimpleFactory, (NULL, UnicodeString("foo"))); | |
322 | TESTCLASSID_DEFAULT(EventListener); | |
323 | #if UOBJTEST_TEST_INTERNALS | |
324 | TESTCLASSID_DEFAULT(ICUResourceBundleFactory); | |
325 | //TESTCLASSID_DEFAULT(Key); // does ont exist? | |
326 | TESTCLASSID_CTOR(LocaleKey, (UnicodeString("baz"), UnicodeString("bat"), NULL, 92)); | |
327 | TESTCLASSID_CTOR(LocaleKeyFactory, (42)); | |
328 | TESTCLASSID_CTOR(SimpleLocaleKeyFactory, (NULL, UnicodeString("bar"), 8, 12) ); | |
329 | #endif | |
330 | #endif | |
331 | ||
332 | #if UOBJTEST_DUMP_IDS | |
333 | int i; | |
334 | for(i=0;i<ids_count;i++) { | |
335 | char junk[800]; | |
336 | sprintf(junk, " %4d:\t%p\t%s\t%s\n", | |
337 | i, ids[i], ids_class[i], ids_factory[i]); | |
338 | logln(UnicodeString(junk)); | |
339 | } | |
340 | #endif | |
341 | } | |
342 | ||
343 | /* --------------- */ | |
344 | ||
345 | #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break; | |
346 | ||
347 | ||
348 | void UObjectTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /* par */ ) | |
349 | { | |
350 | switch (index) { | |
351 | ||
352 | CASE(0, testIDs); | |
353 | ||
354 | default: name = ""; break; //needed to end loop | |
355 | } | |
356 | } |