2115N/A#!/bin/sh
2115N/A
2115N/A#
2362N/A# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2115N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2115N/A#
2115N/A# This code is free software; you can redistribute it and/or modify it
2115N/A# under the terms of the GNU General Public License version 2 only, as
2115N/A# published by the Free Software Foundation.
2115N/A#
2115N/A# This code is distributed in the hope that it will be useful, but WITHOUT
2115N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2115N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2115N/A# version 2 for more details (a copy is included in the LICENSE file that
2115N/A# accompanied this code).
2115N/A#
2115N/A# You should have received a copy of the GNU General Public License version
2115N/A# 2 along with this work; if not, write to the Free Software Foundation,
2115N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2115N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
2115N/A#
2115N/A
2115N/A# @test
2115N/A# @bug 4429040 4591027 4814743
2115N/A# @summary Unit test for charset providers
2115N/A#
2115N/A# @build Test FooCharset FooProvider
2115N/A# @run shell basic.sh
2115N/A# @run shell basic.sh ja_JP.eucJP
2115N/A# @run shell basic.sh tr_TR
2115N/A#
2115N/A
2115N/A# Command-line usage: sh basic.sh /path/to/build [locale]
2115N/A
2115N/Aif [ -z "$TESTJAVA" ]; then
2115N/A if [ $# -lt 1 ]; then exit 1; fi
2115N/A TESTJAVA=$1; shift
2115N/A TESTSRC=`pwd`
2115N/A TESTCLASSES=`pwd`
2115N/Afi
2115N/A
2115N/AJAVA=$TESTJAVA/bin/java
2115N/AJAR=$TESTJAVA/bin/jar
2115N/A
2115N/AJARD=`pwd`/x.jar
2115N/AEXTD=`pwd`/x.ext
2115N/ATESTD=`pwd`/x.test
2115N/A
2115N/ACSS='US-ASCII 8859_1 iso-ir-6 UTF-16 windows-1252 !BAR cp1252'
2115N/A
2115N/A
2115N/Aif [ \! -d $EXTD ]; then
2115N/A # Initialize
2115N/A echo Initializing...
2115N/A rm -rf $JARD $EXTD $TESTD
2115N/A mkdir -p $JARD/META-INF/services x.ext
2115N/A echo FooProvider \
2115N/A >$JARD/META-INF/services/java.nio.charset.spi.CharsetProvider
2115N/A cp $TESTCLASSES/FooProvider.class $TESTCLASSES/FooCharset.class $JARD
2115N/A mkdir $TESTD
2115N/A cp $TESTCLASSES/Test.class $TESTD
2115N/A (cd $JARD; $JAR -cf $EXTD/test.jar *)
2115N/Afi
2115N/A
2115N/Aif [ $# -gt 0 ]; then
2115N/A # Use locale specified on command line, if it's supported
2115N/A L="$1"
2115N/A shift
2115N/A s=`uname -s`
4718N/A if [ $s != Linux -a $s != SunOS -a $s != Darwin ]; then
2115N/A echo "$L: Locales not supported on this system, skipping..."
2115N/A exit 0
2115N/A fi
2115N/A if [ "x`locale -a | grep $L`" != "x$L" ]; then
2115N/A echo "$L: Locale not supported, skipping..."
2115N/A exit 0
2115N/A fi
2115N/A LC_ALL=$L; export LC_ALL
2115N/Afi
2115N/A
2115N/ATMP=${TMP:-$TEMP}; TMP=${TMP:-/tmp}
2115N/Acd $TMP
2115N/A
2115N/Acase `uname` in
4718N/A SunOS | Linux | Darwin ) CPS=':' ;;
2115N/A Windows* ) CPS=';' ;;
2115N/A *) echo "Unknown platform: `uname`"; exit 1 ;;
2115N/Aesac
2115N/A
2115N/Afailures=0
2115N/Afor where in ext app; do
2115N/A for security in none minimal-policy cp-policy; do
2115N/A echo '';
2115N/A echo "LC_ALL=$LC_ALL where=$where security=$security"
2115N/A av=''
2115N/A if [ $where = ext ]; then
2115N/A av="$av -cp $TESTD -Djava.ext.dirs=$EXTD";
2115N/A else
2115N/A av="$av -cp $TESTD$CPS$EXTD/test.jar";
2115N/A fi
2115N/A case $security in
2115N/A none) css="$CSS FOO";;
2115N/A # Minimal policy in this case is more or less carbon copy of jre default
2115N/A # security policy and doesn't give explicit runtime permission
2115N/A # for user provided runtime loadable charsets
2115N/A minimal-policy) css="$CSS !FOO";
2115N/A av="$av -Djava.security.manager -Djava.security.policy==$TESTSRC/default-pol";;
2115N/A cp-policy) css="$CSS FOO";
2115N/A av="$av -Djava.security.manager
2115N/A -Djava.security.policy==$TESTSRC/charsetProvider.sp";;
2115N/A esac
2115N/A if (set -x; $JAVA $av Test $css) 2>&1; then
2115N/A continue;
2115N/A else
2115N/A failures=`expr $failures + 1`
2115N/A fi
2115N/A done
2115N/Adone
2115N/A
2115N/Aecho ''
2115N/Aif [ $failures -gt 0 ];
2115N/A then echo "$failures cases failed";
2115N/A else echo "All cases passed"; fi
2115N/Aexit $failures