Пример #1
0
 public override Object Create(IBM.ICU.Impl.ICUService.Key key, ICUService service)
 {
     if (HandlesKey(key))
     {
         IBM.ICU.Impl.ICULocaleService.LocaleKey lkey = (IBM.ICU.Impl.ICULocaleService.LocaleKey)key;
         ULocale loc    = lkey.CanonicalLocale();
         Object  result = delegat0.CreateCalendar(loc);
         if (result == null)
         {
             result = service.GetKey(key, null, this);
         }
         return(result);
     }
     return(null);
 }
Пример #2
0
        public void TestCoverage()
        {
            // Key
            IBM.ICU.Impl.ICUService.Key key = new IBM.ICU.Impl.ICUService.Key("foobar");
            Logln("ID: " + key.Id());
            Logln("canonicalID: " + key.CanonicalID());
            Logln("currentID: " + key.CurrentID());
            Logln("has fallback: " + key.Fallback());

            // SimpleFactory
            Object obj = new Object();

            IBM.ICU.Impl.ICUService.SimpleFactory sf = new IBM.ICU.Impl.ICUService.SimpleFactory(obj, "object");
            try
            {
                sf = new IBM.ICU.Impl.ICUService.SimpleFactory(null, null);
                Errln("didn't throw exception");
            }
            catch (ArgumentException e)
            {
                Logln("OK: " + e.Message);
            }
            catch (Exception e_0)
            {
                Errln("threw wrong exception" + e_0);
            }
            Logln(sf.GetDisplayName("object", null));

            // ICUService
            ICUService service = new ICUService();

            service.RegisterFactory(sf);

            try
            {
                service.Get(null, null);
                Errln("didn't throw exception");
            }
            catch (NullReferenceException e_1)
            {
                Logln("OK: " + e_1.Message);
            }

            /*
             * catch (Exception e) { errln("threw wrong exception" + e); }
             */
            try
            {
                service.RegisterFactory(null);
                Errln("didn't throw exception");
            }
            catch (NullReferenceException e_2)
            {
                Logln("OK: " + e_2.Message);
            }
            catch (Exception e_3)
            {
                Errln("threw wrong exception" + e_3);
            }

            try
            {
                service.UnregisterFactory(null);
                Errln("didn't throw exception");
            }
            catch (NullReferenceException e_4)
            {
                Logln("OK: " + e_4.Message);
            }
            catch (Exception e_5)
            {
                Errln("threw wrong exception" + e_5);
            }

            Logln("object is: " + service.Get("object"));

            Logln("stats: " + service.Stats());

            // ICURWLock

            ICURWLock rwlock = new ICURWLock();

            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 (InvalidOperationException e_6)
            {
                Logln("OK: " + e_6.Message);
            }

            try
            {
                rwlock.ReleaseWrite();
                Errln("no error thrown");
            }
            catch (InvalidOperationException e_7)
            {
                Logln("OK: " + e_7.Message);
            }

            // ICULocaleService

            // LocaleKey

            // LocaleKey lkey = LocaleKey.create("en_US", "ja_JP");
            // lkey = LocaleKey.create(null, null);
            IBM.ICU.Impl.ICULocaleService.LocaleKey lkey = IBM.ICU.Impl.ICULocaleService.LocaleKey
                                                           .CreateWithCanonicalFallback("en_US", "ja_JP");
            Logln("lkey: " + lkey);

            lkey = IBM.ICU.Impl.ICULocaleService.LocaleKey.CreateWithCanonicalFallback(null, null);
            Logln("lkey from null,null: " + lkey);

            // LocaleKeyFactory
            IBM.ICU.Impl.ICULocaleService.LocaleKeyFactory lkf = new ICUServiceTest.LKFSubclass(false);
            Logln("lkf: " + lkf);
            Logln("obj: " + lkf.Create(lkey, null));
            Logln(lkf.GetDisplayName("foo", null));
            Logln(lkf.GetDisplayName("bar", null));
            lkf.UpdateVisibleIDs(new Hashtable());

            IBM.ICU.Impl.ICULocaleService.LocaleKeyFactory invisibleLKF = new ICUServiceTest.LKFSubclass(false);
            Logln("obj: " + invisibleLKF.Create(lkey, null));
            Logln(invisibleLKF.GetDisplayName("foo", null));
            Logln(invisibleLKF.GetDisplayName("bar", null));
            invisibleLKF.UpdateVisibleIDs(new Hashtable());

            // ResourceBundleFactory
            IBM.ICU.Impl.ICULocaleService.ICUResourceBundleFactory rbf = new IBM.ICU.Impl.ICULocaleService.ICUResourceBundleFactory();
            Logln("RB: " + rbf.Create(lkey, null));

            // ICUNotifier
            ICUNotifier nf = new ICUServiceTest.ICUNSubclass();

            try
            {
                nf.AddListener(null);
                Errln("added null listener");
            }
            catch (NullReferenceException e_8)
            {
                Logln(e_8.Message);
            }
            catch (Exception e_9)
            {
                Errln("got wrong exception");
            }

            try
            {
                nf.AddListener(new ICUServiceTest.WrongListener());
                Errln("added wrong listener");
            }
            catch (InvalidOperationException e_10)
            {
                Logln(e_10.Message);
            }
            catch (Exception e_11)
            {
                Errln("got wrong exception");
            }

            try
            {
                nf.RemoveListener(null);
                Errln("removed null listener");
            }
            catch (NullReferenceException e_12)
            {
                Logln(e_12.Message);
            }
            catch (Exception e_13)
            {
                Errln("got wrong exception");
            }

            nf.RemoveListener(new ICUServiceTest.MyListener());
            nf.NotifyChanged();
            nf.AddListener(new ICUServiceTest.MyListener());
            nf.RemoveListener(new ICUServiceTest.MyListener());
        }
