basic.sh 3.8 KB
Newer Older
1 2 3
#!/bin/sh

#
4
# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
21 22 23
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#

# @test
# @bug 4429040 4591027 4814743
# @summary Unit test for charset providers
#
# @build Test FooCharset FooProvider
# @run shell basic.sh
# @run shell basic.sh ja_JP.eucJP
# @run shell basic.sh tr_TR
#

# Command-line usage: sh basic.sh /path/to/build [locale]

if [ -z "$TESTJAVA" ]; then
  if [ $# -lt 1 ]; then exit 1; fi
  TESTJAVA=$1; shift
41
  COMPILEJDK="${TESTJAVA}"
42 43 44 45 46
  TESTSRC=`pwd`
  TESTCLASSES=`pwd`
fi

JAVA=$TESTJAVA/bin/java
47
JAR=$COMPILEJAVA/bin/jar
48

49 50
DIR=`pwd`
case `uname` in
51
  SunOS | Linux | Darwin ) CPS=':' ;;
52 53 54 55 56 57 58 59 60 61
  Windows* )      CPS=';' ;;
  CYGWIN*  )
    DIR=`/usr/bin/cygpath -a -s -m $DIR`
    CPS=";";;
  *)              echo "Unknown platform: `uname`"; exit 1 ;;
esac

JARD=$DIR/x.jar
EXTD=$DIR/x.ext
TESTD=$DIR/x.test
62 63 64 65 66 67 68 69 70 71 72 73 74 75

CSS='US-ASCII 8859_1 iso-ir-6 UTF-16 windows-1252 !BAR cp1252'


if [ \! -d $EXTD ]; then
    # Initialize
    echo Initializing...
    rm -rf $JARD $EXTD $TESTD
    mkdir -p $JARD/META-INF/services x.ext
    echo FooProvider \
      >$JARD/META-INF/services/java.nio.charset.spi.CharsetProvider
    cp $TESTCLASSES/FooProvider.class $TESTCLASSES/FooCharset.class $JARD
    mkdir $TESTD
    cp $TESTCLASSES/Test.class $TESTD
76
    (cd $JARD; $JAR ${TESTTOOLVMOPTS} -cf $EXTD/test.jar *)
77 78 79 80 81 82 83
fi

if [ $# -gt 0 ]; then
    # Use locale specified on command line, if it's supported
    L="$1"
    shift
    s=`uname -s`
84
    if [ $s != Linux -a $s != SunOS -a $s != Darwin ]; then
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
      echo "$L: Locales not supported on this system, skipping..."
      exit 0
    fi
    if [ "x`locale -a | grep $L`" != "x$L" ]; then
      echo "$L: Locale not supported, skipping..."
      exit 0
    fi
    LC_ALL=$L; export LC_ALL
fi

TMP=${TMP:-$TEMP}; TMP=${TMP:-/tmp}
cd $TMP

failures=0
for where in ext app; do
  for security in none minimal-policy cp-policy; do
    echo '';
    echo "LC_ALL=$LC_ALL where=$where security=$security"
    av=''
    if [ $where = ext ]; then
      av="$av -cp $TESTD -Djava.ext.dirs=$EXTD";
    else
      av="$av -cp $TESTD$CPS$EXTD/test.jar";
    fi
    case $security in
      none)          css="$CSS FOO";;
      # Minimal policy in this case is more or less carbon copy of jre default
      # security policy and doesn't give explicit runtime permission
      # for user provided runtime loadable charsets
      minimal-policy)  css="$CSS !FOO";
		     av="$av -Djava.security.manager -Djava.security.policy==$TESTSRC/default-pol";;
      cp-policy)     css="$CSS FOO";
		     av="$av -Djava.security.manager
		         -Djava.security.policy==$TESTSRC/charsetProvider.sp";;
    esac
120
    if (set -x; $JAVA ${TESTVMOPTS} $av Test $css) 2>&1; then
121 122 123 124 125 126 127 128 129 130 131 132
      continue;
    else
      failures=`expr $failures + 1`
    fi
  done
done

echo ''
if [ $failures -gt 0 ];
  then echo "$failures cases failed";
  else echo "All cases passed"; fi
exit $failures