public void TestLocale() { ICULocaleService service = new ICULocaleService("test locale"); service.RegisterObject("root", ULocale.ROOT); service.RegisterObject("german", "de"); service.RegisterObject("german_Germany", ULocale.GERMANY); service.RegisterObject("japanese", "ja"); service.RegisterObject("japanese_Japan", ULocale.JAPAN); object target = service.Get("de_US"); confirmEqual("test de_US", "german", target); ULocale de = new ULocale("de"); ULocale de_US = new ULocale("de_US"); target = service.Get(de_US); confirmEqual("test de_US 2", "german", target); target = service.Get(de_US, LocaleKey.KIND_ANY); confirmEqual("test de_US 3", "german", target); target = service.Get(de_US, 1234); confirmEqual("test de_US 4", "german", target); ULocale[] actualReturn = new ULocale[1]; target = service.Get(de_US, actualReturn); confirmEqual("test de_US 5", "german", target); confirmEqual("test de_US 6", actualReturn[0], de); actualReturn[0] = null; target = service.Get(de_US, LocaleKey.KIND_ANY, actualReturn); confirmEqual("test de_US 7", actualReturn[0], de); actualReturn[0] = null; target = service.Get(de_US, 1234, actualReturn); confirmEqual("test de_US 8", "german", target); confirmEqual("test de_US 9", actualReturn[0], de); service.RegisterObject("one/de_US", de_US, 1); service.RegisterObject("two/de_US", de_US, 2); target = service.Get(de_US, 1); confirmEqual("test de_US kind 1", "one/de_US", target); target = service.Get(de_US, 2); confirmEqual("test de_US kind 2", "two/de_US", target); target = service.Get(de_US); confirmEqual("test de_US kind 3", "german", target); LocaleKey lkey = LocaleKey.CreateWithCanonicalFallback("en", null, 1234); Logln("lkey prefix: " + lkey.Prefix); Logln("lkey descriptor: " + lkey.CurrentDescriptor()); Logln("lkey current locale: " + lkey.CurrentLocale()); lkey.Fallback(); Logln("lkey descriptor 2: " + lkey.CurrentDescriptor()); lkey.Fallback(); Logln("lkey descriptor 3: " + lkey.CurrentDescriptor()); target = service.Get("za_PPP"); confirmEqual("test zappp", "root", target); ULocale loc = ULocale.GetDefault(); ULocale.SetDefault(ULocale.JAPANESE); target = service.Get("za_PPP"); confirmEqual("test with ja locale", "japanese", target); var ids = service.GetVisibleIDs(); for (var iter = ids.GetEnumerator(); iter.MoveNext();) { Logln("id: " + iter.Current); } ULocale.SetDefault(loc); ids = service.GetVisibleIDs(); for (var iter = ids.GetEnumerator(); iter.MoveNext();) { Logln("id: " + iter.Current); } target = service.Get("za_PPP"); confirmEqual("test with en locale", "root", target); ULocale[] locales = service.GetAvailableULocales(); confirmIdentical("test available locales", locales.Length, 6); Logln("locales: "); for (int i = 0; i < locales.Length; ++i) { Log("\n [" + i + "] " + locales[i]); } Logln(" "); service.RegisterFactory(new ICUResourceBundleFactory()); target = service.Get(ULocale.JAPAN); { int n = 0; var factories = service.Factories(); var iter = factories.GetEnumerator(); while (iter.MoveNext()) { Logln("[" + n++ + "] " + iter.Current); } } // list only the english display names for es, in reverse order // since we're using locale keys, we should get all and only the es locales // hmmm, the default toString function doesn't print in sorted order for TreeMap { var map = service.GetDisplayNames(ULocale.US, new AnonymousComparer <object>(compare: (lhs, rhs) => { return(-StringComparer.OrdinalIgnoreCase.Compare((string)lhs, (string)rhs)); }), // new Comparator() { // @Override // public int compare(object lhs, object rhs) // { // return -string.CASE_INSENSITIVE_ORDER.compare((string)lhs, (string)rhs); // } //}, "es"); Logln("es display names in reverse order " + map); } }
public override Key CreateKey(string id) { return(LocaleKey.CreateWithCanonicalFallback(id, null)); // no fallback locale }
public void TestCoverage() { // Key Key key = new Key("foobar"); Logln("ID: " + key.ID); Logln("canonicalID: " + key.CanonicalID); Logln("currentID: " + key.CurrentID); Logln("has fallback: " + key.Fallback()); // SimpleFactory object obj = new object(); SimpleFactory sf = new SimpleFactory(obj, "object"); try { sf = new SimpleFactory(null, null); Errln("didn't throw exception"); } catch (ArgumentException e) { Logln("OK: " + e.ToString()); } catch (Exception e) { Errln("threw wrong exception" + e); } Logln(sf.GetDisplayName("object", null)); // ICUService ICUService service = new ICUService(); service.RegisterFactory(sf); try { service.Get(null, null); Errln("didn't throw exception"); } catch (ArgumentNullException e) { Logln("OK: " + e.ToString()); } /* * catch (Exception e) { * Errln("threw wrong exception" + e); * } */ try { service.RegisterFactory(null); Errln("didn't throw exception"); } catch (ArgumentNullException e) { Logln("OK: " + e.ToString()); } catch (Exception e) { Errln("threw wrong exception" + e); } try { service.UnregisterFactory(null); Errln("didn't throw exception"); } catch (ArgumentNullException e) { Logln("OK: " + e.ToString()); } catch (Exception e) { Errln("threw wrong exception" + e); } Logln("object is: " + service.Get("object")); Logln("stats: " + service.Stats()); // ICURWLock ICURWLock rwlock = new ICURWLock(); rwlock.ResetStats(); rwlock.AcquireRead(); rwlock.ReleaseRead(); rwlock.AcquireWrite(); rwlock.ReleaseWrite(); Logln("stats: " + rwlock.GetStats()); Logln("stats: " + rwlock.ClearStats()); rwlock.AcquireRead(); rwlock.ReleaseRead(); rwlock.AcquireWrite(); rwlock.ReleaseWrite(); Logln("stats: " + rwlock.GetStats()); try { rwlock.ReleaseRead(); Errln("no error thrown"); } catch (Exception e) { Logln("OK: " + e.ToString()); } try { rwlock.ReleaseWrite(); Errln("no error thrown"); } catch (Exception e) { Logln("OK: " + e.ToString()); } // ICULocaleService // LocaleKey // LocaleKey lkey = LocaleKey.create("en_US", "ja_JP"); // lkey = LocaleKey.create(null, null); LocaleKey lkey = LocaleKey.CreateWithCanonicalFallback("en_US", "ja_JP"); Logln("lkey: " + lkey); lkey = LocaleKey.CreateWithCanonicalFallback(null, null); Logln("lkey from null,null: " + lkey); // LocaleKeyFactory LocaleKeyFactory lkf = new LKFSubclass(false); Logln("lkf: " + lkf); Logln("obj: " + lkf.Create(lkey, null)); Logln(lkf.GetDisplayName("foo", null)); Logln(lkf.GetDisplayName("bar", null)); lkf.UpdateVisibleIDs(new Dictionary <string, IFactory>()); LocaleKeyFactory invisibleLKF = new LKFSubclass(false); Logln("obj: " + invisibleLKF.Create(lkey, null)); Logln(invisibleLKF.GetDisplayName("foo", null)); Logln(invisibleLKF.GetDisplayName("bar", null)); invisibleLKF.UpdateVisibleIDs(new Dictionary <string, IFactory>()); // ResourceBundleFactory ICUResourceBundleFactory rbf = new ICUResourceBundleFactory(); Logln("RB: " + rbf.Create(lkey, null)); // ICUNotifier ICUNotifier nf = new ICUNSubclass(); try { nf.AddListener(null); Errln("added null listener"); } catch (ArgumentNullException e) { Logln(e.ToString()); } catch (Exception e) { Errln("got wrong exception"); } try { nf.AddListener(new WrongListener()); Errln("added wrong listener"); } catch (InvalidOperationException e) { Logln(e.ToString()); } catch (Exception e) { Errln("got wrong exception"); } try { nf.RemoveListener(null); Errln("removed null listener"); } catch (ArgumentNullException e) { Logln(e.ToString()); } catch (Exception e) { Errln("got wrong exception"); } nf.RemoveListener(new MyListener()); nf.NotifyChanged(); nf.AddListener(new MyListener()); nf.RemoveListener(new MyListener()); }