Path: blob/master/test/jdk/java/util/Locale/PrintDefaultLocale.java
41149 views
/*1* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23*24*25* (C) Copyright IBM Corp. 1998 - All Rights Reserved26*27* Portions copyright (c) 2007 Sun Microsystems, Inc.28* All Rights Reserved.29*30* The original version of this source code and documentation31* is copyrighted and owned by Taligent, Inc., a wholly-owned32* subsidiary of IBM. These materials are provided under terms33* of a License Agreement between Taligent and Sun. This technology34* is protected by multiple US and International patents.35*36* This notice and attribution to Taligent may not be removed.37* Taligent is a registered trademark of Taligent, Inc.38*39* Permission to use, copy, modify, and distribute this software40* and its documentation for NON-COMMERCIAL purposes and without41* fee is hereby granted provided that this copyright notice42* appears in all copies. Please refer to the file "copyright.html"43* for further important copyright and licensing information.44*45* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF46* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED47* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A48* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR49* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR50* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.51*52*/53/*54@bug 4123370 4091969 4118731 4182108 47784405556The "at-test" tag was removed from this file, because there's no way to57run this test in an automated test harness. It depends on having various58different locales installed on the machine, and on Windows it depends59on the user going to the "Regional Settings" control panel and changing60the settings before running the test for each bug. We can run this test61manually from time to time to ensure that there has been no regression,62but it's not automated. -- lwerner, 7/6/986364INSTRUCTIONS FOR RUNNING THIS TEST65==================================66This test is designed to check for problems in the JVM code that initializes the67default Java locale (the locale returned by Locale.getDefault()) from the system68locale settings (or from command-line arguments). Since detecting a regression69usually requires setting the environment up in some way prior to running the test,70this is a manual test.7172The test simply prints out the internal ID and display name of the default Java locale,73and the name of the default Java character encoding. It passes if these are what74you expect them to be, and fails if they're not.7576Bug #4091969:77To test for bug #4091969, run this test on a Korean-localized version of78Windows, with the default locale set to Korean. You should get "ko_KR"79as the default locale.8081Bug #4123370:82One part of bug #4123370 duplicates bug #4091969, which is covered by the83instructions above.8485To test the unique part of bug #4123370, use the "Regional Settings" control86panel to set the currect locale to each of the different Spanish-language locales.87Run this test once for each Spanish-language locale. You should see the appropriate88locale ID and name for each locale. Both "Spanish - Traditional Sort" and89"Spanish - Modern Sort" should produce "es_ES" and "Spanish (Spain)".9091Bug #4118731:92The basic issue here was that we had changed so that calling getDisplayName()93on a locale that didn't include a country code no longer included a country94name (instead of picking a default country name, as before), which is the95right answer. The problem is we weren't always getting back a system default96locale from Solaris that includes a country code, even though we should.9798To test this, set the system default locale to a locale that doesn't include99a country code, such as "fr" or "de", using (in the C shell) "setenv LC_ALL fr"100(or whatever the locale ID you want is). Running PrintDefaultLocale should101still produce a locale ID, and a locale display name, that include a country102code (and country name). [Remember to make sure the locale is actually installed103first.]104105To test the specific complaint in the bug, use "setenv LC_ALL ja". Also pay106special attention to Solaris locale IDs that don't match the corresponding java107locales, such as "su" (which should turn into "fi_FI"), "cz" (which should turn108into "cs_CZ"), and "en_UK" (which should turn into "en_GB").109110Bug #4079167:111Test this bug the same way you test bug #4118731. Set the locale to each of112the specified locale IDs (e.g., "setenv LC_ALL japanese"), and then run113PrintDefaultLocale. You should get the following results:114Solaris ID Java ID Java display name Encoding115========== ======= ==================== ========116japanese ja_JP Japanese (Japan) --117korean ko_KR Korean (South Korea) --118tchinese zh_TW Chinese (Taiwan) --119big5 zh_TW Chinese (Taiwan) Big5120(Where "--" is marked for "encoding," the result isn't important-- it's the121default encoding for that locale, which we don't test. It should be something122plausible. Also note that this test presupposed you actually have locales123with these names installed on your system.)124125Bug #4154559, 4778440:126Set the locale to Norwegian (Bokmal) and Norwegian (Nynorsk) using the127Regional Settings control panel on Windows. For each setting, run this program.128You should see no_NO and no_NO_NY, respectively.129130Bug #4182108:131Test this bug the same way you test bug #4118731. Set the locale to132each of the specified locale IDs (e.g., "setenv LC_ALL japanese"), and133then run PrintDefaultLocale. You should get the following results:134135Solaris ID Java ID Encoding136========== ======= ========137cz cs_CZ --138su fi_FI --139fr.ISO8859-15 fr_FR ISO8859-15140fr.ISO8859-15@euro fr_FR ISO8859-15141142Where "--" is marked for "encoding," the result isn't important-- it's143the default encoding for that locale, which we don't test. It should be144something plausible. Also note that this test presupposed you actually145have locales with these names installed on your system.146147As of this writing, there is a bug in Solaris or in the 8859-15/euro148patch for 2.6 (Solaris patch 106842-01) which causes nl_langinfo() to149return the wrong value for 8859-15 locales. As a result, the encoding150returned by this test is currency ISO8859-1 for 8859-15 locales.151152Bug #4778440, 5005601, 5074060, 5107154:153Run the "deflocale" tool found in "data" directory (deflocale.sh on Unix,154deflocale.exe on Windows), and check the following:1551564778440: Check that iw_IL is the default locale if the OS's locale is157Hebrew, and in_ID for Indonesian.1585005601: For Norwegian locales, no_NO is selected for Bokmal, and no_NO_NY159is selected for Nynorsk.1605074060, 5107154: On Windows XP ServicePack 2, check the default locales for the161following Windows locales. Compare with the golden data (deflocale.win):162Bengali - India163Croatian - Bosnia and Herzegovina164Bosnian - Bosnia and Herzegovina165Serbian (Latin) - Bosnia and Herzegovina166Serbian (Cyrillic) - Bosnia and Herzegovina167Welsh - United Kingdom168Maori - New Zealand169Malayalam - India170Maltese - Malta171Quechua - Bolivia172Quechua - Ecuador173Quechua - Peru174Setswana (Tswana) - South Africa175isiXhosa (Xhosa) - South Africa176isiZulu ( Zulu) - South Africa177Sesotho sa Leboa (Northern Sotho) - South Africa178Sami, Northern - Norway179Sami, Northern - Sweden180Sami, Northern - Finland181Sami, Lule - Norway182Sami, Lule - Sweden183Sami, Southern - Norway184Sami, Southern - Sweden185Sami, Skolt - Finland186Sami, Inari - Finland187188Bug # 6409997:189Run the "deflocale.exe" tool found in "data" directory on Windows Vista.190It contains the following new locales:191Tajik (Cyrillic) (Tajikistan) - 1251192Upper Sorbian (Germany) - 1252193Turkmen (Turkmenistan) - 1250194Oriya (India) - 0195Assamese (India) - 0196Tibetan (People's Republic of China) - 0197Khmer (Cambodia) - 0198Lao (Lao P.D.R.) - 0199Sinhala (Sri Lanka) - 0200Inuktitut (Canada) - 0201Amharic (Ethiopia) - 0202Hausa (Latin) (Nigeria) - 1252203Yoruba (Nigeria) - 1252204Bashkir (Russia) - 1251205Greenlandic (Greenland) - 1252206Igbo (Nigeria) - 1252207Yi (People's Republic of China) - 0208Breton (France) - 1252209Uighur (People's Republic of China) - 1256210Occitan (France) - 1252211Corsican (France) - 1252212Alsatian (France) - 1252213Yakut (Russia) - 1251214K'iche (Guatemala) - 1252215Kinyarwanda (Rwanda) - 1252216Wolof (Senegal) - 1252217Dari (Afghanistan) - 1256218Lower Sorbian (Germany) - 1252219Bengali (Bangladesh) - 0220Mongolian (Traditional Mongolian) (People's Republic of China) - 0221Tamazight (Latin) (Algeria) - 1252222English (India) - 1252223English (Malaysia) - 1252224English (Singapore) - 1252225Spanish (United States) - 1252226227*/228import java.nio.charset.Charset;229import java.util.Locale;230231public class PrintDefaultLocale {232public static void main(String[] args) {233System.out.printf("default locale: ID: %s, Name: %s\n",234Locale.getDefault().toString(),235Locale.getDefault().getDisplayName(Locale.US));236System.out.printf("display locale: ID: %s, Name: %s\n",237Locale.getDefault(Locale.Category.DISPLAY).toString(),238Locale.getDefault(Locale.Category.DISPLAY).getDisplayName(Locale.US));239System.out.printf("format locale: ID: %s, Name: %s\n",240Locale.getDefault(Locale.Category.FORMAT).toString(),241Locale.getDefault(Locale.Category.FORMAT).getDisplayName(Locale.US));242System.out.printf("default charset: %s\n", Charset.defaultCharset());243}244}245246247