1 #!/bin/sh 2 3 # 4 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # @test 27 # @bug 4429040 4591027 4814743 28 # @summary Unit test for charset providers 29 # 30 # @build Test FooCharset FooProvider 31 # @run shell basic.sh 32 # @run shell basic.sh ja_JP.eucJP 33 # @run shell basic.sh tr_TR 34 # 35 36 # Command-line usage: sh basic.sh /path/to/build [locale] 37 38 if [ -z "$TESTJAVA" ]; then 39 if [ $# -lt 1 ]; then exit 1; fi 40 TESTJAVA=$1; shift 41 TESTSRC=`pwd` 42 TESTCLASSES=`pwd` 43 fi 44 45 JAVA=$TESTJAVA/bin/java 46 JAR=$TESTJAVA/bin/jar 47 48 JARD=`pwd`/x.jar 49 EXTD=`pwd`/x.ext 50 TESTD=`pwd`/x.test 51 52 CSS='US-ASCII 8859_1 iso-ir-6 UTF-16 windows-1252 !BAR cp1252' 53 54 55 if [ \! -d $EXTD ]; then 56 # Initialize 57 echo Initializing... 58 rm -rf $JARD $EXTD $TESTD 59 mkdir -p $JARD/META-INF/services x.ext 60 echo FooProvider \ 61 >$JARD/META-INF/services/java.nio.charset.spi.CharsetProvider 62 cp $TESTCLASSES/FooProvider.class $TESTCLASSES/FooCharset.class $JARD 63 mkdir $TESTD 64 cp $TESTCLASSES/Test.class $TESTD 65 (cd $JARD; $JAR -cf $EXTD/test.jar *) 66 fi 67 68 if [ $# -gt 0 ]; then 69 # Use locale specified on command line, if it's supported 70 L="$1" 71 shift 72 s=`uname -s` 73 if [ $s != Linux -a $s != SunOS -a $s != Darwin -a $s != AIX ]; then 74 echo "$L: Locales not supported on this system, skipping..." 75 exit 0 76 fi 77 if [ "x`locale -a | grep $L`" != "x$L" ]; then 78 echo "$L: Locale not supported, skipping..." 79 exit 0 80 fi 81 LC_ALL=$L; export LC_ALL 82 fi 83 84 TMP=${TMP:-$TEMP}; TMP=${TMP:-/tmp} 85 cd $TMP 86 87 case `uname` in 88 SunOS | Linux | Darwin | AIX ) CPS=':' ;; 89 Windows* ) CPS=';' ;; 90 *) echo "Unknown platform: `uname`"; exit 1 ;; 91 esac 92 93 failures=0 94 for where in ext app; do 95 for security in none minimal-policy cp-policy; do 96 echo ''; 97 echo "LC_ALL=$LC_ALL where=$where security=$security" 98 av='' 99 if [ $where = ext ]; then 100 av="$av -cp $TESTD -Djava.ext.dirs=$EXTD"; 101 else 102 av="$av -cp $TESTD$CPS$EXTD/test.jar"; 103 fi 104 case $security in 105 none) css="$CSS FOO";; 106 # Minimal policy in this case is more or less carbon copy of jre default 107 # security policy and doesn't give explicit runtime permission 108 # for user provided runtime loadable charsets 109 minimal-policy) css="$CSS !FOO"; 110 av="$av -Djava.security.manager -Djava.security.policy==$TESTSRC/default-pol";; 111 cp-policy) css="$CSS FOO"; 112 av="$av -Djava.security.manager 113 -Djava.security.policy==$TESTSRC/charsetProvider.sp";; 114 esac 115 if (set -x; $JAVA ${TESTVMOPTS} $av Test $css) 2>&1; then 116 continue; 117 else 118 failures=`expr $failures + 1` 119 fi 120 done 121 done 122 123 echo '' 124 if [ $failures -gt 0 ]; 125 then echo "$failures cases failed"; 126 else echo "All cases passed"; fi 127 exit $failures