0N/A/*
4358N/A * Copyright (c) 2007, 2011, 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 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
0N/A * 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
3303N/A * 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
4358N/A * 6786276 7066203
0N/A * @summary test Locales
0N/A */
0N/A/*
0N/A *
0N/A *
0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
0N/A *
0N/A * Portions copyright (c) 2007 Sun Microsystems, Inc.
0N/A * All Rights Reserved.
0N/A *
0N/A * The original version of this source code and documentation
0N/A * is copyrighted and owned by Taligent, Inc., a wholly-owned
0N/A * subsidiary of IBM. These materials are provided under terms
0N/A * of a License Agreement between Taligent and Sun. This technology
0N/A * is protected by multiple US and International patents.
0N/A *
0N/A * This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A * Permission to use, copy, modify, and distribute this software
0N/A * and its documentation for NON-COMMERCIAL purposes and without
0N/A * fee is hereby granted provided that this copyright notice
0N/A * appears in all copies. Please refer to the file "copyright.html"
0N/A * for further important copyright and licensing information.
0N/A *
0N/A * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
0N/A * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
0N/A * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
0N/A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
0N/A * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
0N/A * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
0N/A *
0N/A */
0N/A
0N/Aimport java.text.*;
0N/Aimport java.util.Locale;
0N/Aimport java.util.MissingResourceException;
0N/Aimport java.util.Date;
0N/Aimport java.util.Calendar;
0N/Aimport java.io.*;
0N/A
0N/Apublic class LocaleTest extends LocaleTestFmwk {
0N/A public LocaleTest() {
0N/A }
0N/A
0N/A private int ENGLISH = 0;
0N/A private int FRENCH = 1;
0N/A private int CROATIAN = 2;
0N/A private int GREEK = 3;
0N/A private int NORWEGIAN = 4;
0N/A private int ITALIAN = 5;
0N/A private int DUMMY = 6;
0N/A private int MAX_LOCALES = 6;
0N/A
0N/A private int LANG = 0;
0N/A private int CTRY = 1;
0N/A private int VAR = 2;
0N/A private int NAME = 3;
0N/A private int LANG3 = 4;
0N/A private int CTRY3 = 5;
0N/A private int LCID = 6;
0N/A private int DLANG_EN = 7;
0N/A private int DCTRY_EN = 8;
0N/A private int DVAR_EN = 9;
0N/A private int DNAME_EN = 10;
0N/A private int DLANG_FR = 11;
0N/A private int DCTRY_FR = 12;
0N/A private int DVAR_FR = 13;
0N/A private int DNAME_FR = 14;
0N/A private int DLANG_HR = 15;
0N/A private int DCTRY_HR = 16;
0N/A private int DVAR_HR = 17;
0N/A private int DNAME_HR = 18;
0N/A private int DLANG_EL = 19;
0N/A private int DCTRY_EL = 20;
0N/A private int DVAR_EL = 21;
0N/A private int DNAME_EL = 22;
0N/A private int DLANG_ROOT = 23;
0N/A private int DCTRY_ROOT = 24;
0N/A private int DVAR_ROOT = 25;
0N/A private int DNAME_ROOT = 26;
0N/A
0N/A private String[][] dataTable = {
0N/A // language code
0N/A { "en", "fr", "hr", "el", "no", "it", "xx" },
0N/A // country code
0N/A { "US", "FR", "HR", "GR", "NO", "", "YY" },
0N/A // variant code
0N/A { "", "", "", "", "NY", "", "" },
0N/A // full name
0N/A { "en_US", "fr_FR", "hr_HR", "el_GR", "no_NO_NY", "it", "xx_YY" },
0N/A // ISO-3 language
0N/A { "eng", "fra", "hrv", "ell", "nor", "ita", "" },
0N/A // ISO-3 country
0N/A { "USA", "FRA", "HRV", "GRC", "NOR", "", "" },
0N/A // LCID (not currently public)
0N/A { "0409", "040c", "041a", "0408", "0814", "", "" },
0N/A
0N/A // display language (English)
0N/A { "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" },
0N/A // display country (English)
0N/A { "United States", "France", "Croatia", "Greece", "Norway", "", "YY" },
0N/A // display variant (English)
0N/A { "", "", "", "", "Nynorsk", "", ""},
0N/A // display name (English)
0N/A // Updated no_NO_NY English display name for new pattern-based algorithm
0N/A // (part of Euro support).
0N/A { "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
0N/A
0N/A // display langage (French)
0N/A { "anglais", "fran\u00e7ais", "croate", "grec", "norv\u00e9gien", "italien", "xx" },
0N/A // display country (French)
0N/A { "Etats-Unis", "France", "Croatie", "Gr\u00e8ce", "Norv\u00e8ge", "", "YY" },
0N/A // display variant (French)
0N/A { "", "", "", "", "", "", "" },
0N/A // display name (French)
0N/A { "anglais (Etats-Unis)", "fran\u00e7ais (France)", "croate (Croatie)", "grec (Gr\u00e8ce)", "norv\u00e9gien (Norv\u00e8ge,Nynorsk)", "italien", "xx (YY)" },
0N/A
0N/A // display langage (Croatian)
0N/A { "", "", "hrvatski", "", "", "", "xx" },
0N/A // display country (Croatian)
0N/A { "", "", "Hrvatska", "", "", "", "YY" },
0N/A // display variant (Croatian)
0N/A { "", "", "", "", "", "", ""},
0N/A // display name (Croatian)
0N/A { "", "", "hrvatski (Hrvatska)", "", "", "", "xx (YY)" },
0N/A
0N/A // display langage (Greek)
0N/A { "\u0391\u03b3\u03b3\u03bb\u03b9\u03ba\u03ac", "\u0393\u03b1\u03bb\u03bb\u03b9\u03ba\u03ac", "\u039a\u03c1\u03bf\u03b1\u03c4\u03b9\u03ba\u03ac", "\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac", "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03b9\u03ba\u03ac", "\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac", "xx" },
0N/A // display country (Greek)
0N/A { "\u0397\u03bd\u03c9\u03bc\u03ad\u03bd\u03b5\u03c2 \u03a0\u03bf\u03bb\u03b9\u03c4\u03b5\u03af\u03b5\u03c2", "\u0393\u03b1\u03bb\u03bb\u03af\u03b1", "\u039a\u03c1\u03bf\u03b1\u03c4\u03af\u03b1", "\u0395\u03bb\u03bb\u03ac\u03b4\u03b1", "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03af\u03b1", "", "YY" },
0N/A // display variant (Greek)
0N/A { "", "", "", "", "", "", "" },
0N/A // display name (Greek)
0N/A { "\u0391\u03b3\u03b3\u03bb\u03b9\u03ba\u03ac (\u0397\u03bd\u03c9\u03bc\u03ad\u03bd\u03b5\u03c2 \u03a0\u03bf\u03bb\u03b9\u03c4\u03b5\u03af\u03b5\u03c2)", "\u0393\u03b1\u03bb\u03bb\u03b9\u03ba\u03ac (\u0393\u03b1\u03bb\u03bb\u03af\u03b1)", "\u039a\u03c1\u03bf\u03b1\u03c4\u03b9\u03ba\u03ac (\u039a\u03c1\u03bf\u03b1\u03c4\u03af\u03b1)", "\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac (\u0395\u03bb\u03bb\u03ac\u03b4\u03b1)", "\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03b9\u03ba\u03ac (\u039d\u03bf\u03c1\u03b2\u03b7\u03b3\u03af\u03b1,Nynorsk)", "\u0399\u03c4\u03b1\u03bb\u03b9\u03ba\u03ac", "xx (YY)" },
0N/A
0N/A // display langage (<root>)
0N/A { "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" },
0N/A // display country (<root>)
0N/A { "United States", "France", "Croatia", "Greece", "Norway", "", "YY" },
0N/A // display variant (<root>)
0N/A { "", "", "", "", "Nynorsk", "", ""},
0N/A // display name (<root>)
0N/A { "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
0N/A };
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new LocaleTest().run(args);
0N/A }
0N/A
0N/A public void TestBasicGetters() {
0N/A for (int i = 0; i <= MAX_LOCALES; i++) {
0N/A Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
0N/A logln("Testing " + testLocale + "...");
0N/A
0N/A if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
0N/A errln(" Language code mismatch: " + testLocale.getLanguage() + " versus "
0N/A + dataTable[LANG][i]);
0N/A if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
0N/A errln(" Country code mismatch: " + testLocale.getCountry() + " versus "
0N/A + dataTable[CTRY][i]);
0N/A if (!testLocale.getVariant().equals(dataTable[VAR][i]))
0N/A errln(" Variant code mismatch: " + testLocale.getVariant() + " versus "
0N/A + dataTable[VAR][i]);
0N/A if (!testLocale.toString().equals(dataTable[NAME][i]))
0N/A errln(" Locale name mismatch: " + testLocale.toString() + " versus "
0N/A + dataTable[NAME][i]);
0N/A }
0N/A
0N/A logln("Same thing without variant codes...");
0N/A for (int i = 0; i <= MAX_LOCALES; i++) {
0N/A Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i]);
0N/A logln("Testing " + testLocale + "...");
0N/A
0N/A if (!testLocale.getLanguage().equals(dataTable[LANG][i]))
0N/A errln(" Language code mismatch: " + testLocale.getLanguage() + " versus "
0N/A + dataTable[LANG][i]);
0N/A if (!testLocale.getCountry().equals(dataTable[CTRY][i]))
0N/A errln(" Country code mismatch: " + testLocale.getCountry() + " versus "
0N/A + dataTable[CTRY][i]);
0N/A if (!testLocale.getVariant().equals(""))
0N/A errln(" Variant code mismatch: " + testLocale.getVariant() + " versus \"\"");
0N/A }
0N/A }
0N/A
0N/A public void TestSimpleResourceInfo() {
0N/A for (int i = 0; i <= MAX_LOCALES; i++) {
0N/A if (dataTable[LANG][i].equals("xx"))
0N/A continue;
0N/A
0N/A Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
0N/A logln("Testing " + testLocale + "...");
0N/A
0N/A if (!testLocale.getISO3Language().equals(dataTable[LANG3][i]))
0N/A errln(" ISO-3 language code mismatch: " + testLocale.getISO3Language()
0N/A + " versus " + dataTable[LANG3][i]);
0N/A if (!testLocale.getISO3Country().equals(dataTable[CTRY3][i]))
0N/A errln(" ISO-3 country code mismatch: " + testLocale.getISO3Country()
0N/A + " versus " + dataTable[CTRY3][i]);
0N/A/*
0N/A // getLCID() is currently private
0N/A if (!String.valueOf(testLocale.getLCID()).equals(dataTable[LCID][i]))
0N/A errln(" LCID mismatch: " + testLocale.getLCID() + " versus "
0N/A + dataTable[LCID][i]);
0N/A*/
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * @bug 4101316
0N/A * @bug 4084688 (This bug appears to be a duplicate of something, because it was fixed
0N/A * between 1.1.5 and 1.1.6, but I included a new test for it anyway)
0N/A * @bug 4052440 Stop falling back to the default locale.
0N/A */
0N/A public void TestDisplayNames() {
0N/A Locale saveDefault = Locale.getDefault();
0N/A Locale english = new Locale("en", "US");
0N/A Locale french = new Locale("fr", "FR");
0N/A Locale croatian = new Locale("hr", "HR");
0N/A Locale greek = new Locale("el", "GR");
0N/A
0N/A Locale.setDefault(english);
0N/A logln("With default = en_US...");
0N/A logln(" In default locale...");
0N/A doTestDisplayNames(null, DLANG_EN, false);
0N/A logln(" In locale = en_US...");
0N/A doTestDisplayNames(english, DLANG_EN, false);
0N/A logln(" In locale = fr_FR...");
0N/A doTestDisplayNames(french, DLANG_FR, false);
0N/A logln(" In locale = hr_HR...");
0N/A doTestDisplayNames(croatian, DLANG_HR, false);
0N/A logln(" In locale = el_GR...");
0N/A doTestDisplayNames(greek, DLANG_EL, false);
0N/A
0N/A Locale.setDefault(french);
0N/A logln("With default = fr_FR...");
0N/A logln(" In default locale...");
0N/A doTestDisplayNames(null, DLANG_FR, true);
0N/A logln(" In locale = en_US...");
0N/A doTestDisplayNames(english, DLANG_EN, true);
0N/A logln(" In locale = fr_FR...");
0N/A doTestDisplayNames(french, DLANG_FR, true);
0N/A logln(" In locale = hr_HR...");
0N/A doTestDisplayNames(croatian, DLANG_HR, true);
0N/A logln(" In locale = el_GR...");
0N/A doTestDisplayNames(greek, DLANG_EL, true);
0N/A
0N/A Locale.setDefault(saveDefault);
0N/A }
0N/A
0N/A private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
0N/A if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr"))
0N/A errln("Default locale should be French, but it's really " + Locale.getDefault().getLanguage());
0N/A else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en"))
0N/A errln("Default locale should be English, but it's really " + Locale.getDefault().getLanguage());
0N/A
0N/A for (int i = 0; i <= MAX_LOCALES; i++) {
0N/A Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
0N/A logln(" Testing " + testLocale + "...");
0N/A
0N/A String testLang;
0N/A String testCtry;
0N/A String testVar;
0N/A String testName;
0N/A
0N/A if (inLocale == null) {
0N/A testLang = testLocale.getDisplayLanguage();
0N/A testCtry = testLocale.getDisplayCountry();
0N/A testVar = testLocale.getDisplayVariant();
0N/A testName = testLocale.getDisplayName();
0N/A }
0N/A else {
0N/A testLang = testLocale.getDisplayLanguage(inLocale);
0N/A testCtry = testLocale.getDisplayCountry(inLocale);
0N/A testVar = testLocale.getDisplayVariant(inLocale);
0N/A testName = testLocale.getDisplayName(inLocale);
0N/A }
0N/A
0N/A String expectedLang;
0N/A String expectedCtry;
0N/A String expectedVar;
0N/A String expectedName;
0N/A
0N/A expectedLang = dataTable[compareIndex][i];
0N/A if (expectedLang.equals("") && defaultIsFrench)
0N/A expectedLang = dataTable[DLANG_EN][i];
0N/A if (expectedLang.equals(""))
0N/A expectedLang = dataTable[DLANG_ROOT][i];
0N/A
0N/A expectedCtry = dataTable[compareIndex + 1][i];
0N/A if (expectedCtry.equals("") && defaultIsFrench)
0N/A expectedCtry = dataTable[DCTRY_EN][i];
0N/A if (expectedCtry.equals(""))
0N/A expectedCtry = dataTable[DCTRY_ROOT][i];
0N/A
0N/A expectedVar = dataTable[compareIndex + 2][i];
0N/A if (expectedVar.equals("") && defaultIsFrench)
0N/A expectedVar = dataTable[DVAR_EN][i];
0N/A if (expectedVar.equals(""))
0N/A expectedVar = dataTable[DVAR_ROOT][i];
0N/A
0N/A expectedName = dataTable[compareIndex + 3][i];
0N/A if (expectedName.equals("") && defaultIsFrench)
0N/A expectedName = dataTable[DNAME_EN][i];
0N/A if (expectedName.equals(""))
0N/A expectedName = dataTable[DNAME_ROOT][i];
0N/A
0N/A if (!testLang.equals(expectedLang))
0N/A errln("Display language mismatch: " + testLang + " versus " + expectedLang);
0N/A if (!testCtry.equals(expectedCtry))
0N/A errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
0N/A if (!testVar.equals(expectedVar))
0N/A errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
0N/A if (!testName.equals(expectedName))
0N/A errln("Display name mismatch: " + testName + " versus " + expectedName);
0N/A }
0N/A }
0N/A
0N/A public void TestSimpleObjectStuff() {
0N/A Locale test1 = new Locale("aa", "AA");
0N/A Locale test2 = new Locale("aa", "AA");
0N/A Locale test3 = (Locale)test1.clone();
0N/A Locale test4 = new Locale("zz", "ZZ");
0N/A
0N/A if (test1 == test2 || test1 == test3 || test1 == test4 || test2 == test3)
0N/A errln("Some of the test variables point to the same locale!");
0N/A
0N/A if (test3 == null)
0N/A errln("clone() failed to produce a valid object!");
0N/A
0N/A if (!test1.equals(test2) || !test1.equals(test3) || !test2.equals(test3))
0N/A errln("clone() or equals() failed: objects that should compare equal don't");
0N/A
0N/A if (test1.equals(test4) || test2.equals(test4) || test3.equals(test4))
0N/A errln("equals() failed: objects that shouldn't compare equal do");
0N/A
0N/A int hash1 = test1.hashCode();
0N/A int hash2 = test2.hashCode();
0N/A int hash3 = test3.hashCode();
0N/A
0N/A if (hash1 != hash2 || hash1 != hash3 || hash2 != hash3)
0N/A errln("hashCode() failed: objects that should have the same hash code don't");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4011756 4011380
0N/A */
0N/A public void TestISO3Fallback() {
0N/A Locale test = new Locale("xx", "YY", "");
0N/A boolean gotException = false;
0N/A String result = "";
0N/A
0N/A try {
0N/A result = test.getISO3Language();
0N/A }
0N/A catch (MissingResourceException e) {
0N/A gotException = true;
0N/A }
0N/A if (!gotException)
0N/A errln("getISO3Language() on xx_YY returned " + result + " instead of throwing an exception");
0N/A
0N/A gotException = false;
0N/A try {
0N/A result = test.getISO3Country();
0N/A }
0N/A catch (MissingResourceException e) {
0N/A gotException = true;
0N/A }
0N/A if (!gotException)
0N/A errln("getISO3Country() on xx_YY returned " + result + " instead of throwing an exception");
0N/A }
0N/A
0N/A /**
4358N/A * @bug 4106155 4118587 7066203
0N/A */
0N/A public void TestGetLangsAndCountries() {
0N/A // It didn't seem right to just do an exhaustive test of everything here, so I check
0N/A // for the following things:
0N/A // 1) Does each list have the right total number of entries?
0N/A // 2) Does each list contain certain language and country codes we think are important
0N/A // (the G7 countries, plus a couple others)?
0N/A // 3) Does each list have every entry formatted correctly? (i.e., two characters,
0N/A // all lower case for the language codes, all upper case for the country codes)
0N/A // 4) Is each list in sorted order?
0N/A String[] test = Locale.getISOLanguages();
0N/A String[] spotCheck1 = { "en", "es", "fr", "de", "it", "ja", "ko", "zh", "th",
0N/A "he", "id", "iu", "ug", "yi", "za" };
0N/A
0N/A if (test.length != 188)
0N/A errln("Expected getISOLanguages() to return 188 languages; it returned " + test.length);
0N/A else {
0N/A for (int i = 0; i < spotCheck1.length; i++) {
0N/A int j;
0N/A for (j = 0; j < test.length; j++)
0N/A if (test[j].equals(spotCheck1[i]))
0N/A break;
0N/A if (j == test.length || !test[j].equals(spotCheck1[i]))
0N/A errln("Couldn't find " + spotCheck1[i] + " in language list.");
0N/A }
0N/A }
0N/A for (int i = 0; i < test.length; i++) {
0N/A if (!test[i].equals(test[i].toLowerCase()))
0N/A errln(test[i] + " is not all lower case.");
0N/A if (test[i].length() != 2)
0N/A errln(test[i] + " is not two characters long.");
0N/A if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
0N/A errln(test[i] + " appears in an out-of-order position in the list.");
0N/A }
0N/A
0N/A test = Locale.getISOCountries();
0N/A String[] spotCheck2 = { "US", "CA", "GB", "FR", "DE", "IT", "JP", "KR", "CN", "TW", "TH" };
0N/A
0N/A
4358N/A if (test.length != 249)
4358N/A errln("Expected getISOCountries to return 249 countries; it returned " + test.length);
0N/A else {
0N/A for (int i = 0; i < spotCheck2.length; i++) {
0N/A int j;
0N/A for (j = 0; j < test.length; j++)
0N/A if (test[j].equals(spotCheck2[i]))
0N/A break;
0N/A if (j == test.length || !test[j].equals(spotCheck2[i]))
0N/A errln("Couldn't find " + spotCheck2[i] + " in country list.");
0N/A }
0N/A }
0N/A for (int i = 0; i < test.length; i++) {
0N/A if (!test[i].equals(test[i].toUpperCase()))
0N/A errln(test[i] + " is not all upper case.");
0N/A if (test[i].length() != 2)
0N/A errln(test[i] + " is not two characters long.");
0N/A if (i > 0 && test[i].compareTo(test[i - 1]) <= 0)
0N/A errln(test[i] + " appears in an out-of-order position in the list.");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4126880
0N/A */
0N/A void Test4126880() {
0N/A String[] test;
0N/A
0N/A test = Locale.getISOCountries();
0N/A test[0] = "SUCKER!!!";
0N/A test = Locale.getISOCountries();
0N/A if (test[0].equals("SUCKER!!!"))
0N/A errln("Changed internal country code list!");
0N/A
0N/A test = Locale.getISOLanguages();
0N/A test[0] = "HAHAHAHA!!!";
0N/A test = Locale.getISOLanguages();
0N/A if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
0N/A errln("Changes internal language code list!");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4107014
0N/A */
0N/A public void TestGetAvailableLocales() {
0N/A Locale[] locales = Locale.getAvailableLocales();
0N/A if (locales == null || locales.length == 0)
0N/A errln("Locale.getAvailableLocales() returned no installed locales!");
0N/A else {
0N/A logln("Locale.getAvailableLocales() returned a list of " + locales.length + " locales.");
0N/A for (int i = 0; i < locales.length; i++)
0N/A logln(locales[i].toString());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4135316
0N/A */
0N/A public void TestBug4135316() {
0N/A Locale[] locales1 = Locale.getAvailableLocales();
0N/A Locale[] locales2 = Locale.getAvailableLocales();
0N/A if (locales1 == locales2)
0N/A errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4107953
0N/A */
0N/A/*
0N/Atest commented out pending API-change approval
0N/A public void TestGetLanguagesForCountry() {
0N/A String[] languages = Locale.getLanguagesForCountry("US");
0N/A
0N/A if (!searchStringArrayFor("en", languages))
0N/A errln("Didn't get en as a language for US");
0N/A
0N/A languages = Locale.getLanguagesForCountry("FR");
0N/A if (!searchStringArrayFor("fr", languages))
0N/A errln("Didn't get fr as a language for FR");
0N/A
0N/A languages = Locale.getLanguagesForCountry("CH");
0N/A if (!searchStringArrayFor("fr", languages))
0N/A errln("Didn't get fr as a language for CH");
0N/A if (!searchStringArrayFor("it", languages))
0N/A errln("Didn't get it as a language for CH");
0N/A if (!searchStringArrayFor("de", languages))
0N/A errln("Didn't get de as a language for CH");
0N/A
0N/A languages = Locale.getLanguagesForCountry("JP");
0N/A if (!searchStringArrayFor("ja", languages))
0N/A errln("Didn't get ja as a language for JP");
0N/A }
0N/A*/
0N/A
0N/A private boolean searchStringArrayFor(String s, String[] array) {
0N/A for (int i = 0; i < array.length; i++)
0N/A if (s.equals(array[i]))
0N/A return true;
0N/A return false;
0N/A }
0N/A /**
0N/A * @bug 4110613
0N/A */
0N/A public void TestSerialization() throws ClassNotFoundException, OptionalDataException,
0N/A IOException, StreamCorruptedException
0N/A {
0N/A ObjectOutputStream ostream;
0N/A ByteArrayOutputStream obstream;
0N/A byte[] bytes = null;
0N/A
0N/A obstream = new ByteArrayOutputStream();
0N/A ostream = new ObjectOutputStream(obstream);
0N/A
0N/A Locale test1 = new Locale("zh", "TW", "");
0N/A int dummy = test1.hashCode(); // fill in the cached hash-code value
0N/A ostream.writeObject(test1);
0N/A
0N/A bytes = obstream.toByteArray();
0N/A
0N/A ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));
0N/A
0N/A Locale test2 = (Locale)(istream.readObject());
0N/A
0N/A if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
0N/A errln("Locale failed to deserialize correctly.");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4118587
0N/A */
0N/A public void TestSimpleDisplayNames() {
0N/A // This test is different from TestDisplayNames because TestDisplayNames checks
0N/A // fallback behavior, combination of language and country names to form locale
0N/A // names, and other stuff like that. This test just checks specific language
0N/A // and country codes to make sure we have the correct names for them.
0N/A String[] languageCodes = { "he", "id", "iu", "ug", "yi", "za" };
0N/A String[] languageNames = { "Hebrew", "Indonesian", "Inuktitut", "Uighur", "Yiddish",
0N/A "Zhuang" };
0N/A
0N/A for (int i = 0; i < languageCodes.length; i++) {
0N/A String test = (new Locale(languageCodes[i], "", "")).getDisplayLanguage(Locale.US);
0N/A if (!test.equals(languageNames[i]))
0N/A errln("Got wrong display name for " + languageCodes[i] + ": Expected \"" +
0N/A languageNames[i] + "\", got \"" + test + "\".");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4118595
0N/A */
0N/A public void TestUninstalledISO3Names() {
0N/A // This test checks to make sure getISO3Language and getISO3Country work right
0N/A // even for locales that are not installed.
0N/A String[] iso2Languages = { "am", "ba", "fy", "mr", "rn", "ss", "tw", "zu" };
0N/A String[] iso3Languages = { "amh", "bak", "fry", "mar", "run", "ssw", "twi", "zul" };
0N/A
0N/A for (int i = 0; i < iso2Languages.length; i++) {
0N/A String test = (new Locale(iso2Languages[i], "", "")).getISO3Language();
0N/A if (!test.equals(iso3Languages[i]))
0N/A errln("Got wrong ISO3 code for " + iso2Languages[i] + ": Expected \"" +
0N/A iso3Languages[i] + "\", got \"" + test + "\".");
0N/A }
0N/A
0N/A String[] iso2Countries = { "AF", "BW", "KZ", "MO", "MN", "SB", "TC", "ZW" };
0N/A String[] iso3Countries = { "AFG", "BWA", "KAZ", "MAC", "MNG", "SLB", "TCA", "ZWE" };
0N/A
0N/A for (int i = 0; i < iso2Countries.length; i++) {
0N/A String test = (new Locale("", iso2Countries[i], "")).getISO3Country();
0N/A if (!test.equals(iso3Countries[i]))
0N/A errln("Got wrong ISO3 code for " + iso2Countries[i] + ": Expected \"" +
0N/A iso3Countries[i] + "\", got \"" + test + "\".");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4052404 4778440
0N/A */
0N/A public void TestChangedISO639Codes() {
0N/A Locale hebrewOld = new Locale("iw", "IL", "");
0N/A Locale hebrewNew = new Locale("he", "IL", "");
0N/A Locale yiddishOld = new Locale("ji", "IL", "");
0N/A Locale yiddishNew = new Locale("yi", "IL", "");
0N/A Locale indonesianOld = new Locale("in", "", "");
0N/A Locale indonesianNew = new Locale("id", "", "");
0N/A
0N/A if (!hebrewNew.getLanguage().equals("iw"))
0N/A errln("Got back wrong language code for Hebrew: expected \"iw\", got \"" +
0N/A hebrewNew.getLanguage() + "\"");
0N/A if (!yiddishNew.getLanguage().equals("ji"))
0N/A errln("Got back wrong language code for Yiddish: expected \"ji\", got \"" +
0N/A yiddishNew.getLanguage() + "\"");
0N/A if (!indonesianNew.getLanguage().equals("in"))
0N/A errln("Got back wrong language code for Indonesian: expected \"in\", got \"" +
0N/A indonesianNew.getLanguage() + "\"");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4092475
0N/A * I could not reproduce this bug. I'm pretty convinced it was fixed with the
0N/A * big locale-data reorg of 10/28/97. The lookup logic for language and country
0N/A * display names was also changed at that time in that check-in. --rtg 3/20/98
0N/A
0N/A * This test is not designed to work in any other locale but en_US.
0N/A * Most of the LocaleElements do not contain display names for other languages,
0N/A * so this test fails (bug 4289223) when run under different locales. For example,
0N/A * LocaleElements_es as of kestrel does not have a localized name for Japanese, so
0N/A * the getDisplayName method asks the default locale for a display name. The Japanese
0N/A * localized name for "Japanese" does not equal "Japanese" so this test fails for es
0N/A * display names if run under a ja locale. Eventually, he LocaleElements should probably
0N/A * be updated to contain more localized language and region display names.
0N/A * 1999-11-19 joconner
0N/A *
0N/A */
0N/A public void TestAtypicalLocales() {
0N/A Locale[] localesToTest = { new Locale("de", "CA"),
0N/A new Locale("ja", "ZA"),
0N/A new Locale("ru", "MX"),
0N/A new Locale("en", "FR"),
0N/A new Locale("es", "DE"),
0N/A new Locale("", "HR"),
0N/A new Locale("", "SE"),
0N/A new Locale("", "DO"),
0N/A new Locale("", "BE") };
0N/A String[] englishDisplayNames = { "German (Canada)",
0N/A "Japanese (South Africa)",
0N/A "Russian (Mexico)",
0N/A "English (France)",
0N/A "Spanish (Germany)",
0N/A "Croatia",
0N/A "Sweden",
0N/A "Dominican Republic",
0N/A "Belgium" };
0N/A String[] frenchDisplayNames = { "allemand (Canada)",
0N/A "japonais (Afrique du Sud)",
0N/A "russe (Mexique)",
0N/A "anglais (France)",
0N/A "espagnol (Allemagne)",
0N/A "Croatie",
0N/A "Su\u00e8de",
0N/A "R\u00e9publique Dominicaine",
0N/A "Belgique" };
0N/A String[] spanishDisplayNames = { "alem\u00E1n (Canad\u00E1)",
0N/A "japon\u00E9s (Sud\u00E1frica)",
0N/A "ruso (M\u00e9xico)",
0N/A "ingl\u00E9s (Francia)",
0N/A "espa\u00f1ol (Alemania)",
0N/A "Croacia",
0N/A "Suecia",
0N/A "Rep\u00fablica Dominicana",
0N/A "B\u00E9lgica" };
0N/A
0N/A
0N/A // save the default locale and set to the new default to en_US
0N/A Locale defaultLocale = Locale.getDefault();
0N/A Locale.setDefault(Locale.US);
0N/A
0N/A for (int i = 0; i < localesToTest.length; i++) {
0N/A String name = localesToTest[i].getDisplayName(Locale.US);
0N/A logln(name);
0N/A if (!name.equals(englishDisplayNames[i]))
0N/A errln("Lookup in English failed: expected \"" + englishDisplayNames[i]
0N/A + "\", got \"" + name + "\"");
0N/A }
0N/A
0N/A for (int i = 0; i < localesToTest.length; i++) {
0N/A String name = localesToTest[i].getDisplayName(new Locale("es", "ES"));
0N/A logln(name);
0N/A if (!name.equals(spanishDisplayNames[i]))
0N/A errln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i]
0N/A + "\", got \"" + name + "\"");
0N/A }
0N/A
0N/A for (int i = 0; i < localesToTest.length; i++) {
0N/A String name = localesToTest[i].getDisplayName(Locale.FRANCE);
0N/A logln(name);
0N/A if (!name.equals(frenchDisplayNames[i]))
0N/A errln("Lookup in French failed: expected \"" + frenchDisplayNames[i]
0N/A + "\", got \"" + name + "\"");
0N/A }
0N/A
0N/A // restore the default locale for other tests
0N/A Locale.setDefault(defaultLocale);
0N/A }
0N/A
0N/A /**
0N/A * @bug 4126371
0N/A */
0N/A public void TestNullDefault() {
0N/A // why on earth anyone would ever try to do this is beyond me, but we should
0N/A // definitely make sure we don't let them
0N/A boolean gotException = false;
0N/A try {
0N/A Locale.setDefault(null);
0N/A }
0N/A catch (NullPointerException e) {
0N/A // all other exception types propagate through here back to the test harness
0N/A gotException = true;
0N/A }
0N/A if (Locale.getDefault() == null)
0N/A errln("Locale.getDefault() allowed us to set default to NULL!");
0N/A if (!gotException)
0N/A errln("Trying to set default locale to NULL didn't throw exception!");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4135752
0N/A * This would be better tested by the LocaleDataTest. Will move it when I
0N/A * get the LocaleDataTest working again.
0N/A */
0N/A public void TestThaiCurrencyFormat() {
0N/A DecimalFormat thaiCurrency = (DecimalFormat)NumberFormat.getCurrencyInstance(
0N/A new Locale("th", "TH"));
0N/A if (!thaiCurrency.getPositivePrefix().equals("\u0e3f"))
0N/A errln("Thai currency prefix wrong: expected \"\u0e3f\", got \"" +
0N/A thaiCurrency.getPositivePrefix() + "\"");
0N/A if (!thaiCurrency.getPositiveSuffix().equals(""))
0N/A errln("Thai currency suffix wrong: expected \"\", got \"" +
0N/A thaiCurrency.getPositiveSuffix() + "\"");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4122371
0N/A * Confirm that Euro support works. This test is pretty rudimentary; all it does
0N/A * is check that any locales with the EURO variant format a number using the
0N/A * Euro currency symbol.
0N/A *
0N/A * ASSUME: All locales encode the Euro character "\u20AC".
0N/A * If this is changed to use the single-character Euro symbol, this
0N/A * test must be updated.
0N/A *
0N/A * DON'T ASSUME: Any specific countries support the Euro. Instead,
0N/A * iterate through all locales.
0N/A */
0N/A public void TestEuroSupport() {
0N/A final String EURO_VARIANT = "EURO";
0N/A final String EURO_CURRENCY = "\u20AC"; // Look for this string in formatted Euro currency
0N/A
0N/A Locale[] locales = NumberFormat.getAvailableLocales();
0N/A for (int i=0; i<locales.length; ++i) {
0N/A Locale loc = locales[i];
0N/A if (loc.getVariant().indexOf(EURO_VARIANT) >= 0) {
0N/A NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
0N/A String pos = nf.format(271828.182845);
0N/A String neg = nf.format(-271828.182845);
0N/A if (pos.indexOf(EURO_CURRENCY) >= 0 &&
0N/A neg.indexOf(EURO_CURRENCY) >= 0) {
0N/A logln("Ok: " + loc.toString() +
0N/A ": " + pos + " / " + neg);
0N/A }
0N/A else {
0N/A errln("Fail: " + loc.toString() +
0N/A " formats without " + EURO_CURRENCY +
0N/A ": " + pos + " / " + neg +
0N/A "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4139504
0N/A * toString() doesn't work with language_VARIANT.
0N/A */
0N/A public void TestToString() {
0N/A Object[] DATA = {
0N/A new Locale("xx", "", ""), "xx",
0N/A new Locale("", "YY", ""), "_YY",
0N/A new Locale("", "", "ZZ"), "",
0N/A new Locale("xx", "YY", ""), "xx_YY",
0N/A new Locale("xx", "", "ZZ"), "xx__ZZ",
0N/A new Locale("", "YY", "ZZ"), "_YY_ZZ",
0N/A new Locale("xx", "YY", "ZZ"), "xx_YY_ZZ",
0N/A };
0N/A for (int i=0; i<DATA.length; i+=2) {
0N/A Locale loc = (Locale)DATA[i];
0N/A String fmt = (String)DATA[i+1];
0N/A if (!loc.toString().equals(fmt)) {
0N/A errln("Fail: Locale.toString(" + fmt + ")=>" + loc);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4105828
0N/A * Currency symbol in zh is wrong. We will test this at the NumberFormat
0N/A * end to test the whole pipe.
0N/A */
0N/A public void Test4105828() {
0N/A Locale[] LOC = { Locale.CHINESE, new Locale("zh", "CN", ""),
0N/A new Locale("zh", "TW", ""), new Locale("zh", "HK", "") };
0N/A for (int i=0; i<LOC.length; ++i) {
0N/A NumberFormat fmt = NumberFormat.getPercentInstance(LOC[i]);
0N/A String result = fmt.format(1);
0N/A if (!result.equals("100%")) {
0N/A errln("Percent for " + LOC[i] + " should be 100%, got " + result);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4139940
0N/A * Couldn't reproduce this bug -- probably was fixed earlier.
0N/A *
0N/A * ORIGINAL BUG REPORT:
0N/A * -- basically, hungarian for monday shouldn't have an \u00f4
0N/A * (o circumflex)in it instead it should be an o with 2 inclined
0N/A * (right) lines over it..
0N/A *
0N/A * You may wonder -- why do all this -- why not just add a line to
0N/A * LocaleData? Well, I could see by inspection that the locale file had the
0N/A * right character in it, so I wanted to check the rest of the pipeline -- a
0N/A * very remote possibility, but I wanted to be sure. The other possibility
0N/A * is that something is wrong with the font mapping subsystem, but we can't
0N/A * test that here.
0N/A */
0N/A public void Test4139940() {
0N/A Locale mylocale=new Locale("hu", "", "");
0N/A Date mydate = new Date(98,3,13); // A Monday
0N/A DateFormat df_full = new SimpleDateFormat("EEEE", mylocale);
0N/A String str = df_full.format(mydate);
0N/A // Make sure that o circumflex (\u00F4) is NOT there, and
0N/A // o double acute (\u0151) IS.
0N/A if (str.indexOf('\u0151') < 0 || str.indexOf('\u00F4') >= 0)
0N/A errln("Fail: Monday in Hungarian is wrong");
0N/A }
0N/A
0N/A /**
0N/A * @bug 4143951
0N/A * Russian first day of week should be Monday. Confirmed.
0N/A */
0N/A public void Test4143951() {
0N/A Calendar cal = Calendar.getInstance(new Locale("ru", "", ""));
0N/A if (cal.getFirstDayOfWeek() != Calendar.MONDAY) {
0N/A errln("Fail: First day of week in Russia should be Monday");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @bug 4147315
0N/A * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
0N/A * Should throw an exception for unknown locales
0N/A */
0N/A public void Test4147315() {
0N/A // Try with codes that are the wrong length but happen to match text
0N/A // at a valid offset in the mapping table
0N/A Locale locale = new Locale("aaa", "CCC");
0N/A
0N/A try {
0N/A String result = locale.getISO3Country();
0N/A
0N/A errln("ERROR: getISO3Country() returns: " + result +
0N/A " for locale '" + locale + "' rather than exception" );
0N/A } catch(MissingResourceException e) { }
0N/A }
0N/A
0N/A /**
3303N/A * @bug 4147317 4940539
3303N/A * java.util.Locale.getISO3Language() works wrong for non ISO-639 codes.
3303N/A * Should throw an exception for unknown locales, except they have three
3303N/A * letter language codes.
0N/A */
0N/A public void Test4147317() {
3303N/A // Try a three letter language code, and check whether it is
3303N/A // returned as is.
0N/A Locale locale = new Locale("aaa", "CCC");
0N/A
3303N/A String result = locale.getISO3Language();
3303N/A if (!result.equals("aaa")) {
3303N/A errln("ERROR: getISO3Language() returns: " + result +
3303N/A " for locale '" + locale + "' rather than returning it as is" );
3303N/A }
3303N/A
3303N/A // Try an invalid two letter language code, and check whether it
3303N/A // throws a MissingResourceException.
3303N/A locale = new Locale("zz", "CCC");
3303N/A
0N/A try {
3303N/A result = locale.getISO3Language();
0N/A
0N/A errln("ERROR: getISO3Language() returns: " + result +
0N/A " for locale '" + locale + "' rather than exception" );
0N/A } catch(MissingResourceException e) { }
0N/A }
0N/A
0N/A /*
0N/A * @bug 4147552 4778440
0N/A */
0N/A public void Test4147552() {
0N/A Locale[] locales = { new Locale("no", "NO"), new Locale("no", "NO", "B"),
0N/A new Locale("no", "NO", "NY") };
0N/A String[] englishDisplayNames = { "Norwegian (Norway)",
0N/A "Norwegian (Norway,Bokm\u00e5l)",
0N/A "Norwegian (Norway,Nynorsk)" };
0N/A String[] norwegianDisplayNames = { "norsk (Norge)",
0N/A "norsk (Norge,bokm\u00e5l)", "norsk (Norge,nynorsk)" };
0N/A
0N/A for (int i = 0; i < locales.length; i++) {
0N/A Locale loc = locales[i];
0N/A if (!loc.getDisplayName(Locale.US).equals(englishDisplayNames[i]))
0N/A errln("English display-name mismatch: expected " +
0N/A englishDisplayNames[i] + ", got " + loc.getDisplayName());
0N/A if (!loc.getDisplayName(loc).equals(norwegianDisplayNames[i]))
0N/A errln("Norwegian display-name mismatch: expected " +
0N/A norwegianDisplayNames[i] + ", got " +
0N/A loc.getDisplayName(loc));
0N/A }
0N/A }
0N/A
0N/A static String escapeUnicode(String s) {
0N/A StringBuffer buf = new StringBuffer();
0N/A for (int i=0; i<s.length(); ++i) {
0N/A char c = s.charAt(i);
0N/A if (c >= 0x20 && c <= 0x7F) buf.append(c);
0N/A else {
0N/A buf.append("\\u");
0N/A String h = "000" + Integer.toHexString(c);
0N/A if (h.length() > 4) h = h.substring(h.length() - 4);
0N/A buf.append(h);
0N/A }
0N/A }
0N/A return buf.toString();
0N/A }
0N/A}