1 #
   2 # Copyright (c) 2012, 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 8001205
  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 echo "TESTJAVA=${TESTJAVA}"
  43 if [ "${TESTCLASSES}" = "" ]
  44 then
  45   echo "TESTCLASSES not set.  Test cannot execute.  Failed."
  46   exit 1
  47 fi
  48 echo "TESTCLASSES=${TESTCLASSES}"
  49 echo "CLASSPATH=${CLASSPATH}"
  50 
  51 # set platform-dependent variables
  52 OS=`uname -s`
  53 case "$OS" in
  54   SunOS | Linux | *BSD | Darwin )
  55     PS=":"
  56     FS="/"
  57     ;;
  58   Windows* | CYGWIN* )
  59     PS=";"
  60     FS="\\"
  61     ;;
  62   * )
  63     echo "Unrecognized system!"
  64     exit 1;
  65     ;;
  66 esac
  67 
  68 # create an SPI implementation
  69 mk() {
  70   d=`dirname $1`
  71   if [ ! -d $d ]; then mkdir -p $d; fi
  72   cat - >$1
  73 }
  74 
  75 SPIDIR=${TESTCLASSES}${FS}spi
  76 rm -rf ${SPIDIR}
  77 mk ${SPIDIR}${FS}src${FS}tznp.java << EOF
  78 import java.util.spi.TimeZoneNameProvider;
  79 import java.util.Locale;
  80 
  81 public class tznp extends TimeZoneNameProvider {
  82     public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
  83         return "tznp";
  84     }
  85 
  86     public Locale[] getAvailableLocales() {
  87         Locale[] locales = {Locale.GERMAN, Locale.US, Locale.JAPANESE, Locale.CHINESE};
  88         return locales;
  89     }
  90 }
  91 EOF
  92 mk ${SPIDIR}${FS}dest${FS}META-INF${FS}services${FS}java.util.spi.TimeZoneNameProvider << EOF
  93 tznp
  94 EOF
  95 ${TESTJAVA}${FS}bin${FS}javac -d ${SPIDIR}${FS}dest ${SPIDIR}${FS}src${FS}tznp.java
  96 ${TESTJAVA}${FS}bin${FS}jar cvf ${SPIDIR}${FS}tznp.jar -C ${SPIDIR}${FS}dest .
  97 
  98 # get the platform default locales
  99 PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display`
 100 DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
 101 DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
 102 echo "DEFLANG=${DEFLANG}"
 103 echo "DEFCTRY=${DEFCTRY}"
 104 PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format`
 105 DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
 106 DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
 107 echo "DEFFMTLANG=${DEFFMTLANG}"
 108 echo "DEFFMTCTRY=${DEFFMTCTRY}"
 109 
 110 runTest()
 111 {
 112     RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3"
 113     echo ${RUNCMD}
 114     ${RUNCMD}
 115     result=$?
 116     if [ $result -eq 0 ]
 117     then
 118       echo "Execution successful"
 119     else
 120       echo "Execution of the test case failed."
 121       exit $result
 122     fi
 123 }
 124 
 125 # testing HOST is selected for the default locale, if specified on Windows or MacOSX
 126 METHODNAME=adapterTest
 127 PREFLIST=HOST,JRE
 128 case "$OS" in
 129   Windows_NT* )
 130     WINVER=`uname -r`
 131     if [ "${WINVER}" = "5" ]
 132     then
 133       PARAM1=JRE
 134     else
 135       PARAM1=HOST
 136     fi
 137     ;;
 138   CYGWIN_NT-6* | Darwin )
 139     PARAM1=HOST
 140     ;;
 141   * )
 142     PARAM1=JRE
 143     ;;
 144 esac
 145 PARAM2=${DEFLANG}
 146 PARAM3=${DEFCTRY}
 147 runTest
 148 
 149 # testing HOST is NOT selected for the non-default locale, if specified
 150 METHODNAME=adapterTest
 151 PREFLIST=HOST,JRE
 152 PARAM1=JRE
 153 # Try to find the locale JRE supports which is not the platform default (HOST supports that one)
 154 if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then
 155   PARAM2=en
 156   PARAM3=US
 157 elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then 
 158   PARAM2=ja
 159   PARAM3=JP
 160 else
 161   PARAM2=zh
 162   PARAM3=CN
 163 fi
 164 runTest
 165 
 166 # testing SPI is NOT selected, as there is none.
 167 METHODNAME=adapterTest
 168 PREFLIST=SPI,JRE
 169 PARAM1=JRE
 170 PARAM2=en
 171 PARAM3=US
 172 runTest
 173 
 174 # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR
 175 METHODNAME=adapterTest
 176 PREFLIST=CLDR,JRE
 177 PARAM1=CLDR
 178 PARAM2=en
 179 PARAM3=GB
 180 runTest
 181 
 182 # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR
 183 METHODNAME=adapterTest
 184 PREFLIST=JRE,CLDR
 185 PARAM1=JRE
 186 PARAM2=en
 187 PARAM3=GB
 188 runTest
 189 
 190 # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE.
 191 METHODNAME=adapterTest
 192 PREFLIST=JRE,CLDR
 193 PARAM1=CLDR
 194 PARAM2=haw
 195 PARAM3=GB
 196 runTest
 197 
 198 # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN"
 199 METHODNAME=adapterTest
 200 PREFLIST=CLDR
 201 PARAM1=CLDR
 202 PARAM2=zh
 203 PARAM3=CN
 204 runTest
 205 
 206 # testing FALLBACK provider. SPI and invalid one cases.
 207 METHODNAME=adapterTest
 208 PREFLIST=SPI
 209 PARAM1=FALLBACK
 210 PARAM2=en
 211 PARAM3=US
 212 runTest
 213 PREFLIST=FOO
 214 PARAM1=JRE
 215 PARAM2=en
 216 PARAM3=US
 217 runTest
 218 PREFLIST=BAR,SPI
 219 PARAM1=FALLBACK
 220 PARAM2=en
 221 PARAM3=US
 222 runTest
 223 
 224 # testing 7198834 fix. Only works on Windows Vista or upper.
 225 METHODNAME=bug7198834Test
 226 PREFLIST=HOST
 227 PARAM1=
 228 PARAM2=
 229 PARAM3=
 230 runTest
 231 
 232 # testing 8000245 fix.
 233 METHODNAME=tzNameTest
 234 PREFLIST="JRE -Djava.ext.dirs=${SPIDIR}"
 235 PARAM1=Europe/Moscow
 236 PARAM2=
 237 PARAM3=
 238 runTest
 239 
 240 # testing 8000615 fix.
 241 METHODNAME=tzNameTest
 242 PREFLIST="JRE -Djava.ext.dirs=${SPIDIR}"
 243 PARAM1=America/Los_Angeles
 244 PARAM2=
 245 PARAM3=
 246 runTest
 247 
 248 # testing 8001205 fix.
 249 METHODNAME=bug8001205Test
 250 PREFLIST=SPI
 251 PARAM1=
 252 PARAM2=
 253 PARAM3=
 254 runTest
 255 
 256 exit $result