Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Locale/LocaleProviders.sh
38813 views
#!/bin/sh1#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 it6# under the terms of the GNU General Public License version 2 only, as7# published by the Free Software Foundation.8#9# This code is distributed in the hope that it will be useful, but WITHOUT10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12# version 2 for more details (a copy is included in the LICENSE file that13# accompanied this code).14#15# You should have received a copy of the GNU General Public License version16# 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 USA20# or visit www.oracle.com if you need additional information or have any21# questions.22#23#24# @test25# @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 801066626# 8013086 8013233 8013903 8015960 8028771 815043227# @summary tests for "java.locale.providers" system property28# @compile -XDignore.symbol.file LocaleProviders.java29# @run shell/timeout=600 LocaleProviders.sh3031if [ "${TESTSRC}" = "" ]32then33echo "TESTSRC not set. Test cannot execute. Failed."34exit 135fi36echo "TESTSRC=${TESTSRC}"37if [ "${TESTJAVA}" = "" ]38then39echo "TESTJAVA not set. Test cannot execute. Failed."40exit 141fi42if [ "${COMPILEJAVA}" = "" ]43then44COMPILEJAVA="${TESTJAVA}"45fi46echo "TESTJAVA=${TESTJAVA}"47if [ "${TESTCLASSES}" = "" ]48then49echo "TESTCLASSES not set. Test cannot execute. Failed."50exit 151fi52echo "TESTCLASSES=${TESTCLASSES}"53echo "CLASSPATH=${CLASSPATH}"5455# set platform-dependent variables56OS=`uname -s`57case "$OS" in58SunOS | Linux | *BSD | Darwin | AIX )59PS=":"60FS="/"61;;62Windows* | CYGWIN* )63PS=";"64FS="\\"65;;66* )67echo "Unrecognized system!"68exit 1;69;;70esac7172# create SPI implementations73mk() {74d=`dirname $1`75if [ ! -d $d ]; then mkdir -p $d; fi76cat - >$177}7879SPIDIR=${TESTCLASSES}${FS}spi80rm -rf ${SPIDIR}81mk ${SPIDIR}${FS}src${FS}tznp.java << EOF82import java.util.spi.TimeZoneNameProvider;83import java.util.Locale;8485public class tznp extends TimeZoneNameProvider {86public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {87return "tznp";88}8990public Locale[] getAvailableLocales() {91Locale[] locales = {Locale.US};92return locales;93}94}95EOF96mk ${SPIDIR}${FS}src${FS}tznp8013086.java << EOF97import java.util.spi.TimeZoneNameProvider;98import java.util.Locale;99import java.util.TimeZone;100101public class tznp8013086 extends TimeZoneNameProvider {102public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {103if (!daylight && style==TimeZone.LONG) {104return "tznp8013086";105} else {106return null;107}108}109110public Locale[] getAvailableLocales() {111Locale[] locales = {Locale.JAPAN};112return locales;113}114}115EOF116mk ${SPIDIR}${FS}dest${FS}META-INF${FS}services${FS}java.util.spi.TimeZoneNameProvider << EOF117tznp118tznp8013086119EOF120${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${SPIDIR}${FS}dest \121${SPIDIR}${FS}src${FS}tznp.java \122${SPIDIR}${FS}src${FS}tznp8013086.java123${COMPILEJAVA}${FS}bin${FS}jar ${TESTTOOLVMOPTS} cvf ${SPIDIR}${FS}tznp.jar -C ${SPIDIR}${FS}dest .124125# get the platform default locales126PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display`127DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`128DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`129echo "DEFLANG=${DEFLANG}"130echo "DEFCTRY=${DEFCTRY}"131PLATDEF=`${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format`132DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`133DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`134echo "DEFFMTLANG=${DEFFMTLANG}"135echo "DEFFMTCTRY=${DEFFMTCTRY}"136137runTest()138{139RUNCMD="${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3"140echo ${RUNCMD}141${RUNCMD}142result=$?143if [ $result -eq 0 ]144then145echo "Execution successful"146else147echo "Execution of the test case failed."148exit $result149fi150}151152# testing HOST is selected for the default locale, if specified on Windows or MacOSX153METHODNAME=adapterTest154PREFLIST=HOST,JRE155case "$OS" in156Windows_NT* )157WINVER=`uname -r`158if [ "${WINVER}" = "5" ]159then160PARAM1=JRE161else162PARAM1=HOST163fi164;;165CYGWIN_NT-6* | CYGWIN_NT-10* | Darwin )166PARAM1=HOST167;;168* )169PARAM1=JRE170;;171esac172PARAM2=${DEFLANG}173PARAM3=${DEFCTRY}174runTest175176# testing HOST is NOT selected for the non-default locale, if specified177METHODNAME=adapterTest178PREFLIST=HOST,JRE179PARAM1=JRE180# Try to find the locale JRE supports which is not the platform default (HOST supports that one)181if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then182PARAM2=en183PARAM3=US184elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then185PARAM2=ja186PARAM3=JP187else188PARAM2=zh189PARAM3=CN190fi191runTest192193# testing SPI is NOT selected, as there is none.194METHODNAME=adapterTest195PREFLIST=SPI,JRE196PARAM1=JRE197PARAM2=en198PARAM3=US199runTest200201# testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR202METHODNAME=adapterTest203PREFLIST=CLDR,JRE204PARAM1=CLDR205PARAM2=en206PARAM3=GB207runTest208209# testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR210METHODNAME=adapterTest211PREFLIST=JRE,CLDR212PARAM1=JRE213PARAM2=en214PARAM3=GB215runTest216217# testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE.218METHODNAME=adapterTest219PREFLIST=JRE,CLDR220PARAM1=CLDR221PARAM2=haw222PARAM3=GB223runTest224225# testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN"226METHODNAME=adapterTest227PREFLIST=CLDR228PARAM1=CLDR229PARAM2=zh230PARAM3=CN231runTest232233# testing FALLBACK provider. SPI and invalid one cases.234METHODNAME=adapterTest235PREFLIST=SPI236PARAM1=FALLBACK237PARAM2=en238PARAM3=US239runTest240PREFLIST=FOO241PARAM1=JRE242PARAM2=en243PARAM3=US244runTest245PREFLIST=BAR,SPI246PARAM1=FALLBACK247PARAM2=en248PARAM3=US249runTest250251# testing 7198834 fix. Only works on Windows Vista or upper.252METHODNAME=bug7198834Test253PREFLIST=HOST254PARAM1=255PARAM2=256PARAM3=257runTest258259# testing 8000245 fix.260METHODNAME=tzNameTest261PREFLIST="JRE -Djava.ext.dirs=${SPIDIR}"262PARAM1=Europe/Moscow263PARAM2=264PARAM3=265runTest266267# testing 8000615 fix.268METHODNAME=tzNameTest269PREFLIST="JRE -Djava.ext.dirs=${SPIDIR}"270PARAM1=America/Los_Angeles271PARAM2=272PARAM3=273runTest274275# testing 8001440 fix.276METHODNAME=bug8001440Test277PREFLIST=CLDR278PARAM1=279PARAM2=280PARAM3=281runTest282283# testing 8010666 fix.284if [ "${DEFLANG}" = "en" ]285then286METHODNAME=bug8010666Test287PREFLIST=HOST288PARAM1=289PARAM2=290PARAM3=291runTest292fi293294# testing 8013086 fix.295METHODNAME=bug8013086Test296PREFLIST="JRE,SPI -Djava.ext.dirs=${SPIDIR}"297PARAM1=ja298PARAM2=JP299PARAM3=300runTest301302# testing 8013903 fix. (Windows only)303METHODNAME=bug8013903Test304PREFLIST=HOST,JRE305PARAM1=306PARAM2=307PARAM3=308runTest309METHODNAME=bug8013903Test310PREFLIST=HOST311PARAM1=312PARAM2=313PARAM3=314runTest315316exit $result317318319