ICU-2755 test ucoll_open

X-SVN-Rev: 11943
This commit is contained in:
Doug Felt 2003-05-15 20:22:48 +00:00
parent d85187f3c8
commit a6b61a7bea
3 changed files with 79 additions and 36 deletions

View file

@ -480,16 +480,6 @@ CFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode
Locale validLoc;
lkey.currentLocale(validLoc);
return _delegate->createCollator(validLoc);
/*
Locale requestedLoc;
lkey.canonicalLocale(requestedLoc);
Collator* result = _delegate->createCollator(validLoc);
if (result) {
result->setLocales(requestedLoc, validLoc);
}
return result;
*/
}
return NULL;
}

View file

@ -303,7 +303,7 @@ public:
* locale.
* @see Locale
* @see ResourceLoader
* @stable ICU 2.0
* @stable ICU 2.2
*/
static Collator* createInstance(const Locale& loc, UErrorCode& err);
@ -316,6 +316,9 @@ public:
* locale even when ICU is updated.
* The same locale and version guarantees the same sort keys and
* comparison results.
* <p>
* Note: this API will be removed in a future release. Use
* <tt>createInstance(const Locale&, UErrorCode&) instead.</tt></p>
*
* @param loc The locale ID for which to open a collator.
* @param version The requested collator version.
@ -325,7 +328,7 @@ public:
* or a collator with the requested version is not available.
*
* @see getVersion
* @stable ICU 2.2
* @obsolete ICU 2.6
*/
static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
@ -582,7 +585,9 @@ public:
/**
* Get the set of Locales for which Collations are installed.
*
* <p>Note this does not include locales supported by registered collators.</p>
* <p>Note this does not include locales supported by registered collators.
* If collators might have been registered, use the overload of getAvailableLocales
* that returns a StringEnumeration.</p>
*
* @param count the output parameter of number of elements in the locale list
* @return the list of available locales for which collations are installed
@ -590,6 +595,16 @@ public:
*/
static const Locale* getAvailableLocales(int32_t& count);
/**
* Return a StringEnumeration over the locales available at the time of the call,
* including registered locales. If a severe error occurs (such as out of memory
* condition) this will return null. If there is no locale data, an empty enumeration
* will be returned.
* @return a StringEnumeration over the locales available at the time of the call
* @draft ICU 2.6
*/
static StringEnumeration* getAvailableLocales(void);
/**
* Register a new Collator. The collator will be adopted.
* @param toAdopt the Collator instance to be adopted
@ -621,14 +636,6 @@ public:
*/
static UBool unregister(URegistryKey key, UErrorCode& status);
/**
* Return a StringEnumeration over the locales available at the time of the call,
* including registered locales.
* @return a StringEnumeration over the locales available at the time of the call
* @draft ICU 2.6
*/
static StringEnumeration* getAvailableLocales(void);
/**
* Gets the version information for a Collator.
* @param info the version # information, the result will be filled in
@ -894,9 +901,18 @@ private:
};
/**
* A factory used with registerFactory to register multiple collators and provide
* display names for them. If standard locale display names are sufficient,
* Collator instances may be registered instead.
* A factory, used with registerFactory, the creates multiple collators and provides
* display names for them. A factory supports some number of locales-- these are the
* locales for which it can create collators. The factory can be visible, in which
* case the supported locales will be enumerated by getAvailableLocales, or invisible,
* in which they are not. Invisible locales are still supported, they are just not
* listed by getAvailableLocales.
* <p>
* If standard locale display names are sufficient, Collator instances can
* be registered using registerInstance instead.</p>
* <p>
* Note: if the collators are to be used from C APIs, they must be instances
* of RuleBasedCollator.</p>
*
* @draft ICU 2.6
*/
@ -904,25 +920,28 @@ class U_I18N_API CollatorFactory : public UObject {
public:
/**
* Return true if this factory will be visible. Default is true.
* Return true if this factory is visible. Default is true.
* If not visible, the locales supported by this factory will not
* be listed by getAvailableLocales.
* @return true if the factory is visible.
*/
virtual UBool visible(void) const;
/**
* Return a collator of the appropriate type. If the locale
* is not supported, return null.
* Return a collator for the provided locale. If the locale
* is not supported, return NULL.
* @param loc the locale identifying the collator to be created.
* @return a new collator if the locale is supported, otherwise NULL.
*/
virtual Collator* createCollator(const Locale& loc) = 0;
/**
* Return the name of the collator for the objectLocale, localized for the displayLocale.
* If objectLocale is not visible or not defined by the factory, set the result string
* If objectLocale is not supported, or the factory is not visible, set the result string
* to bogus.
* @param objectLocale the locale identifying the collator
* @param displayLocale the locale for which the display name of the collator should be localized
* @param result an output parameter for the display name, set to bogus if none supported.
* @param result an output parameter for the display name, set to bogus if not supported.
* @return the display name
* @draft ICU 2.6
*/
@ -931,8 +950,12 @@ public:
UnicodeString& result);
/**
* Return the locale names directly supported by this factory. The number of names
* is returned in count;
* Return an array of all the locale names directly supported by this factory.
* The number of names is returned in count. This array is owned by the factory.
* Its contents must never change.
* @param count output parameter for the number of locales supported by the factory
* @param status the in/out error code
* @param return a pointer to an array of count UnicodeStrings.
*/
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
};

View file

@ -14,6 +14,9 @@
#include "unicode/strenum.h"
#include "hash.h"
#include "ucol_imp.h" // internal api needed to test ucollator equality
#include "cstring.h" // internal api used to compare locale strings
void CollationServiceTest::TestRegister()
{
// register a singleton
@ -72,16 +75,18 @@ void CollationServiceTest::TestRegister()
// recreate frcol
frcol = Collator::createInstance(FR, status);
UCollator* frFR = ucol_open("fr_FR", &status);
{ // try create collator for new locale
Locale fu_FU("fu", "FU", "FOO");
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, status);
Collator* ncol = Collator::createInstance(fu_FU_FOO, status);
if (*frcol != *ncol) {
errln("register of fr collator for fu_FU failed");
}
delete ncol; ncol = NULL;
UnicodeString locName = fu_FU.getName();
StringEnumeration* localeEnum = Collator::getAvailableLocales();
@ -103,20 +108,45 @@ void CollationServiceTest::TestRegister()
UnicodeString displayName;
Collator::getDisplayName(fu_FU, displayName);
if (displayName != "fu (FU, FOO)") {
if (displayName != "fu (FU)") {
errln(UnicodeString("found ") + displayName + " for fu_FU");
}
Collator::getDisplayName(fu_FU, fu_FU, displayName);
if (displayName != "fu (FU, FOO)") {
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);
}
ncol = Collator::createInstance(fu_FU, status);
if (*fucol != *ncol) {
errln("collator after unregister does not match original fu_FU");