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