* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
* 8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
* 8150432 8215913 8220227 8228465 8232871 8232860 8236495 8245241
* 8246721 8248695 8257964 8261919
* @summary tests for "java.locale.providers" system property
* @requires vm.flagless
* @library /test/lib
* @build LocaleProviders
* providersrc.spi.src.tznp
* providersrc.spi.src.tznp8013086
* @modules java.base/sun.util.locale
* java.base/sun.util.locale.provider
* @run main/othervm -Djdk.lang.Process.allowAmbiguousCommands=false LocaleProvidersRun
*/
import java.util.Locale;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;
public class LocaleProvidersRun {
public static void main(String[] args) throws Throwable {
Locale platDefLoc = Locale.getDefault(Locale.Category.DISPLAY);
String defLang = platDefLoc.getLanguage();
String defCtry = platDefLoc.getCountry();
System.out.println("DEFLANG = " + defLang);
System.out.println("DEFCTRY = " + defCtry);
Locale platDefFormat = Locale.getDefault(Locale.Category.FORMAT);
String defFmtLang = platDefFormat.getLanguage();
String defFmtCtry = platDefFormat.getCountry();
System.out.println("DEFFMTLANG = " + defFmtLang);
System.out.println("DEFFMTCTRY = " + defFmtCtry);
String osName = System.getProperty("os.name");
String param1 = "JRE";
if(osName.startsWith("Windows") || osName.startsWith("Mac")) {
param1 = "HOST";
}
testRun("HOST,JRE", "adapterTest", param1, defLang, defCtry);
String param2;
String param3;
if (!defLang.equals("en") && !defFmtLang.equals("en")){
param2 = "en";
param3 = "US";
} else if(!defLang.equals("ja") && !defFmtLang.equals("ja")){
param2 = "ja";
param3 = "JP";
} else {
param2 = "zh";
param3 = "CN";
}
testRun("HOST,JRE", "adapterTest", "JRE", param2, param3);
testRun("SPI,JRE", "adapterTest", "JRE", "en", "US");
testRun("SPI,COMPAT", "adapterTest", "JRE", "en", "US");
testRun("CLDR,JRE", "adapterTest", "CLDR", "en", "GB");
testRun("CLDR,COMPAT", "adapterTest", "CLDR", "en", "GB");
testRun("JRE,CLDR", "adapterTest", "JRE", "en", "GB");
testRun("COMPAT,CLDR", "adapterTest", "JRE", "en", "GB");
testRun("JRE,CLDR", "adapterTest", "CLDR", "haw", "");
testRun("COMPAT,CLDR", "adapterTest", "CLDR", "haw", "");
testRun("CLDR", "adapterTest", "CLDR", "zh", "CN");
testRun("SPI", "adapterTest", "FALLBACK", "en", "US");
testRun("FOO", "adapterTest", "CLDR", "en", "US");
testRun("BAR,SPI", "adapterTest", "FALLBACK", "en", "US");
testRun("HOST", "bug7198834Test", "", "", "");
testRun("JRE", "tzNameTest", "Europe/Moscow", "", "");
testRun("COMPAT", "tzNameTest", "Europe/Moscow", "", "");
testRun("JRE", "tzNameTest", "America/Los_Angeles", "", "");
testRun("COMPAT", "tzNameTest", "America/Los_Angeles", "", "");
testRun("CLDR", "bug8001440Test", "", "", "");
if (defLang.equals("en")) {
testRun("HOST", "bug8010666Test", "", "", "");
}
testRun("JRE,SPI", "bug8013086Test", "ja", "JP", "");
testRun("COMPAT,SPI", "bug8013086Test", "ja", "JP", "");
testRun("HOST,JRE", "bug8013903Test", "", "", "");
testRun("HOST", "bug8013903Test", "", "", "");
testRun("HOST,COMPAT", "bug8013903Test", "", "", "");
if (defFmtLang.equals("zh") && defFmtCtry.equals("CN")) {
testRun("JRE,HOST", "bug8027289Test", "FFE5", "", "");
testRun("COMPAT,HOST", "bug8027289Test", "FFE5", "", "");
testRun("HOST", "bug8027289Test", "00A5", "", "");
}
if (!defLang.equals("en")) {
testRun("HOST", "bug8220227Test", "", "", "");
}
testRun("HOST", "bug8228465Test", "", "", "");
testRun("HOST", "bug8232871Test", "", "", "");
testRun("HOST", "bug8232860Test", "", "", "");
testRun("FOO", "bug8245241Test",
"Invalid locale provider adapter \"FOO\" ignored.", "", "");
testRun("HOST", "bug8248695Test", "", "", "");
testRun("HOST", "bug8257964Test", "", "", "");
}
private static void testRun(String prefList, String methodName,
String param1, String param2, String param3) throws Throwable {
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-ea", "-esa",
"-cp", Utils.TEST_CLASS_PATH,
"-Djava.util.logging.config.class=LocaleProviders$LogConfig",
"-Djava.locale.providers=" + prefList,
"--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED",
"LocaleProviders", methodName, param1, param2, param3);
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Unexpected exit code: " + exitCode);
}
}
}