LocaleTest.java revision 4358
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* @test
* @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
* 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
* 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
* 6786276 7066203
* @summary test Locales
*/
/*
*
*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - 1998 - 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.
*
*/
public class LocaleTest extends LocaleTestFmwk {
public LocaleTest() {
}
private int ENGLISH = 0;
private int FRENCH = 1;
private int CROATIAN = 2;
private int GREEK = 3;
private int NORWEGIAN = 4;
private int ITALIAN = 5;
private int DUMMY = 6;
private int MAX_LOCALES = 6;
private int LANG = 0;
private int CTRY = 1;
private int VAR = 2;
private int NAME = 3;
private int LANG3 = 4;
private int CTRY3 = 5;
private int LCID = 6;
private int DLANG_EN = 7;
private int DCTRY_EN = 8;
private int DVAR_EN = 9;
private int DNAME_EN = 10;
private int DLANG_FR = 11;
private int DCTRY_FR = 12;
private int DVAR_FR = 13;
private int DNAME_FR = 14;
private int DLANG_HR = 15;
private int DCTRY_HR = 16;
private int DVAR_HR = 17;
private int DNAME_HR = 18;
private int DLANG_EL = 19;
private int DCTRY_EL = 20;
private int DVAR_EL = 21;
private int DNAME_EL = 22;
private int DLANG_ROOT = 23;
private int DCTRY_ROOT = 24;
private int DVAR_ROOT = 25;
private int DNAME_ROOT = 26;
// language code
{ "en", "fr", "hr", "el", "no", "it", "xx" },
// country code
{ "US", "FR", "HR", "GR", "NO", "", "YY" },
// variant code
{ "", "", "", "", "NY", "", "" },
// full name
{ "en_US", "fr_FR", "hr_HR", "el_GR", "no_NO_NY", "it", "xx_YY" },
// ISO-3 language
{ "eng", "fra", "hrv", "ell", "nor", "ita", "" },
// ISO-3 country
{ "USA", "FRA", "HRV", "GRC", "NOR", "", "" },
// LCID (not currently public)
{ "0409", "040c", "041a", "0408", "0814", "", "" },
// display language (English)
{ "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" },
// display country (English)
{ "United States", "France", "Croatia", "Greece", "Norway", "", "YY" },
// display variant (English)
{ "", "", "", "", "Nynorsk", "", ""},
// display name (English)
// Updated no_NO_NY English display name for new pattern-based algorithm
// (part of Euro support).
{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
// display langage (French)
{ "anglais", "fran\u00e7ais", "croate", "grec", "norv\u00e9gien", "italien", "xx" },
// display country (French)
{ "Etats-Unis", "France", "Croatie", "Gr\u00e8ce", "Norv\u00e8ge", "", "YY" },
// display variant (French)
{ "", "", "", "", "", "", "" },
// display name (French)
{ "anglais (Etats-Unis)", "fran\u00e7ais (France)", "croate (Croatie)", "grec (Gr\u00e8ce)", "norv\u00e9gien (Norv\u00e8ge,Nynorsk)", "italien", "xx (YY)" },
// display langage (Croatian)
{ "", "", "hrvatski", "", "", "", "xx" },
// display country (Croatian)
{ "", "", "Hrvatska", "", "", "", "YY" },
// display variant (Croatian)
{ "", "", "", "", "", "", ""},
// display name (Croatian)
{ "", "", "hrvatski (Hrvatska)", "", "", "", "xx (YY)" },
// display langage (Greek)
{ "\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" },
// display country (Greek)
{ "\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" },
// display variant (Greek)
{ "", "", "", "", "", "", "" },
// display name (Greek)
{ "\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)" },
// display langage (<root>)
{ "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" },
// display country (<root>)
{ "United States", "France", "Croatia", "Greece", "Norway", "", "YY" },
// display variant (<root>)
{ "", "", "", "", "Nynorsk", "", ""},
// display name (<root>)
{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
};
}
public void TestBasicGetters() {
for (int i = 0; i <= MAX_LOCALES; i++) {
}
logln("Same thing without variant codes...");
for (int i = 0; i <= MAX_LOCALES; i++) {
}
}
public void TestSimpleResourceInfo() {
for (int i = 0; i <= MAX_LOCALES; i++) {
continue;
/*
// getLCID() is currently private
if (!String.valueOf(testLocale.getLCID()).equals(dataTable[LCID][i]))
errln(" LCID mismatch: " + testLocale.getLCID() + " versus "
+ dataTable[LCID][i]);
*/
}
}
/*
* @bug 4101316
* @bug 4084688 (This bug appears to be a duplicate of something, because it was fixed
* between 1.1.5 and 1.1.6, but I included a new test for it anyway)
* @bug 4052440 Stop falling back to the default locale.
*/
public void TestDisplayNames() {
logln("With default = en_US...");
logln(" In default locale...");
logln(" In locale = en_US...");
logln(" In locale = fr_FR...");
logln(" In locale = hr_HR...");
logln(" In locale = el_GR...");
logln("With default = fr_FR...");
logln(" In default locale...");
logln(" In locale = en_US...");
logln(" In locale = fr_FR...");
logln(" In locale = hr_HR...");
logln(" In locale = el_GR...");
}
for (int i = 0; i <= MAX_LOCALES; i++) {
}
else {
}
}
}
public void TestSimpleObjectStuff() {
errln("Some of the test variables point to the same locale!");
errln("clone() failed to produce a valid object!");
errln("clone() or equals() failed: objects that should compare equal don't");
errln("equals() failed: objects that shouldn't compare equal do");
errln("hashCode() failed: objects that should have the same hash code don't");
}
/**
* @bug 4011756 4011380
*/
public void TestISO3Fallback() {
boolean gotException = false;
try {
}
catch (MissingResourceException e) {
gotException = true;
}
if (!gotException)
gotException = false;
try {
}
catch (MissingResourceException e) {
gotException = true;
}
if (!gotException)
}
/**
* @bug 4106155 4118587 7066203
*/
public void TestGetLangsAndCountries() {
// It didn't seem right to just do an exhaustive test of everything here, so I check
// for the following things:
// 1) Does each list have the right total number of entries?
// 2) Does each list contain certain language and country codes we think are important
// (the G7 countries, plus a couple others)?
// 3) Does each list have every entry formatted correctly? (i.e., two characters,
// all lower case for the language codes, all upper case for the country codes)
// 4) Is each list in sorted order?
"he", "id", "iu", "ug", "yi", "za" };
else {
int j;
break;
}
}
}
else {
int j;
break;
}
}
}
}
/**
* @bug 4126880
*/
void Test4126880() {
errln("Changed internal country code list!");
errln("Changes internal language code list!");
}
/**
* @bug 4107014
*/
public void TestGetAvailableLocales() {
errln("Locale.getAvailableLocales() returned no installed locales!");
else {
}
}
/**
* @bug 4135316
*/
public void TestBug4135316() {
errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
}
/**
* @bug 4107953
*/
/*
test commented out pending API-change approval
public void TestGetLanguagesForCountry() {
String[] languages = Locale.getLanguagesForCountry("US");
if (!searchStringArrayFor("en", languages))
errln("Didn't get en as a language for US");
languages = Locale.getLanguagesForCountry("FR");
if (!searchStringArrayFor("fr", languages))
errln("Didn't get fr as a language for FR");
languages = Locale.getLanguagesForCountry("CH");
if (!searchStringArrayFor("fr", languages))
errln("Didn't get fr as a language for CH");
if (!searchStringArrayFor("it", languages))
errln("Didn't get it as a language for CH");
if (!searchStringArrayFor("de", languages))
errln("Didn't get de as a language for CH");
languages = Locale.getLanguagesForCountry("JP");
if (!searchStringArrayFor("ja", languages))
errln("Didn't get ja as a language for JP");
}
*/
return true;
return false;
}
/**
* @bug 4110613
*/
{
obstream = new ByteArrayOutputStream();
errln("Locale failed to deserialize correctly.");
}
/**
* @bug 4118587
*/
public void TestSimpleDisplayNames() {
// This test is different from TestDisplayNames because TestDisplayNames checks
// fallback behavior, combination of language and country names to form locale
// names, and other stuff like that. This test just checks specific language
// and country codes to make sure we have the correct names for them.
"Zhuang" };
}
}
/**
* @bug 4118595
*/
public void TestUninstalledISO3Names() {
// This test checks to make sure getISO3Language and getISO3Country work right
// even for locales that are not installed.
}
}
}
/**
* @bug 4052404 4778440
*/
public void TestChangedISO639Codes() {
errln("Got back wrong language code for Hebrew: expected \"iw\", got \"" +
errln("Got back wrong language code for Yiddish: expected \"ji\", got \"" +
errln("Got back wrong language code for Indonesian: expected \"in\", got \"" +
}
/**
* @bug 4092475
* I could not reproduce this bug. I'm pretty convinced it was fixed with the
* big locale-data reorg of 10/28/97. The lookup logic for language and country
* display names was also changed at that time in that check-in. --rtg 3/20/98
* This test is not designed to work in any other locale but en_US.
* Most of the LocaleElements do not contain display names for other languages,
* so this test fails (bug 4289223) when run under different locales. For example,
* LocaleElements_es as of kestrel does not have a localized name for Japanese, so
* the getDisplayName method asks the default locale for a display name. The Japanese
* localized name for "Japanese" does not equal "Japanese" so this test fails for es
* display names if run under a ja locale. Eventually, he LocaleElements should probably
* be updated to contain more localized language and region display names.
* 1999-11-19 joconner
*
*/
public void TestAtypicalLocales() {
"Japanese (South Africa)",
"Russian (Mexico)",
"English (France)",
"Spanish (Germany)",
"Croatia",
"Sweden",
"Dominican Republic",
"Belgium" };
"japonais (Afrique du Sud)",
"russe (Mexique)",
"anglais (France)",
"espagnol (Allemagne)",
"Croatie",
"Su\u00e8de",
"R\u00e9publique Dominicaine",
"Belgique" };
"japon\u00E9s (Sud\u00E1frica)",
"ruso (M\u00e9xico)",
"ingl\u00E9s (Francia)",
"espa\u00f1ol (Alemania)",
"Croacia",
"Suecia",
"Rep\u00fablica Dominicana",
"B\u00E9lgica" };
// save the default locale and set to the new default to en_US
}
}
}
// restore the default locale for other tests
}
/**
* @bug 4126371
*/
public void TestNullDefault() {
// why on earth anyone would ever try to do this is beyond me, but we should
// definitely make sure we don't let them
boolean gotException = false;
try {
}
catch (NullPointerException e) {
// all other exception types propagate through here back to the test harness
gotException = true;
}
errln("Locale.getDefault() allowed us to set default to NULL!");
if (!gotException)
errln("Trying to set default locale to NULL didn't throw exception!");
}
/**
* @bug 4135752
* This would be better tested by the LocaleDataTest. Will move it when I
* get the LocaleDataTest working again.
*/
public void TestThaiCurrencyFormat() {
errln("Thai currency prefix wrong: expected \"\u0e3f\", got \"" +
errln("Thai currency suffix wrong: expected \"\", got \"" +
}
/**
* @bug 4122371
* Confirm that Euro support works. This test is pretty rudimentary; all it does
* is check that any locales with the EURO variant format a number using the
* Euro currency symbol.
*
* ASSUME: All locales encode the Euro character "\u20AC".
* If this is changed to use the single-character Euro symbol, this
* test must be updated.
*
* DON'T ASSUME: Any specific countries support the Euro. Instead,
* iterate through all locales.
*/
public void TestEuroSupport() {
}
else {
" formats without " + EURO_CURRENCY +
"\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
}
}
}
}
/**
* @bug 4139504
* toString() doesn't work with language_VARIANT.
*/
public void TestToString() {
};
}
}
}
/**
* @bug 4105828
* Currency symbol in zh is wrong. We will test this at the NumberFormat
* end to test the whole pipe.
*/
public void Test4105828() {
}
}
}
/**
* @bug 4139940
* Couldn't reproduce this bug -- probably was fixed earlier.
*
* ORIGINAL BUG REPORT:
* -- basically, hungarian for monday shouldn't have an \u00f4
* (o circumflex)in it instead it should be an o with 2 inclined
* (right) lines over it..
*
* You may wonder -- why do all this -- why not just add a line to
* LocaleData? Well, I could see by inspection that the locale file had the
* right character in it, so I wanted to check the rest of the pipeline -- a
* very remote possibility, but I wanted to be sure. The other possibility
* is that something is wrong with the font mapping subsystem, but we can't
* test that here.
*/
public void Test4139940() {
// Make sure that o circumflex (\u00F4) is NOT there, and
// o double acute (\u0151) IS.
errln("Fail: Monday in Hungarian is wrong");
}
/**
* @bug 4143951
* Russian first day of week should be Monday. Confirmed.
*/
public void Test4143951() {
errln("Fail: First day of week in Russia should be Monday");
}
}
/**
* @bug 4147315
* java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
* Should throw an exception for unknown locales
*/
public void Test4147315() {
// Try with codes that are the wrong length but happen to match text
// at a valid offset in the mapping table
try {
} catch(MissingResourceException e) { }
}
/**
* @bug 4147317 4940539
* java.util.Locale.getISO3Language() works wrong for non ISO-639 codes.
* Should throw an exception for unknown locales, except they have three
* letter language codes.
*/
public void Test4147317() {
// Try a three letter language code, and check whether it is
// returned as is.
}
// Try an invalid two letter language code, and check whether it
// throws a MissingResourceException.
try {
} catch(MissingResourceException e) { }
}
/*
* @bug 4147552 4778440
*/
public void Test4147552() {
"Norwegian (Norway,Bokm\u00e5l)",
"Norwegian (Norway,Nynorsk)" };
"norsk (Norge,bokm\u00e5l)", "norsk (Norge,nynorsk)" };
errln("English display-name mismatch: expected " +
errln("Norwegian display-name mismatch: expected " +
norwegianDisplayNames[i] + ", got " +
}
}
for (int i=0; i<s.length(); ++i) {
char c = s.charAt(i);
else {
}
}
}
}