ICU-4092 service code coverage

X-SVN-Rev: 17110
This commit is contained in:
Doug Felt 2005-01-11 20:58:27 +00:00
parent c0c34e6f90
commit 65fd02443d
7 changed files with 125 additions and 42 deletions

View File

@ -251,9 +251,10 @@ class U_COMMON_API ICUServiceFactory : public UObject {
/**
* <p>Return, in result, the display name of the id in the provided locale.
* This is an id, not a descriptor. If the id is
* not visible or not defined by the factory, sets result to bogus. If the
* not visible, sets result to bogus. If the
* incoming result is bogus, it remains bogus. Result is returned as a
* convenience.</p>
* convenience. Results are not defined if id is not one supported by this
* factory.</p>
*
* @param id a visible id supported by this factory.
* @param locale the locale for which to generate the corresponding localized display name.

View File

@ -111,11 +111,11 @@ LocaleKeyFactory::handleCreate(const Locale& /* loc */,
return NULL;
}
UBool
LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
const Hashtable* ids = getSupportedIDs(status);
return ids && ids->get(id);
}
//UBool
//LocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& status) const {
// const Hashtable* ids = getSupportedIDs(status);
// return ids && ids->get(id);
//}
const Hashtable*
LocaleKeyFactory::getSupportedIDs(UErrorCode& /* status */) const {

View File

@ -263,7 +263,7 @@ protected:
* Return true if this id is one the factory supports (visible or
* otherwise).
*/
virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
// virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
/**
* Return the set of ids that this factory supports (visible or
@ -333,7 +333,7 @@ class U_COMMON_API SimpleLocaleKeyFactory : public LocaleKeyFactory {
/**
* Return true if this id is equal to the locale name.
*/
virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
//virtual UBool isSupportedID(const UnicodeString& id, UErrorCode& status) const;
public:

View File

@ -55,6 +55,8 @@ ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, co
if (U_SUCCESS(status)) {
// _bundleName is a package name
// and should only contain invariant characters
// ??? is it always true that the max length of the bundle name is 19?
// who made this change? -- dlf
char pkg[20];
int32_t length;
length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV);

View File

@ -75,11 +75,11 @@ SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* servi
return NULL;
}
UBool
SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
{
return id == _id;
}
//UBool
//SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
//{
// return id == _id;
//}
void
SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const

View File

