public void TestRuleVsLocaleCreationMonkey() { //create a RBC from a collator reader by reading in a locale collation file //also create one simply from a rules string (which should be //pulled from the locale collation file) //and then do crazy monkey testing on it to make sure they are the same. int x, y, z; Random r = CreateRandom(); String randString1; CollationKey key1; CollationKey key2; CultureInfo[] locales = Collator.GetAvailableLocales(); RuleBasedCollator localeCollator; RuleBasedCollator ruleCollator; for (z = 0; z < 60; z++) { x = r.Next(locales.Length); CultureInfo locale = locales[x]; try { //this is making the assumption that the only type of collator that will be made is RBC localeCollator = (RuleBasedCollator)Collator.GetInstance(locale); Logln("Rules for " + locale + " are: " + localeCollator.GetRules()); ruleCollator = new RuleBasedCollator(localeCollator.GetRules()); } catch (Exception e) { Warnln("ERROR: in creation of collator of locale " + locale.DisplayName + ": " + e); return; } //do it several times for each collator int n = 3; for (y = 0; y < n; y++) { randString1 = GenerateNewString(r); key1 = localeCollator.GetCollationKey(randString1); key2 = ruleCollator.GetCollationKey(randString1); Report(locale.DisplayName, randString1, key1, key2); } } }
/** * Check the integrity of the results of Collator.getAvailableULocales(). * Return the number of items returned. */ internal int checkAvailable(String msg) { CultureInfo[] locs = Collator.GetAvailableLocales(); if (!assertTrue("getAvailableLocales != null", locs != null)) { return(-1); } CheckArray(msg, locs, null); ULocale[] ulocs = Collator.GetAvailableULocales(); if (!assertTrue("getAvailableULocales != null", ulocs != null)) { return(-1); } CheckArray(msg, ulocs, null); // This is not true because since ULocale objects with script code cannot be // converted to Locale objects //assertTrue("getAvailableLocales().Length == getAvailableULocales().Length", locs.Length == ulocs.Length); return(locs.Length); }