/** * Check the integrity of the results of Collator.getAvailableULocales(). * Return the number of items returned. */ internal int checkAvailable(String msg) { CultureInfo[] locs = Collator.GetCultures(UCultureTypes.AllCultures); if (!assertTrue("getAvailableLocales != null", locs != null)) { return(-1); } CheckArray(msg, locs, null); UCultureInfo[] ulocs = Collator.GetUCultures(UCultureTypes.AllCultures); if (!assertTrue("getAvailableULocales != null", ulocs != null)) { return(-1); } CheckArray(msg, ulocs, null); // This is not true because since UCultureInfo objects with script code cannot be // converted to Locale objects //assertTrue("getAvailableLocales().Length == getAvailableULocales().Length", locs.Length == ulocs.Length); return(locs.Length); }
public void TestRegisterFactory() { UCultureInfo fu_FU = new UCultureInfo("fu_FU"); UCultureInfo fu_FU_FOO = new UCultureInfo("fu_FU_FOO"); IDictionary <object, object> fuFUNames = new Dictionary <object, object> { { fu_FU, "ze leetle bunny Fu-Fu" }, { fu_FU_FOO, "zee leetel bunny Foo-Foo" }, { new UCultureInfo("en_US"), "little bunny Foo Foo" } }; Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR")); /* Collator uscol = */ Collator.GetInstance(new UCultureInfo("en_US")); Collator gecol = Collator.GetInstance(new UCultureInfo("de_DE")); Collator jpcol = Collator.GetInstance(new UCultureInfo("ja_JP")); Collator fucol = Collator.GetInstance(fu_FU); CollatorInfo[] info = { new CollatorInfo(new UCultureInfo("en_US"), frcol, null), new CollatorInfo(new UCultureInfo("fr_FR"), gecol, null), new CollatorInfo(fu_FU, jpcol, fuFUNames), }; TestFactory factory = null; try { factory = new TestFactory(info); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } // coverage { TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference! Object key = Collator.RegisterFactory(wrapper); String name = null; try { name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } Logln("*** default name: " + name); Collator.Unregister(key); UCultureInfo bar_BAR = new UCultureInfo("bar_BAR"); Collator col = Collator.GetInstance(bar_BAR); UCultureInfo valid = col.ValidCulture; String validName = valid.FullName; if (validName.Length != 0 && !validName.Equals("root")) { Errln("Collation from bar_BAR is really \"" + validName + "\" but should be root"); } } int n1 = checkAvailable("before registerFactory"); { Object key = Collator.RegisterFactory(factory); int n2 = checkAvailable("after registerFactory"); Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!frcol.Equals(ncol)) { Errln("frcoll for en_US failed"); } ncol = Collator.GetInstance(fu_FU_FOO); if (!jpcol.Equals(ncol)) { Errln("jpcol for fu_FU_FOO failed, got: " + ncol); } UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); bool found = false; for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { found = true; break; } } if (!found) { Errln("new locale fu_FU not reported as supported locale"); } String name = Collator.GetDisplayName(fu_FU); if (!"little bunny Foo Foo".Equals(name)) { Errln("found " + name + " for fu_FU"); } name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); if (!"zee leetel bunny Foo-Foo".Equals(name)) { Errln("found " + name + " for fu_FU in fu_FU_FOO"); } if (!Collator.Unregister(key)) { Errln("failed to unregister factory"); } int n3 = checkAvailable("after unregister"); assertTrue("register increases count", n2 > n1); assertTrue("unregister restores count", n3 == n1); ncol = Collator.GetInstance(fu_FU); if (!fucol.Equals(ncol)) { Errln("collator after unregister does not match original fu_FU"); } } }
public void TestRegister() { // register a singleton Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR")); Collator uscol = Collator.GetInstance(new UCultureInfo("en_US")); { // try override en_US collator Object key = Collator.RegisterInstance(frcol, new UCultureInfo("en_US")); Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!frcol.Equals(ncol)) { Errln("register of french collator for en_US failed"); } // coverage Collator test = Collator.GetInstance(new UCultureInfo("de_DE")); // CollatorFactory.handleCreate if (!test.ValidCulture.Equals(new UCultureInfo("de"))) { Errln("Collation from Germany is really " + test.ValidCulture); } if (!Collator.Unregister(key)) { Errln("failed to unregister french collator"); } ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!uscol.Equals(ncol)) { Errln("collator after unregister does not match original"); } } UCultureInfo fu_FU = new UCultureInfo("fu_FU_FOO"); { // try create collator for new locale Collator fucol = Collator.GetInstance(fu_FU); Object key = Collator.RegisterInstance(frcol, fu_FU); Collator ncol = Collator.GetInstance(fu_FU); if (!frcol.Equals(ncol)) { Errln("register of fr collator for fu_FU failed"); } UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); bool found = false; for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { found = true; break; } } if (!found) { Errln("new locale fu_FU not reported as supported locale"); } try { String name = Collator.GetDisplayName(fu_FU); if (!"fu (FU, FOO)".Equals(name) && !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */) { Errln("found " + name + " for fu_FU"); } } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } try { String name = Collator.GetDisplayName(fu_FU, fu_FU); if (!"fu (FU, FOO)".Equals(name) && !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */) { Errln("found " + name + " for fu_FU"); } } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } if (!Collator.Unregister(key)) { Errln("failed to unregister french collator"); } ncol = Collator.GetInstance(fu_FU); if (!fucol.Equals(ncol)) { Errln("collator after unregister does not match original fu_FU"); } } { // coverage after return to default UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures); for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { Errln("new locale fu_FU not reported as supported locale"); break; } } Collator ncol = Collator.GetInstance(new UCultureInfo("en_US")); if (!ncol.ValidCulture.Equals(new UCultureInfo("en_US"))) { Errln("Collation from US is really " + ncol.ValidCulture); } } }