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