1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright (c) 2010, 2012, 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 COMPILEJDK="${TESTJAVA}" |
|
42 TESTSRC=`pwd` |
|
43 TESTCLASSES=`pwd` |
|
44 fi |
|
45 |
|
46 JAVA=$TESTJAVA/bin/java |
|
47 JAR=$COMPILEJAVA/bin/jar |
|
48 |
|
49 DIR=`pwd` |
|
50 case `uname` in |
|
51 SunOS | Linux | Darwin | AIX ) CPS=':' ;; |
|
52 Windows* ) CPS=';' ;; |
|
53 CYGWIN* ) |
|
54 DIR=`/usr/bin/cygpath -a -s -m $DIR` |
|
55 CPS=";";; |
|
56 *) echo "Unknown platform: `uname`"; exit 1 ;; |
|
57 esac |
|
58 |
|
59 JARD=$DIR/x.jar |
|
60 APPD=$DIR/x.ext |
|
61 TESTD=$DIR/x.test |
|
62 |
|
63 CSS='US-ASCII 8859_1 iso-ir-6 UTF-16 windows-1252 !BAR cp1252' |
|
64 |
|
65 |
|
66 if [ \! -d $APPD ]; then |
|
67 # Initialize |
|
68 echo Initializing... |
|
69 rm -rf $JARD $APPD $TESTD |
|
70 mkdir -p $JARD/META-INF/services x.ext |
|
71 echo FooProvider \ |
|
72 >$JARD/META-INF/services/java.nio.charset.spi.CharsetProvider |
|
73 cp $TESTCLASSES/FooProvider.class $TESTCLASSES/FooCharset.class $JARD |
|
74 mkdir $TESTD |
|
75 cp $TESTCLASSES/Test.class $TESTD |
|
76 (cd $JARD; $JAR ${TESTTOOLVMOPTS} -cf $APPD/test.jar *) |
|
77 fi |
|
78 |
|
79 if [ $# -gt 0 ]; then |
|
80 # Use locale specified on command line, if it's supported |
|
81 L="$1" |
|
82 shift |
|
83 s=`uname -s` |
|
84 if [ $s != Linux -a $s != SunOS -a $s != Darwin -a $s != AIX ]; then |
|
85 echo "$L: Locales not supported on this system, skipping..." |
|
86 exit 0 |
|
87 fi |
|
88 if [ "x`locale -a | grep $L`" != "x$L" ]; then |
|
89 echo "$L: Locale not supported, skipping..." |
|
90 exit 0 |
|
91 fi |
|
92 LC_ALL=$L; export LC_ALL |
|
93 fi |
|
94 |
|
95 TMP=${TMP:-$TEMP}; TMP=${TMP:-/tmp} |
|
96 cd $TMP |
|
97 |
|
98 failures=0 |
|
99 for where in app; do |
|
100 for security in none minimal-policy cp-policy; do |
|
101 echo ''; |
|
102 echo "LC_ALL=$LC_ALL where=$where security=$security" |
|
103 av='' |
|
104 if [ $where = app ]; then |
|
105 av="$av -cp $TESTD$CPS$APPD/test.jar"; |
|
106 fi |
|
107 case $security in |
|
108 none) css="$CSS FOO";; |
|
109 # Minimal policy in this case is more or less carbon copy of jre default |
|
110 # security policy and doesn't give explicit runtime permission |
|
111 # for user provided runtime loadable charsets |
|
112 minimal-policy) css="$CSS !FOO"; |
|
113 av="$av -Djava.security.manager -Djava.security.policy==$TESTSRC/default-pol";; |
|
114 cp-policy) css="$CSS FOO"; |
|
115 av="$av -Djava.security.manager |
|
116 -Djava.security.policy=$TESTSRC/charsetProvider.sp";; |
|
117 esac |
|
118 if (set -x; $JAVA ${TESTVMOPTS} $av Test $css) 2>&1; then |
|
119 continue; |
|
120 else |
|
121 failures=`expr $failures + 1` |
|
122 fi |
|
123 done |
|
124 done |
|
125 |
|
126 echo '' |
|
127 if [ $failures -gt 0 ]; |
|
128 then echo "$failures cases failed"; |
|
129 else echo "All cases passed"; fi |
|
130 exit $failures |
|