0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*
0N/A * @test
0N/A * @bug 4449637
0N/A * @summary Basic acceptance test for international J2RE. Verifies that the
0N/A * most important locale data and character converters exist and are
0N/A * minimally functional.
0N/A */
0N/A
0N/Aimport java.io.UnsupportedEncodingException;
0N/Aimport java.text.DateFormat;
0N/Aimport java.util.Calendar;
0N/Aimport java.util.Date;
0N/Aimport java.util.Locale;
0N/Aimport java.util.TimeZone;
0N/A
0N/Apublic class InternationalBAT {
0N/A
0N/A public static void main(String[] args) {
0N/A boolean pass = true;
0N/A if (!testRequiredLocales()) {
0N/A pass = false;
0N/A }
0N/A if (!testRequiredEncodings()) {
0N/A pass = false;
0N/A }
0N/A
0N/A if (!pass) {
0N/A System.out.println("\nSome tests failed.\n"
0N/A + "If you installed the US-only J2RE for Windows, "
0N/A + "failures are expected and OK.\n"
0N/A + "If you installed the international J2RE, or any J2SDK, "
0N/A + "or if this occurs on any platform other than Windows, "
0N/A + "please file a bug report.\n"
0N/A + "Unfortunately, this test cannot determine whether you "
0N/A + "installed a US-only J2RE, an international J2RE, or "
0N/A + "a J2SDK.\n");
0N/A throw new RuntimeException();
0N/A }
0N/A }
0N/A
0N/A // We require the "fully supported locales" for java.util and java.text:
0N/A // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#util-text
0N/A
0N/A private static Locale[] requiredLocales = {
0N/A new Locale("ar", "SA"),
0N/A new Locale("zh", "CN"),
0N/A new Locale("zh", "TW"),
0N/A new Locale("nl", "NL"),
0N/A new Locale("en", "AU"),
0N/A new Locale("en", "CA"),
0N/A new Locale("en", "GB"),
0N/A new Locale("en", "US"),
0N/A new Locale("fr", "CA"),
0N/A new Locale("fr", "FR"),
0N/A new Locale("de", "DE"),
0N/A new Locale("iw", "IL"),
0N/A new Locale("hi", "IN"),
0N/A new Locale("it", "IT"),
0N/A new Locale("ja", "JP"),
0N/A new Locale("ko", "KR"),
0N/A new Locale("pt", "BR"),
0N/A new Locale("es", "ES"),
0N/A new Locale("sv", "SE"),
0N/A new Locale("th", "TH"),
0N/A };
0N/A
0N/A // Date strings for May 10, 2001, for the required locales
0N/A private static String[] requiredLocaleDates = {
0N/A "10 \u0645\u0627\u064A\u0648, 2001",
0N/A "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
0N/A "2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB",
0N/A "donderdag 10 mei 2001",
0N/A "Thursday, 10 May 2001",
0N/A "Thursday, May 10, 2001",
0N/A "Thursday, 10 May 2001",
0N/A "Thursday, May 10, 2001",
0N/A "jeudi 10 mai 2001",
0N/A "jeudi 10 mai 2001",
0N/A "Donnerstag, 10. Mai 2001",
0N/A "\u05D9\u05D5\u05DD \u05D7\u05DE\u05D9\u05E9\u05D9 10 \u05DE\u05D0\u05D9 2001",
0N/A "\u0917\u0941\u0930\u0941\u0935\u093E\u0930, \u0967\u0966 \u092E\u0908, \u0968\u0966\u0966\u0967",
0N/A "gioved\u00EC 10 maggio 2001",
0N/A "2001\u5E745\u670810\u65E5", // ja_JP
0N/A "2001\uB144 5\uC6D4 10\uC77C \uBAA9\uC694\uC77C",
0N/A "Quinta-feira, 10 de Maio de 2001",
0N/A "jueves 10 de mayo de 2001",
0N/A "den 10 maj 2001",
0N/A "\u0E27\u0E31\u0E19\u0E1E\u0E24\u0E2B\u0E31\u0E2A\u0E1A\u0E14\u0E35\u0E17\u0E35\u0E48 10 \u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21 \u0E1E.\u0E28. 2544",
0N/A };
0N/A
0N/A private static boolean testRequiredLocales() {
0N/A boolean pass = true;
0N/A
0N/A TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
0N/A Calendar calendar = Calendar.getInstance(Locale.US);
0N/A calendar.clear();
0N/A calendar.set(2001, 4, 10, 12, 0, 0);
0N/A Date date = calendar.getTime();
0N/A
0N/A Locale[] available = Locale.getAvailableLocales();
0N/A for (int i = 0; i < requiredLocales.length; i++) {
0N/A Locale locale = requiredLocales[i];
0N/A boolean found = false;
0N/A for (int j = 0; j < available.length; j++) {
0N/A if (available[j].equals(locale)) {
0N/A found = true;
0N/A break;
0N/A }
0N/A }
0N/A if (!found) {
0N/A System.out.println("Locale not available: " + locale);
0N/A pass = false;
0N/A } else {
0N/A DateFormat format =
0N/A DateFormat.getDateInstance(DateFormat.FULL, locale);
0N/A String dateString = format.format(date);
0N/A if (!dateString.equals(requiredLocaleDates[i])) {
0N/A System.out.println("Incorrect date string for locale "
0N/A + locale + ". Expected: " + requiredLocaleDates[i]
0N/A + ", got: " + dateString);
0N/A pass = false;
0N/A }
0N/A }
0N/A }
0N/A return pass;
0N/A }
0N/A
0N/A // We require the encodings of the fully supported writing systems:
0N/A // http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#jfc
0N/A
0N/A private static String[] requiredEncodings = {
0N/A "Cp1256",
0N/A "MS936",
0N/A "MS950",
0N/A "Cp1255",
0N/A "MS932",
0N/A "MS949",
0N/A "Cp1252",
0N/A "MS874",
0N/A "ISO8859_6",
0N/A "EUC_CN",
0N/A "UTF8",
0N/A "GBK",
0N/A "EUC_TW",
0N/A "ISO8859_8",
0N/A "EUC_JP",
0N/A "PCK",
0N/A "EUC_KR",
0N/A "ISO8859_1",
0N/A "ISO8859_15",
0N/A "TIS620",
0N/A };
0N/A
0N/A // one sample locale each for the required encodings
0N/A
0N/A private static Locale[] sampleLocales = {
0N/A new Locale("ar", "SA"),
0N/A new Locale("zh", "CN"),
0N/A new Locale("zh", "TW"),
0N/A new Locale("iw", "IL"),
0N/A new Locale("ja", "JP"),
0N/A new Locale("ko", "KR"),
0N/A new Locale("it", "IT"),
0N/A new Locale("th", "TH"),
0N/A new Locale("ar", "SA"),
0N/A new Locale("zh", "CN"),
0N/A new Locale("zh", "CN"),
0N/A new Locale("zh", "CN"),
0N/A new Locale("zh", "TW"),
0N/A new Locale("iw", "IL"),
0N/A new Locale("ja", "JP"),
0N/A new Locale("ja", "JP"),
0N/A new Locale("ko", "KR"),
0N/A new Locale("it", "IT"),
0N/A new Locale("it", "IT"),
0N/A new Locale("th", "TH"),
0N/A };
0N/A
0N/A // expected conversion results for the date strings of the sample locales
0N/A
0N/A private static byte[][] expectedBytes = {
0N/A { 0x31, 0x30, 0x20, (byte) 0xE3, (byte) 0xC7, (byte) 0xED, (byte) 0xE6, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xA6, 0x7E, 0x35, (byte) 0xA4, (byte) 0xEB, 0x31, 0x30, (byte) 0xA4, (byte) 0xE9, 0x20, (byte) 0xAC, (byte)0x50, (byte) 0xB4, (byte) 0xC1, (byte) 0xA5, (byte) 0x7C},
0N/A { (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, },
0N/A { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, },
0N/A { 0x31, 0x30, 0x20, (byte) 0xE5, (byte) 0xC7, (byte) 0xEA, (byte) 0xE8, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xE5, (byte) 0xB9, (byte) 0xB4, 0x35, (byte) 0xE6, (byte) 0x9C, (byte) 0x88, 0x31, 0x30, (byte) 0xE6, (byte) 0x97, (byte) 0xA5, 0x20, (byte) 0xE6, (byte)0x98, (byte) 0x9F, (byte) 0xE6, (byte) 0x9C, (byte) 0x9F, (byte) 0xE5, (byte) 0x9B, (byte) 0x9B},
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4},
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xC8, (byte) 0xA1, 0x35, (byte) 0xC5, (byte) 0xCC, 0x31, 0x30, (byte) 0xC5, (byte) 0xCA, 0x20, (byte) 0xD1, (byte) 0xD3, (byte) 0xDF, (byte) 0xE6, (byte) 0xC6, (byte) 0xBE},
0N/A { (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xC7, (byte) 0xAF, 0x35, (byte) 0xB7, (byte) 0xEE, 0x31, 0x30, (byte) 0xC6, (byte) 0xFC, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, },
0N/A { 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, },
0N/A { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, },
0N/A { (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, },
0N/A };
0N/A
0N/A
0N/A private static boolean testRequiredEncodings() {
0N/A boolean pass = true;
0N/A
0N/A for (int i = 0; i < requiredEncodings.length; i++) {
0N/A String encoding = requiredEncodings[i];
0N/A Locale sampleLocale = sampleLocales[i];
0N/A try {
0N/A int index = 0;
0N/A while (!sampleLocale.equals(requiredLocales[index])) {
0N/A index++;
0N/A }
0N/A byte[] out = requiredLocaleDates[index].getBytes(encoding);
0N/A byte[] expected = expectedBytes[i];
0N/A if (out.length != expected.length) {
0N/A reportConversionError(encoding, expected, out);
0N/A pass = false;
0N/A } else {
0N/A for (int j = 0; j < out.length; j++) {
0N/A if (out[j] != expected[j]) {
0N/A reportConversionError(encoding, expected, out);
0N/A pass = false;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A } catch (UnsupportedEncodingException e) {
0N/A System.out.println("Encoding not available: " + encoding);
0N/A pass = false;
0N/A }
0N/A }
0N/A return pass;
0N/A }
0N/A
0N/A private static void reportConversionError(String encoding,
0N/A byte[] expected, byte[] actual) {
0N/A
0N/A System.out.println("Incorrect conversion for encoding: " + encoding);
0N/A System.out.println("Expected output:");
0N/A dumpBytes(expected);
0N/A System.out.println("Actual output:");
0N/A dumpBytes(actual);
0N/A }
0N/A
0N/A private static void dumpBytes(byte[] bytes) {
0N/A System.out.print(" { ");
0N/A for (int i = 0; i < bytes.length; i++) {
0N/A byte b = bytes[i];
0N/A if (b < 0) {
0N/A System.out.print("(byte) ");
0N/A }
0N/A System.out.print("0x" + toHex((b & 0x00F0) >> 4)
0N/A + toHex((b & 0x000F)) + ", ");
0N/A }
0N/A System.out.println("},");
0N/A }
0N/A
0N/A private static char toHex(int i) {
0N/A if (i <= 9) {
0N/A return (char) ('0' + i);
0N/A } else {
0N/A return (char) ('A' + i - 10);
0N/A }
0N/A }
0N/A}