1 #!/bin/ksh -p 2 3 # 4 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 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 # 27 # @test 28 # @bug 6282388 29 # @summary Tests that AWT use correct toolkit to be wrapped into HeadlessToolkit 30 # @author artem.ananiev@sun.com: area=awt.headless 31 # @compile TestWrapped.java 32 # @run shell WrappedToolkitTest.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 # end of subroutines 55 56 57 # The beginning of the script proper 58 59 # Checking for proper OS 60 OS=`uname -s` 61 case "$OS" in 62 SunOS ) 63 VAR="One value for Sun" 64 DEFAULT_JDK=/usr/local/java/jdk1.2/solaris 65 FILESEP="/" 66 ;; 67 68 Linux ) 69 VAR="A different value for Linux" 70 DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386 71 FILESEP="/" 72 ;; 73 74 Windows* | CYGWIN* ) 75 VAR="A different value for Win32" 76 DEFAULT_JDK=/usr/local/java/jdk1.2/win32 77 FILESEP="\\" 78 ;; 79 80 # catch all other OSs 81 * ) 82 echo "Unrecognized system! $OS" 83 fail "Unrecognized system! $OS" 84 ;; 85 esac 86 87 # check that some executable or other file you need is available, abort if not 88 # note that the name of the executable is in the fail string as well. 89 # this is how to check for presence of the compiler, etc. 90 #RESOURCE=`whence SomeProgramOrFileNeeded` 91 #if [ "${RESOURCE}" = "" ] ; 92 # then fail "Need SomeProgramOrFileNeeded to perform the test" ; 93 #fi 94 95 # Want this test to run standalone as well as in the harness, so do the 96 # following to copy the test's directory into the harness's scratch directory 97 # and set all appropriate variables: 98 99 if [ -z "${TESTJAVA}" ] ; then 100 # TESTJAVA is not set, so the test is running stand-alone. 101 # TESTJAVA holds the path to the root directory of the build of the JDK 102 # to be tested. That is, any java files run explicitly in this shell 103 # should use TESTJAVA in the path to the java interpreter. 104 # So, we'll set this to the JDK spec'd on the command line. If none 105 # is given on the command line, tell the user that and use a cheesy 106 # default. 107 # THIS IS THE JDK BEING TESTED. 108 if [ -n "$1" ] ; 109 then TESTJAVA=$1 110 else echo "no JDK specified on command line so using default!" 111 TESTJAVA=$DEFAULT_JDK 112 fi 113 TESTSRC=. 114 TESTCLASSES=. 115 STANDALONE=1; 116 fi 117 echo "JDK under test is: $TESTJAVA" 118 119 #Deal with .class files: 120 if [ -n "${STANDALONE}" ] ; then 121 # then compile all .java files (if there are any) into .class files 122 if [ -a *.java ]; then 123 ${TESTJAVA}/bin/javac$ ./*.java ; 124 fi 125 # else in harness so copy all the class files from where jtreg put them 126 # over to the scratch directory this test is running in. 127 else cp ${TESTCLASSES}/*.class . ; 128 fi 129 130 #if in test harness, then copy the entire directory that the test is in over 131 # to the scratch directory. This catches any support files needed by the test. 132 if [ -z "${STANDALONE}" ] ; 133 then cp ${TESTSRC}/* . 134 fi 135 136 #Just before executing anything, make sure it has executable permission! 137 chmod 777 ./* 138 139 ############### YOUR TEST CODE HERE!!!!!!! ############# 140 141 case "$OS" in 142 Windows* | CYGWIN* ) 143 ${TESTJAVA}/bin/java -Djava.awt.headless=true \ 144 TestWrapped sun.awt.windows.WToolkit 145 status=$? 146 if [ ! $status -eq "0" ]; then 147 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit"; 148 fi 149 ${TESTJAVA}/bin/java -Djava.awt.headless=true \ 150 -Dawt.toolkit=sun.awt.windows.WToolkit \ 151 TestWrapped sun.awt.windows.WToolkit 152 status=$? 153 if [ ! $status -eq "0" ]; then 154 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit"; 155 fi 156 ;; 157 158 SunOS | Linux ) 159 ${TESTJAVA}/bin/java -Djava.awt.headless=true \ 160 -Dawt.toolkit=sun.awt.X11.XToolkit \ 161 TestWrapped sun.awt.X11.XToolkit 162 status=$? 163 if [ ! $status -eq "0" ]; then 164 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit"; 165 fi 166 AWT_TOOLKIT=XToolkit ${TESTJAVA}/bin/java -Djava.awt.headless=true \ 167 TestWrapped sun.awt.X11.XToolkit 168 status=$? 169 if [ ! $status -eq "0" ]; then 170 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit"; 171 fi 172 ;; 173 174 esac 175 176 pass "All the tests are PASSED"; 177 178 #For additional examples of how to write platform independent KSH scripts, 179 # see the jtreg file itself. It is a KSH script for both Solaris and Win32