LocaleTest.java revision 831
0N/A * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613 0N/A * 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951 831N/A * 4147315 4147317 4147552 4335196 4778440 5010672 6475525 6544471 6627549 6786276 0N/A * @summary test Locales 0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved 0N/A * Portions copyright (c) 2007 Sun Microsystems, Inc. 0N/A * All Rights Reserved. 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 * This notice and attribution to Taligent may not be removed. 0N/A * Taligent is a registered trademark of Taligent, Inc. 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 * for further important copyright and licensing information. 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 {
"en",
"fr",
"hr",
"el",
"no",
"it",
"xx" },
0N/A {
"US",
"FR",
"HR",
"GR",
"NO",
"",
"YY" },
0N/A {
"",
"",
"",
"",
"NY",
"",
"" },
0N/A {
"en_US",
"fr_FR",
"hr_HR",
"el_GR",
"no_NO_NY",
"it",
"xx_YY" },
0N/A {
"eng",
"fra",
"hrv",
"ell",
"nor",
"ita",
"" },
0N/A {
"USA",
"FRA",
"HRV",
"GRC",
"NOR",
"",
"" },
0N/A // LCID (not currently public) 0N/A {
"0409",
"040c",
"041a",
"0408",
"0814",
"",
"" },
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 // 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 // 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 // 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 // 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 logln(
"Same thing without variant codes...");
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 * @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 errln(
"Some of the test variables point to the same locale!");
0N/A errln(
"clone() failed to produce a valid object!");
0N/A errln(
"clone() or equals() failed: objects that should compare equal don't");
0N/A errln(
"equals() failed: objects that shouldn't compare equal do");
0N/A errln(
"hashCode() failed: objects that should have the same hash code don't");
0N/A * @bug 4011756 4011380 0N/A errln(
"getISO3Language() on xx_YY returned " +
result +
" instead of throwing an exception");
0N/A errln(
"getISO3Country() on xx_YY returned " +
result +
" instead of throwing an exception");
0N/A * @bug 4106155 4118587 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 "he",
"id",
"iu",
"ug",
"yi",
"za" };
0N/A errln(
test[i] +
" appears in an out-of-order position in the list.");
0N/A String[]
spotCheck2 = {
"US",
"CA",
"GB",
"FR",
"DE",
"IT",
"JP",
"KR",
"CN",
"TW",
"TH" };
0N/A errln(
test[i] +
" appears in an out-of-order position in the list.");
0N/A errln(
"Changed internal country code list!");
0N/A errln(
"Changes internal language code list!");
0N/A errln(
"Locale.getAvailableLocales() returned no installed locales!");
0N/A errln(
"Locale.getAvailableLocales() doesn't clone its internal storage!");
0N/Atest commented out pending API-change approval 0N/A public void TestGetLanguagesForCountry() { 0N/A String[] languages = Locale.getLanguagesForCountry("US"); 0N/A if (!searchStringArrayFor("en", languages)) 0N/A errln("Didn't get en as a language for US"); 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 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 languages = Locale.getLanguagesForCountry("JP"); 0N/A if (!searchStringArrayFor("ja", languages)) 0N/A errln("Didn't get ja as a language for JP"); 0N/A errln(
"Locale failed to deserialize correctly.");
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 // This test checks to make sure getISO3Language and getISO3Country work right 0N/A // even for locales that are not installed. 0N/A * @bug 4052404 4778440 0N/A errln(
"Got back wrong language code for Hebrew: expected \"iw\", got \"" +
0N/A errln(
"Got back wrong language code for Yiddish: expected \"ji\", got \"" +
0N/A errln(
"Got back wrong language code for Indonesian: expected \"in\", got \"" +
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 * 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 "Japanese (South Africa)",
0N/A "Spanish (Germany)",
0N/A "Dominican Republic",
0N/A "japonais (Afrique du Sud)",
0N/A "espagnol (Allemagne)",
0N/A "R\u00e9publique Dominicaine",
0N/A "japon\u00E9s (Sud\u00E1frica)",
0N/A "ruso (M\u00e9xico)",
0N/A "ingl\u00E9s (Francia)",
0N/A "espa\u00f1ol (Alemania)",
0N/A "Rep\u00fablica Dominicana",
0N/A // save the default locale and set to the new default to en_US 0N/A // restore the default locale for other tests 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 // all other exception types propagate through here back to the test harness 0N/A errln(
"Locale.getDefault() allowed us to set default to NULL!");
0N/A errln(
"Trying to set default locale to NULL didn't throw exception!");
0N/A * This would be better tested by the LocaleDataTest. Will move it when I 0N/A * get the LocaleDataTest working again. 0N/A errln(
"Thai currency prefix wrong: expected \"\u0e3f\", got \"" +
0N/A errln(
"Thai currency suffix wrong: expected \"\", got \"" +
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 * 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 * DON'T ASSUME: Any specific countries support the Euro. Instead, 0N/A * iterate through all locales. 0N/A "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
0N/A * toString() doesn't work with language_VARIANT. 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 * Couldn't reproduce this bug -- probably was fixed earlier. 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 * 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 // Make sure that o circumflex (\u00F4) is NOT there, and 0N/A // o double acute (\u0151) IS. 0N/A errln(
"Fail: Monday in Hungarian is wrong");
0N/A * Russian first day of week should be Monday. Confirmed. 0N/A errln(
"Fail: First day of week in Russia should be Monday");
0N/A * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes. 0N/A * Should throw an exception for unknown locales 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 " for locale '" +
locale +
"' rather than exception" );
0N/A * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes. 0N/A * Should throw an exception for unknown locales 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 " for locale '" +
locale +
"' rather than exception" );
0N/A * @bug 4147552 4778440 0N/A "Norwegian (Norway,Bokm\u00e5l)",
0N/A "Norwegian (Norway,Nynorsk)" };
0N/A "norsk (Norge,bokm\u00e5l)",
"norsk (Norge,nynorsk)" };
0N/A errln(
"English display-name mismatch: expected " +
0N/A errln(
"Norwegian display-name mismatch: expected " +