1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/*
* 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 {
//get the platform default locales
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);
//Run Test
//testing HOST is selected for the default locale,
// if specified on Windows or MacOSX
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);
//testing HOST is NOT selected for the non-default locale, if specified
//Try to find the locale JRE supports which is not the platform default
// (HOST supports that one)
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);
//testing SPI is NOT selected, as there is none.
testRun("SPI,JRE", "adapterTest", "JRE", "en", "US");
testRun("SPI,COMPAT", "adapterTest", "JRE", "en", "US");
//testing the order, variant #1. This assumes en_GB DateFormat data are
// available both in JRE & CLDR
testRun("CLDR,JRE", "adapterTest", "CLDR", "en", "GB");
testRun("CLDR,COMPAT", "adapterTest", "CLDR", "en", "GB");
//testing the order, variant #2. This assumes en_GB DateFormat data are
// available both in JRE & CLDR
testRun("JRE,CLDR", "adapterTest", "JRE", "en", "GB");
testRun("COMPAT,CLDR", "adapterTest", "JRE", "en", "GB");
//testing the order, variant #3 for non-existent locale in JRE
// assuming "haw" is not in JRE.
testRun("JRE,CLDR", "adapterTest", "CLDR", "haw", "");
testRun("COMPAT,CLDR", "adapterTest", "CLDR", "haw", "");
//testing the order, variant #4 for the bug 7196799. CLDR's "zh" data
// should be used in "zh_CN"
testRun("CLDR", "adapterTest", "CLDR", "zh", "CN");
//testing FALLBACK provider. SPI and invalid one cases.
testRun("SPI", "adapterTest", "FALLBACK", "en", "US");
testRun("FOO", "adapterTest", "CLDR", "en", "US");
testRun("BAR,SPI", "adapterTest", "FALLBACK", "en", "US");
//testing 7198834 fix.
testRun("HOST", "bug7198834Test", "", "", "");
//testing 8000245 fix.
testRun("JRE", "tzNameTest", "Europe/Moscow", "", "");
testRun("COMPAT", "tzNameTest", "Europe/Moscow", "", "");
//testing 8000615 fix.
testRun("JRE", "tzNameTest", "America/Los_Angeles", "", "");
testRun("COMPAT", "tzNameTest", "America/Los_Angeles", "", "");
//testing 8001440 fix.
testRun("CLDR", "bug8001440Test", "", "", "");
//testing 8010666 fix.
if (defLang.equals("en")) {
testRun("HOST", "bug8010666Test", "", "", "");
}
//testing 8013086 fix.
testRun("JRE,SPI", "bug8013086Test", "ja", "JP", "");
testRun("COMPAT,SPI", "bug8013086Test", "ja", "JP", "");
//testing 8013903 fix. (Windows only)
testRun("HOST,JRE", "bug8013903Test", "", "", "");
testRun("HOST", "bug8013903Test", "", "", "");
testRun("HOST,COMPAT", "bug8013903Test", "", "", "");
//testing 8027289 fix, if the platform format default is zh_CN
// this assumes Windows' currency symbol for zh_CN is \u00A5, the yen
// (yuan) sign.
if (defFmtLang.equals("zh") && defFmtCtry.equals("CN")) {
testRun("JRE,HOST", "bug8027289Test", "FFE5", "", "");
testRun("COMPAT,HOST", "bug8027289Test", "FFE5", "", "");
testRun("HOST", "bug8027289Test", "00A5", "", "");
}
//testing 8220227 fix. (Windows only)
if (!defLang.equals("en")) {
testRun("HOST", "bug8220227Test", "", "", "");
}
//testing 8228465 fix. (Windows only)
testRun("HOST", "bug8228465Test", "", "", "");
//testing 8232871 fix. (macOS only)
testRun("HOST", "bug8232871Test", "", "", "");
//testing 8232860 fix. (macOS/Windows only)
testRun("HOST", "bug8232860Test", "", "", "");
//testing 8245241 fix.
//jdk.lang.Process.allowAmbiguousCommands=false is needed for properly escaping
//double quotes in the string argument.
testRun("FOO", "bug8245241Test",
"Invalid locale provider adapter \"FOO\" ignored.", "", "");
//testing 8248695 fix.
testRun("HOST", "bug8248695Test", "", "", "");
//testing 8257964 fix. (macOS/Windows only)
testRun("HOST", "bug8257964Test", "", "", "");
}
private static void testRun(String prefList, String methodName,
String param1, String param2, String param3) throws Throwable {
// Build process (without VM flags)
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);
// Evaluate process status
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
if (exitCode != 0) {
throw new RuntimeException("Unexpected exit code: " + exitCode);
}
}
}
|