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