1 #!/bin/sh 2 # 3 # Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 # 6 # This code is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 only, as 8 # published by the Free Software Foundation. 9 # 10 # This code is distributed in the hope that it will be useful, but WITHOUT 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 # version 2 for more details (a copy is included in the LICENSE file that 14 # accompanied this code). 15 # 16 # You should have received a copy of the GNU General Public License version 17 # 2 along with this work; if not, write to the Free Software Foundation, 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 # 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 # or visit www.oracle.com if you need additional information or have any 22 # questions. 23 # 24 # 25 # @test 26 # @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577 27 # 8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006 28 # 8150432 29 # @summary tests for "java.locale.providers" system property 30 # @modules java.base/sun.util.locale 31 # java.base/sun.util.locale.provider 32 # @compile LocaleProviders.java 33 # @run shell/timeout=600 LocaleProviders.sh 34 35 if [ "${TESTSRC}" = "" ] 36 then 37 echo "TESTSRC not set. Test cannot execute. Failed." 38 exit 1 39 fi 40 echo "TESTSRC=${TESTSRC}" 41 if [ "${TESTJAVA}" = "" ] 42 then 43 echo "TESTJAVA not set. Test cannot execute. Failed." 44 exit 1 45 fi 46 if [ "${COMPILEJAVA}" = "" ] 47 then 48 COMPILEJAVA="${TESTJAVA}" 49 fi 50 echo "TESTJAVA=${TESTJAVA}" 51 if [ "${TESTCLASSES}" = "" ] 52 then 53 echo "TESTCLASSES not set. Test cannot execute. Failed." 54 exit 1 55 fi 56 echo "TESTCLASSES=${TESTCLASSES}" 57 echo "CLASSPATH=${CLASSPATH}" 58 59 # set platform-dependent variables 60 OS=`uname -s` 61 case "$OS" in 62 SunOS | Linux | *BSD | Darwin | AIX ) 63 PS=":" 64 FS="/" 65 ;; 66 Windows* | CYGWIN* ) 67 PS=";" 68 FS="\\" 69 ;; 70 * ) 71 echo "Unrecognized system!" 72 exit 1; 73 ;; 74 esac 75 76 # create SPI implementations 77 mk() { 78 d=`dirname $1` 79 if [ ! -d $d ]; then mkdir -p $d; fi 80 cat - >$1 81 } 82 83 SPIDIR=${TESTCLASSES}${FS}spi 84 rm -rf ${SPIDIR} 85 mk ${SPIDIR}${FS}src${FS}tznp.java << EOF 86 import java.util.spi.TimeZoneNameProvider; 87 import java.util.Locale; 88 89 public class tznp extends TimeZoneNameProvider { 90 public String getDisplayName(String ID, boolean daylight, int style, Locale locale) { 91 return "tznp"; 92 } 93 94 public Locale[] getAvailableLocales() { 95 Locale[] locales = {Locale.US}; 96 return locales; 97 } 98 } 99 EOF 100 mk ${SPIDIR}${FS}src${FS}tznp8013086.java << EOF 101 import java.util.spi.TimeZoneNameProvider; 102 import java.util.Locale; 103 import java.util.TimeZone; 104 105 public class tznp8013086 extends TimeZoneNameProvider { 106 public String getDisplayName(String ID, boolean daylight, int style, Locale locale) { 107 if (!daylight && style==TimeZone.LONG) { 108 return "tznp8013086"; 109 } else { 110 return null; 111 } 112 } 113 114 public Locale[] getAvailableLocales() { 115 Locale[] locales = {Locale.JAPAN}; 116 return locales; 117 } 118 } 119 EOF 120 mk ${SPIDIR}${FS}dest${FS}META-INF${FS}services${FS}java.util.spi.TimeZoneNameProvider << EOF 121 tznp 122 tznp8013086 123 EOF 124 125 EXTRAOPTS="-XaddExports:java.base/sun.util.locale=ALL-UNNAMED,java.base/sun.util.locale.provider=ALL-UNNAMED" 126 127 ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${SPIDIR}${FS}dest \ 128 ${SPIDIR}${FS}src${FS}tznp.java \ 129 ${SPIDIR}${FS}src${FS}tznp8013086.java 130 ${COMPILEJAVA}${FS}bin${FS}jar ${TESTTOOLVMOPTS} cvf ${SPIDIR}${FS}tznp.jar -C ${SPIDIR}${FS}dest . 131 132 # get the platform default locales 133 PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display` 134 DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"` 135 DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"` 136 echo "DEFLANG=${DEFLANG}" 137 echo "DEFCTRY=${DEFCTRY}" 138 PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format` 139 DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"` 140 DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"` 141 echo "DEFFMTLANG=${DEFFMTLANG}" 142 echo "DEFFMTCTRY=${DEFFMTCTRY}" 143 144 runTest() 145 { 146 RUNCMD="${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES}${PS}${SPICLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3" 147 echo ${RUNCMD} 148 ${RUNCMD} 149 result=$? 150 if [ $result -eq 0 ] 151 then 152 echo "Execution successful" 153 else 154 echo "Execution of the test case failed." 155 exit $result 156 fi 157 } 158 159 # testing HOST is selected for the default locale, if specified on Windows or MacOSX 160 METHODNAME=adapterTest 161 PREFLIST=HOST,JRE 162 case "$OS" in 163 Windows_NT* ) 164 WINVER=`uname -r` 165 if [ "${WINVER}" = "5" ] 166 then 167 PARAM1=JRE 168 else 169 PARAM1=HOST 170 fi 171 ;; 172 CYGWIN_NT-6* | CYGWIN_NT-10* | Darwin ) 173 PARAM1=HOST 174 ;; 175 * ) 176 PARAM1=JRE 177 ;; 178 esac 179 PARAM2=${DEFLANG} 180 PARAM3=${DEFCTRY} 181 runTest 182 183 # testing HOST is NOT selected for the non-default locale, if specified 184 METHODNAME=adapterTest 185 PREFLIST=HOST,JRE 186 PARAM1=JRE 187 # Try to find the locale JRE supports which is not the platform default (HOST supports that one) 188 if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then 189 PARAM2=en 190 PARAM3=US 191 elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then 192 PARAM2=ja 193 PARAM3=JP 194 else 195 PARAM2=zh 196 PARAM3=CN 197 fi 198 SPICLASSES= 199 runTest 200 201 # testing SPI is NOT selected, as there is none. 202 METHODNAME=adapterTest 203 PREFLIST=SPI,JRE 204 PARAM1=JRE 205 PARAM2=en 206 PARAM3=US 207 SPICLASSES= 208 runTest 209 PREFLIST=SPI,COMPAT 210 runTest 211 212 # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR 213 METHODNAME=adapterTest 214 PREFLIST=CLDR,JRE 215 PARAM1=CLDR 216 PARAM2=en 217 PARAM3=GB 218 SPICLASSES= 219 runTest 220 PREFLIST=CLDR,COMPAT 221 runTest 222 223 # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR 224 METHODNAME=adapterTest 225 PREFLIST=JRE,CLDR 226 PARAM1=JRE 227 PARAM2=en 228 PARAM3=GB 229 SPICLASSES= 230 runTest 231 PREFLIST=COMPAT,CLDR 232 runTest 233 234 # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE. 235 METHODNAME=adapterTest 236 PREFLIST=JRE,CLDR 237 PARAM1=CLDR 238 PARAM2=haw 239 PARAM3= 240 SPICLASSES= 241 runTest 242 PREFLIST=COMPAT,CLDR 243 runTest 244 245 # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN" 246 METHODNAME=adapterTest 247 PREFLIST=CLDR 248 PARAM1=CLDR 249 PARAM2=zh 250 PARAM3=CN 251 SPICLASSES= 252 runTest 253 254 # testing FALLBACK provider. SPI and invalid one cases. 255 METHODNAME=adapterTest 256 PREFLIST=SPI 257 PARAM1=FALLBACK 258 PARAM2=en 259 PARAM3=US 260 SPICLASSES= 261 runTest 262 PREFLIST=FOO 263 PARAM1=CLDR 264 PARAM2=en 265 PARAM3=US 266 SPICLASSES= 267 runTest 268 PREFLIST=BAR,SPI 269 PARAM1=FALLBACK 270 PARAM2=en 271 PARAM3=US 272 SPICLASSES= 273 runTest 274 275 # testing 7198834 fix. Only works on Windows Vista or upper. 276 METHODNAME=bug7198834Test 277 PREFLIST=HOST 278 PARAM1= 279 PARAM2= 280 PARAM3= 281 SPICLASSES= 282 runTest 283 284 # testing 8000245 fix. 285 METHODNAME=tzNameTest 286 PREFLIST=JRE 287 PARAM1=Europe/Moscow 288 PARAM2= 289 PARAM3= 290 SPICLASSES=${SPIDIR} 291 runTest 292 PREFLIST=COMPAT 293 runTest 294 295 # testing 8000615 fix. 296 METHODNAME=tzNameTest 297 PREFLIST=JRE 298 PARAM1=America/Los_Angeles 299 PARAM2= 300 PARAM3= 301 SPICLASSES=${SPIDIR} 302 runTest 303 PREFLIST=COMPAT 304 runTest 305 306 # testing 8001440 fix. 307 METHODNAME=bug8001440Test 308 PREFLIST=CLDR 309 PARAM1= 310 PARAM2= 311 PARAM3= 312 SPICLASSES= 313 runTest 314 315 # testing 8010666 fix. 316 if [ "${DEFLANG}" = "en" ] 317 then 318 METHODNAME=bug8010666Test 319 PREFLIST=HOST 320 PARAM1= 321 PARAM2= 322 PARAM3= 323 SPICLASSES= 324 runTest 325 fi 326 327 # testing 8013086 fix. 328 METHODNAME=bug8013086Test 329 PREFLIST=JRE,SPI 330 PARAM1=ja 331 PARAM2=JP 332 PARAM3= 333 SPICLASSES=${SPIDIR} 334 runTest 335 PREFLIST=COMPAT,SPI 336 runTest 337 338 # testing 8013903 fix. (Windows only) 339 METHODNAME=bug8013903Test 340 PREFLIST=HOST,JRE 341 PARAM1= 342 PARAM2= 343 PARAM3= 344 SPICLASSES= 345 runTest 346 PREFLIST=HOST 347 runTest 348 PREFLIST=HOST,COMPAT 349 runTest 350 351 # testing 8027289 fix, if the platform format default is zh_CN 352 # this assumes Windows' currency symbol for zh_CN is \u00A5, the yen 353 # (yuan) sign. 354 if [ "${DEFFMTLANG}" = "zh" ] && [ "${DEFFMTCTRY}" = "CN" ]; then 355 METHODNAME=bug8027289Test 356 PREFLIST=JRE,HOST 357 PARAM1=FFE5 358 PARAM2= 359 PARAM3= 360 SPICLASSES= 361 runTest 362 PREFLIST=COMPAT,HOST 363 runTest 364 PREFLIST=HOST 365 PARAM1=00A5 366 runTest 367 fi 368 369 exit $result