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