2002-11-27 21:20:20 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2011-02-03 05:28:01 +00:00
|
|
|
* Copyright (c) 1997-2011, International Business Machines Corporation and
|
2002-11-27 21:20:20 +00:00
|
|
|
* others. All Rights Reserved.
|
2010-01-16 03:07:18 +00:00
|
|
|
* Copyright (C) 2010 , Yahoo! Inc.
|
2002-11-27 21:20:20 +00:00
|
|
|
********************************************************************/
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <typeinfo> // for 'typeid' to work
|
|
|
|
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "uobjtest.h"
|
2003-12-17 00:34:44 +00:00
|
|
|
#include "cmemory.h" // UAlignedMemory
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2002-12-16 19:51:39 +00:00
|
|
|
/**
|
|
|
|
* Test for UObject, currently only the classID.
|
|
|
|
*
|
|
|
|
* Usage
|
2010-05-19 17:29:33 +00:00
|
|
|
* TESTCLASSID_NONE_DEFAULT(Foo)
|
|
|
|
* -- Foo is expected to not support "poor man's RTTI".
|
|
|
|
* Beginning with ICU 4.6, we only use compiler RTTI in new class hierarchies.
|
|
|
|
*
|
|
|
|
* TESTCLASSID_NONE_CTOR(Foo, (1, 2, 3, status))
|
|
|
|
* -- Combines TESTCLASSID_NONE_DEFAULT() and TESTCLASSID_CTOR().
|
|
|
|
*
|
|
|
|
* TESTCLASSID_NONE_FACTORY(Foo, (1, 2, 3, status))
|
|
|
|
* -- Combines TESTCLASSID_NONE_DEFAULT() and TESTCLASSID_FACTORY().
|
|
|
|
*
|
2002-12-16 19:51:39 +00:00
|
|
|
* TESTCLASSID_ABSTRACT(Bar)
|
|
|
|
* -- Bar is expected to be abstract. Only the static ID will be tested.
|
|
|
|
*
|
|
|
|
* TESTCLASSID_DEFAULT(Foo)
|
|
|
|
* -- Foo will be default-constructed.
|
|
|
|
*
|
|
|
|
* TESTCLASSID_CTOR(Foo, (1, 2, 3, status))
|
|
|
|
* -- Second argument is (parenthesized) constructor argument.
|
|
|
|
* Will be called as: new Foo ( 1, 2, 3, status) [status is tested]
|
|
|
|
*
|
|
|
|
* TESTCLASSID_FACTORY(Foo, fooCreateFunction(status) )
|
|
|
|
* -- call fooCreateFunction. 'status' will be tested & reset
|
2007-06-14 19:48:47 +00:00
|
|
|
*
|
|
|
|
* TESTCLASSID_FACTORY_HIDDEN(class, factory)
|
|
|
|
* -- call factory. Class is not available from a header.
|
|
|
|
* 'status' will be tested & reset. This only tests uniqueness.
|
2002-12-16 19:51:39 +00:00
|
|
|
*/
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
#define TESTCLASSID_NONE_DEFAULT(c) \
|
|
|
|
delete testClassNoClassID(new c, #c, "new " #c)
|
|
|
|
#define TESTCLASSID_NONE_CTOR(c, x) { \
|
|
|
|
delete testClassNoClassID(new c x, #c, "new " #c #x); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TESTCLASSID_NONE_FACTORY(c, f) { \
|
|
|
|
delete testClassNoClassID(f, #c, #f); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TESTCLASSID_FACTORY(c, f) { \
|
|
|
|
delete testClass(f, #c, #f, c ::getStaticClassID()); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TESTCLASSID_TRANSLIT(c, t) { \
|
|
|
|
delete testClass(Transliterator::createInstance(UnicodeString(t), UTRANS_FORWARD,parseError,status), #c, "Transliterator: " #t, c ::getStaticClassID()); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - Transliterator: " #t " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TESTCLASSID_CTOR(c, x) { \
|
|
|
|
delete testClass(new c x, #c, "new " #c #x, c ::getStaticClassID()); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TESTCLASSID_DEFAULT(c) \
|
|
|
|
delete testClass(new c, #c, "new " #c , c::getStaticClassID())
|
|
|
|
#define TESTCLASSID_ABSTRACT(c) \
|
|
|
|
testClass(NULL, #c, NULL, c::getStaticClassID())
|
|
|
|
#define TESTCLASSID_FACTORY_HIDDEN(c, f) { \
|
|
|
|
UObject *objVar = f; \
|
|
|
|
delete testClass(objVar, #c, #f, objVar!=NULL? objVar->getDynamicClassID(): NULL); \
|
|
|
|
if(U_FAILURE(status)) { \
|
|
|
|
dataerrln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); \
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
} \
|
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2002-12-16 19:51:39 +00:00
|
|
|
#define MAX_CLASS_ID 200
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2006-10-01 06:45:25 +00:00
|
|
|
static UClassID ids[MAX_CLASS_ID];
|
|
|
|
static const char *ids_factory[MAX_CLASS_ID];
|
|
|
|
static const char *ids_class[MAX_CLASS_ID];
|
|
|
|
static uint32_t ids_count = 0;
|
2002-11-27 21:20:20 +00:00
|
|
|
|
|
|
|
UObject *UObjectTest::testClass(UObject *obj,
|
2004-11-11 23:34:58 +00:00
|
|
|
const char *className, const char *factory,
|
|
|
|
UClassID staticID)
|
2002-11-27 21:20:20 +00:00
|
|
|
{
|
2006-11-15 00:33:39 +00:00
|
|
|
uint32_t i;
|
|
|
|
UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; ";
|
|
|
|
UClassID dynamicID = NULL;
|
|
|
|
|
|
|
|
if(ids_count >= MAX_CLASS_ID) {
|
|
|
|
char count[100];
|
|
|
|
sprintf(count, " (currently %d) ", MAX_CLASS_ID);
|
|
|
|
errln("FAIL: Fatal: Ran out of IDs! Increase MAX_CLASS_ID." + UnicodeString(count) + what);
|
|
|
|
return obj;
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|
2002-12-16 19:51:39 +00:00
|
|
|
|
2006-11-15 00:33:39 +00:00
|
|
|
if(obj) {
|
|
|
|
dynamicID = obj->getDynamicClassID();
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|
2006-11-15 00:33:39 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
char tmp[500];
|
|
|
|
sprintf(tmp, " [static=%p, dynamic=%p] ", staticID, dynamicID);
|
|
|
|
logln(what + tmp);
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|
|
|
|
|
2006-11-15 00:33:39 +00:00
|
|
|
if(staticID == NULL) {
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("FAIL: staticID == NULL! " + what);
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|
|
|
|
|
2006-11-15 00:33:39 +00:00
|
|
|
if(factory != NULL) { /* NULL factory means: abstract */
|
|
|
|
if(!obj) {
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln( "FAIL: ==NULL! " + what);
|
2006-11-15 00:33:39 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dynamicID == NULL) {
|
|
|
|
errln("FAIL: dynamicID == NULL!" + what);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dynamicID != staticID) {
|
2009-06-12 19:34:21 +00:00
|
|
|
dataerrln("FAIL: dynamicID != staticID! " + what);
|
2006-11-15 00:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bail out if static ID is null. Error message was already printed.
|
|
|
|
if(staticID == NULL) {
|
|
|
|
return obj;
|
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2006-11-15 00:33:39 +00:00
|
|
|
for(i=0;i<ids_count;i++) {
|
|
|
|
if(staticID == ids[i]) {
|
|
|
|
if(!strcmp(ids_class[i], className)) {
|
|
|
|
logln("OK: ID found is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what);
|
|
|
|
return obj;
|
|
|
|
} else {
|
|
|
|
errln("FAIL: ID is the same as " + UnicodeString(ids_class[i]) + UnicodeString(" *y= ") + ids_factory[i] + what);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ids[ids_count] = staticID;
|
|
|
|
ids_factory[ids_count] = factory;
|
|
|
|
ids_class[ids_count] = className;
|
|
|
|
ids_count++;
|
|
|
|
|
|
|
|
return obj;
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
UObject *UObjectTest::testClassNoClassID(UObject *obj, const char *className, const char *factory)
|
|
|
|
{
|
2010-07-14 16:09:03 +00:00
|
|
|
if (!obj) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-05-19 17:29:33 +00:00
|
|
|
UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; ";
|
|
|
|
UClassID dynamicID = obj->getDynamicClassID();
|
|
|
|
|
|
|
|
{
|
|
|
|
char tmp[500];
|
|
|
|
sprintf(tmp, " [dynamic=%p] ", dynamicID);
|
|
|
|
logln(what + tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(factory != NULL) { /* NULL factory means: abstract */
|
|
|
|
if(!obj) {
|
|
|
|
dataerrln( "FAIL: ==NULL! " + what);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dynamicID != NULL) {
|
|
|
|
errln("FAIL: dynamicID != NULL! for non-poor-man's-RTTI " + what);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
|
|
|
|
// begin actual #includes for things to be tested
|
|
|
|
//
|
|
|
|
// The following script will generate the #includes needed here:
|
|
|
|
//
|
|
|
|
// find common i18n -name '*.h' -print | xargs fgrep ClassID | cut -d: -f1 | cut -d\/ -f2- | sort | uniq | sed -e 's%.*%#include "&"%'
|
|
|
|
|
2002-12-16 19:51:39 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
// Internal Things (woo)
|
2003-02-14 01:44:49 +00:00
|
|
|
#include "cpdtrans.h"
|
|
|
|
#include "rbt.h"
|
|
|
|
#include "rbt_data.h"
|
|
|
|
#include "nultrans.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "anytrans.h"
|
|
|
|
#include "digitlst.h"
|
|
|
|
#include "esctrn.h"
|
|
|
|
#include "funcrepl.h"
|
2004-12-21 06:55:20 +00:00
|
|
|
#include "servnotf.h"
|
|
|
|
#include "serv.h"
|
2004-12-22 08:02:08 +00:00
|
|
|
#include "servloc.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "name2uni.h"
|
|
|
|
#include "nfsubs.h"
|
|
|
|
#include "nortrans.h"
|
|
|
|
#include "quant.h"
|
|
|
|
#include "remtrans.h"
|
|
|
|
#include "strmatch.h"
|
|
|
|
#include "strrepl.h"
|
|
|
|
#include "titletrn.h"
|
|
|
|
#include "tolowtrn.h"
|
|
|
|
#include "toupptrn.h"
|
|
|
|
#include "unesctrn.h"
|
|
|
|
#include "uni2name.h"
|
2002-12-16 19:51:39 +00:00
|
|
|
#include "uvector.h"
|
2004-12-20 23:07:25 +00:00
|
|
|
#include "uvectr32.h"
|
2004-12-14 17:43:56 +00:00
|
|
|
#include "currfmt.h"
|
|
|
|
#include "buddhcal.h"
|
2003-12-04 23:16:04 +00:00
|
|
|
#include "islamcal.h"
|
2004-12-14 17:43:56 +00:00
|
|
|
#include "japancal.h"
|
|
|
|
#include "hebrwcal.h"
|
2007-06-03 06:08:46 +00:00
|
|
|
#include "persncal.h"
|
2008-01-02 23:53:26 +00:00
|
|
|
#include "taiwncal.h"
|
|
|
|
#include "indiancal.h"
|
|
|
|
#include "chnsecal.h"
|
2007-06-07 22:05:26 +00:00
|
|
|
#include "windtfmt.h"
|
|
|
|
#include "winnmfmt.h"
|
2004-12-21 06:55:20 +00:00
|
|
|
#include "ustrenum.h"
|
2006-11-15 00:33:39 +00:00
|
|
|
#include "olsontz.h"
|
2007-06-03 06:08:46 +00:00
|
|
|
#include "reldtfmt.h"
|
2002-12-16 19:51:39 +00:00
|
|
|
|
|
|
|
// External Things
|
2011-02-03 05:28:01 +00:00
|
|
|
#include "unicode/appendable.h"
|
2011-05-03 20:14:49 +00:00
|
|
|
#include "unicode/alphaindex.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/brkiter.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/caniter.h"
|
|
|
|
#include "unicode/chariter.h"
|
|
|
|
#include "unicode/choicfmt.h"
|
|
|
|
#include "unicode/coleitr.h"
|
|
|
|
#include "unicode/coll.h"
|
2004-12-14 17:43:56 +00:00
|
|
|
#include "unicode/curramt.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/datefmt.h"
|
|
|
|
#include "unicode/dcfmtsym.h"
|
|
|
|
#include "unicode/decimfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
2008-01-02 23:53:26 +00:00
|
|
|
#include "unicode/dtptngen.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/fieldpos.h"
|
|
|
|
#include "unicode/fmtable.h"
|
|
|
|
#include "unicode/format.h"
|
|
|
|
#include "unicode/gregocal.h"
|
2010-06-15 15:54:53 +00:00
|
|
|
#include "unicode/idna.h"
|
2010-05-19 17:29:33 +00:00
|
|
|
#include "unicode/locdspnm.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/locid.h"
|
|
|
|
#include "unicode/msgfmt.h"
|
|
|
|
#include "unicode/normlzr.h"
|
2010-05-19 17:29:33 +00:00
|
|
|
#include "unicode/normalizer2.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/numfmt.h"
|
|
|
|
#include "unicode/parsepos.h"
|
2008-01-02 23:53:26 +00:00
|
|
|
#include "unicode/plurrule.h"
|
|
|
|
#include "unicode/plurfmt.h"
|
2010-01-16 03:07:18 +00:00
|
|
|
#include "unicode/selfmt.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/rbbi.h"
|
|
|
|
#include "unicode/rbnf.h"
|
|
|
|
#include "unicode/regex.h"
|
|
|
|
#include "unicode/resbund.h"
|
|
|
|
#include "unicode/schriter.h"
|
|
|
|
#include "unicode/simpletz.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/sortkey.h"
|
|
|
|
#include "unicode/stsearch.h"
|
|
|
|
#include "unicode/tblcoll.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/translit.h"
|
|
|
|
#include "unicode/uchriter.h"
|
2011-05-03 20:14:49 +00:00
|
|
|
#include "unicode/uloc.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
#include "unicode/unifilt.h"
|
|
|
|
#include "unicode/unifunct.h"
|
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "unicode/uobject.h"
|
|
|
|
#include "unicode/usetiter.h"
|
2002-12-16 19:51:39 +00:00
|
|
|
//#include "unicode/bidi.h"
|
|
|
|
//#include "unicode/convert.h"
|
2002-11-27 21:20:20 +00:00
|
|
|
|
|
|
|
// END includes =============================================================
|
|
|
|
|
2002-12-16 22:21:49 +00:00
|
|
|
#define UOBJTEST_TEST_INTERNALS 0 /* do NOT test Internal things - their functions aren't exported on Win32 */
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2005-07-07 07:54:43 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2004-12-22 08:02:08 +00:00
|
|
|
/* The whole purpose of this class is to expose the constructor, and gain access to the superclasses RTTI. */
|
|
|
|
class TestLocaleKeyFactory : public LocaleKeyFactory {
|
|
|
|
public:
|
|
|
|
TestLocaleKeyFactory(int32_t coverage) : LocaleKeyFactory(coverage) {}
|
|
|
|
};
|
2005-07-07 07:54:43 +00:00
|
|
|
#endif
|
2004-12-22 08:02:08 +00:00
|
|
|
|
2011-02-03 22:07:22 +00:00
|
|
|
// Appendable is abstract; we define a subclass to verify that there is no "poor man's RTTI".
|
|
|
|
class DummyAppendable : public Appendable {
|
2011-02-03 05:28:01 +00:00
|
|
|
public:
|
|
|
|
virtual UBool appendCodeUnit(UChar /*c*/) { return TRUE; }
|
|
|
|
};
|
|
|
|
|
2002-11-27 21:20:20 +00:00
|
|
|
void UObjectTest::testIDs()
|
|
|
|
{
|
2002-11-30 02:31:06 +00:00
|
|
|
ids_count = 0;
|
2004-12-31 17:31:47 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-12-16 22:21:49 +00:00
|
|
|
|
2005-07-07 07:54:43 +00:00
|
|
|
#if !UCONFIG_NO_TRANSLITERATION || !UCONFIG_NO_FORMATTING
|
2002-11-30 02:31:06 +00:00
|
|
|
UParseError parseError;
|
2002-12-10 18:52:21 +00:00
|
|
|
#endif
|
2002-12-16 19:51:39 +00:00
|
|
|
|
|
|
|
|
2003-05-06 01:22:23 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2010-05-19 17:29:33 +00:00
|
|
|
UnicodeString emptyString;
|
|
|
|
TESTCLASSID_CTOR(Normalizer, (emptyString, UNORM_NONE));
|
|
|
|
const Normalizer2 *noNormalizer2 = NULL;
|
|
|
|
UnicodeSet emptySet;
|
|
|
|
TESTCLASSID_NONE_CTOR(FilteredNormalizer2, (*noNormalizer2, emptySet));
|
2002-11-30 02:31:06 +00:00
|
|
|
TESTCLASSID_FACTORY(CanonicalIterator, new CanonicalIterator(UnicodeString("abc"), status));
|
2010-06-15 15:54:53 +00:00
|
|
|
#endif
|
|
|
|
#if !UCONFIG_NO_IDNA
|
|
|
|
TESTCLASSID_NONE_FACTORY(IDNA, IDNA::createUTS46Instance(0, status));
|
2003-05-06 01:22:23 +00:00
|
|
|
#endif
|
2002-11-30 02:31:06 +00:00
|
|
|
//TESTCLASSID_DEFAULT(CollationElementIterator);
|
2002-12-10 18:52:21 +00:00
|
|
|
#if !UCONFIG_NO_COLLATION
|
2002-11-30 02:31:06 +00:00
|
|
|
TESTCLASSID_DEFAULT(CollationKey);
|
2004-12-21 06:55:20 +00:00
|
|
|
TESTCLASSID_FACTORY(UStringEnumeration, Collator::getKeywords(status));
|
2007-06-14 20:46:45 +00:00
|
|
|
//TESTCLASSID_FACTORY_HIDDEN(CollationLocaleListEnumeration, Collator::getAvailableLocales());
|
2002-12-10 18:52:21 +00:00
|
|
|
#endif
|
2002-11-30 02:31:06 +00:00
|
|
|
//TESTCLASSID_FACTORY(CompoundTransliterator, Transliterator::createInstance(UnicodeString("Any-Jex;Hangul-Jamo"), UTRANS_FORWARD, parseError, status));
|
|
|
|
|
2002-12-10 18:52:21 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2002-12-16 19:51:39 +00:00
|
|
|
/* TESTCLASSID_FACTORY(NFSubstitution, NFSubstitution::makeSubstitution(8, */
|
|
|
|
/* TESTCLASSID_DEFAULT(DigitList); UMemory but not UObject*/
|
2004-06-01 23:36:32 +00:00
|
|
|
TESTCLASSID_ABSTRACT(NumberFormat);
|
2004-12-31 17:31:47 +00:00
|
|
|
TESTCLASSID_CTOR(RuleBasedNumberFormat, (UnicodeString("%default: -x: minus >>;"), parseError, status));
|
2004-12-14 17:43:56 +00:00
|
|
|
TESTCLASSID_CTOR(ChoiceFormat, (UNICODE_STRING_SIMPLE("0#are no files|1#is one file|1<are many files"), status));
|
2004-12-31 17:31:47 +00:00
|
|
|
TESTCLASSID_CTOR(MessageFormat, (UnicodeString(), status));
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_CTOR(DateFormatSymbols, (status));
|
2008-01-02 23:53:26 +00:00
|
|
|
TESTCLASSID_CTOR(PluralFormat, (status));
|
|
|
|
TESTCLASSID_CTOR(PluralRules, (status));
|
2010-01-30 07:12:52 +00:00
|
|
|
TESTCLASSID_CTOR(SelectFormat, (UnicodeString("feminine {feminineVerbValue} other{otherVerbValue}"), status) );
|
2008-01-02 23:53:26 +00:00
|
|
|
TESTCLASSID_FACTORY(DateTimePatternGenerator, DateTimePatternGenerator::createInstance(status));
|
2007-06-03 06:08:46 +00:00
|
|
|
TESTCLASSID_FACTORY(RelativeDateFormat, DateFormat::createDateInstance(DateFormat::kFullRelative, Locale::getUS()));
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_CTOR(DecimalFormatSymbols, (status));
|
|
|
|
TESTCLASSID_DEFAULT(FieldPosition);
|
2002-11-30 02:31:06 +00:00
|
|
|
TESTCLASSID_DEFAULT(Formattable);
|
2011-04-25 20:47:32 +00:00
|
|
|
|
|
|
|
static const UChar SMALL_STR[] = {0x51, 0x51, 0x51, 0}; // "QQQ"
|
2004-12-14 17:43:56 +00:00
|
|
|
TESTCLASSID_CTOR(CurrencyAmount, (1.0, SMALL_STR, status));
|
|
|
|
TESTCLASSID_CTOR(CurrencyUnit, (SMALL_STR, status));
|
2010-05-19 17:29:33 +00:00
|
|
|
TESTCLASSID_NONE_FACTORY(LocaleDisplayNames, LocaleDisplayNames::createInstance("de"));
|
2008-01-02 23:53:26 +00:00
|
|
|
TESTCLASSID_FACTORY_HIDDEN(CurrencyFormat, MeasureFormat::createCurrencyFormat(Locale::getUS(), status));
|
2007-06-03 06:08:46 +00:00
|
|
|
TESTCLASSID_FACTORY(GregorianCalendar, Calendar::createInstance(Locale("@calendar=gregorian"), status));
|
|
|
|
TESTCLASSID_FACTORY(BuddhistCalendar, Calendar::createInstance(Locale("@calendar=buddhist"), status));
|
|
|
|
TESTCLASSID_FACTORY(IslamicCalendar, Calendar::createInstance(Locale("@calendar=islamic"), status));
|
|
|
|
TESTCLASSID_FACTORY(JapaneseCalendar, Calendar::createInstance(Locale("@calendar=japanese"), status));
|
|
|
|
TESTCLASSID_FACTORY(HebrewCalendar, Calendar::createInstance(Locale("@calendar=hebrew"), status));
|
|
|
|
TESTCLASSID_FACTORY(PersianCalendar, Calendar::createInstance(Locale("@calendar=persian"), status));
|
2008-01-02 23:53:26 +00:00
|
|
|
TESTCLASSID_FACTORY(IndianCalendar, Calendar::createInstance(Locale("@calendar=indian"), status));
|
|
|
|
TESTCLASSID_FACTORY(ChineseCalendar, Calendar::createInstance(Locale("@calendar=chinese"), status));
|
2008-05-16 15:01:02 +00:00
|
|
|
TESTCLASSID_FACTORY(TaiwanCalendar, Calendar::createInstance(Locale("@calendar=roc"), status));
|
2007-06-07 22:05:26 +00:00
|
|
|
#ifdef U_WINDOWS
|
|
|
|
TESTCLASSID_FACTORY(Win32DateFormat, DateFormat::createDateInstance(DateFormat::kFull, Locale("@compat=host")));
|
|
|
|
TESTCLASSID_FACTORY(Win32NumberFormat, NumberFormat::createInstance(Locale("@compat=host"), status));
|
|
|
|
#endif
|
2002-12-16 19:51:39 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-04 21:09:17 +00:00
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO
|
2002-12-16 19:51:39 +00:00
|
|
|
/* TESTCLASSID_ABSTRACT(BreakIterator); No staticID! */
|
|
|
|
TESTCLASSID_FACTORY(RuleBasedBreakIterator, BreakIterator::createLineInstance("mt",status));
|
2006-03-23 00:54:12 +00:00
|
|
|
//TESTCLASSID_FACTORY(DictionaryBasedBreakIterator, BreakIterator::createLineInstance("th",status));
|
2007-06-14 19:48:47 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
TESTCLASSID_FACTORY_HIDDEN(ICULocaleService, BreakIterator::getAvailableLocales());
|
|
|
|
#endif
|
2002-12-10 18:52:21 +00:00
|
|
|
#endif
|
2002-11-30 02:31:06 +00:00
|
|
|
|
|
|
|
//TESTCLASSID_DEFAULT(GregorianCalendar);
|
|
|
|
|
2002-12-10 18:52:21 +00:00
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_TRANSLIT(AnyTransliterator, "Any-Latin");
|
|
|
|
TESTCLASSID_TRANSLIT(CompoundTransliterator, "Latin-Greek");
|
|
|
|
TESTCLASSID_TRANSLIT(EscapeTransliterator, "Any-Hex");
|
|
|
|
TESTCLASSID_TRANSLIT(LowercaseTransliterator, "Lower");
|
|
|
|
TESTCLASSID_TRANSLIT(NameUnicodeTransliterator, "Name-Any");
|
|
|
|
TESTCLASSID_TRANSLIT(NormalizationTransliterator, "NFD");
|
|
|
|
TESTCLASSID_TRANSLIT(NullTransliterator, "Null");
|
|
|
|
TESTCLASSID_TRANSLIT(RemoveTransliterator, "Remove");
|
2007-06-11 15:05:52 +00:00
|
|
|
TESTCLASSID_FACTORY(RuleBasedTransliterator, Transliterator::createFromRules(UnicodeString("abcd"),UnicodeString("a>b;"),UTRANS_FORWARD,parseError,status));
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_TRANSLIT(TitlecaseTransliterator, "Title");
|
|
|
|
TESTCLASSID_TRANSLIT(UnescapeTransliterator, "Hex-Any");
|
|
|
|
TESTCLASSID_TRANSLIT(UnicodeNameTransliterator, "Any-Name");
|
|
|
|
TESTCLASSID_TRANSLIT(UppercaseTransliterator, "Upper");
|
2008-01-04 08:45:10 +00:00
|
|
|
TESTCLASSID_ABSTRACT(CaseMapTransliterator);
|
2007-06-14 19:03:30 +00:00
|
|
|
TESTCLASSID_ABSTRACT(Transliterator);
|
2007-06-25 22:09:38 +00:00
|
|
|
TESTCLASSID_FACTORY_HIDDEN(TransliteratorRegistry::Enumeration, Transliterator::getAvailableIDs(status));
|
2007-06-14 19:03:30 +00:00
|
|
|
|
|
|
|
#if UOBJTEST_TEST_INTERNALS
|
2006-02-08 19:43:00 +00:00
|
|
|
TESTCLASSID_CTOR(Quantifier, (NULL, 0, 0));
|
2007-06-03 06:08:46 +00:00
|
|
|
TESTCLASSID_CTOR(FunctionReplacer, (NULL,NULL));
|
2007-06-14 19:03:30 +00:00
|
|
|
TESTCLASSID_CTOR(StringMatcher, (UnicodeString("x"), 0,0,0,TransliterationRuleData(status)));
|
|
|
|
TESTCLASSID_CTOR(StringReplacer,(UnicodeString(),new TransliterationRuleData(status)));
|
|
|
|
#endif
|
2002-12-10 18:52:21 +00:00
|
|
|
#endif
|
2002-11-30 02:31:06 +00:00
|
|
|
|
|
|
|
TESTCLASSID_FACTORY(Locale, new Locale("123"));
|
2007-06-14 19:48:47 +00:00
|
|
|
TESTCLASSID_FACTORY_HIDDEN(KeywordEnumeration, Locale("@a=b").createKeywords(status));
|
2002-12-16 19:51:39 +00:00
|
|
|
|
2002-11-30 02:31:06 +00:00
|
|
|
//TESTCLASSID_DEFAULT(NumeratorSubstitution);
|
|
|
|
|
2002-12-10 18:52:21 +00:00
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-11-30 02:31:06 +00:00
|
|
|
TESTCLASSID_DEFAULT(ParsePosition);
|
2002-12-16 19:51:39 +00:00
|
|
|
#endif
|
2002-11-30 02:31:06 +00:00
|
|
|
|
2002-12-16 19:51:39 +00:00
|
|
|
|
|
|
|
// NO_REG_EX
|
2002-11-30 02:31:06 +00:00
|
|
|
//TESTCLASSID_DEFAULT(RegexCompile);
|
|
|
|
//TESTCLASSID_DEFAULT(RegexMatcher);
|
|
|
|
//TESTCLASSID_DEFAULT(RegexPattern);
|
2002-12-16 19:51:39 +00:00
|
|
|
|
2002-11-30 02:31:06 +00:00
|
|
|
//TESTCLASSID_DEFAULT(ReplaceableGlue);
|
|
|
|
TESTCLASSID_FACTORY(ResourceBundle, new ResourceBundle(UnicodeString(), status) );
|
|
|
|
//TESTCLASSID_DEFAULT(RuleBasedTransliterator);
|
|
|
|
|
|
|
|
//TESTCLASSID_DEFAULT(SimpleFwdCharIterator);
|
|
|
|
//TESTCLASSID_DEFAULT(StringReplacer);
|
|
|
|
//TESTCLASSID_DEFAULT(StringSearch);
|
|
|
|
|
|
|
|
//TESTCLASSID_DEFAULT(TestMultipleKeyStringFactory);
|
|
|
|
//TESTCLASSID_DEFAULT(TestReplaceable);
|
2004-06-01 23:36:32 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
TESTCLASSID_ABSTRACT(TimeZone);
|
2007-06-03 06:08:46 +00:00
|
|
|
TESTCLASSID_FACTORY(OlsonTimeZone, TimeZone::createTimeZone(UnicodeString("America/Los_Angeles")));
|
2007-06-14 20:46:45 +00:00
|
|
|
TESTCLASSID_FACTORY_HIDDEN(KeywordEnumeration, TimeZone::createEnumeration());
|
2004-06-01 23:36:32 +00:00
|
|
|
#endif
|
2011-02-03 05:28:01 +00:00
|
|
|
|
|
|
|
TESTCLASSID_NONE_DEFAULT(DummyAppendable);
|
2002-11-30 02:31:06 +00:00
|
|
|
TESTCLASSID_DEFAULT(UnicodeString);
|
2002-12-16 22:21:49 +00:00
|
|
|
TESTCLASSID_CTOR(UnicodeSet, (0, 1));
|
2004-06-01 23:36:32 +00:00
|
|
|
TESTCLASSID_ABSTRACT(UnicodeFilter);
|
|
|
|
TESTCLASSID_ABSTRACT(UnicodeFunctor);
|
2002-12-16 22:21:49 +00:00
|
|
|
TESTCLASSID_CTOR(UnicodeSetIterator,(UnicodeSet(0,1)));
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_CTOR(UStack, (status));
|
|
|
|
TESTCLASSID_CTOR(UVector, (status));
|
2004-12-20 23:07:25 +00:00
|
|
|
TESTCLASSID_CTOR(UVector32, (status));
|
2002-12-16 19:51:39 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
TESTCLASSID_CTOR(SimpleFactory, (NULL, UnicodeString("foo")));
|
|
|
|
TESTCLASSID_DEFAULT(EventListener);
|
|
|
|
TESTCLASSID_DEFAULT(ICUResourceBundleFactory);
|
2004-12-21 06:55:20 +00:00
|
|
|
//TESTCLASSID_DEFAULT(Key); // does not exist?
|
|
|
|
UnicodeString baz("baz");
|
|
|
|
UnicodeString bat("bat");
|
|
|
|
TESTCLASSID_FACTORY(LocaleKey, LocaleKey::createWithCanonicalFallback(&baz, &bat, LocaleKey::KIND_ANY, status));
|
2002-12-16 19:51:39 +00:00
|
|
|
TESTCLASSID_CTOR(SimpleLocaleKeyFactory, (NULL, UnicodeString("bar"), 8, 12) );
|
2004-12-22 08:02:08 +00:00
|
|
|
TESTCLASSID_CTOR(TestLocaleKeyFactory, (42)); // Test replacement for LocaleKeyFactory
|
|
|
|
//#if UOBJTEST_TEST_INTERNALS
|
|
|
|
// TESTCLASSID_CTOR(LocaleKeyFactory, (42));
|
|
|
|
//#endif
|
2002-12-16 22:21:49 +00:00
|
|
|
#endif
|
2011-05-03 20:14:49 +00:00
|
|
|
TESTCLASSID_NONE_CTOR(AlphabeticIndex, (Locale::getEnglish(), status));
|
2002-12-16 22:21:49 +00:00
|
|
|
|
|
|
|
#if UOBJTEST_DUMP_IDS
|
2002-11-30 02:31:06 +00:00
|
|
|
int i;
|
|
|
|
for(i=0;i<ids_count;i++) {
|
|
|
|
char junk[800];
|
|
|
|
sprintf(junk, " %4d:\t%p\t%s\t%s\n",
|
|
|
|
i, ids[i], ids_class[i], ids_factory[i]);
|
|
|
|
logln(UnicodeString(junk));
|
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-12-17 00:34:44 +00:00
|
|
|
void UObjectTest::testUMemory() {
|
|
|
|
// additional tests for code coverage
|
|
|
|
#if U_OVERRIDE_CXX_ALLOCATION && U_HAVE_PLACEMENT_NEW
|
2010-07-12 18:03:29 +00:00
|
|
|
union {
|
|
|
|
UAlignedMemory align_;
|
|
|
|
char bytes_[sizeof(UnicodeString)];
|
|
|
|
} stackMemory;
|
|
|
|
char *bytes = stackMemory.bytes_;
|
2003-12-17 00:34:44 +00:00
|
|
|
UnicodeString *p;
|
|
|
|
enum { len=20 };
|
|
|
|
|
2010-07-12 18:03:29 +00:00
|
|
|
p=new(bytes) UnicodeString(len, (UChar32)0x20ac, len);
|
|
|
|
if((void *)p!=(void *)bytes) {
|
2003-12-17 00:34:44 +00:00
|
|
|
errln("placement new did not place the object at the expected address");
|
|
|
|
}
|
|
|
|
if(p->length()!=len || p->charAt(0)!=0x20ac || p->charAt(len-1)!=0x20ac) {
|
|
|
|
errln("constructor used with placement new did not work right");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is not possible to simply say
|
|
|
|
* delete(p, stackMemory);
|
|
|
|
* which results in a call to the normal, non-placement delete operator.
|
|
|
|
*
|
|
|
|
* Via a search on google.com for "c++ placement delete" I found
|
|
|
|
* http://cpptips.hyperformix.com/cpptips/placement_del3
|
|
|
|
* which says:
|
|
|
|
*
|
|
|
|
* TITLE: using placement delete
|
|
|
|
*
|
|
|
|
* (Newsgroups: comp.std.c++, 27 Aug 97)
|
|
|
|
*
|
|
|
|
* ISJ: isj@image.dk
|
|
|
|
*
|
|
|
|
* > I do not completely understand how placement works on operator delete.
|
|
|
|
* > ...
|
|
|
|
* There is no delete-expression which will invoke a placement
|
|
|
|
* form of operator delete. You can still call the function
|
|
|
|
* explicitly. Example:
|
|
|
|
* ...
|
|
|
|
* // destroy object and delete space manually
|
|
|
|
* p->~T();
|
|
|
|
* operator delete(p, 12);
|
|
|
|
*
|
|
|
|
* ... so that's what I am doing here.
|
|
|
|
* markus 20031216
|
|
|
|
*/
|
|
|
|
// destroy object and delete space manually
|
|
|
|
p->~UnicodeString();
|
2010-07-12 18:03:29 +00:00
|
|
|
|
|
|
|
// You normally wouldn't call an operator delete for object placed on the
|
|
|
|
// stack with a placement new().
|
|
|
|
// This overload of delete is a nop, and is called here for code coverage purposes.
|
|
|
|
UnicodeString::operator delete(p, bytes);
|
2005-07-14 23:24:38 +00:00
|
|
|
|
|
|
|
// Jitterbug 4452, for coverage
|
|
|
|
UnicodeString *pa = new UnicodeString[2];
|
|
|
|
if ( !pa[0].isEmpty() || !pa[1].isEmpty()){
|
|
|
|
errln("constructor used with array new did not work right");
|
|
|
|
}
|
|
|
|
delete [] pa;
|
2003-12-17 00:34:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// try to call the compiler-generated UMemory::operator=(class UMemory const &)
|
|
|
|
UMemory m, n;
|
|
|
|
m=n;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:27:00 +00:00
|
|
|
void UObjectTest::TestMFCCompatibility() {
|
|
|
|
#if U_HAVE_DEBUG_LOCATION_NEW
|
|
|
|
/* Make sure that it compiles with MFC's debuggable new usage. */
|
|
|
|
UnicodeString *str = new(__FILE__, __LINE__) UnicodeString();
|
|
|
|
str->append((UChar)0x0040); // Is it usable?
|
|
|
|
if(str->charAt(0) != 0x0040) {
|
|
|
|
errln("debug new doesn't work.");
|
|
|
|
}
|
2005-07-14 23:24:38 +00:00
|
|
|
UnicodeString::operator delete(str, __FILE__, __LINE__);
|
2005-07-07 22:27:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
void UObjectTest::TestCompilerRTTI() {
|
2011-04-25 20:47:32 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2010-05-19 17:29:33 +00:00
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
NumberFormat *nf = NumberFormat::createInstance("de", errorCode);
|
|
|
|
if (U_FAILURE(errorCode)) {
|
2010-07-14 16:09:03 +00:00
|
|
|
dataerrln("NumberFormat::createInstance(de) failed - %s", u_errorName(errorCode));
|
2010-05-19 17:29:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dynamic_cast<DecimalFormat *>(nf) == NULL || dynamic_cast<ChoiceFormat *>(nf) != NULL) {
|
|
|
|
errln("dynamic_cast<>(NumberFormat) failed");
|
|
|
|
}
|
|
|
|
UnicodeSet emptySet;
|
|
|
|
if (&typeid(*nf) == NULL || typeid(*nf) == typeid(UObject) || typeid(*nf) == typeid(Format) ||
|
|
|
|
typeid(*nf) != typeid(DecimalFormat) || typeid(*nf) == typeid(ChoiceFormat) ||
|
|
|
|
typeid(*nf) == typeid(emptySet)
|
|
|
|
) {
|
|
|
|
errln("typeid(NumberFormat) failed");
|
|
|
|
}
|
2010-05-27 20:23:49 +00:00
|
|
|
delete nf;
|
2011-04-25 20:47:32 +00:00
|
|
|
#endif
|
2010-05-19 17:29:33 +00:00
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
/* --------------- */
|
2002-11-27 21:20:20 +00:00
|
|
|
|
|
|
|
void UObjectTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /* par */ )
|
|
|
|
{
|
2002-11-30 02:31:06 +00:00
|
|
|
switch (index) {
|
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
TESTCASE(0, testIDs);
|
|
|
|
TESTCASE(1, testUMemory);
|
|
|
|
TESTCASE(2, TestMFCCompatibility);
|
|
|
|
TESTCASE(3, TestCompilerRTTI);
|
2002-11-27 21:20:20 +00:00
|
|
|
|
2002-11-30 02:31:06 +00:00
|
|
|
default: name = ""; break; //needed to end loop
|
|
|
|
}
|
2002-11-27 21:20:20 +00:00
|
|
|
}
|