1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /********************************************************************
4*0e209d39SAndroid Build Coastguard Worker * COPYRIGHT:
5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 1997-2012, International Business Machines Corporation and
6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2010 , Yahoo! Inc.
8*0e209d39SAndroid Build Coastguard Worker ********************************************************************/
9*0e209d39SAndroid Build Coastguard Worker
10*0e209d39SAndroid Build Coastguard Worker #include <stdio.h>
11*0e209d39SAndroid Build Coastguard Worker #include <string.h>
12*0e209d39SAndroid Build Coastguard Worker #include "utypeinfo.h" // for 'typeid' to work
13*0e209d39SAndroid Build Coastguard Worker
14*0e209d39SAndroid Build Coastguard Worker #include "uobjtest.h"
15*0e209d39SAndroid Build Coastguard Worker #include "cmemory.h" // UAlignedMemory
16*0e209d39SAndroid Build Coastguard Worker
17*0e209d39SAndroid Build Coastguard Worker /**
18*0e209d39SAndroid Build Coastguard Worker * Test for UObject, currently only the classID.
19*0e209d39SAndroid Build Coastguard Worker *
20*0e209d39SAndroid Build Coastguard Worker * Usage
21*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_NONE_DEFAULT(Foo)
22*0e209d39SAndroid Build Coastguard Worker * -- Foo is expected to not support "poor man's RTTI".
23*0e209d39SAndroid Build Coastguard Worker * Beginning with ICU 4.6, we only use compiler RTTI in new class hierarchies.
24*0e209d39SAndroid Build Coastguard Worker *
25*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_NONE_CTOR(Foo, (1, 2, 3, status))
26*0e209d39SAndroid Build Coastguard Worker * -- Combines TESTCLASSID_NONE_DEFAULT() and TESTCLASSID_CTOR().
27*0e209d39SAndroid Build Coastguard Worker *
28*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_NONE_FACTORY(Foo, (1, 2, 3, status))
29*0e209d39SAndroid Build Coastguard Worker * -- Combines TESTCLASSID_NONE_DEFAULT() and TESTCLASSID_FACTORY().
30*0e209d39SAndroid Build Coastguard Worker *
31*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_ABSTRACT(Bar)
32*0e209d39SAndroid Build Coastguard Worker * -- Bar is expected to be abstract. Only the static ID will be tested.
33*0e209d39SAndroid Build Coastguard Worker *
34*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_DEFAULT(Foo)
35*0e209d39SAndroid Build Coastguard Worker * -- Foo will be default-constructed.
36*0e209d39SAndroid Build Coastguard Worker *
37*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_CTOR(Foo, (1, 2, 3, status))
38*0e209d39SAndroid Build Coastguard Worker * -- Second argument is (parenthesized) constructor argument.
39*0e209d39SAndroid Build Coastguard Worker * Will be called as: new Foo ( 1, 2, 3, status) [status is tested]
40*0e209d39SAndroid Build Coastguard Worker *
41*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_FACTORY(Foo, fooCreateFunction(status) )
42*0e209d39SAndroid Build Coastguard Worker * -- call fooCreateFunction. 'status' will be tested & reset
43*0e209d39SAndroid Build Coastguard Worker *
44*0e209d39SAndroid Build Coastguard Worker * TESTCLASSID_FACTORY_HIDDEN(class, factory)
45*0e209d39SAndroid Build Coastguard Worker * -- call factory. Class is not available from a header.
46*0e209d39SAndroid Build Coastguard Worker * 'status' will be tested & reset. This only tests uniqueness.
47*0e209d39SAndroid Build Coastguard Worker */
48*0e209d39SAndroid Build Coastguard Worker
49*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_NONE_DEFAULT(c) \
50*0e209d39SAndroid Build Coastguard Worker delete testClassNoClassID(new c, #c, "new " #c)
51*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_NONE_CTOR(c, x) UPRV_BLOCK_MACRO_BEGIN { \
52*0e209d39SAndroid Build Coastguard Worker delete testClassNoClassID(new c x, #c, "new " #c #x); \
53*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
54*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); \
55*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
56*0e209d39SAndroid Build Coastguard Worker } \
57*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
58*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_NONE_FACTORY(c, f) UPRV_BLOCK_MACRO_BEGIN { \
59*0e209d39SAndroid Build Coastguard Worker delete testClassNoClassID(f, #c, #f); \
60*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
61*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
62*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
63*0e209d39SAndroid Build Coastguard Worker } \
64*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
65*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_FACTORY(c, f) UPRV_BLOCK_MACRO_BEGIN { \
66*0e209d39SAndroid Build Coastguard Worker delete testClass(f, #c, #f, c ::getStaticClassID()); \
67*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
68*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
69*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
70*0e209d39SAndroid Build Coastguard Worker } \
71*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
72*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_TRANSLIT(c, t) UPRV_BLOCK_MACRO_BEGIN { \
73*0e209d39SAndroid Build Coastguard Worker delete testClass(Transliterator::createInstance(UnicodeString(t), UTRANS_FORWARD,parseError,status), #c, "Transliterator: " #t, c ::getStaticClassID()); \
74*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
75*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - Transliterator: " #t " - got err status ") + UnicodeString(u_errorName(status))); \
76*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
77*0e209d39SAndroid Build Coastguard Worker } \
78*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
79*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_CTOR(c, x) UPRV_BLOCK_MACRO_BEGIN { \
80*0e209d39SAndroid Build Coastguard Worker delete testClass(new c x, #c, "new " #c #x, c ::getStaticClassID()); \
81*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
82*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); \
83*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
84*0e209d39SAndroid Build Coastguard Worker } \
85*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
86*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_DEFAULT(c) \
87*0e209d39SAndroid Build Coastguard Worker delete testClass(new c, #c, "new " #c , c::getStaticClassID())
88*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_ABSTRACT(c) \
89*0e209d39SAndroid Build Coastguard Worker testClass(nullptr, #c, nullptr, c::getStaticClassID())
90*0e209d39SAndroid Build Coastguard Worker #define TESTCLASSID_FACTORY_HIDDEN(c, f) UPRV_BLOCK_MACRO_BEGIN { \
91*0e209d39SAndroid Build Coastguard Worker UObject *objVar = f; \
92*0e209d39SAndroid Build Coastguard Worker delete testClass(objVar, #c, #f, objVar!=nullptr? objVar->getDynamicClassID(): nullptr); \
93*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) { \
94*0e209d39SAndroid Build Coastguard Worker dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
95*0e209d39SAndroid Build Coastguard Worker status = U_ZERO_ERROR; \
96*0e209d39SAndroid Build Coastguard Worker } \
97*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
98*0e209d39SAndroid Build Coastguard Worker
99*0e209d39SAndroid Build Coastguard Worker #define MAX_CLASS_ID 200
100*0e209d39SAndroid Build Coastguard Worker
101*0e209d39SAndroid Build Coastguard Worker static UClassID ids[MAX_CLASS_ID];
102*0e209d39SAndroid Build Coastguard Worker static const char *ids_factory[MAX_CLASS_ID];
103*0e209d39SAndroid Build Coastguard Worker static const char *ids_class[MAX_CLASS_ID];
104*0e209d39SAndroid Build Coastguard Worker static uint32_t ids_count = 0;
105*0e209d39SAndroid Build Coastguard Worker
testClass(UObject * obj,const char * className,const char * factory,UClassID staticID)106*0e209d39SAndroid Build Coastguard Worker UObject *UObjectTest::testClass(UObject *obj,
107*0e209d39SAndroid Build Coastguard Worker const char *className, const char *factory,
108*0e209d39SAndroid Build Coastguard Worker UClassID staticID)
109*0e209d39SAndroid Build Coastguard Worker {
110*0e209d39SAndroid Build Coastguard Worker uint32_t i;
111*0e209d39SAndroid Build Coastguard Worker UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; ";
112*0e209d39SAndroid Build Coastguard Worker UClassID dynamicID = nullptr;
113*0e209d39SAndroid Build Coastguard Worker
114*0e209d39SAndroid Build Coastguard Worker if(ids_count >= MAX_CLASS_ID) {
115*0e209d39SAndroid Build Coastguard Worker char count[100];
116*0e209d39SAndroid Build Coastguard Worker snprintf(count, sizeof(count), " (currently %d) ", MAX_CLASS_ID);
117*0e209d39SAndroid Build Coastguard Worker errln("FAIL: Fatal: Ran out of IDs! Increase MAX_CLASS_ID." + UnicodeString(count) + what);
118*0e209d39SAndroid Build Coastguard Worker return obj;
119*0e209d39SAndroid Build Coastguard Worker }
120*0e209d39SAndroid Build Coastguard Worker
121*0e209d39SAndroid Build Coastguard Worker if(obj) {
122*0e209d39SAndroid Build Coastguard Worker dynamicID = obj->getDynamicClassID();
123*0e209d39SAndroid Build Coastguard Worker }
124*0e209d39SAndroid Build Coastguard Worker
125*0e209d39SAndroid Build Coastguard Worker {
126*0e209d39SAndroid Build Coastguard Worker char tmp[500];
127*0e209d39SAndroid Build Coastguard Worker snprintf(tmp, sizeof(tmp), " [static=%p, dynamic=%p] ", staticID, dynamicID);
128*0e209d39SAndroid Build Coastguard Worker logln(what + tmp);
129*0e209d39SAndroid Build Coastguard Worker }
130*0e209d39SAndroid Build Coastguard Worker
131*0e209d39SAndroid Build Coastguard Worker if(staticID == nullptr) {
132*0e209d39SAndroid Build Coastguard Worker dataerrln("FAIL: staticID == nullptr! " + what);
133*0e209d39SAndroid Build Coastguard Worker }
134*0e209d39SAndroid Build Coastguard Worker
135*0e209d39SAndroid Build Coastguard Worker if(factory != nullptr) { /* nullptr factory means: abstract */
136*0e209d39SAndroid Build Coastguard Worker if(!obj) {
137*0e209d39SAndroid Build Coastguard Worker dataerrln( "FAIL: ==nullptr! " + what);
138*0e209d39SAndroid Build Coastguard Worker return obj;
139*0e209d39SAndroid Build Coastguard Worker }
140*0e209d39SAndroid Build Coastguard Worker
141*0e209d39SAndroid Build Coastguard Worker if(dynamicID == nullptr) {
142*0e209d39SAndroid Build Coastguard Worker errln("FAIL: dynamicID == nullptr!" + what);
143*0e209d39SAndroid Build Coastguard Worker }
144*0e209d39SAndroid Build Coastguard Worker
145*0e209d39SAndroid Build Coastguard Worker if(dynamicID != staticID) {
146*0e209d39SAndroid Build Coastguard Worker dataerrln("FAIL: dynamicID != staticID! " + what);
147*0e209d39SAndroid Build Coastguard Worker }
148*0e209d39SAndroid Build Coastguard Worker }
149*0e209d39SAndroid Build Coastguard Worker
150*0e209d39SAndroid Build Coastguard Worker // Bail out if static ID is null. Error message was already printed.
151*0e209d39SAndroid Build Coastguard Worker if(staticID == nullptr) {
152*0e209d39SAndroid Build Coastguard Worker return obj;
153*0e209d39SAndroid Build Coastguard Worker }
154*0e209d39SAndroid Build Coastguard Worker
155*0e209d39SAndroid Build Coastguard Worker for(i=0;i<ids_count;i++) {
156*0e209d39SAndroid Build Coastguard Worker if(staticID == ids[i]) {
157*0e209d39SAndroid Build Coastguard Worker if(!strcmp(ids_class[i], className)) {
158*0e209d39SAndroid Build Coastguard Worker logln("OK: ID found is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what);
159*0e209d39SAndroid Build Coastguard Worker return obj;
160*0e209d39SAndroid Build Coastguard Worker } else {
161*0e209d39SAndroid Build Coastguard Worker errln("FAIL: ID is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what);
162*0e209d39SAndroid Build Coastguard Worker return obj;
163*0e209d39SAndroid Build Coastguard Worker }
164*0e209d39SAndroid Build Coastguard Worker }
165*0e209d39SAndroid Build Coastguard Worker }
166*0e209d39SAndroid Build Coastguard Worker
167*0e209d39SAndroid Build Coastguard Worker ids[ids_count] = staticID;
168*0e209d39SAndroid Build Coastguard Worker ids_factory[ids_count] = factory;
169*0e209d39SAndroid Build Coastguard Worker ids_class[ids_count] = className;
170*0e209d39SAndroid Build Coastguard Worker ids_count++;
171*0e209d39SAndroid Build Coastguard Worker
172*0e209d39SAndroid Build Coastguard Worker return obj;
173*0e209d39SAndroid Build Coastguard Worker }
174*0e209d39SAndroid Build Coastguard Worker
testClassNoClassID(UObject * obj,const char * className,const char * factory)175*0e209d39SAndroid Build Coastguard Worker UObject *UObjectTest::testClassNoClassID(UObject *obj, const char *className, const char *factory)
176*0e209d39SAndroid Build Coastguard Worker {
177*0e209d39SAndroid Build Coastguard Worker if (!obj) {
178*0e209d39SAndroid Build Coastguard Worker return nullptr;
179*0e209d39SAndroid Build Coastguard Worker }
180*0e209d39SAndroid Build Coastguard Worker UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; ";
181*0e209d39SAndroid Build Coastguard Worker UClassID dynamicID = obj->getDynamicClassID();
182*0e209d39SAndroid Build Coastguard Worker
183*0e209d39SAndroid Build Coastguard Worker {
184*0e209d39SAndroid Build Coastguard Worker char tmp[500];
185*0e209d39SAndroid Build Coastguard Worker snprintf(tmp, sizeof(tmp), " [dynamic=%p] ", dynamicID);
186*0e209d39SAndroid Build Coastguard Worker logln(what + tmp);
187*0e209d39SAndroid Build Coastguard Worker }
188*0e209d39SAndroid Build Coastguard Worker
189*0e209d39SAndroid Build Coastguard Worker if(factory != nullptr) { /* nullptr factory means: abstract */
190*0e209d39SAndroid Build Coastguard Worker if(!obj) {
191*0e209d39SAndroid Build Coastguard Worker dataerrln( "FAIL: ==nullptr! " + what);
192*0e209d39SAndroid Build Coastguard Worker return obj;
193*0e209d39SAndroid Build Coastguard Worker }
194*0e209d39SAndroid Build Coastguard Worker
195*0e209d39SAndroid Build Coastguard Worker if(dynamicID != nullptr) {
196*0e209d39SAndroid Build Coastguard Worker errln("FAIL: dynamicID != nullptr! for non-poor-man's-RTTI " + what);
197*0e209d39SAndroid Build Coastguard Worker }
198*0e209d39SAndroid Build Coastguard Worker }
199*0e209d39SAndroid Build Coastguard Worker
200*0e209d39SAndroid Build Coastguard Worker return obj;
201*0e209d39SAndroid Build Coastguard Worker }
202*0e209d39SAndroid Build Coastguard Worker
203*0e209d39SAndroid Build Coastguard Worker // begin actual #includes for things to be tested
204*0e209d39SAndroid Build Coastguard Worker //
205*0e209d39SAndroid Build Coastguard Worker // The following script will generate the #includes needed here:
206*0e209d39SAndroid Build Coastguard Worker //
207*0e209d39SAndroid Build Coastguard Worker // find common i18n -name '*.h' -print | xargs fgrep ClassID | cut -d: -f1 | cut -d\/ -f2- | sort | uniq | sed -e 's%.*%#include "&"%'
208*0e209d39SAndroid Build Coastguard Worker
209*0e209d39SAndroid Build Coastguard Worker
210*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
211*0e209d39SAndroid Build Coastguard Worker
212*0e209d39SAndroid Build Coastguard Worker // Internal Things (woo)
213*0e209d39SAndroid Build Coastguard Worker #include "cpdtrans.h"
214*0e209d39SAndroid Build Coastguard Worker #include "rbt.h"
215*0e209d39SAndroid Build Coastguard Worker #include "rbt_data.h"
216*0e209d39SAndroid Build Coastguard Worker #include "nultrans.h"
217*0e209d39SAndroid Build Coastguard Worker #include "anytrans.h"
218*0e209d39SAndroid Build Coastguard Worker #include "esctrn.h"
219*0e209d39SAndroid Build Coastguard Worker #include "funcrepl.h"
220*0e209d39SAndroid Build Coastguard Worker #include "servnotf.h"
221*0e209d39SAndroid Build Coastguard Worker #include "serv.h"
222*0e209d39SAndroid Build Coastguard Worker #include "servloc.h"
223*0e209d39SAndroid Build Coastguard Worker #include "name2uni.h"
224*0e209d39SAndroid Build Coastguard Worker #include "nfsubs.h"
225*0e209d39SAndroid Build Coastguard Worker #include "nortrans.h"
226*0e209d39SAndroid Build Coastguard Worker #include "quant.h"
227*0e209d39SAndroid Build Coastguard Worker #include "remtrans.h"
228*0e209d39SAndroid Build Coastguard Worker #include "strmatch.h"
229*0e209d39SAndroid Build Coastguard Worker #include "strrepl.h"
230*0e209d39SAndroid Build Coastguard Worker #include "titletrn.h"
231*0e209d39SAndroid Build Coastguard Worker #include "tolowtrn.h"
232*0e209d39SAndroid Build Coastguard Worker #include "toupptrn.h"
233*0e209d39SAndroid Build Coastguard Worker #include "unesctrn.h"
234*0e209d39SAndroid Build Coastguard Worker #include "uni2name.h"
235*0e209d39SAndroid Build Coastguard Worker #include "uvector.h"
236*0e209d39SAndroid Build Coastguard Worker #include "uvectr32.h"
237*0e209d39SAndroid Build Coastguard Worker #include "currfmt.h"
238*0e209d39SAndroid Build Coastguard Worker #include "buddhcal.h"
239*0e209d39SAndroid Build Coastguard Worker #include "islamcal.h"
240*0e209d39SAndroid Build Coastguard Worker #include "japancal.h"
241*0e209d39SAndroid Build Coastguard Worker #include "hebrwcal.h"
242*0e209d39SAndroid Build Coastguard Worker #include "persncal.h"
243*0e209d39SAndroid Build Coastguard Worker #include "taiwncal.h"
244*0e209d39SAndroid Build Coastguard Worker #include "indiancal.h"
245*0e209d39SAndroid Build Coastguard Worker #include "chnsecal.h"
246*0e209d39SAndroid Build Coastguard Worker #include "windtfmt.h"
247*0e209d39SAndroid Build Coastguard Worker #include "winnmfmt.h"
248*0e209d39SAndroid Build Coastguard Worker #include "ustrenum.h"
249*0e209d39SAndroid Build Coastguard Worker #include "olsontz.h"
250*0e209d39SAndroid Build Coastguard Worker #include "reldtfmt.h"
251*0e209d39SAndroid Build Coastguard Worker
252*0e209d39SAndroid Build Coastguard Worker // External Things
253*0e209d39SAndroid Build Coastguard Worker #include "unicode/appendable.h"
254*0e209d39SAndroid Build Coastguard Worker #include "unicode/alphaindex.h"
255*0e209d39SAndroid Build Coastguard Worker #include "unicode/brkiter.h"
256*0e209d39SAndroid Build Coastguard Worker #include "unicode/calendar.h"
257*0e209d39SAndroid Build Coastguard Worker #include "unicode/caniter.h"
258*0e209d39SAndroid Build Coastguard Worker #include "unicode/chariter.h"
259*0e209d39SAndroid Build Coastguard Worker #include "unicode/choicfmt.h"
260*0e209d39SAndroid Build Coastguard Worker #include "unicode/coleitr.h"
261*0e209d39SAndroid Build Coastguard Worker #include "unicode/coll.h"
262*0e209d39SAndroid Build Coastguard Worker #include "unicode/curramt.h"
263*0e209d39SAndroid Build Coastguard Worker #include "unicode/datefmt.h"
264*0e209d39SAndroid Build Coastguard Worker #include "unicode/dcfmtsym.h"
265*0e209d39SAndroid Build Coastguard Worker #include "unicode/decimfmt.h"
266*0e209d39SAndroid Build Coastguard Worker #include "unicode/dtfmtsym.h"
267*0e209d39SAndroid Build Coastguard Worker #include "unicode/dtptngen.h"
268*0e209d39SAndroid Build Coastguard Worker #include "unicode/fieldpos.h"
269*0e209d39SAndroid Build Coastguard Worker #include "unicode/fmtable.h"
270*0e209d39SAndroid Build Coastguard Worker #include "unicode/format.h"
271*0e209d39SAndroid Build Coastguard Worker #include "unicode/gregocal.h"
272*0e209d39SAndroid Build Coastguard Worker #include "unicode/idna.h"
273*0e209d39SAndroid Build Coastguard Worker #include "unicode/locdspnm.h"
274*0e209d39SAndroid Build Coastguard Worker #include "unicode/locid.h"
275*0e209d39SAndroid Build Coastguard Worker #include "unicode/measunit.h"
276*0e209d39SAndroid Build Coastguard Worker #include "unicode/msgfmt.h"
277*0e209d39SAndroid Build Coastguard Worker #include "unicode/normlzr.h"
278*0e209d39SAndroid Build Coastguard Worker #include "unicode/normalizer2.h"
279*0e209d39SAndroid Build Coastguard Worker #include "unicode/numfmt.h"
280*0e209d39SAndroid Build Coastguard Worker #include "unicode/parsepos.h"
281*0e209d39SAndroid Build Coastguard Worker #include "unicode/plurrule.h"
282*0e209d39SAndroid Build Coastguard Worker #include "unicode/plurfmt.h"
283*0e209d39SAndroid Build Coastguard Worker #include "unicode/selfmt.h"
284*0e209d39SAndroid Build Coastguard Worker #include "unicode/rbbi.h"
285*0e209d39SAndroid Build Coastguard Worker #include "unicode/rbnf.h"
286*0e209d39SAndroid Build Coastguard Worker #include "unicode/regex.h"
287*0e209d39SAndroid Build Coastguard Worker #include "unicode/resbund.h"
288*0e209d39SAndroid Build Coastguard Worker #include "unicode/schriter.h"
289*0e209d39SAndroid Build Coastguard Worker #include "unicode/simpletz.h"
290*0e209d39SAndroid Build Coastguard Worker #include "unicode/smpdtfmt.h"
291*0e209d39SAndroid Build Coastguard Worker #include "unicode/sortkey.h"
292*0e209d39SAndroid Build Coastguard Worker #include "unicode/stsearch.h"
293*0e209d39SAndroid Build Coastguard Worker #include "unicode/tblcoll.h"
294*0e209d39SAndroid Build Coastguard Worker #include "unicode/timezone.h"
295*0e209d39SAndroid Build Coastguard Worker #include "unicode/tmunit.h"
296*0e209d39SAndroid Build Coastguard Worker #include "unicode/translit.h"
297*0e209d39SAndroid Build Coastguard Worker #include "unicode/uchriter.h"
298*0e209d39SAndroid Build Coastguard Worker #include "unicode/uloc.h"
299*0e209d39SAndroid Build Coastguard Worker #include "unicode/unifilt.h"
300*0e209d39SAndroid Build Coastguard Worker #include "unicode/unifunct.h"
301*0e209d39SAndroid Build Coastguard Worker #include "unicode/uniset.h"
302*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
303*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
304*0e209d39SAndroid Build Coastguard Worker #include "unicode/usetiter.h"
305*0e209d39SAndroid Build Coastguard Worker //#include "unicode/bidi.h"
306*0e209d39SAndroid Build Coastguard Worker //#include "unicode/convert.h"
307*0e209d39SAndroid Build Coastguard Worker
308*0e209d39SAndroid Build Coastguard Worker // END includes =============================================================
309*0e209d39SAndroid Build Coastguard Worker
310*0e209d39SAndroid Build Coastguard Worker #define UOBJTEST_TEST_INTERNALS 0 /* do NOT test Internal things - their functions aren't exported on Win32 */
311*0e209d39SAndroid Build Coastguard Worker
312*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
313*0e209d39SAndroid Build Coastguard Worker /* The whole purpose of this class is to expose the constructor, and gain access to the superclasses RTTI. */
314*0e209d39SAndroid Build Coastguard Worker class TestLocaleKeyFactory : public LocaleKeyFactory {
315*0e209d39SAndroid Build Coastguard Worker public:
TestLocaleKeyFactory(int32_t coverage)316*0e209d39SAndroid Build Coastguard Worker TestLocaleKeyFactory(int32_t coverage) : LocaleKeyFactory(coverage) {}
317*0e209d39SAndroid Build Coastguard Worker };
318*0e209d39SAndroid Build Coastguard Worker #endif
319*0e209d39SAndroid Build Coastguard Worker
320*0e209d39SAndroid Build Coastguard Worker // Appendable is abstract; we define a subclass to verify that there is no "poor man's RTTI".
321*0e209d39SAndroid Build Coastguard Worker class DummyAppendable : public Appendable {
322*0e209d39SAndroid Build Coastguard Worker public:
appendCodeUnit(char16_t)323*0e209d39SAndroid Build Coastguard Worker virtual UBool appendCodeUnit(char16_t /*c*/) override { return true; }
324*0e209d39SAndroid Build Coastguard Worker };
325*0e209d39SAndroid Build Coastguard Worker
testIDs()326*0e209d39SAndroid Build Coastguard Worker void UObjectTest::testIDs()
327*0e209d39SAndroid Build Coastguard Worker {
328*0e209d39SAndroid Build Coastguard Worker ids_count = 0;
329*0e209d39SAndroid Build Coastguard Worker UErrorCode status = U_ZERO_ERROR;
330*0e209d39SAndroid Build Coastguard Worker
331*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_CTOR(UObject, ());
332*0e209d39SAndroid Build Coastguard Worker
333*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_TRANSLITERATION || !UCONFIG_NO_FORMATTING
334*0e209d39SAndroid Build Coastguard Worker UParseError parseError;
335*0e209d39SAndroid Build Coastguard Worker #endif
336*0e209d39SAndroid Build Coastguard Worker
337*0e209d39SAndroid Build Coastguard Worker
338*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_NORMALIZATION
339*0e209d39SAndroid Build Coastguard Worker UnicodeString emptyString;
340*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(Normalizer, (emptyString, UNORM_NONE));
341*0e209d39SAndroid Build Coastguard Worker const Normalizer2* nfc_singleton = Normalizer2::getNFCInstance(status);
342*0e209d39SAndroid Build Coastguard Worker UnicodeSet emptySet;
343*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_CTOR(FilteredNormalizer2, (*nfc_singleton, emptySet));
344*0e209d39SAndroid Build Coastguard Worker
345*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(CanonicalIterator, new CanonicalIterator(UnicodeString("abc"), status));
346*0e209d39SAndroid Build Coastguard Worker #endif
347*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_IDNA
348*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_FACTORY(IDNA, IDNA::createUTS46Instance(0, status));
349*0e209d39SAndroid Build Coastguard Worker #endif
350*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(CollationElementIterator);
351*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION
352*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(CollationKey);
353*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(UStringEnumeration, Collator::getKeywords(status));
354*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_FACTORY_HIDDEN(CollationLocaleListEnumeration, Collator::getAvailableLocales());
355*0e209d39SAndroid Build Coastguard Worker #endif
356*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_FACTORY(CompoundTransliterator, Transliterator::createInstance(UnicodeString("Any-Jex;Hangul-Jamo"), UTRANS_FORWARD, parseError, status));
357*0e209d39SAndroid Build Coastguard Worker
358*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
359*0e209d39SAndroid Build Coastguard Worker /* TESTCLASSID_FACTORY(NFSubstitution, NFSubstitution::makeSubstitution(8, */
360*0e209d39SAndroid Build Coastguard Worker /* TESTCLASSID_DEFAULT(DigitList); UMemory but not UObject*/
361*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(NumberFormat);
362*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(RuleBasedNumberFormat, (UnicodeString("%default: -x: minus >>;"), parseError, status));
363*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(ChoiceFormat, (UNICODE_STRING_SIMPLE("0#are no files|1#is one file|1<are many files"), status));
364*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(MessageFormat, (UnicodeString(), status));
365*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(DateFormatSymbols, (status));
366*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(PluralFormat, (status));
367*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(PluralRules, (status));
368*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(SelectFormat, (UnicodeString("feminine {feminineVerbValue} other{otherVerbValue}"), status) );
369*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(DateTimePatternGenerator, DateTimePatternGenerator::createInstance(status));
370*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(RelativeDateFormat, DateFormat::createDateInstance(DateFormat::kFullRelative, Locale::getUS()));
371*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(DecimalFormatSymbols, (status));
372*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(FieldPosition);
373*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(Formattable);
374*0e209d39SAndroid Build Coastguard Worker
375*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(MeasureUnit, MeasureUnit::createMeter(status));
376*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(TimeUnit, TimeUnit::createInstance(TimeUnit::UTIMEUNIT_YEAR, status));
377*0e209d39SAndroid Build Coastguard Worker static const char16_t SMALL_STR[] = u"QQQ";
378*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(CurrencyAmount, (1.0, SMALL_STR, status));
379*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(CurrencyUnit, (SMALL_STR, status));
380*0e209d39SAndroid Build Coastguard Worker
381*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_FACTORY(LocaleDisplayNames, LocaleDisplayNames::createInstance("de"));
382*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY_HIDDEN(CurrencyFormat, MeasureFormat::createCurrencyFormat(Locale::getUS(), status));
383*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(GregorianCalendar, Calendar::createInstance(Locale("@calendar=gregorian"), status));
384*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(BuddhistCalendar, Calendar::createInstance(Locale("@calendar=buddhist"), status));
385*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(IslamicCalendar, Calendar::createInstance(Locale("@calendar=islamic"), status));
386*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(JapaneseCalendar, Calendar::createInstance(Locale("@calendar=japanese"), status));
387*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(HebrewCalendar, Calendar::createInstance(Locale("@calendar=hebrew"), status));
388*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(PersianCalendar, Calendar::createInstance(Locale("@calendar=persian"), status));
389*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(IndianCalendar, Calendar::createInstance(Locale("@calendar=indian"), status));
390*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(ChineseCalendar, Calendar::createInstance(Locale("@calendar=chinese"), status));
391*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(TaiwanCalendar, Calendar::createInstance(Locale("@calendar=roc"), status));
392*0e209d39SAndroid Build Coastguard Worker #if U_PLATFORM_USES_ONLY_WIN32_API
393*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(Win32DateFormat, DateFormat::createDateInstance(DateFormat::kFull, Locale("@compat=host")));
394*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(Win32NumberFormat, NumberFormat::createInstance(Locale("@compat=host"), status));
395*0e209d39SAndroid Build Coastguard Worker #endif
396*0e209d39SAndroid Build Coastguard Worker #endif
397*0e209d39SAndroid Build Coastguard Worker
398*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO
399*0e209d39SAndroid Build Coastguard Worker /* TESTCLASSID_ABSTRACT(BreakIterator); No staticID! */
400*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(RuleBasedBreakIterator, BreakIterator::createLineInstance("mt",status));
401*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_FACTORY(DictionaryBasedBreakIterator, BreakIterator::createLineInstance("th",status));
402*0e209d39SAndroid Build Coastguard Worker
403*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
404*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY_HIDDEN(ICULocaleService, BreakIterator::getAvailableLocales());
405*0e209d39SAndroid Build Coastguard Worker #endif
406*0e209d39SAndroid Build Coastguard Worker #endif
407*0e209d39SAndroid Build Coastguard Worker
408*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(GregorianCalendar);
409*0e209d39SAndroid Build Coastguard Worker
410*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_TRANSLITERATION
411*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(AnyTransliterator, "Any-Latin");
412*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(CompoundTransliterator, "Latin-Greek");
413*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(EscapeTransliterator, "Any-Hex");
414*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(LowercaseTransliterator, "Lower");
415*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(NameUnicodeTransliterator, "Name-Any");
416*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(NormalizationTransliterator, "NFD");
417*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(NullTransliterator, "Null");
418*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(RemoveTransliterator, "Remove");
419*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(RuleBasedTransliterator, Transliterator::createFromRules(UnicodeString("abcd"),UnicodeString("a>b;"),UTRANS_FORWARD,parseError,status));
420*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(TitlecaseTransliterator, "Title");
421*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(UnescapeTransliterator, "Hex-Any");
422*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(UnicodeNameTransliterator, "Any-Name");
423*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_TRANSLIT(UppercaseTransliterator, "Upper");
424*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(CaseMapTransliterator);
425*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(Transliterator);
426*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY_HIDDEN(TransliteratorRegistry::Enumeration, Transliterator::getAvailableIDs(status));
427*0e209d39SAndroid Build Coastguard Worker
428*0e209d39SAndroid Build Coastguard Worker #if UOBJTEST_TEST_INTERNALS
429*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(Quantifier, (nullptr, 0, 0));
430*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(FunctionReplacer, (nullptr,nullptr));
431*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(StringMatcher, (UnicodeString("x"), 0,0,0,TransliterationRuleData(status)));
432*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(StringReplacer,(UnicodeString(),new TransliterationRuleData(status)));
433*0e209d39SAndroid Build Coastguard Worker #endif
434*0e209d39SAndroid Build Coastguard Worker #endif
435*0e209d39SAndroid Build Coastguard Worker
436*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(Locale, new Locale("123"));
437*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY_HIDDEN(KeywordEnumeration, Locale("@a=b").createKeywords(status));
438*0e209d39SAndroid Build Coastguard Worker
439*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(NumeratorSubstitution);
440*0e209d39SAndroid Build Coastguard Worker
441*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_TRANSLITERATION
442*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(ParsePosition);
443*0e209d39SAndroid Build Coastguard Worker #endif
444*0e209d39SAndroid Build Coastguard Worker
445*0e209d39SAndroid Build Coastguard Worker
446*0e209d39SAndroid Build Coastguard Worker // NO_REG_EX
447*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(RegexCompile);
448*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(RegexMatcher);
449*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(RegexPattern);
450*0e209d39SAndroid Build Coastguard Worker
451*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(ReplaceableGlue);
452*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(ResourceBundle, new ResourceBundle(UnicodeString(), status) );
453*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(RuleBasedTransliterator);
454*0e209d39SAndroid Build Coastguard Worker
455*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(SimpleFwdCharIterator);
456*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(StringReplacer);
457*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(StringSearch);
458*0e209d39SAndroid Build Coastguard Worker
459*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(TestMultipleKeyStringFactory);
460*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(TestReplaceable);
461*0e209d39SAndroid Build Coastguard Worker
462*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
463*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(TimeZone);
464*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(OlsonTimeZone, TimeZone::createTimeZone(UnicodeString("America/Los_Angeles")));
465*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY_HIDDEN(KeywordEnumeration, TimeZone::createEnumeration());
466*0e209d39SAndroid Build Coastguard Worker #endif
467*0e209d39SAndroid Build Coastguard Worker
468*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_DEFAULT(DummyAppendable);
469*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(UnicodeString);
470*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(UnicodeSet, (0, 1));
471*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(UnicodeFilter);
472*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_ABSTRACT(UnicodeFunctor);
473*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(UnicodeSetIterator,(UnicodeSet(0,1)));
474*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(UStack, (status));
475*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(UVector, (status));
476*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(UVector32, (status));
477*0e209d39SAndroid Build Coastguard Worker
478*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
479*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(SimpleFactory, (nullptr, UnicodeString("foo")));
480*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(EventListener);
481*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_DEFAULT(ICUResourceBundleFactory);
482*0e209d39SAndroid Build Coastguard Worker //TESTCLASSID_DEFAULT(Key); // does not exist?
483*0e209d39SAndroid Build Coastguard Worker UnicodeString baz("baz");
484*0e209d39SAndroid Build Coastguard Worker UnicodeString bat("bat");
485*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_FACTORY(LocaleKey, LocaleKey::createWithCanonicalFallback(&baz, &bat, LocaleKey::KIND_ANY, status));
486*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(SimpleLocaleKeyFactory, (nullptr, UnicodeString("bar"), 8, 12) );
487*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_CTOR(TestLocaleKeyFactory, (42)); // Test replacement for LocaleKeyFactory
488*0e209d39SAndroid Build Coastguard Worker //#if UOBJTEST_TEST_INTERNALS
489*0e209d39SAndroid Build Coastguard Worker // TESTCLASSID_CTOR(LocaleKeyFactory, (42));
490*0e209d39SAndroid Build Coastguard Worker //#endif
491*0e209d39SAndroid Build Coastguard Worker #endif
492*0e209d39SAndroid Build Coastguard Worker
493*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
494*0e209d39SAndroid Build Coastguard Worker TESTCLASSID_NONE_CTOR(AlphabeticIndex, (Locale::getEnglish(), status));
495*0e209d39SAndroid Build Coastguard Worker #endif
496*0e209d39SAndroid Build Coastguard Worker
497*0e209d39SAndroid Build Coastguard Worker #ifdef UOBJTEST_DUMP_IDS
498*0e209d39SAndroid Build Coastguard Worker int i;
499*0e209d39SAndroid Build Coastguard Worker for(i=0;i<ids_count;i++) {
500*0e209d39SAndroid Build Coastguard Worker char junk[800];
501*0e209d39SAndroid Build Coastguard Worker snprintf(junk, sizeof(junk), " %4d:\t%p\t%s\t%s\n",
502*0e209d39SAndroid Build Coastguard Worker i, ids[i], ids_class[i], ids_factory[i]);
503*0e209d39SAndroid Build Coastguard Worker logln(UnicodeString(junk));
504*0e209d39SAndroid Build Coastguard Worker }
505*0e209d39SAndroid Build Coastguard Worker #endif
506*0e209d39SAndroid Build Coastguard Worker }
507*0e209d39SAndroid Build Coastguard Worker
testUMemory()508*0e209d39SAndroid Build Coastguard Worker void UObjectTest::testUMemory() {
509*0e209d39SAndroid Build Coastguard Worker // additional tests for code coverage
510*0e209d39SAndroid Build Coastguard Worker #if U_OVERRIDE_CXX_ALLOCATION && U_HAVE_PLACEMENT_NEW
511*0e209d39SAndroid Build Coastguard Worker alignas(UnicodeString) char bytes[sizeof(UnicodeString)];
512*0e209d39SAndroid Build Coastguard Worker UnicodeString *p;
513*0e209d39SAndroid Build Coastguard Worker enum { len=20 };
514*0e209d39SAndroid Build Coastguard Worker
515*0e209d39SAndroid Build Coastguard Worker p=new(bytes) UnicodeString(len, (UChar32)U'€', len);
516*0e209d39SAndroid Build Coastguard Worker if((void *)p!=(void *)bytes) {
517*0e209d39SAndroid Build Coastguard Worker errln("placement new did not place the object at the expected address");
518*0e209d39SAndroid Build Coastguard Worker }
519*0e209d39SAndroid Build Coastguard Worker if(p->length()!=len || p->charAt(0)!=u'€' || p->charAt(len-1)!=u'€') {
520*0e209d39SAndroid Build Coastguard Worker errln("constructor used with placement new did not work right");
521*0e209d39SAndroid Build Coastguard Worker }
522*0e209d39SAndroid Build Coastguard Worker
523*0e209d39SAndroid Build Coastguard Worker /*
524*0e209d39SAndroid Build Coastguard Worker * It is not possible to simply say
525*0e209d39SAndroid Build Coastguard Worker * delete(p, stackMemory);
526*0e209d39SAndroid Build Coastguard Worker * which results in a call to the normal, non-placement delete operator.
527*0e209d39SAndroid Build Coastguard Worker *
528*0e209d39SAndroid Build Coastguard Worker * Via a search on google.com for "c++ placement delete" I found
529*0e209d39SAndroid Build Coastguard Worker * http://cpptips.hyperformix.com/cpptips/placement_del3
530*0e209d39SAndroid Build Coastguard Worker * which says:
531*0e209d39SAndroid Build Coastguard Worker *
532*0e209d39SAndroid Build Coastguard Worker * TITLE: using placement delete
533*0e209d39SAndroid Build Coastguard Worker *
534*0e209d39SAndroid Build Coastguard Worker * (Newsgroups: comp.std.c++, 27 Aug 97)
535*0e209d39SAndroid Build Coastguard Worker *
536*0e209d39SAndroid Build Coastguard Worker * ISJ: [email protected]
537*0e209d39SAndroid Build Coastguard Worker *
538*0e209d39SAndroid Build Coastguard Worker * > I do not completely understand how placement works on operator delete.
539*0e209d39SAndroid Build Coastguard Worker * > ...
540*0e209d39SAndroid Build Coastguard Worker * There is no delete-expression which will invoke a placement
541*0e209d39SAndroid Build Coastguard Worker * form of operator delete. You can still call the function
542*0e209d39SAndroid Build Coastguard Worker * explicitly. Example:
543*0e209d39SAndroid Build Coastguard Worker * ...
544*0e209d39SAndroid Build Coastguard Worker * // destroy object and delete space manually
545*0e209d39SAndroid Build Coastguard Worker * p->~T();
546*0e209d39SAndroid Build Coastguard Worker * operator delete(p, 12);
547*0e209d39SAndroid Build Coastguard Worker *
548*0e209d39SAndroid Build Coastguard Worker * ... so that's what I am doing here.
549*0e209d39SAndroid Build Coastguard Worker * markus 20031216
550*0e209d39SAndroid Build Coastguard Worker */
551*0e209d39SAndroid Build Coastguard Worker // destroy object and delete space manually
552*0e209d39SAndroid Build Coastguard Worker p->~UnicodeString();
553*0e209d39SAndroid Build Coastguard Worker
554*0e209d39SAndroid Build Coastguard Worker // You normally wouldn't call an operator delete for object placed on the
555*0e209d39SAndroid Build Coastguard Worker // stack with a placement new().
556*0e209d39SAndroid Build Coastguard Worker // This overload of delete is a nop, and is called here for code coverage purposes.
557*0e209d39SAndroid Build Coastguard Worker UnicodeString::operator delete(p, bytes);
558*0e209d39SAndroid Build Coastguard Worker
559*0e209d39SAndroid Build Coastguard Worker // Jitterbug 4452, for coverage
560*0e209d39SAndroid Build Coastguard Worker UnicodeString *pa = new UnicodeString[2];
561*0e209d39SAndroid Build Coastguard Worker if ( !pa[0].isEmpty() || !pa[1].isEmpty()){
562*0e209d39SAndroid Build Coastguard Worker errln("constructor used with array new did not work right");
563*0e209d39SAndroid Build Coastguard Worker }
564*0e209d39SAndroid Build Coastguard Worker delete [] pa;
565*0e209d39SAndroid Build Coastguard Worker #endif
566*0e209d39SAndroid Build Coastguard Worker
567*0e209d39SAndroid Build Coastguard Worker // try to call the compiler-generated UMemory::operator=(class UMemory const &)
568*0e209d39SAndroid Build Coastguard Worker UMemory m, n;
569*0e209d39SAndroid Build Coastguard Worker m=n;
570*0e209d39SAndroid Build Coastguard Worker }
571*0e209d39SAndroid Build Coastguard Worker
TestMFCCompatibility()572*0e209d39SAndroid Build Coastguard Worker void UObjectTest::TestMFCCompatibility() {
573*0e209d39SAndroid Build Coastguard Worker #if U_HAVE_DEBUG_LOCATION_NEW
574*0e209d39SAndroid Build Coastguard Worker /* Make sure that it compiles with MFC's debuggable new usage. */
575*0e209d39SAndroid Build Coastguard Worker UnicodeString *str = new(__FILE__, __LINE__) UnicodeString();
576*0e209d39SAndroid Build Coastguard Worker str->append((char16_t)0x0040); // Is it usable?
577*0e209d39SAndroid Build Coastguard Worker if(str->charAt(0) != 0x0040) {
578*0e209d39SAndroid Build Coastguard Worker errln("debug new doesn't work.");
579*0e209d39SAndroid Build Coastguard Worker }
580*0e209d39SAndroid Build Coastguard Worker UnicodeString::operator delete(str, __FILE__, __LINE__);
581*0e209d39SAndroid Build Coastguard Worker #endif
582*0e209d39SAndroid Build Coastguard Worker }
583*0e209d39SAndroid Build Coastguard Worker
TestCompilerRTTI()584*0e209d39SAndroid Build Coastguard Worker void UObjectTest::TestCompilerRTTI() {
585*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
586*0e209d39SAndroid Build Coastguard Worker UErrorCode errorCode = U_ZERO_ERROR;
587*0e209d39SAndroid Build Coastguard Worker NumberFormat *nf = NumberFormat::createInstance("de", errorCode);
588*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(errorCode)) {
589*0e209d39SAndroid Build Coastguard Worker dataerrln("NumberFormat::createInstance(de) failed - %s", u_errorName(errorCode));
590*0e209d39SAndroid Build Coastguard Worker return;
591*0e209d39SAndroid Build Coastguard Worker }
592*0e209d39SAndroid Build Coastguard Worker if (dynamic_cast<DecimalFormat *>(nf) == nullptr || dynamic_cast<ChoiceFormat *>(nf) != nullptr) {
593*0e209d39SAndroid Build Coastguard Worker errln("dynamic_cast<>(NumberFormat) failed");
594*0e209d39SAndroid Build Coastguard Worker }
595*0e209d39SAndroid Build Coastguard Worker UnicodeSet emptySet;
596*0e209d39SAndroid Build Coastguard Worker if (&typeid(*nf) == nullptr || typeid(*nf) == typeid(UObject) || typeid(*nf) == typeid(Format) ||
597*0e209d39SAndroid Build Coastguard Worker typeid(*nf) != typeid(DecimalFormat) || typeid(*nf) == typeid(ChoiceFormat) ||
598*0e209d39SAndroid Build Coastguard Worker typeid(*nf) == typeid(emptySet)
599*0e209d39SAndroid Build Coastguard Worker ) {
600*0e209d39SAndroid Build Coastguard Worker errln("typeid(NumberFormat) failed");
601*0e209d39SAndroid Build Coastguard Worker }
602*0e209d39SAndroid Build Coastguard Worker delete nf;
603*0e209d39SAndroid Build Coastguard Worker #endif
604*0e209d39SAndroid Build Coastguard Worker }
605*0e209d39SAndroid Build Coastguard Worker
606*0e209d39SAndroid Build Coastguard Worker /* --------------- */
607*0e209d39SAndroid Build Coastguard Worker
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)608*0e209d39SAndroid Build Coastguard Worker void UObjectTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /* par */ )
609*0e209d39SAndroid Build Coastguard Worker {
610*0e209d39SAndroid Build Coastguard Worker switch (index) {
611*0e209d39SAndroid Build Coastguard Worker
612*0e209d39SAndroid Build Coastguard Worker TESTCASE(0, testIDs);
613*0e209d39SAndroid Build Coastguard Worker TESTCASE(1, testUMemory);
614*0e209d39SAndroid Build Coastguard Worker TESTCASE(2, TestMFCCompatibility);
615*0e209d39SAndroid Build Coastguard Worker TESTCASE(3, TestCompilerRTTI);
616*0e209d39SAndroid Build Coastguard Worker
617*0e209d39SAndroid Build Coastguard Worker default: name = ""; break; //needed to end loop
618*0e209d39SAndroid Build Coastguard Worker }
619*0e209d39SAndroid Build Coastguard Worker }
620