Path: blob/master/test/jdk/java/util/Locale/LocaleProvidersRun.java
41149 views
/*1* Copyright (c) 2012, 2021, 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*/2223/*24* @test25* @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 800857726* 8010666 8013086 8013233 8013903 8015960 8028771 8054482 806200627* 8150432 8215913 8220227 8228465 8232871 8232860 8236495 824524128* 8246721 8248695 8257964 826191929* @summary tests for "java.locale.providers" system property30* @library /test/lib31* @build LocaleProviders32* providersrc.spi.src.tznp33* providersrc.spi.src.tznp801308634* @modules java.base/sun.util.locale35* java.base/sun.util.locale.provider36* @run main/othervm -Djdk.lang.Process.allowAmbiguousCommands=false LocaleProvidersRun37*/3839import java.util.Locale;4041import jdk.test.lib.JDKToolLauncher;42import jdk.test.lib.process.ProcessTools;43import jdk.test.lib.Utils;4445public class LocaleProvidersRun {46public static void main(String[] args) throws Throwable {47//get the platform default locales48Locale platDefLoc = Locale.getDefault(Locale.Category.DISPLAY);49String defLang = platDefLoc.getLanguage();50String defCtry = platDefLoc.getCountry();51System.out.println("DEFLANG = " + defLang);52System.out.println("DEFCTRY = " + defCtry);5354Locale platDefFormat = Locale.getDefault(Locale.Category.FORMAT);55String defFmtLang = platDefFormat.getLanguage();56String defFmtCtry = platDefFormat.getCountry();57System.out.println("DEFFMTLANG = " + defFmtLang);58System.out.println("DEFFMTCTRY = " + defFmtCtry);5960//Run Test61//testing HOST is selected for the default locale,62// if specified on Windows or MacOSX63String osName = System.getProperty("os.name");64String param1 = "JRE";65if(osName.startsWith("Windows") || osName.startsWith("Mac")) {66param1 = "HOST";67}68testRun("HOST,JRE", "adapterTest", param1, defLang, defCtry);6970//testing HOST is NOT selected for the non-default locale, if specified71//Try to find the locale JRE supports which is not the platform default72// (HOST supports that one)73String param2;74String param3;75if (!defLang.equals("en") && !defFmtLang.equals("en")){76param2 = "en";77param3 = "US";78} else if(!defLang.equals("ja") && !defFmtLang.equals("ja")){79param2 = "ja";80param3 = "JP";81} else {82param2 = "zh";83param3 = "CN";84}85testRun("HOST,JRE", "adapterTest", "JRE", param2, param3);8687//testing SPI is NOT selected, as there is none.88testRun("SPI,JRE", "adapterTest", "JRE", "en", "US");89testRun("SPI,COMPAT", "adapterTest", "JRE", "en", "US");9091//testing the order, variant #1. This assumes en_GB DateFormat data are92// available both in JRE & CLDR93testRun("CLDR,JRE", "adapterTest", "CLDR", "en", "GB");94testRun("CLDR,COMPAT", "adapterTest", "CLDR", "en", "GB");9596//testing the order, variant #2. This assumes en_GB DateFormat data are97// available both in JRE & CLDR98testRun("JRE,CLDR", "adapterTest", "JRE", "en", "GB");99testRun("COMPAT,CLDR", "adapterTest", "JRE", "en", "GB");100101//testing the order, variant #3 for non-existent locale in JRE102// assuming "haw" is not in JRE.103testRun("JRE,CLDR", "adapterTest", "CLDR", "haw", "");104testRun("COMPAT,CLDR", "adapterTest", "CLDR", "haw", "");105106//testing the order, variant #4 for the bug 7196799. CLDR's "zh" data107// should be used in "zh_CN"108testRun("CLDR", "adapterTest", "CLDR", "zh", "CN");109110//testing FALLBACK provider. SPI and invalid one cases.111testRun("SPI", "adapterTest", "FALLBACK", "en", "US");112testRun("FOO", "adapterTest", "CLDR", "en", "US");113testRun("BAR,SPI", "adapterTest", "FALLBACK", "en", "US");114115//testing 7198834 fix.116testRun("HOST", "bug7198834Test", "", "", "");117118//testing 8000245 fix.119testRun("JRE", "tzNameTest", "Europe/Moscow", "", "");120testRun("COMPAT", "tzNameTest", "Europe/Moscow", "", "");121122//testing 8000615 fix.123testRun("JRE", "tzNameTest", "America/Los_Angeles", "", "");124testRun("COMPAT", "tzNameTest", "America/Los_Angeles", "", "");125126//testing 8001440 fix.127testRun("CLDR", "bug8001440Test", "", "", "");128129//testing 8010666 fix.130if (defLang.equals("en")) {131testRun("HOST", "bug8010666Test", "", "", "");132}133134//testing 8013086 fix.135testRun("JRE,SPI", "bug8013086Test", "ja", "JP", "");136testRun("COMPAT,SPI", "bug8013086Test", "ja", "JP", "");137138//testing 8013903 fix. (Windows only)139testRun("HOST,JRE", "bug8013903Test", "", "", "");140testRun("HOST", "bug8013903Test", "", "", "");141testRun("HOST,COMPAT", "bug8013903Test", "", "", "");142143//testing 8027289 fix, if the platform format default is zh_CN144// this assumes Windows' currency symbol for zh_CN is \u00A5, the yen145// (yuan) sign.146if (defFmtLang.equals("zh") && defFmtCtry.equals("CN")) {147testRun("JRE,HOST", "bug8027289Test", "FFE5", "", "");148testRun("COMPAT,HOST", "bug8027289Test", "FFE5", "", "");149testRun("HOST", "bug8027289Test", "00A5", "", "");150}151152//testing 8220227 fix. (Windows only)153if (!defLang.equals("en")) {154testRun("HOST", "bug8220227Test", "", "", "");155}156157//testing 8228465 fix. (Windows only)158testRun("HOST", "bug8228465Test", "", "", "");159160//testing 8232871 fix. (macOS only)161testRun("HOST", "bug8232871Test", "", "", "");162163//testing 8232860 fix. (macOS/Windows only)164testRun("HOST", "bug8232860Test", "", "", "");165166//testing 8245241 fix.167//jdk.lang.Process.allowAmbiguousCommands=false is needed for properly escaping168//double quotes in the string argument.169testRun("FOO", "bug8245241Test",170"Invalid locale provider adapter \"FOO\" ignored.", "", "");171172//testing 8248695 fix.173testRun("HOST", "bug8248695Test", "", "", "");174175//testing 8257964 fix. (macOS/Windows only)176testRun("HOST", "bug8257964Test", "", "", "");177}178179private static void testRun(String prefList, String methodName,180String param1, String param2, String param3) throws Throwable{181JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");182launcher.addToolArg("-ea")183.addToolArg("-esa")184.addToolArg("-cp")185.addToolArg(Utils.TEST_CLASS_PATH)186.addToolArg("-Djava.util.logging.config.class=LocaleProviders$LogConfig")187.addToolArg("-Djava.locale.providers=" + prefList)188.addToolArg("--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED")189.addToolArg("LocaleProviders")190.addToolArg(methodName)191.addToolArg(param1)192.addToolArg(param2)193.addToolArg(param3);194int exitCode = ProcessTools.executeCommand(launcher.getCommand())195.getExitValue();196if (exitCode != 0) {197throw new RuntimeException("Unexpected exit code: " + exitCode);198}199}200}201202203