errln("FAIL: getDisplayName must throw IllegalArgumentException for type 100");
}
}
public void TestDateFormat() {
GlobalizationPreferences gp = new GlobalizationPreferences();
String pattern;
DateFormat df;
// Set unsupported locale - ach
logln("Set locale - ach");
gp.setLocale(new ULocale("ach"));
// Date - short
df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
// root pattern must be used
if (!pattern.equals("yyyy-MM-dd")) {
errln("FAIL: SHORT date pattern is " + pattern + " Expected: yyyy-MM-dd");
}
// Set locale - fr, fr_CA, fr_FR
ArrayList lcls = new ArrayList(3);
lcls.add(new ULocale("fr"));
lcls.add(new ULocale("fr_CA"));
lcls.add(new ULocale("fr_FR"));
logln("Set locales - fr, fr_CA, fr_FR");
gp.setLocales(lcls);
// Date - short
df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
// fr_CA pattern must be used
if (!pattern.equals("yy-MM-dd")) {
errln("FAIL: SHORT date pattern is " + pattern + " Expected: yy-MM-dd");
}
// Set locale - en_GB
logln("Set locale - en_GB");
gp.setLocale(new ULocale("en_GB"));
// Date - full
df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("EEEE, d MMMM y")) {
errln("FAIL: FULL date pattern is " + pattern + " Expected: EEEE, d MMMM y");
}
// Date - long
df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("d MMMM y")) {
errln("FAIL: LONG date pattern is " + pattern + " Expected: d MMMM y");
}
// Date - medium
df = gp.getDateFormat(GlobalizationPreferences.DF_MEDIUM, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("d MMM y")) {
errln("FAIL: MEDIUM date pattern is " + pattern + " Expected: d MMM y");
}
// Date - short
df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_NONE);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("dd/MM/yyyy")) {
errln("FAIL: SHORT date pattern is " + pattern + " Expected: dd/MM/yyyy");
}
// Time - full
df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_FULL);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("HH:mm:ss zzzz")) {
errln("FAIL: FULL time pattern is " + pattern + " Expected: HH:mm:ss zzzz");
}
// Time - long
df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_LONG);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("HH:mm:ss z")) {
errln("FAIL: LONG time pattern is " + pattern + " Expected: HH:mm:ss z");
}
// Time - medium
df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_MEDIUM);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("HH:mm:ss")) {
errln("FAIL: MEDIUM time pattern is " + pattern + " Expected: HH:mm:ss");
}
// Time - short
df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_SHORT);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("HH:mm")) {
errln("FAIL: SHORT time pattern is " + pattern + " Expected: HH:mm");
}
// Date/Time - full
df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_FULL);
pattern = ((SimpleDateFormat)df).toPattern();
if (!pattern.equals("EEEE, d MMMM y HH:mm:ss zzzz")) {
errln("FAIL: FULL date/time pattern is " + pattern + " Expected: EEEE, d MMMM y HH:mm:ss zzzz");
}
// Invalid style
boolean illegalArg = false;
try {
df = gp.getDateFormat(-1, GlobalizationPreferences.DF_NONE);
} catch (IllegalArgumentException iae) {
logln("Illegal date style -1");
illegalArg = true;
}
if (!illegalArg) {
errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle -1");
}
illegalArg = false;
try {
df = gp.getDateFormat(GlobalizationPreferences.DF_NONE, GlobalizationPreferences.DF_NONE);
} catch (IllegalArgumentException iae) {
logln("Illegal style - dateStyle:DF_NONE / timeStyle:DF_NONE");
illegalArg = true;
}
if (!illegalArg) {
errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle:DF_NONE/timeStyle:DF_NONE");
}
// Set explicit time zone
logln("Set timezone - America/Sao_Paulo");
TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo");
gp.setTimeZone(tz);
df = gp.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_MEDIUM);
String tzid = df.getTimeZone().getID();
if (!tzid.equals("America/Sao_Paulo")) {
errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
}
// Set explicit calendar
logln("Set calendar - japanese");
Calendar jcal = new JapaneseCalendar();
jcal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
gp.setCalendar(jcal);
df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_SHORT);
Calendar dfCal = df.getCalendar();
if (!(dfCal instanceof JapaneseCalendar)) {
errln("FAIL: The DateFormat instance must use Japanese calendar");
}
// TimeZone must be still America/Sao_Paulo
tzid = df.getTimeZone().getID();
if (!tzid.equals("America/Sao_Paulo")) {
errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
}
// Set explicit DateFormat
logln("Set explicit date format - full date");
DateFormat customFD = DateFormat.getDateInstance(new IslamicCalendar(), DateFormat.FULL, new ULocale("ar_SA"));
customFD.setTimeZone(TimeZone.getTimeZone("Asia/Riyadh"));
gp.setDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE, customFD);
df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
dfCal = df.getCalendar();
if (!(dfCal instanceof IslamicCalendar)) {
errln("FAIL: The DateFormat instance must use Islamic calendar");
}
// TimeZone in the custom DateFormat is overridden by GP's timezone setting
tzid = df.getTimeZone().getID();
if (!tzid.equals("America/Sao_Paulo")) {
errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
}
// Freeze
logln("Freeze this object");
gp.freeze();
DateFormat customLD = DateFormat.getDateInstance(new BuddhistCalendar(), DateFormat.LONG, new ULocale("th"));
customLD.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok"));
boolean isFrozen = false;
try {
gp.setDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE, customLD);
} catch (UnsupportedOperationException uoe) {
logln("setDateFormat is blocked");
isFrozen = true;
}
if (!isFrozen) {
errln("FAIL: setDateFormat must be blocked after frozen");
}
// Modifiable clone
logln("cloneAsThawed");
GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
gp1.setDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE, customLD);
df = gp1.getDateFormat(GlobalizationPreferences.DF_SHORT, GlobalizationPreferences.DF_SHORT);
dfCal = df.getCalendar();
if (!(dfCal instanceof JapaneseCalendar)) {
errln("FAIL: The DateFormat instance must use Japanese calendar");
}
// TimeZone must be still America/Sao_Paulo
tzid = df.getTimeZone().getID();
if (!tzid.equals("America/Sao_Paulo")) {
errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
}
df = gp1.getDateFormat(GlobalizationPreferences.DF_LONG, GlobalizationPreferences.DF_NONE);
dfCal = df.getCalendar();
if (!(dfCal instanceof BuddhistCalendar)) {
errln("FAIL: The DateFormat instance must use Buddhist calendar");
}
// TimeZone must be still America/Sao_Paulo