Пример #3
0
        public void TestLocale()
        {
            ICULocaleService service = new ICULocaleService("test locale");

            service.RegisterObject("root", IBM.ICU.Util.ULocale.ROOT);
            service.RegisterObject("german", "de");
            service.RegisterObject("german_Germany", IBM.ICU.Util.ULocale.GERMANY);
            service.RegisterObject("japanese", "ja");
            service.RegisterObject("japanese_Japan", IBM.ICU.Util.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, IBM.ICU.Impl.ICULocaleService.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, IBM.ICU.Impl.ICULocaleService.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);

            IBM.ICU.Impl.ICULocaleService.LocaleKey lkey = IBM.ICU.Impl.ICULocaleService.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 = IBM.ICU.Util.ULocale.GetDefault();

            IBM.ICU.Util.ULocale.SetDefault(IBM.ICU.Util.ULocale.JAPANESE);
            target = service.Get("za_PPP");
            ConfirmEqual("test with ja locale", "japanese", target);

            ILOG.J2CsMapping.Collections.ISet ids_0 = service.GetVisibleIDs();
            for (IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(ids_0.GetEnumerator()); iter.HasNext();)
            {
                Logln("id: " + iter.Next());
            }

            IBM.ICU.Util.ULocale.SetDefault(loc);
            ids_0 = service.GetVisibleIDs();
            for (IIterator iter_1 = new ILOG.J2CsMapping.Collections.IteratorAdapter(ids_0.GetEnumerator()); iter_1.HasNext();)
            {
                Logln("id: " + iter_1.Next());
            }

            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 IBM.ICU.Impl.ICULocaleService.ICUResourceBundleFactory());
            target = service.Get(IBM.ICU.Util.ULocale.JAPAN);

            {
                int       n_2       = 0;
                IList     factories = service.Factories();
                IIterator iter_3    = new ILOG.J2CsMapping.Collections.IteratorAdapter(factories.GetEnumerator());
                while (iter_3.HasNext())
                {
                    Logln("[" + n_2++ + "] " + iter_3.Next());
                }
            }

            // 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
            {
                SortedList map = service.GetDisplayNames(IBM.ICU.Util.ULocale.US,
                                                         new ICUServiceTest.Anonymous_C0(), "es");

                Logln("es display names in reverse order " + map);
            }
        }