2003-05-01 18:27:24 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2004-04-16 21:07:10 +00:00
|
|
|
* Copyright (C) 2003-2004, International Business Machines Corporation and *
|
2003-05-01 18:27:24 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2003-05-01 18:27:24 +00:00
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
|
|
|
#include "svccoll.h"
|
|
|
|
#include "unicode/coll.h"
|
|
|
|
#include "unicode/strenum.h"
|
|
|
|
#include "hash.h"
|
2004-04-24 03:00:12 +00:00
|
|
|
#include "uassert.h"
|
2003-05-01 18:27:24 +00:00
|
|
|
|
2003-05-15 20:22:48 +00:00
|
|
|
#include "ucol_imp.h" // internal api needed to test ucollator equality
|
|
|
|
#include "cstring.h" // internal api used to compare locale strings
|
|
|
|
|
2004-04-24 03:00:12 +00:00
|
|
|
void CollationServiceTest::runIndexedTest(int32_t index, UBool exec, const char* &name, char* /*par */)
|
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite CollationServiceTest: ");
|
|
|
|
switch (index) {
|
|
|
|
TESTCASE(0, TestRegister);
|
|
|
|
TESTCASE(1, TestRegisterFactory);
|
|
|
|
TESTCASE(2, TestSeparateTree);
|
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-01 18:27:24 +00:00
|
|
|
void CollationServiceTest::TestRegister()
|
|
|
|
{
|
2004-07-18 02:02:06 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
// register a singleton
|
2003-06-09 16:35:12 +00:00
|
|
|
const Locale& FR = Locale::getFrance();
|
2004-04-14 20:28:35 +00:00
|
|
|
const Locale& FRENCH = Locale::getFrench();
|
2003-06-09 16:35:12 +00:00
|
|
|
const Locale& US = Locale::getUS();
|
|
|
|
const Locale US_FOO("en", "US", "FOO");
|
2003-05-01 18:27:24 +00:00
|
|
|
|
2003-06-09 16:35:12 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
Collator* frcol = Collator::createInstance(FR, status);
|
|
|
|
Collator* uscol = Collator::createInstance(US, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Failed to create collators with %s", u_errorName(status));
|
|
|
|
delete frcol;
|
|
|
|
delete uscol;
|
|
|
|
return;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-06-09 16:35:12 +00:00
|
|
|
|
|
|
|
{ // try override en_US collator
|
|
|
|
URegistryKey key = Collator::registerInstance(frcol, US, status);
|
|
|
|
|
|
|
|
Collator* ncol = Collator::createInstance(US_FOO, status);
|
|
|
|
if (*frcol != *ncol) {
|
|
|
|
errln("register of french collator for en_US failed on request for en_US_FOO");
|
|
|
|
}
|
|
|
|
// ensure original collator's params not touched
|
|
|
|
Locale loc = frcol->getLocale(ULOC_REQUESTED_LOCALE, status);
|
2004-04-16 21:07:10 +00:00
|
|
|
if (loc != FR) {
|
2004-04-14 20:28:35 +00:00
|
|
|
errln(UnicodeString("fr collator's requested locale changed to ") + loc.getName());
|
2003-06-09 16:35:12 +00:00
|
|
|
}
|
|
|
|
loc = frcol->getLocale(ULOC_VALID_LOCALE, status);
|
2004-04-14 20:28:35 +00:00
|
|
|
if (loc != FRENCH) {
|
|
|
|
errln(UnicodeString("fr collator's valid locale changed to ") + loc.getName());
|
2003-06-09 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status);
|
|
|
|
if (loc != US_FOO) {
|
|
|
|
errln(UnicodeString("requested locale for en_US_FOO is not en_US_FOO but ") + loc.getName());
|
|
|
|
}
|
|
|
|
loc = ncol->getLocale(ULOC_VALID_LOCALE, status);
|
|
|
|
if (loc != US) {
|
|
|
|
errln(UnicodeString("valid locale for en_US_FOO is not en_US but ") + loc.getName());
|
|
|
|
}
|
|
|
|
loc = ncol->getLocale(ULOC_ACTUAL_LOCALE, status);
|
|
|
|
if (loc != US) {
|
|
|
|
errln(UnicodeString("actual locale for en_US_FOO is not en_US but ") + loc.getName());
|
|
|
|
}
|
|
|
|
delete ncol; ncol = NULL;
|
|
|
|
|
|
|
|
if (!Collator::unregister(key, status)) {
|
|
|
|
errln("failed to unregister french collator");
|
|
|
|
}
|
|
|
|
// !!! frcol pointer is now invalid !!!
|
|
|
|
|
|
|
|
ncol = Collator::createInstance(US, status);
|
|
|
|
if (*uscol != *ncol) {
|
|
|
|
errln("collator after unregister does not match original");
|
|
|
|
}
|
|
|
|
delete ncol; ncol = NULL;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-06-09 16:35:12 +00:00
|
|
|
|
|
|
|
// recreate frcol
|
|
|
|
frcol = Collator::createInstance(FR, status);
|
|
|
|
|
|
|
|
UCollator* frFR = ucol_open("fr_FR", &status);
|
|
|
|
|
|
|
|
{ // try create collator for new locale
|
|
|
|
Locale fu_FU_FOO("fu", "FU", "FOO");
|
|
|
|
Locale fu_FU("fu", "FU", "");
|
|
|
|
|
|
|
|
Collator* fucol = Collator::createInstance(fu_FU, status);
|
|
|
|
URegistryKey key = Collator::registerInstance(frcol, fu_FU, status);
|
|
|
|
Collator* ncol = Collator::createInstance(fu_FU_FOO, status);
|
|
|
|
if (*frcol != *ncol) {
|
|
|
|
errln("register of fr collator for fu_FU failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString locName = fu_FU.getName();
|
|
|
|
StringEnumeration* localeEnum = Collator::getAvailableLocales();
|
|
|
|
UBool found = FALSE;
|
2003-11-05 02:06:36 +00:00
|
|
|
const UnicodeString* locStr, *ls2;
|
2003-06-09 16:35:12 +00:00
|
|
|
for (locStr = localeEnum->snext(status);
|
|
|
|
!found && locStr != NULL;
|
|
|
|
locStr = localeEnum->snext(status)) {
|
|
|
|
//
|
|
|
|
if (locName == *locStr) {
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2003-11-05 02:06:36 +00:00
|
|
|
|
|
|
|
StringEnumeration *le2 = NULL;
|
|
|
|
localeEnum->reset(status);
|
|
|
|
int32_t i, count;
|
|
|
|
count = localeEnum->count(status);
|
|
|
|
for(i = 0; i < count; ++i) {
|
|
|
|
if(i == count / 2) {
|
|
|
|
le2 = localeEnum->clone();
|
|
|
|
if(le2 == NULL || count != le2->count(status)) {
|
|
|
|
errln("ServiceEnumeration.clone() failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i >= count / 2) {
|
|
|
|
locStr = localeEnum->snext(status);
|
|
|
|
ls2 = le2->snext(status);
|
|
|
|
if(*locStr != *ls2) {
|
|
|
|
errln("ServiceEnumeration.clone() failed for item %d", i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localeEnum->snext(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-09 16:35:12 +00:00
|
|
|
delete localeEnum;
|
2003-11-05 02:06:36 +00:00
|
|
|
delete le2;
|
2003-06-09 16:35:12 +00:00
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
errln("new locale fu_FU not reported as supported locale");
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString displayName;
|
|
|
|
Collator::getDisplayName(fu_FU, displayName);
|
|
|
|
if (displayName != "fu (FU)") {
|
|
|
|
errln(UnicodeString("found ") + displayName + " for fu_FU");
|
|
|
|
}
|
|
|
|
|
|
|
|
Collator::getDisplayName(fu_FU, fu_FU, displayName);
|
|
|
|
if (displayName != "fu (FU)") {
|
|
|
|
errln(UnicodeString("found ") + displayName + " for fu_FU");
|
|
|
|
}
|
|
|
|
|
|
|
|
// test ucol_open
|
|
|
|
UCollator* fufu = ucol_open("fu_FU_FOO", &status);
|
|
|
|
if (!fufu) {
|
|
|
|
errln("could not open fu_FU_FOO with ucol_open");
|
|
|
|
} else {
|
|
|
|
if (!ucol_equals(fufu, frFR)) {
|
|
|
|
errln("collator fufu != collator frFR");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Collator::unregister(key, status)) {
|
|
|
|
errln("failed to unregister french collator");
|
|
|
|
}
|
|
|
|
// !!! note frcoll invalid again, but we're no longer using it
|
|
|
|
|
|
|
|
// other collators should still work ok
|
|
|
|
Locale nloc = ncol->getLocale(ULOC_VALID_LOCALE, status);
|
|
|
|
if (nloc != fu_FU) {
|
|
|
|
errln(UnicodeString("asked for nloc valid locale after close and got") + nloc.getName());
|
|
|
|
}
|
|
|
|
delete ncol; ncol = NULL;
|
|
|
|
|
|
|
|
if (fufu) {
|
|
|
|
const char* nlocstr = ucol_getLocale(fufu, ULOC_VALID_LOCALE, &status);
|
|
|
|
if (uprv_strcmp(nlocstr, "fu_FU") != 0) {
|
|
|
|
errln(UnicodeString("asked for uloc valid locale after close and got ") + nlocstr);
|
|
|
|
}
|
|
|
|
ucol_close(fufu);
|
|
|
|
}
|
|
|
|
ucol_close(frFR);
|
|
|
|
|
|
|
|
ncol = Collator::createInstance(fu_FU, status);
|
|
|
|
if (*fucol != *ncol) {
|
|
|
|
errln("collator after unregister does not match original fu_FU");
|
|
|
|
}
|
|
|
|
delete uscol; uscol = NULL;
|
|
|
|
delete ncol; ncol = NULL;
|
|
|
|
delete fucol; fucol = NULL;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2004-07-18 02:02:06 +00:00
|
|
|
#endif
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------
|
|
|
|
|
2004-07-18 02:02:06 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2003-05-01 18:27:24 +00:00
|
|
|
struct CollatorInfo {
|
|
|
|
Locale locale;
|
|
|
|
Collator* collator;
|
|
|
|
Hashtable* displayNames; // locale name -> string
|
|
|
|
|
|
|
|
CollatorInfo(const Locale& locale, Collator* collatorToAdopt, Hashtable* displayNamesToAdopt);
|
|
|
|
~CollatorInfo();
|
|
|
|
UnicodeString& getDisplayName(const Locale& displayLocale, UnicodeString& name) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
CollatorInfo::CollatorInfo(const Locale& _locale, Collator* _collator, Hashtable* _displayNames)
|
|
|
|
: locale(_locale)
|
|
|
|
, collator(_collator)
|
|
|
|
, displayNames(_displayNames)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CollatorInfo::~CollatorInfo() {
|
|
|
|
delete collator;
|
|
|
|
delete displayNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
CollatorInfo::getDisplayName(const Locale& displayLocale, UnicodeString& name) const {
|
|
|
|
if (displayNames) {
|
|
|
|
UnicodeString* val = (UnicodeString*)displayNames->get(displayLocale.getName());
|
|
|
|
if (val) {
|
|
|
|
name = *val;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return locale.getDisplayName(displayLocale, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
|
|
|
|
class TestFactory : public CollatorFactory {
|
|
|
|
CollatorInfo** info;
|
|
|
|
int32_t count;
|
|
|
|
UnicodeString* ids;
|
|
|
|
|
|
|
|
const CollatorInfo* getInfo(const Locale& loc) const {
|
|
|
|
for (CollatorInfo** p = info; *p; ++p) {
|
|
|
|
if (loc == (**p).locale) {
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
TestFactory(CollatorInfo** _info)
|
|
|
|
: info(_info)
|
|
|
|
, count(0)
|
|
|
|
, ids(NULL)
|
|
|
|
{
|
|
|
|
CollatorInfo** p;
|
|
|
|
for (p = info; *p; ++p) {}
|
|
|
|
count = p - info;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestFactory() {
|
|
|
|
for (CollatorInfo** p = info; *p; ++p) {
|
|
|
|
delete *p;
|
|
|
|
}
|
2003-05-08 23:34:14 +00:00
|
|
|
delete[] info;
|
2003-05-01 18:27:24 +00:00
|
|
|
delete[] ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Collator* createCollator(const Locale& loc) {
|
|
|
|
const CollatorInfo* ci = getInfo(loc);
|
|
|
|
if (ci) {
|
|
|
|
return ci->collator->clone();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UnicodeString& getDisplayName(const Locale& objectLocale,
|
|
|
|
const Locale& displayLocale,
|
|
|
|
UnicodeString& result)
|
|
|
|
{
|
|
|
|
const CollatorInfo* ci = getInfo(objectLocale);
|
|
|
|
if (ci) {
|
|
|
|
ci->getDisplayName(displayLocale, result);
|
|
|
|
} else {
|
|
|
|
result.setToBogus();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-05-08 22:41:26 +00:00
|
|
|
const UnicodeString* getSupportedIDs(int32_t& _count, UErrorCode& status) {
|
2003-05-01 18:27:24 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
if (!ids) {
|
|
|
|
ids = new UnicodeString[count];
|
|
|
|
if (!ids) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
_count = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
ids[i] = info[i]->locale.getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_count = count;
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual inline UClassID getDynamicClassID() const {
|
|
|
|
return (UClassID)&gClassID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UClassID getStaticClassID() {
|
|
|
|
return (UClassID)&gClassID;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static char gClassID;
|
|
|
|
};
|
|
|
|
|
|
|
|
char TestFactory::gClassID = 0;
|
2004-07-18 02:02:06 +00:00
|
|
|
#endif
|
2003-05-01 18:27:24 +00:00
|
|
|
|
|
|
|
void CollationServiceTest::TestRegisterFactory(void)
|
|
|
|
{
|
2004-07-18 02:02:06 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2004-04-24 03:00:12 +00:00
|
|
|
int32_t n1, n2, n3;
|
2003-05-06 20:37:31 +00:00
|
|
|
Locale fu_FU("fu", "FU", "");
|
|
|
|
Locale fu_FU_FOO("fu", "FU", "FOO");
|
2003-05-01 18:27:24 +00:00
|
|
|
|
2003-05-06 20:37:31 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
Hashtable* fuFUNames = new Hashtable(FALSE, status);
|
|
|
|
if (!fuFUNames) {
|
|
|
|
errln("memory allocation error");
|
|
|
|
return;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
fuFUNames->setValueDeleter(uhash_deleteUnicodeString);
|
|
|
|
|
|
|
|
fuFUNames->put(fu_FU.getName(), new UnicodeString("ze leetle bunny Fu-Fu"), status);
|
|
|
|
fuFUNames->put(fu_FU_FOO.getName(), new UnicodeString("zee leetel bunny Foo-Foo"), status);
|
2004-04-26 18:32:35 +00:00
|
|
|
fuFUNames->put(Locale::getDefault().getName(), new UnicodeString("little bunny Foo Foo"), status);
|
2003-05-06 20:37:31 +00:00
|
|
|
|
|
|
|
Collator* frcol = Collator::createInstance(Locale::getFrance(), status);
|
|
|
|
Collator* gecol = Collator::createInstance(Locale::getGermany(), status);
|
|
|
|
Collator* jpcol = Collator::createInstance(Locale::getJapan(), status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Failed to create collators with %s", u_errorName(status));
|
|
|
|
delete frcol;
|
|
|
|
delete gecol;
|
|
|
|
delete jpcol;
|
|
|
|
delete fuFUNames;
|
|
|
|
return;
|
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
|
|
|
|
CollatorInfo** info = new CollatorInfo*[4];
|
|
|
|
if (!info) {
|
|
|
|
errln("memory allocation error");
|
|
|
|
return;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
|
|
|
|
info[0] = new CollatorInfo(Locale::getUS(), frcol, NULL);
|
|
|
|
info[1] = new CollatorInfo(Locale::getFrance(), gecol, NULL);
|
|
|
|
info[2] = new CollatorInfo(fu_FU, jpcol, fuFUNames);
|
|
|
|
info[3] = NULL;
|
|
|
|
|
|
|
|
TestFactory* factory = new TestFactory(info);
|
|
|
|
if (!factory) {
|
|
|
|
errln("memory allocation error");
|
|
|
|
return;
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
|
|
|
|
Collator* uscol = Collator::createInstance(Locale::getUS(), status);
|
|
|
|
Collator* fucol = Collator::createInstance(fu_FU, status);
|
|
|
|
|
|
|
|
{
|
2004-04-24 03:00:12 +00:00
|
|
|
n1 = checkAvailable("before registerFactory");
|
|
|
|
|
2003-05-06 20:37:31 +00:00
|
|
|
URegistryKey key = Collator::registerFactory(factory, status);
|
2004-04-24 03:00:12 +00:00
|
|
|
|
|
|
|
n2 = checkAvailable("after registerFactory");
|
|
|
|
assertTrue("count after > count before", n2 > n1);
|
|
|
|
|
2003-05-06 20:37:31 +00:00
|
|
|
Collator* ncol = Collator::createInstance(Locale::getUS(), status);
|
|
|
|
if (*frcol != *ncol) {
|
|
|
|
errln("frcoll for en_US failed");
|
|
|
|
}
|
|
|
|
delete ncol; ncol = NULL;
|
|
|
|
|
|
|
|
ncol = Collator::createInstance(fu_FU_FOO, status);
|
|
|
|
if (*jpcol != *ncol) {
|
|
|
|
errln("jpcol for fu_FU_FOO failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
Locale loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status);
|
|
|
|
if (loc != fu_FU_FOO) {
|
|
|
|
errln(UnicodeString("requested locale for fu_FU_FOO is not fu_FU_FOO but ") + loc.getName());
|
|
|
|
}
|
|
|
|
loc = ncol->getLocale(ULOC_VALID_LOCALE, status);
|
|
|
|
if (loc != fu_FU) {
|
|
|
|
errln(UnicodeString("valid locale for fu_FU_FOO is not fu_FU but ") + loc.getName());
|
|
|
|
}
|
|
|
|
delete ncol; ncol = NULL;
|
|
|
|
|
|
|
|
UnicodeString locName = fu_FU.getName();
|
|
|
|
StringEnumeration* localeEnum = Collator::getAvailableLocales();
|
|
|
|
UBool found = FALSE;
|
|
|
|
const UnicodeString* locStr;
|
|
|
|
for (locStr = localeEnum->snext(status);
|
|
|
|
!found && locStr != NULL;
|
|
|
|
locStr = localeEnum->snext(status))
|
|
|
|
{
|
|
|
|
if (locName == *locStr) {
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete localeEnum;
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
errln("new locale fu_FU not reported as supported locale");
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString name;
|
|
|
|
Collator::getDisplayName(fu_FU, name);
|
|
|
|
if (name != "little bunny Foo Foo") {
|
|
|
|
errln(UnicodeString("found ") + name + " for fu_FU");
|
|
|
|
}
|
|
|
|
|
|
|
|
Collator::getDisplayName(fu_FU, fu_FU_FOO, name);
|
|
|
|
if (name != "zee leetel bunny Foo-Foo") {
|
|
|
|
errln(UnicodeString("found ") + name + " for fu_FU in fu_FU_FOO");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Collator::unregister(key, status)) {
|
|
|
|
errln("failed to unregister factory");
|
|
|
|
}
|
|
|
|
// ja, fr, ge collators no longer valid
|
|
|
|
|
|
|
|
ncol = Collator::createInstance(fu_FU, status);
|
|
|
|
if (*fucol != *ncol) {
|
|
|
|
errln("collator after unregister does not match original fu_FU");
|
|
|
|
}
|
2004-04-24 03:00:12 +00:00
|
|
|
delete ncol;
|
|
|
|
|
|
|
|
n3 = checkAvailable("after unregister");
|
|
|
|
assertTrue("count after unregister == count before register", n3 == n1);
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
|
|
|
|
delete fucol;
|
|
|
|
delete uscol;
|
2004-07-18 02:02:06 +00:00
|
|
|
#endif
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
|
|
|
|
2004-04-24 03:00:12 +00:00
|
|
|
/**
|
|
|
|
* Iterate through the given iterator, checking to see that all the strings
|
|
|
|
* in the expected array are present.
|
|
|
|
* @param expected array of strings we expect to see, or NULL
|
|
|
|
* @param expectedCount number of elements of expected, or 0
|
|
|
|
*/
|
|
|
|
int32_t CollationServiceTest::checkStringEnumeration(const char* msg,
|
|
|
|
StringEnumeration& iter,
|
|
|
|
const char** expected,
|
|
|
|
int32_t expectedCount) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
U_ASSERT(expectedCount >= 0 && expectedCount < 31); // [sic] 31 not 32
|
|
|
|
int32_t i = 0, n = iter.count(ec);
|
|
|
|
assertSuccess("count", ec);
|
|
|
|
UnicodeString buf;
|
|
|
|
int32_t seenMask = 0;
|
|
|
|
for (;; ++i) {
|
|
|
|
const UnicodeString* s = iter.snext(ec);
|
|
|
|
if (!assertSuccess("snext", ec) || s == NULL) break;
|
|
|
|
if (i != 0) buf.append(", ");
|
|
|
|
buf.append(*s);
|
|
|
|
// check expected list
|
|
|
|
for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) {
|
|
|
|
if ((seenMask&bit)==0) {
|
|
|
|
UnicodeString exp(expected[j], (char*)NULL);
|
|
|
|
if (*s == exp) {
|
|
|
|
seenMask |= bit;
|
|
|
|
logln((UnicodeString)"Ok: \"" + exp + "\" seen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-06 20:37:31 +00:00
|
|
|
}
|
2004-04-24 03:00:12 +00:00
|
|
|
// can't get pesky operator+(const US&, foo) to cooperate; use toString
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2004-04-24 03:00:12 +00:00
|
|
|
logln(UnicodeString() + msg + " = [" + buf + "] (" + toString(i) + ")");
|
2004-06-10 23:51:33 +00:00
|
|
|
#else
|
|
|
|
logln(UnicodeString() + msg + " = [" + buf + "] (??? NO_FORMATTING)");
|
|
|
|
#endif
|
2004-04-24 03:00:12 +00:00
|
|
|
assertTrue("count verified", i==n);
|
|
|
|
// did we see all expected strings?
|
|
|
|
if (((1<<expectedCount)-1) != seenMask) {
|
|
|
|
for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) {
|
|
|
|
if ((seenMask&bit)==0) {
|
|
|
|
errln((UnicodeString)"FAIL: \"" + expected[j] + "\" not seen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the integrity of the results of Collator::getAvailableLocales().
|
|
|
|
* Return the number of items returned.
|
|
|
|
*/
|
2004-07-18 02:02:06 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
2004-04-24 03:00:12 +00:00
|
|
|
int32_t CollationServiceTest::checkAvailable(const char* msg) {
|
|
|
|
StringEnumeration *iter = Collator::getAvailableLocales();
|
|
|
|
if (!assertTrue("getAvailableLocales != NULL", iter!=NULL)) return -1;
|
|
|
|
int32_t n = checkStringEnumeration(msg, *iter, NULL, 0);
|
|
|
|
delete iter;
|
|
|
|
return n;
|
|
|
|
}
|
2004-07-18 02:02:06 +00:00
|
|
|
#endif
|
2004-04-24 03:00:12 +00:00
|
|
|
|
|
|
|
static const char* KW[] = {
|
|
|
|
"collation"
|
|
|
|
};
|
|
|
|
static const int32_t KW_COUNT = sizeof(KW)/sizeof(KW[0]);
|
|
|
|
|
|
|
|
static const char* KWVAL[] = {
|
|
|
|
"phonebook",
|
|
|
|
"stroke"
|
|
|
|
};
|
|
|
|
static const int32_t KWVAL_COUNT = sizeof(KWVAL)/sizeof(KWVAL[0]);
|
|
|
|
|
|
|
|
void CollationServiceTest::TestSeparateTree() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
StringEnumeration *iter = Collator::getKeywords(ec);
|
|
|
|
if (!assertTrue("getKeywords != NULL", iter!=NULL)) return;
|
|
|
|
if (!assertSuccess("getKeywords", ec)) return;
|
|
|
|
checkStringEnumeration("getKeywords", *iter, KW, KW_COUNT);
|
|
|
|
delete iter;
|
|
|
|
|
|
|
|
iter = Collator::getKeywordValues(KW[0], ec);
|
|
|
|
if (!assertTrue("getKeywordValues != NULL", iter!=NULL)) return;
|
|
|
|
if (!assertSuccess("getKeywordValues", ec)) return;
|
|
|
|
checkStringEnumeration("getKeywordValues", *iter, KWVAL, KWVAL_COUNT);
|
|
|
|
delete iter;
|
2004-04-26 19:12:14 +00:00
|
|
|
|
|
|
|
UBool isAvailable;
|
2004-05-03 18:15:13 +00:00
|
|
|
Locale equiv = Collator::getFunctionalEquivalent("collation",
|
|
|
|
Locale::createFromName("fr"),
|
2004-04-26 19:12:14 +00:00
|
|
|
isAvailable, ec);
|
|
|
|
assertSuccess("getFunctionalEquivalent", ec);
|
|
|
|
assertEquals("getFunctionalEquivalent(fr)", "fr", equiv.getName());
|
|
|
|
assertTrue("getFunctionalEquivalent(fr).isAvailable==TRUE",
|
|
|
|
isAvailable == TRUE);
|
|
|
|
|
2004-05-03 18:15:13 +00:00
|
|
|
equiv = Collator::getFunctionalEquivalent("collation",
|
|
|
|
Locale::createFromName("fr_FR"),
|
2004-04-26 19:12:14 +00:00
|
|
|
isAvailable, ec);
|
|
|
|
assertSuccess("getFunctionalEquivalent", ec);
|
|
|
|
assertEquals("getFunctionalEquivalent(fr_FR)", "fr", equiv.getName());
|
|
|
|
assertTrue("getFunctionalEquivalent(fr_FR).isAvailable==FALSE",
|
|
|
|
isAvailable == FALSE);
|
2003-05-01 18:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|