8165296: update existing i18n test cases of test/java/util

Reviewed-by: okutsu
This commit is contained in:
Nancy Nigam 2016-11-17 11:40:50 +05:30 committed by Nishit Jain
parent a7d4828bea
commit 5b06ce3c07
23 changed files with 2006 additions and 2037 deletions

View File

@ -89,6 +89,9 @@ public abstract class IntlTest {
case "-nothrow":
nothrow = true;
break;
case "-exitcode":
exitCode = true;
break;
default:
Method m = testMethods.get(arg);
if (m == null) {
@ -138,8 +141,13 @@ public abstract class IntlTest {
}
}
if (nothrow) {
if (exitCode) {
System.exit(errorCount);
}
if (errorCount > 0) {
throw new IllegalArgumentException("encountered " + errorCount + " errors");
}
}
}
/**
@ -243,7 +251,7 @@ public abstract class IntlTest {
*/
void usage() {
System.out.println(getClass().getName() +
": [-verbose] [-nothrow] [-prompt] [test names]");
": [-verbose] [-nothrow] [-exitcode] [-prompt] [test names]");
System.out.println(" Available test names:");
for (String methodName : testMethods.keySet()) {
@ -254,7 +262,7 @@ public abstract class IntlTest {
private boolean prompt;
private boolean nothrow;
protected boolean verbose;
private boolean exitCode;
private PrintWriter log;
private int indentLevel;
private boolean needLineFeed;

View File

@ -29,9 +29,11 @@
import java.util.GregorianCalendar;
@SuppressWarnings("serial")
public class Bug4766302 {
static class MyCalendar extends GregorianCalendar {
boolean isTimeStillSet() {
return isTimeSet;
}

View File

@ -29,9 +29,11 @@
import java.util.Locale;
import java.util.TimeZone;
import static java.util.Calendar.*;
public class Bug4958050 {
static int errorCount = 0;
public static void main(String[] args) {
@ -49,14 +51,14 @@ public class Bug4958050 {
cal.set(1919, DECEMBER, 14 - 7, 23, 50, 00);
cal.add(weekFields[i], +1);
if (!cal.checkDate(1919, DECEMBER, 14)) {
error("1919/12/07: add("+cal.getFieldName(weekFields[i])+", +1)\n"
error("1919/12/07: add(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
cal.clear();
cal.set(1930, JUNE, 21 - 7);
cal.add(weekFields[i], +1);
if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) {
error("1930/6/14: add("+cal.getFieldName(weekFields[i])+", +1)\n"
error("1930/6/14: add(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
@ -65,14 +67,14 @@ public class Bug4958050 {
cal.set(1919, DECEMBER, 14 - 7, 23, 50, 00);
cal.roll(weekFields[i], +1);
if (!cal.checkDate(1919, DECEMBER, 14)) {
error("1919/12/07: roll("+cal.getFieldName(weekFields[i])+", +1)\n"
error("1919/12/07: roll(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
cal.clear();
cal.set(1930, JUNE, 21 - 7);
cal.roll(weekFields[i], +1);
if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) {
error("1930/6/14: roll("+cal.getFieldName(weekFields[i])+", +1)\n"
error("1930/6/14: roll(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
}
@ -86,28 +88,28 @@ public class Bug4958050 {
cal.set(1919, DECEMBER, 14 - 1, 23, 50, 00);
cal.add(field, +1);
if (!cal.checkDate(1919, DECEMBER, 14)) {
error("1919/12/13: add("+cal.getFieldName(field)+", +1)\n"
error("1919/12/13: add(" + Koyomi.getFieldName(field) + ", +1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
cal.clear();
cal.set(1919, DECEMBER, 14, 00, 00, 00);
cal.add(field, -1);
if (!cal.checkDate(1919, DECEMBER, 13)) {
error("1919/12/14: add("+cal.getFieldName(field)+", -1)\n"
error("1919/12/14: add(" + Koyomi.getFieldName(field) + ", -1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
cal.clear();
cal.set(1930, JUNE, 21 - 1);
cal.add(field, +1);
if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) {
error("1930/6/20: add("+cal.getFieldName(field)+", +1)\n"
error("1930/6/20: add(" + Koyomi.getFieldName(field) + ", +1)\n"
+ cal.getMessage() + cal.toDateTimeString());
}
cal.clear();
cal.set(1930, JUNE, 21, 01, 00, 00);
cal.add(field, -1);
if (!cal.checkDateTime(1930, JUNE, 20, 01, 00, 00, 000)) {
error("1930/6/21: add("+cal.getFieldName(field)+", -1)\n"
error("1930/6/21: add(" + Koyomi.getFieldName(field) + ", -1)\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
@ -120,7 +122,7 @@ public class Bug4958050 {
}
cal.roll(field, amount);
if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) {
error("1930/6/20: roll("+cal.getFieldName(field)+", +"+amount+")\n"
error("1930/6/20: roll(" + Koyomi.getFieldName(field) + ", +" + amount + ")\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
cal.clear();
@ -131,7 +133,7 @@ public class Bug4958050 {
}
cal.roll(field, amount);
if (!cal.checkDateTime(1930, JUNE, 20, 01, 00, 00, 000)) {
error("1930/6/21: roll("+cal.getFieldName(field)+", "+amount+")\n"
error("1930/6/21: roll(" + Koyomi.getFieldName(field) + ", " + amount + ")\n"
+ cal.getMessage() + " " + cal.toDateTimeString());
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,9 +27,13 @@
* @summary Unit test for calendar types
*/
import java.util.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Set;
public class CalendarTypeTest {
// Calendar types supported in JRE
static Locale[] locales = new Locale[] {
Locale.US,
@ -37,17 +41,14 @@ public class CalendarTypeTest {
new Locale("th", "TH"),
Locale.forLanguageTag("en-US-u-ca-buddhist"),
new Locale("ja", "JP", "JP"),
Locale.forLanguageTag("en-US-u-ca-japanese"),
};
Locale.forLanguageTag("en-US-u-ca-japanese")};
static final String[] TYPES = new String[] {
"gregory",
"buddhist",
"japanese",
};
"japanese"};
static final String[] ALIASES = new String[] {
"gregorian",
"iso8601",
};
"iso8601"};
public static void main(String[] args) {
for (int i = 0; i < locales.length; i++) {
@ -88,10 +89,13 @@ public class CalendarTypeTest {
}
}
@SuppressWarnings("serial")
private static class Gregorian extends GregorianCalendar {
}
@SuppressWarnings("serial")
private static class Koyomi extends Calendar {
@Override
protected void computeTime() {
throw new UnsupportedOperationException("Not supported yet.");

View File

@ -145,7 +145,10 @@ public class FieldStateTest extends IntlTest {
logln("Set day of week to SUNDAY and date to 2003/10/31. "
+ "Then, getTime and set week of year to 43.");
cal.setTime(new Date(2003-1990, OCTOBER, 31));
@SuppressWarnings("deprecation")
Date d = new Date(2003 - 1990, OCTOBER, 31);
cal.setTime(d);
cal.set(DAY_OF_WEEK, SUNDAY);
cal.set(2003, OCTOBER, 31); // 2003/10/31 is Friday.
cal.set(ZONE_OFFSET, 0);
@ -166,8 +169,8 @@ public class FieldStateTest extends IntlTest {
* 4916815: REGRESSION: Problem with java.util.Calendar VM 1.4.2-b28
*/
public void Test4916815() {
logln("Set date to 2003/9/26 (Fri). Roll to Aug and back to Sep. "+
"Set dayofweek to Sunday which should be 2003/9/21.");
logln("Set date to 2003/9/26 (Fri). Roll to Aug and back to Sep. "
+ "Set dayofweek to Sunday which should be 2003/9/21.");
Koyomi cal = new Koyomi();
cal.clear();
// 2003/9/26 (Fri)

View File

@ -76,7 +76,9 @@ public class GregorianCutoverTest extends IntlTest {
checkContinuity(cal, WEEK_OF_YEAR);
// Use large date (year >= 50000)
cal.setGregorianChange(new Date(50000-1900, JANUARY, 20));
@SuppressWarnings("deprecation")
Date d = new Date(50000 - 1900, JANUARY, 20);
cal.setGregorianChange(d);
cal.set(49998, JANUARY, 1);
checkContinuity(cal, DAY_OF_YEAR);
checkContinuity(cal, WEEK_OF_YEAR);
@ -124,7 +126,9 @@ public class GregorianCutoverTest extends IntlTest {
// should handle the gap between 1969/12/22 (Julian) to 1970/1/5 (Gregorian)
logln("Cutover date is 1970/1/5");
cal.setGregorianChange(new Date(1970-1900, JANUARY, 5));
@SuppressWarnings("deprecation")
Date d1 = new Date(1970 - 1900, JANUARY, 5);
cal.setGregorianChange(d1);
cal.set(ERA, AD);
cal.set(YEAR, 1970);
logln(" Set DAY_OF_YEAR to the 28th day of 1970");
@ -203,6 +207,7 @@ public class GregorianCutoverTest extends IntlTest {
public void Test4928615() {
Koyomi cal = new Koyomi();
logln("Today is 2003/10/1 Gregorian.");
@SuppressWarnings("deprecation")
Date x = new Date(2003 - 1900, 10 - 1, 1);
cal.setTime(x);
@ -261,7 +266,9 @@ public class GregorianCutoverTest extends IntlTest {
cal = new Koyomi();
logln("Change the cutover date to 1970/1/5.");
cal.setGregorianChange(new Date(1970-1900, 0, 5));
@SuppressWarnings("deprecation")
Date d = new Date(1970 - 1900, 0, 5);
cal.setGregorianChange(d);
if (!cal.checkLeastMaximum(DAY_OF_YEAR, 356)) {
errln(" " + cal.getMessage());
}
@ -287,15 +294,15 @@ public class GregorianCutoverTest extends IntlTest {
int hour = 13865672;
Koyomi gc1 = new Koyomi();
gc1.clear();
gc1.set(1, gc1.JANUARY, 1, 0, 0, 0);
gc1.set(gc1.HOUR_OF_DAY, hour);
if (!gc1.checkDate(1582, gc1.OCTOBER, 4)) {
gc1.set(1, JANUARY, 1, 0, 0, 0);
gc1.set(HOUR_OF_DAY, hour);
if (!gc1.checkDate(1582, OCTOBER, 4)) {
errln("test case 1: " + gc1.getMessage());
}
gc1.clear();
gc1.set(1, gc1.JANUARY, 1, 0, 0, 0);
gc1.set(gc1.HOUR_OF_DAY, hour + 24);
if (!gc1.checkDate(1582, gc1.OCTOBER, 15)) {
gc1.set(1, JANUARY, 1, 0, 0, 0);
gc1.set(HOUR_OF_DAY, hour + 24);
if (!gc1.checkDate(1582, OCTOBER, 15)) {
errln("test case 2: " + gc1.getMessage());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,16 +28,16 @@
* @key randomness
*/
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
public class JavatimeTest {
@ -46,6 +46,7 @@ public class JavatimeTest {
public static void main(String[] args) throws Throwable {
int N = 10000;
@SuppressWarnings("deprecation")
long t1970 = new java.util.Date(70, 0, 01).getTime();
Random r = new Random();
for (int i = 0; i < N; i++) {
@ -61,15 +62,15 @@ public class JavatimeTest {
///////////// java.util.Date /////////////////////////
Date jud = new java.util.Date(millis);
Instant inst0 = jud.toInstant();
if (jud.getTime() != inst0.toEpochMilli() ||
!jud.equals(Date.from(inst0))) {
if (jud.getTime() != inst0.toEpochMilli()
|| !jud.equals(Date.from(inst0))) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
throw new RuntimeException("FAILED: j.u.d -> instant -> j.u.d");
}
// roundtrip only with millis precision
Date jud0 = Date.from(inst_ms);
if (jud0.getTime() != inst_ms.toEpochMilli() ||
!inst_ms.equals(jud0.toInstant())) {
if (jud0.getTime() != inst_ms.toEpochMilli()
|| !inst_ms.equals(jud0.toInstant())) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
throw new RuntimeException("FAILED: instant -> j.u.d -> instant");
}
@ -82,8 +83,8 @@ public class JavatimeTest {
cal.setMinimalDaysInFirstWeek(4);
cal.setTimeInMillis(millis);
ZonedDateTime zdt0 = cal.toZonedDateTime();
if (cal.getTimeInMillis() != zdt0.toInstant().toEpochMilli() ||
!cal.equals(GregorianCalendar.from(zdt0))) {
if (cal.getTimeInMillis() != zdt0.toInstant().toEpochMilli()
|| !cal.equals(GregorianCalendar.from(zdt0))) {
System.out.println("cal:" + cal);
System.out.println("zdt:" + zdt0);
System.out.println("calNew:" + GregorianCalendar.from(zdt0));
@ -97,8 +98,8 @@ public class JavatimeTest {
}
ZonedDateTime zdt = ZonedDateTime.of(ldt_ms, ZoneId.systemDefault());
GregorianCalendar cal0 = GregorianCalendar.from(zdt);
if (zdt.toInstant().toEpochMilli() != cal0.getTimeInMillis() ||
!zdt.equals(GregorianCalendar.from(zdt).toZonedDateTime())) {
if (zdt.toInstant().toEpochMilli() != cal0.getTimeInMillis()
|| !zdt.equals(GregorianCalendar.from(zdt).toZonedDateTime())) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
throw new RuntimeException("FAILED: zdt -> gcal -> zdt");
}
@ -107,12 +108,12 @@ public class JavatimeTest {
///////////// java.util.TimeZone /////////////////////////
for (String zidStr : TimeZone.getAvailableIDs()) {
// TBD: tzdt intergration
if (zidStr.startsWith("SystemV") ||
zidStr.contains("Riyadh8") ||
zidStr.equals("US/Pacific-New") ||
zidStr.equals("EST") ||
zidStr.equals("HST") ||
zidStr.equals("MST")) {
if (zidStr.startsWith("SystemV")
|| zidStr.contains("Riyadh8")
|| zidStr.equals("US/Pacific-New")
|| zidStr.equals("EST")
|| zidStr.equals("HST")
|| zidStr.equals("MST")) {
continue;
}
ZoneId zid = ZoneId.of(zidStr, ZoneId.SHORT_IDS);
@ -121,9 +122,9 @@ public class JavatimeTest {
}
TimeZone tz = TimeZone.getTimeZone(zidStr);
// no round-trip for alias and "GMT"
if (!tz.equals(TimeZone.getTimeZone(tz.toZoneId())) &&
!ZoneId.SHORT_IDS.containsKey(zidStr) &&
!zidStr.startsWith("GMT")) {
if (!tz.equals(TimeZone.getTimeZone(tz.toZoneId()))
&& !ZoneId.SHORT_IDS.containsKey(zidStr)
&& !zidStr.startsWith("GMT")) {
throw new RuntimeException("FAILED: tz -> zid -> tz :" + zidStr);
}
}

View File

@ -21,8 +21,6 @@
* questions.
*/
import static java.util.Calendar.*;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
@ -30,7 +28,9 @@ import java.util.TimeZone;
/**
* GregorianCalendar subclass for testing.
*/
@SuppressWarnings("serial")
public class Koyomi extends GregorianCalendar {
static final String[] FIELD_NAMES = {
"ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH",
"DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR",
@ -270,8 +270,8 @@ public class Koyomi extends GregorianCalendar {
boolean checkFieldValue(int field, int expectedValue) {
int val;
if ((val = get(field)) != expectedValue) {
appendMessage("get(" + FIELD_NAMES[field] + "): got " + val +
", expected " + expectedValue + "; ");
appendMessage("get(" + FIELD_NAMES[field] + "): got " + val
+ ", expected " + expectedValue + "; ");
return false;
}
return true;
@ -280,8 +280,8 @@ public class Koyomi extends GregorianCalendar {
boolean checkInternalFieldValue(int field, int expectedValue) {
int val;
if ((val = internalGet(field)) != expectedValue) {
appendMessage("internalGet(" + FIELD_NAMES[field] + "): got " + val +
", expected " + expectedValue + "; ");
appendMessage("internalGet(" + FIELD_NAMES[field] + "): got " + val
+ ", expected " + expectedValue + "; ");
return false;
}
return true;

View File

@ -28,7 +28,10 @@
* @library /java/text/testlib
*/
import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import static java.util.Calendar.*;
@ -129,7 +132,6 @@ public class NonLenientTest extends IntlTest {
validate(cal, "6th Sunday in Jan 2003");
}
/**
* 4726030: GregorianCalendar doesn't check invalid dates in non-lenient
*/
@ -148,14 +150,14 @@ public class NonLenientTest extends IntlTest {
Koyomi calendar = getNonLenient();
Date date = (new GregorianCalendar(1996, 0, 3)).getTime();
for (int field = 0; field < Calendar.FIELD_COUNT; field++) {
for (int field = 0; field < FIELD_COUNT; field++) {
calendar.setTime(date);
int max = calendar.getActualMaximum(field);
int value = max + 1;
calendar.set(field, value);
try {
calendar.computeTime(); // call method under test
errln("Test failed with field " + calendar.getFieldName(field)
errln("Test failed with field " + Koyomi.getFieldName(field)
+ "\n\tdate before: " + date
+ "\n\tdate after: " + calendar.getTime()
+ "\n\tvalue: " + value + " (max = " + max + ")");
@ -163,14 +165,14 @@ public class NonLenientTest extends IntlTest {
}
}
for (int field = 0; field < Calendar.FIELD_COUNT; field++) {
for (int field = 0; field < FIELD_COUNT; field++) {
calendar.setTime(date);
int min = calendar.getActualMinimum(field);
int value = min - 1;
calendar.set(field, value);
try {
calendar.computeTime(); // call method under test
errln("Test failed with field " + calendar.getFieldName(field)
errln("Test failed with field " + Koyomi.getFieldName(field)
+ "\n\tdate before: " + date
+ "\n\tdate after: " + calendar.getTime()
+ "\n\tvalue: " + value + " (min = " + min + ")");
@ -194,9 +196,9 @@ public class NonLenientTest extends IntlTest {
// In non-lenient, calendar field values that have beeb set by
// user shouldn't be modified.
int[] afterFields = cal.getFields();
for (int i = 0; i < Calendar.FIELD_COUNT; i++) {
for (int i = 0; i < FIELD_COUNT; i++) {
if (cal.isSet(i) && originalFields[i] != afterFields[i]) {
errln(" complete() modified fields[" + cal.getFieldName(i) + "] got "
errln(" complete() modified fields[" + Koyomi.getFieldName(i) + "] got "
+ afterFields[i] + ", expected " + originalFields[i]);
}
}

View File

@ -28,12 +28,20 @@
* taken into account for time calculations.
*/
import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import static java.util.GregorianCalendar.*;
public class ZoneOffsets {
// This TimeZone always returns the dstOffset value.
@SuppressWarnings("serial")
private static class TestTimeZone extends TimeZone {
private int gmtOffset;
private int dstOffset;
@ -80,8 +88,7 @@ public class ZoneOffsets {
private static Locale[] locales = {
Locale.getDefault(),
new Locale("th", "TH"),
new Locale("ja", "JP", "JP"),
};
new Locale("ja", "JP", "JP")};
private static final int HOUR = 60 * 60 * 1000;
@ -94,8 +101,7 @@ public class ZoneOffsets {
{-8 * HOUR, 2 * HOUR},
{9 * HOUR, 0},
{9 * HOUR, HOUR},
{ 9 * HOUR, 2 * HOUR },
};
{9 * HOUR, 2 * HOUR}};
public static void main(String[] args) {
for (int l = 0; l < locales.length; l++) {

View File

@ -28,9 +28,8 @@
* @library /java/text/testlib
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import static java.util.GregorianCalendar.*;
@ -70,22 +69,21 @@ public class bug4372743 extends IntlTest {
{BC, 1, JANUARY},
{BC, 2, DECEMBER},
{BC, 2, NOVEMBER},
{BC, 2, OCTOBER},
};
{BC, 2, OCTOBER}};
private int tablesize = data.length;
private void check(GregorianCalendar gc, int index) {
if (gc.get(ERA) != data[index][ERA]) {
errln("Invalid era :" + gc.get(ERA) +
", expected :" + data[index][ERA]);
errln("Invalid era :" + gc.get(ERA)
+ ", expected :" + data[index][ERA]);
}
if (gc.get(YEAR) != data[index][YEAR]) {
errln("Invalid year :" + gc.get(YEAR) +
", expected :" + data[index][YEAR]);
errln("Invalid year :" + gc.get(YEAR)
+ ", expected :" + data[index][YEAR]);
}
if (gc.get(MONTH) != data[index][MONTH]) {
errln("Invalid month :" + gc.get(MONTH) +
", expected :" + data[index][MONTH]);
errln("Invalid month :" + gc.get(MONTH)
+ ", expected :" + data[index][MONTH]);
}
}
@ -100,33 +98,32 @@ public class bug4372743 extends IntlTest {
gc = new GregorianCalendar(2, MARCH, 3);
for (int i = 0; i < tablesize; i++) {
check(gc, i);
gc.add(gc.MONTH, -1);
gc.add(MONTH, -1);
}
/* Again, Set March 3, A.D. 2 */
gc = new GregorianCalendar(2, MARCH, 3);
for (int i = 0; i < tablesize; i += 7) {
check(gc, i);
gc.add(gc.MONTH, -7);
gc.add(MONTH, -7);
}
/* Set March 10, 2 B.C. */
gc = new GregorianCalendar(2, OCTOBER, 10);
gc.add(gc.YEAR, -3);
gc.add(YEAR, -3);
for (int i = tablesize - 1; i >= 0; i--) {
check(gc, i);
gc.add(gc.MONTH, 1);
gc.add(MONTH, 1);
}
/* Again, Set March 10, 2 B.C. */
gc = new GregorianCalendar(2, OCTOBER, 10);
gc.add(gc.YEAR, -3);
gc.add(YEAR, -3);
for (int i = tablesize - 1; i >= 0; i -= 8) {
check(gc, i);
gc.add(gc.MONTH, 8);
gc.add(MONTH, 8);
}
}
finally {
} finally {
TimeZone.setDefault(saveZone);
}
}

View File

@ -28,7 +28,10 @@
* @library /java/text/testlib
*/
import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.util.GregorianCalendar.*;
public class bug4401223 extends IntlTest {
@ -37,11 +40,12 @@ public class bug4401223 extends IntlTest {
String s = null;
try {
Date date = new Date(2000-1900, Calendar.FEBRUARY, 29);
@SuppressWarnings("deprecation")
Date date = new Date(2000 - 1900, FEBRUARY, 29);
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
gc.setLenient(false);
gc.set(Calendar.YEAR, 2001);
gc.set(YEAR, 2001);
s = "02/29/00 & set(YEAR,2001) = " + gc.getTime().toString();
} catch (Exception ex) {
status++;
@ -59,16 +63,17 @@ public class bug4401223 extends IntlTest {
String s = null;
try {
Date date = new Date(2000-1900, Calendar.DECEMBER, 31);
@SuppressWarnings("deprecation")
Date date = new Date(2000 - 1900, DECEMBER, 31);
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
gc.setLenient(false);
gc.set(Calendar.YEAR, 2001);
gc.set(YEAR, 2001);
if (gc.get(Calendar.YEAR) != 2001 ||
gc.get(Calendar.MONTH) != Calendar.DECEMBER ||
gc.get(Calendar.DATE) != 31 ||
gc.get(Calendar.DAY_OF_YEAR) != 365) {
if (gc.get(YEAR) != 2001
|| gc.get(MONTH) != DECEMBER
|| gc.get(DATE) != 31
|| gc.get(DAY_OF_YEAR) != 365) {
status++;
s = "Wrong Date : 12/31/00 & set(YEAR,2001) ---> " + gc.getTime().toString();
} else {

View File

@ -27,7 +27,12 @@
* @summary Confirm that GregorianCalendar.roll() works properly during transition from Daylight Saving Time to Standard Time.
*/
import java.util.*;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import static java.util.GregorianCalendar.*;
public class bug4514831 {
@ -45,43 +50,43 @@ public class bug4514831 {
TimeZone.setDefault(TimeZone.getTimeZone("US/Pacific"));
String test_roll = "";
GregorianCalendar c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);
GregorianCalendar c_roll = new GregorianCalendar(2001, OCTOBER, 27);
for (int i = 0; i < 7; i++) {
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
c_roll.roll(c_roll.DAY_OF_YEAR, true);
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
test_roll += c_roll.get(DAY_OF_MONTH) + "-";
c_roll.roll(DAY_OF_YEAR, true);
test_roll += c_roll.get(DAY_OF_MONTH) + " ";
}
if (!test_roll.equals(golden_data1)) {
err = true;
System.err.println("Wrong roll(DAY_OF_YEAR) transition: got "+
test_roll + "expected " + golden_data1);
System.err.println("Wrong roll(DAY_OF_YEAR) transition: got "
+ test_roll + "expected " + golden_data1);
}
test_roll = "";
c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 27);
c_roll.setFirstDayOfWeek(Calendar.THURSDAY);
c_roll = new GregorianCalendar(2001, OCTOBER, 27);
c_roll.setFirstDayOfWeek(THURSDAY);
for (int i = 0; i < 7; i++) {
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
c_roll.roll(c_roll.DAY_OF_WEEK, true);
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
test_roll += c_roll.get(DAY_OF_MONTH) + "-";
c_roll.roll(DAY_OF_WEEK, true);
test_roll += c_roll.get(DAY_OF_MONTH) + " ";
}
if (!test_roll.equals(golden_data2)) {
err = true;
System.err.println("Wrong roll(DAY_OF_WEEK) transition: got "+
test_roll + "expected " + golden_data2);
System.err.println("Wrong roll(DAY_OF_WEEK) transition: got "
+ test_roll + "expected " + golden_data2);
}
test_roll = "";
c_roll = new GregorianCalendar(2001, Calendar.OCTOBER, 1);
c_roll = new GregorianCalendar(2001, OCTOBER, 1);
for (int i = 0; i < 7; i++) {
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + "-";
c_roll.roll(c_roll.DAY_OF_WEEK_IN_MONTH, true);
test_roll += c_roll.get(c_roll.DAY_OF_MONTH) + " ";
test_roll += c_roll.get(DAY_OF_MONTH) + "-";
c_roll.roll(DAY_OF_WEEK_IN_MONTH, true);
test_roll += c_roll.get(DAY_OF_MONTH) + " ";
}
if (!test_roll.equals(golden_data3)) {
err = true;
System.err.println("Wrong roll(DAY_OF_WEEK_IN_MONTH) transition: got "+
test_roll + "expected " + golden_data3);
System.err.println("Wrong roll(DAY_OF_WEEK_IN_MONTH) transition: got "
+ test_roll + "expected " + golden_data3);
}
} finally {
Locale.setDefault(savedLocale);

View File

@ -28,11 +28,15 @@
* same date/time. Both are new implementations in 1.5.
*/
import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import static java.util.GregorianCalendar.*;
@SuppressWarnings("deprecation")
public class Bug4955000 {
// Tests for Date.UTC(), derived from JCK
// Date.miscTests.Date1025 and Date2015
public static void main(String[] args) {
@ -51,7 +55,7 @@ public class Bug4955000 {
};
for (int i = 0; i < years1.length; i++) {
gc.clear();
gc.set(years1[i], gc.JANUARY, 1);
gc.set(years1[i], JANUARY, 1);
long t = gc.getTimeInMillis();
long utc = Date.UTC(years1[i] - 1900, 1 - 1, 1,
0, 0, 0); // Jan 1 00:00:00
@ -61,7 +65,7 @@ public class Bug4955000 {
}
// Date2015
int years[] = {
int[] years = {
gc.getGreatestMinimum(YEAR),
gc.getGreatestMinimum(YEAR) + 1,
-1,
@ -71,35 +75,35 @@ public class Bug4955000 {
gc.getLeastMaximum(YEAR)
};
int months[] = {
int[] months = {
gc.getMinimum(MONTH),
gc.getMinimum(MONTH) + 1,
gc.getMaximum(MONTH) - 1,
gc.getMaximum(MONTH)
};
int dates[] = {
int[] dates = {
gc.getMinimum(DAY_OF_MONTH),
gc.getMinimum(DAY_OF_MONTH) + 1,
gc.getMaximum(DAY_OF_MONTH) - 1,
gc.getMaximum(DAY_OF_MONTH)
};
int hs[] = {
int[] hs = {
gc.getMinimum(HOUR),
gc.getMinimum(HOUR) + 1,
gc.getMaximum(HOUR) - 1,
gc.getMaximum(HOUR)
};
int ms[] = {
int[] ms = {
gc.getMinimum(MINUTE),
gc.getMinimum(MINUTE) + 1,
gc.getMaximum(MINUTE) - 1,
gc.getMaximum(MINUTE)
};
int ss[] = {
int[] ss = {
gc.getMinimum(SECOND),
gc.getMinimum(SECOND) + 1,
gc.getMaximum(SECOND) - 1,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@
/*
* @test
* @summary test ISO639-2 language codes
* @library /java/text/testlib
* @compile -encoding ascii Bug4175998Test.java
* @run main Bug4175998Test
* @bug 4175998
@ -43,14 +44,13 @@
*/
import java.util.*;
import java.io.*;
/**
* Bug4175998Test verifies that the following bug has been fixed:
* Bug 4175998 - The java.util.Locale.getISO3Language() returns wrong result for a locale with
* language code 'ta'(Tamil).
*/
public class Bug4175998Test extends LocaleTestFmwk {
public class Bug4175998Test extends IntlTest {
public static void main(String[] args) throws Exception {
new Bug4175998Test().run(args);
//generateTables(); //uncomment this to regenerate data tables

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,7 @@
/*
@test
@summary test that locale invariants are preserved across serialization
@library /java/text/testlib
@run main Bug4184873Test
@bug 4184873
*/
@ -63,7 +64,7 @@ import java.io.*;
/**
* A Locale can never contain the following language codes: he, yi or id.
*/
public class Bug4184873Test extends LocaleTestFmwk {
public class Bug4184873Test extends IntlTest {
public static void main(String[] args) throws Exception {
if (args.length == 1 && args[0].equals("prepTest")) {
prepTest();

View File

@ -30,12 +30,20 @@
* @run main Bug8001562
*/
import java.text.*;
import java.util.*;
import java.text.BreakIterator;
import java.text.Collator;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class Bug8001562 {
static final String[] jdk7availTags = {
static final List<String> jdk7availTags = List.of(
"ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW",
"ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SD", "ar-SY",
"ar-TN", "ar-YE", "be", "be-BY", "bg", "bg-BG", "ca", "ca-ES", "cs",
@ -55,12 +63,13 @@ public class Bug8001562 {
"sl-SI", "sq", "sq-AL", "sr", "sr-BA", "sr-CS", "sr-Latn", "sr-Latn-BA",
"sr-Latn-ME", "sr-Latn-RS", "sr-ME", "sr-RS", "sv", "sv-SE", "th",
"th-TH", "th-TH-u-nu-thai-x-lvariant-TH", "tr", "tr-TR", "uk", "uk-UA",
"vi", "vi-VN", "zh", "zh-CN", "zh-HK", "zh-SG", "zh-TW", };
static List<Locale> jdk7availLocs = new ArrayList<>();
"vi", "vi-VN", "zh", "zh-CN", "zh-HK", "zh-SG", "zh-TW");
static List<Locale> jdk7availLocs;
static {
for (String locStr : jdk7availTags) {
jdk7availLocs.add(Locale.forLanguageTag(locStr));
}
jdk7availLocs = jdk7availTags.stream()
.map(Locale::forLanguageTag)
.collect(Collectors.toList());
}
public static void main(String[] args) {
@ -86,7 +95,7 @@ public class Bug8001562 {
diffLocale(Locale.class, avail);
}
static void diffLocale(Class c, List<Locale> locs) {
static void diffLocale(Class<?> c, List<Locale> locs) {
String diff = "";
System.out.printf("Only in target locales (%s.getAvailableLocales()): ", c.getSimpleName());

View File

@ -27,14 +27,17 @@
* @modules jdk.localedata
*/
import java.util.*;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class HashCodeTest {
public static void main(String[] args) {
Locale[] locales = Locale.getAvailableLocales();
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
Map map = new HashMap(locales.length);
Map<Integer, Locale> map = new HashMap<>(locales.length);
int conflicts = 0;
for (int i = 0; i < locales.length; i++) {
@ -42,10 +45,10 @@ public class HashCodeTest {
int hc = loc.hashCode();
min = Math.min(hc, min);
max = Math.max(hc, max);
Integer key = new Integer(hc);
Integer key = hc;
if (map.containsKey(key)) {
conflicts++;
System.out.println("conflict: " + (Locale) map.get(key) + ", " + loc);
System.out.println("conflict: " + map.get(key) + ", " + loc);
} else {
map.put(key, loc);
}

View File

@ -46,11 +46,12 @@ import java.util.Set;
* @bug 6875847 6992272 7002320 7015500 7023613 7032820 7033504 7004603
* 7044019 8008577
* @summary test API changes to Locale
* @library /java/text/testlib
* @modules jdk.localedata
* @compile LocaleEnhanceTest.java
* @run main/othervm -Djava.locale.providers=JRE,SPI -esa LocaleEnhanceTest
*/
public class LocaleEnhanceTest extends LocaleTestFmwk {
public class LocaleEnhanceTest extends IntlTest {
public static void main(String[] args) throws Exception {
List<String> argList = new ArrayList<String>();

View File

@ -27,6 +27,7 @@
* 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
* 6786276 7066203 7085757 8008577 8030696
* @summary test Locales
* @library /java/text/testlib
* @modules jdk.localedata
* @run main/othervm -Djava.locale.providers=JRE,SPI LocaleTest
*/
@ -63,16 +64,25 @@
*
*/
import java.text.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.io.StreamCorruptedException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Date;
import java.util.Calendar;
import java.io.*;
public class LocaleTest extends LocaleTestFmwk {
public class LocaleTest extends IntlTest {
public LocaleTest() {
}
@ -186,50 +196,60 @@ public class LocaleTest extends LocaleTestFmwk {
Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
logln("Testing " + testLocale + "...");
if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
if (!testLocale.getLanguage().equals(dataTable[LANG][i])) {
errln(" Language code mismatch: " + testLocale.getLanguage() + " versus "
+ dataTable[LANG][i]);
if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
}
if (!testLocale.getCountry().equals(dataTable[CTRY][i])) {
errln(" Country code mismatch: " + testLocale.getCountry() + " versus "
+ dataTable[CTRY][i]);
if (!testLocale.getVariant().equals(dataTable[VAR][i]))
}
if (!testLocale.getVariant().equals(dataTable[VAR][i])) {
errln(" Variant code mismatch: " + testLocale.getVariant() + " versus "
+ dataTable[VAR][i]);
if (!testLocale.toString().equals(dataTable[NAME][i]))
}
if (!testLocale.toString().equals(dataTable[NAME][i])) {
errln(" Locale name mismatch: " + testLocale.toString() + " versus "
+ dataTable[NAME][i]);
}
}
logln("Same thing without variant codes...");
for (int i = 0; i <= MAX_LOCALES; i++) {
Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i]);
logln("Testing " + testLocale + "...");
if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
if (!testLocale.getLanguage().equals(dataTable[LANG][i])) {
errln(" Language code mismatch: " + testLocale.getLanguage() + " versus "
+ dataTable[LANG][i]);
if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
}
if (!testLocale.getCountry().equals(dataTable[CTRY][i])) {
errln(" Country code mismatch: " + testLocale.getCountry() + " versus "
+ dataTable[CTRY][i]);
if (!testLocale.getVariant().equals(""))
}
if (!testLocale.getVariant().equals("")) {
errln(" Variant code mismatch: " + testLocale.getVariant() + " versus \"\"");
}
}
}
public void TestSimpleResourceInfo() {
for (int i = 0; i <= MAX_LOCALES; i++) {
if (dataTable[LANG][i].equals("xx"))
if (dataTable[LANG][i].equals("xx")) {
continue;
}
Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
logln("Testing " + testLocale + "...");
if (!testLocale.getISO3Language().equals(dataTable[LANG3][i]))
if (!testLocale.getISO3Language().equals(dataTable[LANG3][i])) {
errln(" ISO-3 language code mismatch: " + testLocale.getISO3Language()
+ " versus " + dataTable[LANG3][i]);
if (!testLocale.getISO3Country().equals(dataTable[CTRY3][i]))
}
if (!testLocale.getISO3Country().equals(dataTable[CTRY3][i])) {
errln(" ISO-3 country code mismatch: " + testLocale.getISO3Country()
+ " versus " + dataTable[CTRY3][i]);
}
/*
// getLCID() is currently private
if (!String.valueOf(testLocale.getLCID()).equals(dataTable[LCID][i]))
@ -282,10 +302,13 @@ public class LocaleTest extends LocaleTestFmwk {
}
private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr"))
errln("Default locale should be French, but it's really " + Locale.getDefault().getLanguage());
else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en"))
errln("Default locale should be English, but it's really " + Locale.getDefault().getLanguage());
String language = Locale.getDefault().getLanguage();
if (defaultIsFrench && !language.equals("fr")) {
errln("Default locale should be French, but it's really " + language);
} else if (!defaultIsFrench && !language.equals("en")) {
errln("Default locale should be English, but it's really " + language);
}
for (int i = 0; i <= MAX_LOCALES; i++) {
Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
@ -301,8 +324,7 @@ public class LocaleTest extends LocaleTestFmwk {
testCtry = testLocale.getDisplayCountry();
testVar = testLocale.getDisplayVariant();
testName = testLocale.getDisplayName();
}
else {
} else {
testLang = testLocale.getDisplayLanguage(inLocale);
testCtry = testLocale.getDisplayCountry(inLocale);
testVar = testLocale.getDisplayVariant(inLocale);
@ -315,39 +337,51 @@ public class LocaleTest extends LocaleTestFmwk {
String expectedName;
expectedLang = dataTable[compareIndex][i];
if (expectedLang.equals("") && defaultIsFrench)
if (expectedLang.equals("") && defaultIsFrench) {
expectedLang = dataTable[DLANG_EN][i];
if (expectedLang.equals(""))
}
if (expectedLang.equals("")) {
expectedLang = dataTable[DLANG_ROOT][i];
}
expectedCtry = dataTable[compareIndex + 1][i];
if (expectedCtry.equals("") && defaultIsFrench)
if (expectedCtry.equals("") && defaultIsFrench) {
expectedCtry = dataTable[DCTRY_EN][i];
if (expectedCtry.equals(""))
}
if (expectedCtry.equals("")) {
expectedCtry = dataTable[DCTRY_ROOT][i];
}
expectedVar = dataTable[compareIndex + 2][i];
if (expectedVar.equals("") && defaultIsFrench)
if (expectedVar.equals("") && defaultIsFrench) {
expectedVar = dataTable[DVAR_EN][i];
if (expectedVar.equals(""))
}
if (expectedVar.equals("")) {
expectedVar = dataTable[DVAR_ROOT][i];
}
expectedName = dataTable[compareIndex + 3][i];
if (expectedName.equals("") && defaultIsFrench)
if (expectedName.equals("") && defaultIsFrench) {
expectedName = dataTable[DNAME_EN][i];
if (expectedName.equals(""))
}
if (expectedName.equals("")) {
expectedName = dataTable[DNAME_ROOT][i];
}
if (!testLang.equals(expectedLang))
if (!testLang.equals(expectedLang)) {
errln("Display language mismatch: " + testLang + " versus " + expectedLang);
if (!testCtry.equals(expectedCtry))
}
if (!testCtry.equals(expectedCtry)) {
errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
if (!testVar.equals(expectedVar))
}
if (!testVar.equals(expectedVar)) {
errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
if (!testName.equals(expectedName))
}
if (!testName.equals(expectedName)) {
errln("Display name mismatch: " + testName + " versus " + expectedName);
}
}
}
public void TestSimpleObjectStuff() {
Locale test1 = new Locale("aa", "AA");
@ -355,25 +389,30 @@ public class LocaleTest extends LocaleTestFmwk {
Locale test3 = (Locale) test1.clone();
Locale test4 = new Locale("zz", "ZZ");
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3) {
errln("Some of the test variables point to the same locale!");
}
if (test3 == null)
if (test3 == null) {
errln("clone() failed to produce a valid object!");
}
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3)) {
errln("clone() or equals() failed: objects that should compare equal don't");
}
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4)) {
errln("equals() failed: objects that shouldn't compare equal do");
}
int hash1 = test1.hashCode();
int hash2 = test2.hashCode();
int hash3 = test3.hashCode();
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3) {
errln("hashCode() failed: objects that should have the same hash code don't");
}
}
/**
* @bug 4011756 4011380
@ -385,23 +424,23 @@ public class LocaleTest extends LocaleTestFmwk {
try {
result = test.getISO3Language();
}
catch (MissingResourceException e) {
} catch (MissingResourceException e) {
gotException = true;
}
if (!gotException)
if (!gotException) {
errln("getISO3Language() on xx_YY returned " + result + " instead of throwing an exception");
}
gotException = false;
try {
result = test.getISO3Country();
}
catch (MissingResourceException e) {
} catch (MissingResourceException e) {
gotException = true;
}
if (!gotException)
if (!gotException) {
errln("getISO3Country() on xx_YY returned " + result + " instead of throwing an exception");
}
}
/**
* @bug 4106155 4118587 7066203 7085757
@ -419,52 +458,64 @@ public class LocaleTest extends LocaleTestFmwk {
String[] spotCheck1 = {"en", "es", "fr", "de", "it", "ja", "ko", "zh", "th",
"he", "id", "iu", "ug", "yi", "za"};
if (test.length != 188)
if (test.length != 188) {
errln("Expected getISOLanguages() to return 188 languages; it returned " + test.length);
else {
} else {
for (int i = 0; i < spotCheck1.length; i++) {
int j;
for (j = 0; j < test.length; j++)
if (test[j].equals(spotCheck1[i]))
for (j = 0; j < test.length; j++) {
if (test[j].equals(spotCheck1[i])) {
break;
if (j == test.length || !test[j].equals(spotCheck1[i]))
}
}
if (j == test.length || !test[j].equals(spotCheck1[i])) {
errln("Couldn't find " + spotCheck1[i] + " in language list.");
}
}
}
for (int i = 0; i < test.length; i++) {
if (!test[i].equals(test[i].toLowerCase()))
if (!test[i].equals(test[i].toLowerCase())) {
errln(test[i] + " is not all lower case.");
if (test[i].length() != 2)
}
if (test[i].length() != 2) {
errln(test[i] + " is not two characters long.");
if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
}
if (i > 0 && test[i].compareTo(test[i - 1]) <= 0) {
errln(test[i] + " appears in an out-of-order position in the list.");
}
}
test = Locale.getISOCountries();
String[] spotCheck2 = {"US", "CA", "GB", "FR", "DE", "IT", "JP", "KR", "CN", "TW", "TH"};
if (test.length != 250)
if (test.length != 250) {
errln("Expected getISOCountries to return 250 countries; it returned " + test.length);
else {
} else {
for (int i = 0; i < spotCheck2.length; i++) {
int j;
for (j = 0; j < test.length; j++)
if (test[j].equals(spotCheck2[i]))
for (j = 0; j < test.length; j++) {
if (test[j].equals(spotCheck2[i])) {
break;
if (j == test.length || !test[j].equals(spotCheck2[i]))
}
}
if (j == test.length || !test[j].equals(spotCheck2[i])) {
errln("Couldn't find " + spotCheck2[i] + " in country list.");
}
}
}
for (int i = 0; i < test.length; i++) {
if (!test[i].equals(test[i].toUpperCase()))
if (!test[i].equals(test[i].toUpperCase())) {
errln(test[i] + " is not all upper case.");
if (test[i].length() != 2)
}
if (test[i].length() != 2) {
errln(test[i] + " is not two characters long.");
if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
}
if (i > 0 && test[i].compareTo(test[i - 1]) <= 0) {
errln(test[i] + " appears in an out-of-order position in the list.");
}
}
}
/**
* @bug 4126880
@ -475,29 +526,32 @@ public class LocaleTest extends LocaleTestFmwk {
test = Locale.getISOCountries();
test[0] = "SUCKER!!!";
test = Locale.getISOCountries();
if (test[0].equals("SUCKER!!!"))
if (test[0].equals("SUCKER!!!")) {
errln("Changed internal country code list!");
}
test = Locale.getISOLanguages();
test[0] = "HAHAHAHA!!!";
test = Locale.getISOLanguages();
if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
if (test[0].equals("HAHAHAHA!!!")) { // Fixed typo
errln("Changes internal language code list!");
}
}
/**
* @bug 4107014
*/
public void TestGetAvailableLocales() {
Locale[] locales = Locale.getAvailableLocales();
if (locales == null || locales.length == 0)
if (locales == null || locales.length == 0) {
errln("Locale.getAvailableLocales() returned no installed locales!");
else {
} else {
logln("Locale.getAvailableLocales() returned a list of " + locales.length + " locales.");
for (int i = 0; i < locales.length; i++)
for (int i = 0; i < locales.length; i++) {
logln(locales[i].toString());
}
}
}
/**
* @bug 4135316
@ -505,9 +559,10 @@ public class LocaleTest extends LocaleTestFmwk {
public void TestBug4135316() {
Locale[] locales1 = Locale.getAvailableLocales();
Locale[] locales2 = Locale.getAvailableLocales();
if (locales1 == locales2)
if (locales1 == locales2) {
errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
}
}
/**
* @bug 4107953
@ -548,8 +603,7 @@ test commented out pending API-change approval
* @bug 4110613
*/
public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
IOException, StreamCorruptedException
{
IOException, StreamCorruptedException {
ObjectOutputStream ostream;
ByteArrayOutputStream obstream;
byte[] bytes = null;
@ -567,9 +621,10 @@ test commented out pending API-change approval
Locale test2 = (Locale) (istream.readObject());
if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
if (!test1.equals(test2) || test1.hashCode() != test2.hashCode()) {
errln("Locale failed to deserialize correctly.");
}
}
/**
* @bug 4118587
@ -585,9 +640,10 @@ test commented out pending API-change approval
for (int i = 0; i < languageCodes.length; i++) {
String test = (new Locale(languageCodes[i], "", "")).getDisplayLanguage(Locale.US);
if (!test.equals(languageNames[i]))
errln("Got wrong display name for " + languageCodes[i] + ": Expected \"" +
languageNames[i] + "\", got \"" + test + "\".");
if (!test.equals(languageNames[i])) {
errln("Got wrong display name for " + languageCodes[i] + ": Expected \""
+ languageNames[i] + "\", got \"" + test + "\".");
}
}
}
@ -602,9 +658,10 @@ test commented out pending API-change approval
for (int i = 0; i < iso2Languages.length; i++) {
String test = (new Locale(iso2Languages[i], "", "")).getISO3Language();
if (!test.equals(iso3Languages[i]))
errln("Got wrong ISO3 code for " + iso2Languages[i] + ": Expected \"" +
iso3Languages[i] + "\", got \"" + test + "\".");
if (!test.equals(iso3Languages[i])) {
errln("Got wrong ISO3 code for " + iso2Languages[i] + ": Expected \""
+ iso3Languages[i] + "\", got \"" + test + "\".");
}
}
String[] iso2Countries = {"AF", "BW", "KZ", "MO", "MN", "SB", "TC", "ZW"};
@ -612,9 +669,10 @@ test commented out pending API-change approval
for (int i = 0; i < iso2Countries.length; i++) {
String test = (new Locale("", iso2Countries[i], "")).getISO3Country();
if (!test.equals(iso3Countries[i]))
errln("Got wrong ISO3 code for " + iso2Countries[i] + ": Expected \"" +
iso3Countries[i] + "\", got \"" + test + "\".");
if (!test.equals(iso3Countries[i])) {
errln("Got wrong ISO3 code for " + iso2Countries[i] + ": Expected \""
+ iso3Countries[i] + "\", got \"" + test + "\".");
}
}
}
@ -629,15 +687,18 @@ test commented out pending API-change approval
Locale indonesianOld = new Locale("in", "", "");
Locale indonesianNew = new Locale("id", "", "");
if (!hebrewNew.getLanguage().equals("iw"))
errln("Got back wrong language code for Hebrew: expected \"iw\", got \"" +
hebrewNew.getLanguage() + "\"");
if (!yiddishNew.getLanguage().equals("ji"))
errln("Got back wrong language code for Yiddish: expected \"ji\", got \"" +
yiddishNew.getLanguage() + "\"");
if (!indonesianNew.getLanguage().equals("in"))
errln("Got back wrong language code for Indonesian: expected \"in\", got \"" +
indonesianNew.getLanguage() + "\"");
if (!hebrewNew.getLanguage().equals("iw")) {
errln("Got back wrong language code for Hebrew: expected \"iw\", got \""
+ hebrewNew.getLanguage() + "\"");
}
if (!yiddishNew.getLanguage().equals("ji")) {
errln("Got back wrong language code for Yiddish: expected \"ji\", got \""
+ yiddishNew.getLanguage() + "\"");
}
if (!indonesianNew.getLanguage().equals("in")) {
errln("Got back wrong language code for Indonesian: expected \"in\", got \""
+ indonesianNew.getLanguage() + "\"");
}
}
/**
@ -703,26 +764,29 @@ test commented out pending API-change approval
for (int i = 0; i < localesToTest.length; i++) {
String name = localesToTest[i].getDisplayName(Locale.US);
logln(name);
if (!name.equals(englishDisplayNames[i]))
if (!name.equals(englishDisplayNames[i])) {
errln("Lookup in English failed: expected \"" + englishDisplayNames[i]
+ "\", got \"" + name + "\"");
}
}
for (int i = 0; i < localesToTest.length; i++) {
String name = localesToTest[i].getDisplayName(new Locale("es", "ES"));
logln(name);
if (!name.equals(spanishDisplayNames[i]))
if (!name.equals(spanishDisplayNames[i])) {
errln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i]
+ "\", got \"" + name + "\"");
}
}
for (int i = 0; i < localesToTest.length; i++) {
String name = localesToTest[i].getDisplayName(Locale.FRANCE);
logln(name);
if (!name.equals(frenchDisplayNames[i]))
if (!name.equals(frenchDisplayNames[i])) {
errln("Lookup in French failed: expected \"" + frenchDisplayNames[i]
+ "\", got \"" + name + "\"");
}
}
// restore the default locale for other tests
Locale.setDefault(defaultLocale);
@ -737,16 +801,17 @@ test commented out pending API-change approval
boolean gotException = false;
try {
Locale.setDefault(null);
}
catch (NullPointerException e) {
} catch (NullPointerException e) {
// all other exception types propagate through here back to the test harness
gotException = true;
}
if (Locale.getDefault() == null)
if (Locale.getDefault() == null) {
errln("Locale.getDefault() allowed us to set default to NULL!");
if (!gotException)
}
if (!gotException) {
errln("Trying to set default locale to NULL didn't throw exception!");
}
}
/**
* @bug 4135752
@ -756,12 +821,14 @@ test commented out pending API-change approval
public void TestThaiCurrencyFormat() {
DecimalFormat thaiCurrency = (DecimalFormat) NumberFormat.getCurrencyInstance(
new Locale("th", "TH"));
if (!thaiCurrency.getPositivePrefix().equals("\u0e3f"))
errln("Thai currency prefix wrong: expected \"\u0e3f\", got \"" +
thaiCurrency.getPositivePrefix() + "\"");
if (!thaiCurrency.getPositiveSuffix().equals(""))
errln("Thai currency suffix wrong: expected \"\", got \"" +
thaiCurrency.getPositiveSuffix() + "\"");
if (!thaiCurrency.getPositivePrefix().equals("\u0e3f")) {
errln("Thai currency prefix wrong: expected \"\u0e3f\", got \""
+ thaiCurrency.getPositivePrefix() + "\"");
}
if (!thaiCurrency.getPositiveSuffix().equals("")) {
errln("Thai currency suffix wrong: expected \"\", got \""
+ thaiCurrency.getPositiveSuffix() + "\"");
}
}
/**
@ -788,16 +855,15 @@ test commented out pending API-change approval
NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
String pos = nf.format(271828.182845);
String neg = nf.format(-271828.182845);
if (pos.indexOf(EURO_CURRENCY) >= 0 &&
neg.indexOf(EURO_CURRENCY) >= 0) {
logln("Ok: " + loc.toString() +
": " + pos + " / " + neg);
}
else {
errln("Fail: " + loc.toString() +
" formats without " + EURO_CURRENCY +
": " + pos + " / " + neg +
"\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
if (pos.indexOf(EURO_CURRENCY) >= 0
&& neg.indexOf(EURO_CURRENCY) >= 0) {
logln("Ok: " + loc.toString()
+ ": " + pos + " / " + neg);
} else {
errln("Fail: " + loc.toString()
+ " formats without " + EURO_CURRENCY
+ ": " + pos + " / " + neg
+ "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
}
}
}
@ -861,14 +927,16 @@ test commented out pending API-change approval
*/
public void Test4139940() {
Locale mylocale = new Locale("hu", "", "");
@SuppressWarnings("deprecation")
Date mydate = new Date(98, 3, 13); // A Monday
DateFormat df_full = new SimpleDateFormat("EEEE", mylocale);
String str = df_full.format(mydate);
// Make sure that o circumflex (\u00F4) is NOT there, and
// o double acute (\u0151) IS.
if (str.indexOf('\u0151') < 0 || str.indexOf('\u00F4') >= 0)
if (str.indexOf('\u0151') < 0 || str.indexOf('\u00F4') >= 0) {
errln("Fail: Monday in Hungarian is wrong");
}
}
/**
* @bug 4143951
@ -894,9 +962,10 @@ test commented out pending API-change approval
try {
String result = locale.getISO3Country();
errln("ERROR: getISO3Country() returns: " + result +
" for locale '" + locale + "' rather than exception" );
} catch(MissingResourceException e) { }
errln("ERROR: getISO3Country() returns: " + result
+ " for locale '" + locale + "' rather than exception");
} catch (MissingResourceException e) {
}
}
/**
@ -912,8 +981,8 @@ test commented out pending API-change approval
String result = locale.getISO3Language();
if (!result.equals("aaa")) {
errln("ERROR: getISO3Language() returns: " + result +
" for locale '" + locale + "' rather than returning it as is" );
errln("ERROR: getISO3Language() returns: " + result
+ " for locale '" + locale + "' rather than returning it as is");
}
// Try an invalid two letter language code, and check whether it
@ -923,9 +992,10 @@ test commented out pending API-change approval
try {
result = locale.getISO3Language();
errln("ERROR: getISO3Language() returns: " + result +
" for locale '" + locale + "' rather than exception" );
} catch(MissingResourceException e) { }
errln("ERROR: getISO3Language() returns: " + result
+ " for locale '" + locale + "' rather than exception");
} catch (MissingResourceException e) {
}
}
/*
@ -946,13 +1016,15 @@ test commented out pending API-change approval
for (int i = 0; i < locales.length; i++) {
Locale loc = locales[i];
if (!loc.getDisplayName(Locale.US).equals(englishDisplayNames[i]))
errln("English display-name mismatch: expected " +
englishDisplayNames[i] + ", got " + loc.getDisplayName());
if (!loc.getDisplayName(loc).equals(norwegianDisplayNames[i]))
errln("Norwegian display-name mismatch: expected " +
norwegianDisplayNames[i] + ", got " +
loc.getDisplayName(loc));
if (!loc.getDisplayName(Locale.US).equals(englishDisplayNames[i])) {
errln("English display-name mismatch: expected "
+ englishDisplayNames[i] + ", got " + loc.getDisplayName());
}
if (!loc.getDisplayName(loc).equals(norwegianDisplayNames[i])) {
errln("Norwegian display-name mismatch: expected "
+ norwegianDisplayNames[i] + ", got "
+ loc.getDisplayName(loc));
}
}
}
@ -961,8 +1033,8 @@ test commented out pending API-change approval
*/
public void Test8030696() {
List<Locale> av = Arrays.asList(Locale.getAvailableLocales());
if (!av.contains(new Locale("nb", "NO")) ||
!av.contains(new Locale("nn", "NO"))) {
if (!av.contains(new Locale("nb", "NO"))
|| !av.contains(new Locale("nn", "NO"))) {
errln("\"nb-NO\" and/or \"nn-NO\" locale(s) not returned from getAvailableLocales().");
}
}
@ -971,11 +1043,14 @@ test commented out pending API-change approval
StringBuffer buf = new StringBuffer();
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if (c >= 0x20 && c <= 0x7F) buf.append(c);
else {
if (c >= 0x20 && c <= 0x7F) {
buf.append(c);
} else {
buf.append("\\u");
String h = "000" + Integer.toHexString(c);
if (h.length() > 4) h = h.substring(h.length() - 4);
if (h.length() > 4) {
h = h.substring(h.length() - 4);
}
buf.append(h);
}
}

View File

@ -1,267 +0,0 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*
*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
*
* Portions copyright (c) 2007 Sun Microsystems, Inc.
* All Rights Reserved.
*
* The original version of this source code and documentation
* is copyrighted and owned by Taligent, Inc., a wholly-owned
* subsidiary of IBM. These materials are provided under terms
* of a License Agreement between Taligent and Sun. This technology
* is protected by multiple US and International patents.
*
* This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
import java.lang.reflect.*;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.io.*;
import java.text.*;
/**
* LocaleTestFmwk is a base class for tests that can be run conveniently from
* the command line as well as under the Java test harness.
* <p>
* Sub-classes implement a set of methods named Test<something>. Each
* of these methods performs some test. Test methods should indicate
* errors by calling either err or errln. This will increment the
* errorCount field and may optionally print a message to the log.
* Debugging information may also be added to the log via the log
* and logln methods. These methods will add their arguments to the
* log only if the test is being run in verbose mode.
*/
public class LocaleTestFmwk {
//------------------------------------------------------------------------
// Everything below here is boilerplate code that makes it possible
// to add a new test by simply adding a function to an existing class
//------------------------------------------------------------------------
protected LocaleTestFmwk() {
// Create a hashtable containing all the test methods.
testMethods = new Hashtable();
Method[] methods = getClass().getDeclaredMethods();
for( int i=0; i<methods.length; i++ ) {
if( methods[i].getName().startsWith("Test")
|| methods[i].getName().startsWith("test")) {
testMethods.put( methods[i].getName(), methods[i] );
}
}
}
protected void run(String[] args) throws Exception
{
System.out.println(getClass().getName() + " {");
indentLevel++;
// Set up the log and reference streams. We use PrintWriters in order to
// take advantage of character conversion. The JavaEsc converter will
// convert Unicode outside the ASCII range to Java's \\uxxxx notation.
log = new PrintWriter(System.out,true);
// Parse the test arguments. They can be either the flag
// "-verbose" or names of test methods. Create a list of
// tests to be run.
Vector testsToRun = new Vector( args.length );
for( int i=0; i<args.length; i++ ) {
if( args[i].equals("-verbose") ) {
verbose = true;
}
else if( args[i].equals("-prompt") ) {
prompt = true;
} else if (args[i].equals("-nothrow")) {
nothrow = true;
} else if (args[i].equals("-exitcode")) {
exitcode = true;
} else {
Object m = testMethods.get( args[i] );
if( m != null ) {
testsToRun.addElement( m );
}
else {
usage();
return;
}
}
}
// If no test method names were given explicitly, run them all.
if( testsToRun.size() == 0 ) {
Enumeration methodNames = testMethods.elements();
while( methodNames.hasMoreElements() ) {
testsToRun.addElement( methodNames.nextElement() );
}
}
// Run the list of tests given in the test arguments
for( int i=0; i<testsToRun.size(); i++ ) {
int oldCount = errorCount;
Method testMethod = (Method)testsToRun.elementAt(i);
writeTestName(testMethod.getName());
try {
testMethod.invoke(this, new Object[0]);
}
catch( IllegalAccessException e ) {
errln("Can't acces test method " + testMethod.getName());
}
catch( InvocationTargetException e ) {
errln("Uncaught exception thrown in test method "
+ testMethod.getName());
e.getTargetException().printStackTrace(this.log);
}
writeTestResult(errorCount - oldCount);
}
indentLevel--;
writeTestResult(errorCount);
if (prompt) {
System.out.println("Hit RETURN to exit...");
try {
System.in.read();
}
catch (IOException e) {
System.out.println("Exception: " + e.toString() + e.getMessage());
}
}
if (nothrow) {
if (exitcode) {
System.exit(errorCount);
}
if (errorCount > 0) {
throw new IllegalArgumentException("encountered " + errorCount + " errors");
}
}
}
/**
* Adds given string to the log if we are in verbose mode.
*/
protected void log( String message ) {
if( verbose ) {
indent(indentLevel + 1);
log.print( message );
}
}
protected void logln( String message ) {
log(message + System.getProperty("line.separator"));
}
/**
* Report an error
*/
protected void err( String message ) {
errorCount++;
indent(indentLevel + 1);
log.print( message );
log.flush();
if (!nothrow) {
throw new RuntimeException(message);
}
}
protected void errln( String message ) {
err(message + System.getProperty("line.separator"));
}
protected void writeTestName(String testName) {
indent(indentLevel);
log.print(testName);
log.flush();
needLineFeed = true;
}
protected void writeTestResult(int count) {
if (!needLineFeed) {
indent(indentLevel);
log.print("}");
}
needLineFeed = false;
if (count != 0)
log.println(" FAILED");
else
log.println(" Passed");
}
private final void indent(int distance) {
if (needLineFeed) {
log.println(" {");
needLineFeed = false;
}
log.print(spaces.substring(0, distance * 2));
}
/**
* Print a usage message for this test class.
*/
void usage() {
System.out.println(getClass().getName() +
": [-verbose] [-nothrow] [-exitcode] [-prompt] [test names]");
System.out.println("test names:");
Enumeration methodNames = testMethods.keys();
while( methodNames.hasMoreElements() ) {
System.out.println("\t" + methodNames.nextElement() );
}
}
private boolean prompt = false;
private boolean nothrow = false;
private boolean exitcode = false;
protected boolean verbose = false;
private PrintWriter log;
private int indentLevel = 0;
private boolean needLineFeed = false;
private int errorCount = 0;
private Hashtable testMethods;
private final String spaces = " ";
}