1 #
   2 # Copyright (c) 2008, 2012, 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 it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  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 #!/bin/ksh -p
  27 #
  28 #   @test    IOExceptionIfEncodedURLTest.sh
  29 #   @bug     6193279 6619458
  30 #   @summary REGRESSION: AppletViewer throws IOException when path is encoded URL
  31 #   @author  Dmitry Cherepanov: area=appletviewer
  32 #   @run compile IOExceptionIfEncodedURLTest.java
  33 #   @run main IOExceptionIfEncodedURLTest
  34 #   @run shell IOExceptionIfEncodedURLTest.sh
  35 
  36 # Beginning of subroutines:
  37 status=1
  38 
  39 #Call this from anywhere to fail the test with an error message
  40 # usage: fail "reason why the test failed"
  41 fail()
  42  { echo "The test failed :-("
  43    echo "$*" 1>&2
  44    echo "exit status was $status"
  45    exit $status
  46  } #end of fail()
  47 
  48 #Call this from anywhere to pass the test with a message
  49 # usage: pass "reason why the test passed if applicable"
  50 pass()
  51  { echo "The test passed!!!"
  52    echo "$*" 1>&2
  53    exit 0
  54  } #end of pass()
  55 
  56 #Call this to run the test with a file name
  57 test()
  58  {
  59    ${TESTJAVA}${FILESEP}bin${FILESEP}appletviewer -Xnosecurity ${URL} > err 2>&1 &
  60    APPLET_ID=$!
  61    sleep 15
  62    kill -9 $APPLET_ID
  63 
  64    # these exceptions will be thrown if the test fails
  65    cat err | grep "I/O exception while reading"
  66    exception=$?
  67    if [ $exception = "0" ];
  68        then fail "test failed for "${URL}", see err file and CRs #6193279,6329251,6376334"
  69    fi
  70 
  71    cat err | grep "java.lang.ClassNotFoundException"
  72    exception=$?
  73    if [ $exception = "0" ];
  74        then fail "test failed for "${URL}", see err file and CRs #6193279,6329251,6376334"
  75    fi
  76 
  77    # the applet will log the same message
  78    cat err | grep "the appletviewer started"
  79    started=$?
  80 
  81    echo $started | grep "2"
  82    if [ $? = 0 ] ;
  83        then fail "test failed for "${URL}": syntax errors or inaccessible files"
  84    fi
  85 
  86    if [ $started = "0" ];
  87        then echo "the test passed for "${URL}
  88        else fail "test failed for "${URL}": the appletviewer behaviour is unexpected: "$started", see err file"
  89    fi
  90  }
  91 
  92 # end of subroutines
  93 
  94 
  95 # The beginning of the script proper
  96 
  97 # Checking for proper OS
  98 OS=`uname -s`
  99 case "$OS" in
 100    SunOS )
 101       VAR="One value for Sun"
 102       DEFAULT_JDK=/
 103       FILESEP="/"
 104       PATHSEP=":"
 105       TMP="/tmp"
 106       ;;
 107 
 108    Linux )
 109       VAR="A different value for Linux"
 110       DEFAULT_JDK=/
 111       FILESEP="/"
 112       PATHSEP=":"
 113       TMP="/tmp"
 114       ;;
 115 
 116    Darwin )
 117       VAR="A different value for MacOSX"
 118       DEFAULT_JDK=/usr
 119       FILESEP="/"
 120       PATHSEP=":"
 121       TMP="/tmp"
 122       ;;
 123 
 124    Windows* )
 125       VAR="A different value for Win32"
 126       DEFAULT_JDK="C:/Program Files/Java/jdk1.8.0"
 127       FILESEP="\\"
 128       PATHSEP=";"
 129       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 130       ;;
 131 
 132     CYGWIN* )
 133       VAR="A different value for Cygwin"
 134       DEFAULT_JDK="/cygdrive/c/Program\ Files/Java/jdk1.8.0"
 135       FILESEP="/"
 136       PATHSEP=";"
 137       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 138       ;;
 139 
 140    # catch all other OSs
 141    * )
 142       echo "Unrecognized system!  $OS"
 143       fail "Unrecognized system!  $OS"
 144       ;;
 145 esac
 146 
 147 # 6438730: Only a minimal set of env variables are set for shell tests.
 148 # To guarantee that env variable holds correct value we need to set it ourselves.
 149 if [ -z "${PWD}" ] ; then
 150     PWD=`pwd`
 151 fi
 152 
 153 # check that some executable or other file you need is available, abort if not
 154 #  note that the name of the executable is in the fail string as well.
 155 # this is how to check for presence of the compiler, etc.
 156 #RESOURCE=`whence SomeProgramOrFileNeeded`
 157 #if [ "${RESOURCE}" = "" ] ;
 158 #   then fail "Need SomeProgramOrFileNeeded to perform the test" ;
 159 #fi
 160 
 161 # Want this test to run standalone as well as in the harness, so do the
 162 #  following to copy the test's directory into the harness's scratch directory
 163 #  and set all appropriate variables:
 164 
 165 if [ -z "${TESTJAVA}" ] ; then
 166    # TESTJAVA is not set, so the test is running stand-alone.
 167    # TESTJAVA holds the path to the root directory of the build of the JDK
 168    # to be tested.  That is, any java files run explicitly in this shell
 169    # should use TESTJAVA in the path to the java interpreter.
 170    # So, we'll set this to the JDK spec'd on the command line.  If none
 171    # is given on the command line, tell the user that and use a cheesy
 172    # default.
 173    # THIS IS THE JDK BEING TESTED.
 174    if [ -n "$1" ] ;
 175       then TESTJAVA=$1
 176       else echo "no JDK specified on command line so using default!"
 177      TESTJAVA=$DEFAULT_JDK
 178    fi
 179    TESTSRC=.
 180    TESTCLASSES=.
 181    STANDALONE=1;
 182 fi
 183 echo "JDK under test is: $TESTJAVA"
 184 
 185 #Deal with .class files:
 186 if [ -n "${STANDALONE}" ] ;
 187    then
 188    #if standalone, remind user to cd to dir. containing test before running it
 189    echo "Just a reminder: cd to the dir containing this test when running it"
 190    # then compile all .java files (if there are any) into .class files
 191    if [ -a *.java ] ;
 192       then echo "Reminder, this test should be in its own directory with all"
 193       echo "supporting files it needs in the directory with it."
 194       ${TESTJAVA}/bin/javac ./*.java ;
 195    fi
 196    # else in harness so copy all the class files from where jtreg put them
 197    # over to the scratch directory this test is running in.
 198    else cp ${TESTCLASSES}/*.class . ;
 199 fi
 200 
 201 #if in test harness, then copy the entire directory that the test is in over
 202 # to the scratch directory.  This catches any support files needed by the test.
 203 #if [ -z "${STANDALONE}" ] ;
 204 #   then cp ${TESTSRC}/* .
 205 #fi
 206 
 207 #Just before executing anything, make sure it has executable permission!
 208 chmod 777 ./*
 209 
 210 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 211 
 212 #All files required for the test should be in the same directory with
 213 # this file.  If converting a standalone test to run with the harness,
 214 # as long as all files are in the same directory and it returns 0 for
 215 # pass, you should be able to cut and paste it into here and it will
 216 # run with the test harness.
 217 
 218 # This is an example of running something -- test
 219 # The stuff below catches the exit status of test then passes or fails
 220 # this shell test as appropriate ( 0 status is considered a pass here )
 221 
 222 # The test verifies that appletviewer correctly works with the different
 223 # names of the files, including relative and absolute paths
 224 
 225 # 6619458: exclude left brace from the name of the files managed by the VCS
 226 NAME='test.html'
 227 
 228 ENCODED='te%7Bst.html'
 229 UNENCODED='te{st.html'
 230 
 231 # Copy needed files into the harness's scratch directory
 232 # or create a copy with the required name if the test is
 233 # running as stand-alone
 234 cp ${TESTSRC}${FILESEP}${NAME} ${UNENCODED}
 235 
 236 # the encoded name, the path is absolute
 237 URL="file:"${PWD}${FILESEP}${ENCODED}
 238 test
 239 
 240 # the encoded name, the path is relative
 241 URL="file:"${ENCODED}
 242 test
 243 
 244 # the unencoded name, the path is absolute
 245 URL="file:"${PWD}${FILESEP}${UNENCODED}
 246 test
 247 
 248 # the unencoded name, the path is relative
 249 URL="file:"${UNENCODED}
 250 test
 251 
 252 # pick up our toys from the scratch directory
 253 rm ${UNENCODED}