WrappedToolkitTest.sh revision 16177:89ef4b822745
1183878Sraj#!/bin/ksh -p 2183878Sraj 3183878Sraj# 4183878Sraj# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 5183878Sraj# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6183878Sraj# 7183878Sraj# This code is free software; you can redistribute it and/or modify it 8183878Sraj# under the terms of the GNU General Public License version 2 only, as 9183878Sraj# published by the Free Software Foundation. 10183878Sraj# 11183878Sraj# This code is distributed in the hope that it will be useful, but WITHOUT 12183878Sraj# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13183878Sraj# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14183878Sraj# version 2 for more details (a copy is included in the LICENSE file that 15183878Sraj# accompanied this code). 16183878Sraj# 17183878Sraj# You should have received a copy of the GNU General Public License version 18183878Sraj# 2 along with this work; if not, write to the Free Software Foundation, 19183878Sraj# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20183878Sraj# 21183878Sraj# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22183878Sraj# or visit www.oracle.com if you need additional information or have any 23183878Sraj# questions. 24183878Sraj# 25183878Sraj 26183878Sraj# 27183878Sraj# @test 28183878Sraj# @bug 6282388 8030640 29183878Sraj# @summary Tests that AWT use correct toolkit to be wrapped into HeadlessToolkit 30183878Sraj# @author artem.ananiev@sun.com: area=awt.headless 31183878Sraj# compile TestWrapped.java 32183878Sraj# @run shell WrappedToolkitTest.sh 33183878Sraj 34183878Sraj# Beginning of subroutines: 35183878Srajstatus=1 36183878Sraj 37183878Sraj#Call this from anywhere to fail the test with an error message 38183878Sraj# usage: fail "reason why the test failed" 39183878Srajfail() 40183878Sraj { echo "The test failed :-(" 41183878Sraj echo "$*" 1>&2 42183878Sraj echo "exit status was $status" 43183878Sraj exit $status 44183878Sraj } #end of fail() 45183878Sraj 46183878Sraj#Call this from anywhere to pass the test with a message 47183878Sraj# usage: pass "reason why the test passed if applicable" 48183878Srajpass() 49183878Sraj { echo "The test passed!!!" 50183878Sraj echo "$*" 1>&2 51183878Sraj exit 0 52183878Sraj } #end of pass() 53183878Sraj 54183878Sraj# end of subroutines 55183878Sraj 56183878Sraj 57183878Sraj# The beginning of the script proper 58183878Sraj 59183878Sraj# Checking for proper OS 60183878SrajOS=`uname -s` 61183878Srajcase "$OS" in 62183878Sraj SunOS | Linux | Darwin | CYGWIN* ) 63183878Sraj FILESEP="/" 64183878Sraj ;; 65183878Sraj 66183878Sraj Windows* ) 67183878Sraj FILESEP="\\" 68183878Sraj ;; 69183878Sraj 70183878Sraj # catch all other OSs 71183878Sraj * ) 72183878Sraj echo "Unrecognized system! $OS" 73183878Sraj fail "Unrecognized system! $OS" 74183878Sraj ;; 75183878Srajesac 76183878Sraj 77183878Sraj# check that some executable or other file you need is available, abort if not 78183878Sraj# note that the name of the executable is in the fail string as well. 79183878Sraj# this is how to check for presence of the compiler, etc. 80183878Sraj#RESOURCE=`whence SomeProgramOrFileNeeded` 81183878Sraj#if [ "${RESOURCE}" = "" ] ; 82183878Sraj# then fail "Need SomeProgramOrFileNeeded to perform the test" ; 83183878Sraj#fi 84183878Sraj 85183878Sraj# Want this test to run standalone as well as in the harness, so do the 86183878Sraj# following to copy the test's directory into the harness's scratch directory 87183878Sraj# and set all appropriate variables: 88183878Sraj 89183878Srajif [ -z "${TESTJAVA}" ] ; then 90183878Sraj # TESTJAVA is not set, so the test is running stand-alone. 91183878Sraj # TESTJAVA holds the path to the root directory of the build of the JDK 92183878Sraj # to be tested. That is, any java files run explicitly in this shell 93183878Sraj # should use TESTJAVA in the path to the java interpreter. 94 # So, we'll set this to the JDK spec'd on the command line. If none 95 # is given on the command line, tell the user that and use a cheesy 96 # default. 97 # THIS IS THE JDK BEING TESTED. 98 if [ -n "$1" ] ; 99 then TESTJAVA=$1 100 else fail "no JDK specified on command line!" 101 fi 102 TESTSRC=. 103 TESTCLASSES=. 104 STANDALONE=1; 105fi 106echo "JDK under test is: $TESTJAVA" 107 108#if in test harness, then copy the entire directory that the test is in over 109# to the scratch directory. This catches any support files needed by the test. 110if [ -z "${STANDALONE}" ] ; 111 then cp ${TESTSRC}/* . 112fi 113case "$OS" in 114 Windows* | CYGWIN* ) 115 ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \ 116 --add-exports java.desktop/sun.awt=ALL-UNNAMED \ 117 --add-exports java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \ 118 *.java 119 status=$? 120 if [ ! $status -eq "0" ]; then 121 fail "Compilation failed"; 122 fi 123 ;; 124 125 SunOS | Linux ) 126 ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \ 127 --add-exports java.desktop/sun.awt=ALL-UNNAMED \ 128 --add-exports java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \ 129 *.java 130 status=$? 131 if [ ! $status -eq "0" ]; then 132 fail "Compilation failed"; 133 fi 134 ;; 135 136 Darwin) 137 ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \ 138 --add-exports java.desktop/sun.awt=ALL-UNNAMED \ 139 --add-exports java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \ 140 *.java 141 status=$? 142 if [ ! $status -eq "0" ]; then 143 fail "Compilation failed"; 144 fi 145 ;; 146 147esac 148 149#Just before executing anything, make sure it has executable permission! 150chmod 777 ./* 151 152############### YOUR TEST CODE HERE!!!!!!! ############# 153 154case "$OS" in 155 Windows* | CYGWIN* ) 156 ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \ 157 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 158 --add-opens java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \ 159 TestWrapped sun.awt.windows.WToolkit 160 status=$? 161 if [ ! $status -eq "0" ]; then 162 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit"; 163 fi 164 ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \ 165 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 166 --add-opens java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \ 167 -Dawt.toolkit=sun.awt.windows.WToolkit \ 168 TestWrapped sun.awt.windows.WToolkit 169 status=$? 170 if [ ! $status -eq "0" ]; then 171 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit"; 172 fi 173 ;; 174 175 SunOS | Linux ) 176 ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \ 177 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 178 --add-opens java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \ 179 -Dawt.toolkit=sun.awt.X11.XToolkit \ 180 TestWrapped sun.awt.X11.XToolkit 181 status=$? 182 if [ ! $status -eq "0" ]; then 183 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit"; 184 fi 185 AWT_TOOLKIT=XToolkit ${TESTJAVA}/bin/java ${TESTVMOPTS} \ 186 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 187 --add-opens java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \ 188 -Djava.awt.headless=true \ 189 TestWrapped sun.awt.X11.XToolkit 190 status=$? 191 if [ ! $status -eq "0" ]; then 192 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit"; 193 fi 194 ;; 195 196 Darwin) 197 ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \ 198 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 199 --add-opens java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \ 200 TestWrapped sun.lwawt.macosx.LWCToolkit 201 status=$? 202 if [ ! $status -eq "0" ]; then 203 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit"; 204 fi 205 ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \ 206 --add-opens java.desktop/sun.awt=ALL-UNNAMED \ 207 --add-opens java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \ 208 -Dawt.toolkit=sun.lwawt.macosx.LWCToolkit \ 209 TestWrapped sun.lwawt.macosx.LWCToolkit 210 status=$? 211 if [ ! $status -eq "0" ]; then 212 fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit"; 213 fi 214 ;; 215 216esac 217 218pass "All the tests are PASSED"; 219 220#For additional examples of how to write platform independent KSH scripts, 221# see the jtreg file itself. It is a KSH script for both Solaris and Win32 222