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