@ -197,14 +197,14 @@ public:
virtual ~BasicCalendarFactory() {}
protected:
virtual UBool isSupportedID( const UnicodeString& id, UErrorCode& status) const {
if(U_FAILURE(status)) {
return FALSE;
}
char keyword[ULOC_FULLNAME_CAPACITY];
getCalendarKeyword(id, keyword, (int32_t)sizeof(keyword));
return isStandardSupportedKeyword(keyword, status);
}
//virtual UBool isSupportedID( const UnicodeString& id, UErrorCode& status) const {
// if(U_FAILURE(status)) {
// return FALSE;
// }
// char keyword[ULOC_FULLNAME_CAPACITY];
// getCalendarKeyword(id, keyword, (int32_t)sizeof(keyword));
// return isStandardSupportedKeyword(keyword, status);
//}
virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const
{

View File

@ -33,6 +33,15 @@ class ICUNSubclass : public ICUNotifier {
}
};
// This factory does nothing
class LKFSubclass0 : public LocaleKeyFactory {
public:
LKFSubclass0()
: LocaleKeyFactory(VISIBLE, "LKFSubclass0")
{
}
};
class LKFSubclass : public LocaleKeyFactory {
Hashtable table;
@ -460,6 +469,25 @@ ICUServiceTest::testAPI_One()
/*
******************************************************************
*/
class TestStringSimpleKeyService : public ICUService {
public:
virtual ICUServiceFactory* createSimpleFactory(UObject* obj, const UnicodeString& id, UBool visible, UErrorCode& status)
{
// We could put this type check into ICUService itself, but we'd still
// have to implement cloneInstance. Otherwise we could just tell the service
// what the object type is when we create it, and the default implementation
// could handle everything for us. Phooey.
if (obj && obj->getDynamicClassID() == UnicodeString::getStaticClassID()) {
return ICUService::createSimpleFactory(obj, id, visible, status);
}
return NULL;
}
virtual UObject* cloneInstance(UObject* instance) const {
return instance ? new UnicodeString(*(UnicodeString*)instance) : NULL;
}
};
class TestStringService : public ICUService {
public:
@ -668,7 +696,7 @@ ICUServiceTest::testAPI_Two()
{
UErrorCode status = U_ZERO_ERROR;
UVector names(userv_deleteStringPair, NULL, status);
service.getDisplayNames(names, Locale::getGerman(), status);
service.getDisplayNames(names, status);
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
logln(" " + pair->displayName + " --> " + pair->id);
@ -1014,7 +1042,7 @@ void ICUServiceTest::testLocale() {
service.registerInstance(root, "", status);
service.registerInstance(german, "de", status);
service.registerInstance(germany, Locale::getGermany(), status);
service.registerInstance(japanese, "ja", status);
service.registerInstance(japanese, (UnicodeString)"ja", TRUE, status);
service.registerInstance(japan, Locale::getJapan(), status);
{
@ -1303,18 +1331,45 @@ void ICUServiceTest::testCoverage()
}
// ICUService
TestStringService service;
service.registerFactory(sf, status);
{
TestStringService service;
service.registerFactory(sf, status);
{
UnicodeString* result = (UnicodeString*)service.get("object", status);
if (result) {
logln("object is: " + *result);
delete result;
} else {
errln("could not get object");
}
}
{
UnicodeString* result = (UnicodeString*)service.get("object", status);
if (result) {
logln("object is: " + *result);
delete result;
} else {
errln("could not get object");
}
}
}
}
// ICUServiceKey
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* howdy = new UnicodeString("Howdy");
TestStringSimpleKeyService service;
service.registerInstance(howdy, "Greetings", status);
{
UnicodeString* result = (UnicodeString*)service.get("Greetings", status);
if (result) {
logln("object is: " + *result);
delete result;
} else {
errln("could not get object");
}
}
UVector ids(uhash_deleteUnicodeString, uhash_compareUnicodeString, status);
// yuck, this is awkward to use. All because we pass null in an overload.
// TODO: change this.
UnicodeString str("Greet");
service.getVisibleIDs(ids, &str, status);
confirmIdentical("no fallback of greet", ids.size(), 0);
}
// ICULocaleService
@ -1374,15 +1429,40 @@ void ICUServiceTest::testCoverage()
}
delete obj;
delete key;
key = LocaleKey::createWithCanonicalFallback(&primary, &fallback, 123, status);
if (U_SUCCESS(status)) {
UnicodeString str;
key->currentDescriptor(str);
key->parsePrefix(str);
if (str != "123") {
errln("did not get expected prefix");
}
delete key;
}
// coverage, getSupportedIDs is either overridden or the calling method is
LKFSubclass0 lkFactory;
Hashtable table0;
lkFactory.updateVisibleIDs(table0, status);
if (table0.count() != 0) {
errln("LKF returned non-empty hashtable");
}
// ResourceBundleFactory
key = LocaleKey::createWithCanonicalFallback(&primary, &fallback, status);
ICUResourceBundleFactory rbf;
UObject* icurb = rbf.create(*key, NULL, status);
if (icurb != NULL) {
logln("got resource bundle for key");
delete icurb;
}
delete key;
}
#if 0
// ResourceBundleFactory
ICUResourceBundleFactory rbf = new ICUResourceBundleFactory();
logln("RB: " + rbf.create(lkey, null));
// ICUNotifier
#if 0
// ICUNotifier
ICUNotifier nf = new ICUNSubclass();
try {
nf.addListener(null);