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 AIX ) 139 VAR="A different value for AIX" 140 DEFAULT_JDK=/ 141 FILESEP="/" 142 PATHSEP=":" 143 TMP="/tmp" 144 ;; 145 146 # catch all other OSs 147 * ) 148 echo "Unrecognized system! $OS" 149 fail "Unrecognized system! $OS" 150 ;; 151 esac 152 153 # 6438730: Only a minimal set of env variables are set for shell tests. 154 # To guarantee that env variable holds correct value we need to set it ourselves. 155 if [ -z "${PWD}" ] ; then 156 PWD=`pwd` 157 fi 158 159 # check that some executable or other file you need is available, abort if not 160 # note that the name of the executable is in the fail string as well. 161 # this is how to check for presence of the compiler, etc. 162 #RESOURCE=`whence SomeProgramOrFileNeeded` 163 #if [ "${RESOURCE}" = "" ] ; 164 # then fail "Need SomeProgramOrFileNeeded to perform the test" ; 165 #fi 166 167 # Want this test to run standalone as well as in the harness, so do the 168 # following to copy the test's directory into the harness's scratch directory 169 # and set all appropriate variables: 170 171 if [ -z "${TESTJAVA}" ] ; then 172 # TESTJAVA is not set, so the test is running stand-alone. 173 # TESTJAVA holds the path to the root directory of the build of the JDK 174 # to be tested. That is, any java files run explicitly in this shell 175 # should use TESTJAVA in the path to the java interpreter. 176 # So, we'll set this to the JDK spec'd on the command line. If none 177 # is given on the command line, tell the user that and use a cheesy 178 # default. 179 # THIS IS THE JDK BEING TESTED. 180 if [ -n "$1" ] ; 181 then TESTJAVA=$1 182 else echo "no JDK specified on command line so using default!" 183 TESTJAVA=$DEFAULT_JDK 184 fi 185 TESTSRC=. 186 TESTCLASSES=. 187 STANDALONE=1; 188 fi 189 echo "JDK under test is: $TESTJAVA" 190 191 #Deal with .class files: 192 if [ -n "${STANDALONE}" ] ; 193 then 194 #if standalone, remind user to cd to dir. containing test before running it 195 echo "Just a reminder: cd to the dir containing this test when running it" 196 # then compile all .java files (if there are any) into .class files 197 if [ -a *.java ] ; 198 then echo "Reminder, this test should be in its own directory with all" 199 echo "supporting files it needs in the directory with it." 200 ${TESTJAVA}/bin/javac ./*.java ; 201 fi 202 # else in harness so copy all the class files from where jtreg put them 203 # over to the scratch directory this test is running in. 204 else cp ${TESTCLASSES}/*.class . ; 205 fi 206 207 #if in test harness, then copy the entire directory that the test is in over 208 # to the scratch directory. This catches any support files needed by the test. 209 #if [ -z "${STANDALONE}" ] ; 210 # then cp ${TESTSRC}/* . 211 #fi 212 213 #Just before executing anything, make sure it has executable permission! 214 chmod 777 ./* 215 216 ############### YOUR TEST CODE HERE!!!!!!! ############# 217 218 #All files required for the test should be in the same directory with 219 # this file. If converting a standalone test to run with the harness, 220 # as long as all files are in the same directory and it returns 0 for 221 # pass, you should be able to cut and paste it into here and it will 222 # run with the test harness. 223 224 # This is an example of running something -- test 225 # The stuff below catches the exit status of test then passes or fails 226 # this shell test as appropriate ( 0 status is considered a pass here ) 227 228 # The test verifies that appletviewer correctly works with the different 229 # names of the files, including relative and absolute paths 230 231 # 6619458: exclude left brace from the name of the files managed by the VCS 232 NAME='test.html' 233 234 ENCODED='te%7Bst.html' 235 UNENCODED='te{st.html' 236 237 # Copy needed files into the harness's scratch directory 238 # or create a copy with the required name if the test is 239 # running as stand-alone 240 cp ${TESTSRC}${FILESEP}${NAME} ${UNENCODED} 241 242 # the encoded name, the path is absolute 243 URL="file:"${PWD}${FILESEP}${ENCODED} 244 test 245 246 # the encoded name, the path is relative 247 URL="file:"${ENCODED} 248 test 249 250 # the unencoded name, the path is absolute 251 URL="file:"${PWD}${FILESEP}${UNENCODED} 252 test 253 254 # the unencoded name, the path is relative 255 URL="file:"${UNENCODED} 256 test 257 258 # pick up our toys from the scratch directory 259 rm ${UNENCODED}