public object Create(Key key, ICUService serviceArg) { if (key.CurrentID.Equals(greetingID)) { object previous = serviceArg.GetKey(key, null, this); return("A different greeting: \"" + previous + "\""); } return(null); }
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()); }