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="--add-exports java.base/sun.util.locale=ALL-UNNAMED \ 126 --add-exports java.base/sun.util.locale.provider=ALL-UNNAMED" 127 128 ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${SPIDIR}${FS}dest \ 129 ${SPIDIR}${FS}src${FS}tznp.java \ 130 ${SPIDIR}${FS}src${FS}tznp8013086.java 131 ${COMPILEJAVA}${FS}bin${FS}jar ${TESTTOOLVMOPTS} cvf ${SPIDIR}${FS}tznp.jar -C ${SPIDIR}${FS}dest . 132 133 # get the platform default locales 134 PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display` 135 DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"` 136 DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"` 137 echo "DEFLANG=${DEFLANG}" 138 echo "DEFCTRY=${DEFCTRY}" 139 PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format` 140 DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"` 141 DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"` 142 echo "DEFFMTLANG=${DEFFMTLANG}" 143 echo "DEFFMTCTRY=${DEFFMTCTRY}" 144 145 runTest() 146 { 147 RUNCMD="${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} ${EXTRAOPTS} -classpath ${TESTCLASSES}${PS}${SPICLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3" 148 echo ${RUNCMD} 149 ${RUNCMD} 150 result=$? 151 if [ $result -eq 0 ] 152 then 153 echo "Execution successful" 154 else 155 echo "Execution of the test case failed." 156 exit $result 157 fi 158 } 159 160 # testing HOST is selected for the default locale, if specified on Windows or MacOSX 161 METHODNAME=adapterTest 162 PREFLIST=HOST,JRE 163 case "$OS" in 164 Windows_NT* ) 165 WINVER=`uname -r` 166 if [ "${WINVER}" = "5" ] 167 then 168 PARAM1=JRE 169 else 170 PARAM1=HOST 171 fi 172 ;; 173 CYGWIN_NT-6* | CYGWIN_NT-10* | Darwin ) 174 PARAM1=HOST 175 ;; 176 * ) 177 PARAM1=JRE 178 ;; 179 esac 180 PARAM2=${DEFLANG} 181 PARAM3=${DEFCTRY} 182 runTest 183 184 # testing HOST is NOT selected for the non-default locale, if specified 185 METHODNAME=adapterTest 186 PREFLIST=HOST,JRE 187 PARAM1=JRE 188 # Try to find the locale JRE supports which is not the platform default (HOST supports that one) 189 if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then 190 PARAM2=en 191 PARAM3=US 192 elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then 193 PARAM2=ja 194 PARAM3=JP 195 else 196 PARAM2=zh 197 PARAM3=CN 198 fi 199 SPICLASSES= 200 runTest 201 202 # testing SPI is NOT selected, as there is none. 203 METHODNAME=adapterTest 204 PREFLIST=SPI,JRE 205 PARAM1=JRE 206 PARAM2=en 207 PARAM3=US 208 SPICLASSES= 209 runTest 210 PREFLIST=SPI,COMPAT 211 runTest 212 213 # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR 214 METHODNAME=adapterTest 215 PREFLIST=CLDR,JRE 216 PARAM1=CLDR 217 PARAM2=en 218 PARAM3=GB 219 SPICLASSES= 220 runTest 221 PREFLIST=CLDR,COMPAT 222 runTest 223 224 # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR 225 METHODNAME=adapterTest 226 PREFLIST=JRE,CLDR 227 PARAM1=JRE 228 PARAM2=en 229 PARAM3=GB 230 SPICLASSES= 231 runTest 232 PREFLIST=COMPAT,CLDR 233 runTest 234 235 # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE. 236 METHODNAME=adapterTest 237 PREFLIST=JRE,CLDR 238 PARAM1=CLDR 239 PARAM2=haw 240 PARAM3= 241 SPICLASSES= 242 runTest 243 PREFLIST=COMPAT,CLDR 244 runTest 245 246 # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN" 247 METHODNAME=adapterTest 248 PREFLIST=CLDR 249 PARAM1=CLDR 250 PARAM2=zh 251 PARAM3=CN 252 SPICLASSES= 253 runTest 254 255 # testing FALLBACK provider. SPI and invalid one cases. 256 METHODNAME=adapterTest 257 PREFLIST=SPI 258 PARAM1=FALLBACK 259 PARAM2=en 260 PARAM3=US 261 SPICLASSES= 262 runTest 263 PREFLIST=FOO 264 PARAM1=CLDR 265 PARAM2=en 266 PARAM3=US 267 SPICLASSES= 268 runTest 269 PREFLIST=BAR,SPI 270 PARAM1=FALLBACK 271 PARAM2=en 272 PARAM3=US 273 SPICLASSES= 274 runTest 275 276 # testing 7198834 fix. Only works on Windows Vista or upper. 277 METHODNAME=bug7198834Test 278 PREFLIST=HOST 279 PARAM1= 280 PARAM2= 281 PARAM3= 282 SPICLASSES= 283 runTest 284 285 # testing 8000245 fix. 286 METHODNAME=tzNameTest 287 PREFLIST=JRE 288 PARAM1=Europe/Moscow 289 PARAM2= 290 PARAM3= 291 SPICLASSES=${SPIDIR} 292 runTest 293 PREFLIST=COMPAT 294 runTest 295 296 # testing 8000615 fix. 297 METHODNAME=tzNameTest 298 PREFLIST=JRE 299 PARAM1=America/Los_Angeles 300 PARAM2= 301 PARAM3= 302 SPICLASSES=${SPIDIR} 303 runTest 304 PREFLIST=COMPAT 305 runTest 306 307 # testing 8001440 fix. 308 METHODNAME=bug8001440Test 309 PREFLIST=CLDR 310 PARAM1= 311 PARAM2= 312 PARAM3= 313 SPICLASSES= 314 runTest 315 316 # testing 8010666 fix. 317 if [ "${DEFLANG}" = "en" ] 318 then 319 METHODNAME=bug8010666Test 320 PREFLIST=HOST 321 PARAM1= 322 PARAM2= 323 PARAM3= 324 SPICLASSES= 325 runTest 326 fi 327 328 # testing 8013086 fix. 329 METHODNAME=bug8013086Test 330 PREFLIST=JRE,SPI 331 PARAM1=ja 332 PARAM2=JP 333 PARAM3= 334 SPICLASSES=${SPIDIR} 335 runTest 336 PREFLIST=COMPAT,SPI 337 runTest 338 339 # testing 8013903 fix. (Windows only) 340 METHODNAME=bug8013903Test 341 PREFLIST=HOST,JRE 342 PARAM1= 343 PARAM2= 344 PARAM3= 345 SPICLASSES= 346 runTest 347 PREFLIST=HOST 348 runTest 349 PREFLIST=HOST,COMPAT 350 runTest 351 352 # testing 8027289 fix, if the platform format default is zh_CN 353 # this assumes Windows' currency symbol for zh_CN is \u00A5, the yen 354 # (yuan) sign. 355 if [ "${DEFFMTLANG}" = "zh" ] && [ "${DEFFMTCTRY}" = "CN" ]; then 356 METHODNAME=bug8027289Test 357 PREFLIST=JRE,HOST 358 PARAM1=FFE5 359 PARAM2= 360 PARAM3= 361 SPICLASSES= 362 runTest 363 PREFLIST=COMPAT,HOST 364 runTest 365 PREFLIST=HOST 366 PARAM1=00A5 367 runTest 368 fi 369 370 exit $result