X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..48b980fed3435926e0b3a8d72ecb58be703a1c7a:/icuSources/test/intltest/icusvtst.cpp diff --git a/icuSources/test/intltest/icusvtst.cpp b/icuSources/test/intltest/icusvtst.cpp index 1a25027a..c2e97f29 100644 --- a/icuSources/test/intltest/icusvtst.cpp +++ b/icuSources/test/intltest/icusvtst.cpp @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2004, International Business Machines Corporation and * + * Copyright (C) 2001-2008, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -12,7 +12,7 @@ #if !UCONFIG_NO_SERVICE #include "icusvtst.h" -#include "iculserv.h" +#include "servloc.h" #include @@ -24,15 +24,24 @@ class WrongListener : public EventListener { class ICUNSubclass : public ICUNotifier { public: - UBool acceptsListener(const EventListener& l) const { + UBool acceptsListener(const EventListener& /*l*/) const { return TRUE; // return l instanceof MyListener; } - virtual void notifyListener(EventListener& l) const { + virtual void notifyListener(EventListener& /*l*/) const { } }; +// This factory does nothing +class LKFSubclass0 : public LocaleKeyFactory { +public: + LKFSubclass0() + : LocaleKeyFactory(VISIBLE, "LKFSubclass0") + { + } +}; + class LKFSubclass : public LocaleKeyFactory { Hashtable table; @@ -62,22 +71,22 @@ class Integer : public UObject { virtual ~Integer() { } - virtual UBool operator==(const UObject& other) const - { - return other.getDynamicClassID() == getStaticClassID() && - _val == ((Integer&)other)._val; - } - public: /** * UObject boilerplate. */ + static UClassID getStaticClassID() { + return (UClassID)&fgClassID; + } + virtual UClassID getDynamicClassID() const { return getStaticClassID(); } - static UClassID getStaticClassID() { - return (UClassID)&fgClassID; + virtual UBool operator==(const UObject& other) const + { + return other.getDynamicClassID() == getStaticClassID() && + _val == ((Integer&)other)._val; } public: @@ -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: @@ -497,14 +525,14 @@ class AnonymousStringFactory : public ICUServiceFactory return result; } - virtual UClassID getDynamicClassID() const { - return getStaticClassID(); - } - static UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual UClassID getDynamicClassID() const { + return getStaticClassID(); + } + private: static const char fgClassID; }; @@ -573,14 +601,14 @@ class TestMultipleKeyStringFactory : public ICUServiceFactory { return result; } - virtual UClassID getDynamicClassID() const { - return getStaticClassID(); - } - static UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual UClassID getDynamicClassID() const { + return getStaticClassID(); + } + private: static const char fgClassID; }; @@ -667,8 +695,8 @@ ICUServiceTest::testAPI_Two() // iterate over the display names { UErrorCode status = U_ZERO_ERROR; - UVector names(userv_deleteStringPair, NULL, status); - service.getDisplayNames(names, Locale::getGerman(), status); + UVector names(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); @@ -707,13 +735,13 @@ ICUServiceTest::testAPI_Two() // Rad dude's surfer gal 'replaces' Later's surfer gal { UErrorCode status = U_ZERO_ERROR; - UVector names(userv_deleteStringPair, NULL, status); + UVector names(status); service.getDisplayNames(names, Locale("es"), status); for (int i = 0; i < names.size(); ++i) { const StringPair* pair = (const StringPair*)names[i]; logln(" " + pair->displayName + " --> " + pair->id); } - confirmIdentical("26) display names", names.size(), 7); + confirmIdentical("29) display names", names.size(), 7); } // we should get the display name corresponding to the actual id @@ -878,7 +906,7 @@ ICUServiceTest::testRBF() // this should be fast since the display names were cached. { UErrorCode status = U_ZERO_ERROR; - UVector names(userv_deleteStringPair, NULL, status); + UVector names(status); service.getDisplayNames(names, Locale::getGermany(), status); logln("service display names for de_DE"); for (int i = 0; i < names.size(); ++i) { @@ -904,7 +932,7 @@ ICUServiceTest::testRBF() logln(UnicodeString("\n --- ") + idNames[i] + " ---"); { UErrorCode status = U_ZERO_ERROR; - UVector names(userv_deleteStringPair, NULL, status); + UVector names(status); service.getDisplayNames(names, idNames[i], status); for (int i = 0; i < names.size(); ++i) { const StringPair* pair = (const StringPair*)names[i]; @@ -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); { @@ -1225,14 +1253,14 @@ class WrapFactory : public ICUServiceFactory { /** * UObject boilerplate. */ - virtual UClassID getDynamicClassID() const { - return getStaticClassID(); - } - static UClassID getStaticClassID() { return (UClassID)&fgClassID; } + virtual UClassID getDynamicClassID() const { + return getStaticClassID(); + } + private: static const char fgClassID; static UnicodeString* greetingID; @@ -1303,18 +1331,45 @@ void ICUServiceTest::testCoverage() } // ICUService - 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"); - } - } + { + 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"); + } + } + } + } + + // 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"); + } -#if 0 - // ResourceBundleFactory - ICUResourceBundleFactory rbf = new ICUResourceBundleFactory(); - logln("RB: " + rbf.create(lkey, null)); - // ICUNotifier + // 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 + // ICUNotifier ICUNotifier nf = new ICUNSubclass(); try { nf.addListener(null);