GlobalizationPreferences gp = new GlobalizationPreferences();
// Set locale - tr
logln("Set locale - tr");
gp.setLocale(new ULocale("tr"));
Collator coll = gp.getCollator();
String locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
if (!locStr.equals("tr")) {
errln("FAIL: Collator locale is " + locStr + " Expected: tr");
}
// Unsupported collator locale - zun
logln("Set locale - zun");
gp.setLocale(new ULocale("zun"));
coll = gp.getCollator();
locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
if (!locStr.equals("root")) {
errln("FAIL: Collator locale is " + locStr + " Expected: root");
}
// Set locales - en_JP, fr, en_US, fr_FR
logln("Set locale - en_JP, fr, en_US, fr_FR");
ULocale[] locales = new ULocale[4];
locales[0] = new ULocale("en_JP");
locales[1] = new ULocale("fr");
locales[2] = new ULocale("en_US");
locales[3] = new ULocale("fr_FR");
gp.setLocales(locales);
coll = gp.getCollator();
locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
if (!locStr.equals("fr_FR")) {
errln("FAIL: Collator locale is " + locStr + " Expected: fr_FR");
}
// Set explicit Collator
Collator coll1 = Collator.getInstance(new ULocale("it"));
coll1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
logln("Set collator for it in canonical deconposition mode");
gp.setCollator(coll1);
coll1.setStrength(Collator.IDENTICAL);
coll = gp.getCollator();
locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
if (!locStr.equals("it")) {
errln("FAIL: Collator locale is " + locStr + " Expected: it");
}
if (coll1.equals(coll)) {
errln("FAIL: setCollator must use a safe copy of a Collator");
}
// Freeze
logln("Freeze this object");