1 #!/bin/ksh -p
   2 
   3 #
   4 # Copyright (c) 2012, 2014, 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 8030640
  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 | Linux | Darwin | CYGWIN* )
  63       FILESEP="/"
  64       ;;
  65     
  66    Windows* )
  67       FILESEP="\\"
  68       ;;
  69 
  70    # catch all other OSs
  71    * )
  72       echo "Unrecognized system!  $OS"
  73       fail "Unrecognized system!  $OS"
  74       ;;
  75 esac
  76 
  77 # check that some executable or other file you need is available, abort if not
  78 #  note that the name of the executable is in the fail string as well.
  79 # this is how to check for presence of the compiler, etc.
  80 #RESOURCE=`whence SomeProgramOrFileNeeded`
  81 #if [ "${RESOURCE}" = "" ] ; 
  82 #   then fail "Need SomeProgramOrFileNeeded to perform the test" ; 
  83 #fi
  84 
  85 # Want this test to run standalone as well as in the harness, so do the 
  86 #  following to copy the test's directory into the harness's scratch directory 
  87 #  and set all appropriate variables:
  88 
  89 if [ -z "${TESTJAVA}" ] ; then
  90    # TESTJAVA is not set, so the test is running stand-alone.
  91    # TESTJAVA holds the path to the root directory of the build of the JDK
  92    # to be tested.  That is, any java files run explicitly in this shell
  93    # 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;
 105 fi
 106 echo "JDK under test is: $TESTJAVA"
 107 
 108 ##Deal with .class files:
 109 #if [ -n "${STANDALONE}" ] ; then
 110 #   # then compile all .java files (if there are any) into .class files
 111 #   if [ -a *.java ]; then
 112 #      ${TESTJAVA}/bin/javac$ ./*.java ;
 113 #   fi
 114 #   # else in harness so copy all the class files from where jtreg put them
 115 #   # over to the scratch directory this test is running in. 
 116 #   else cp ${TESTCLASSES}/*.class . ;
 117 #fi
 118 #
 119 #if in test harness, then copy the entire directory that the test is in over 
 120 # to the scratch directory.  This catches any support files needed by the test.
 121 if [ -z "${STANDALONE}" ] ; 
 122    then cp ${TESTSRC}/* . 
 123 fi
 124 case "$OS" in
 125   Windows* | CYGWIN* )
 126     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 127                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 128                          *.java
 129     status=$?
 130     if [ ! $status -eq "0" ]; then
 131       fail "Compilation failed";
 132     fi
 133     ;;
 134 
 135   SunOS | Linux )
 136     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 137                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 138                          *.java
 139     status=$?
 140     if [ ! $status -eq "0" ]; then
 141       fail "Compilation failed";
 142     fi
 143     ;;
 144 
 145   Darwin)
 146     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 147                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 148                          *.java
 149     status=$?
 150     if [ ! $status -eq "0" ]; then
 151       fail "Compilation failed";
 152     fi
 153     ;;
 154 
 155 esac
 156 
 157 #Just before executing anything, make sure it has executable permission!
 158 chmod 777 ./*
 159 
 160 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 161 
 162 case "$OS" in
 163   Windows* | CYGWIN* )
 164     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 165                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 166                          TestWrapped sun.awt.windows.WToolkit
 167     status=$?
 168     if [ ! $status -eq "0" ]; then
 169       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 170     fi
 171     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 172                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 173                          -Dawt.toolkit=sun.awt.windows.WToolkit \
 174                          TestWrapped sun.awt.windows.WToolkit
 175     status=$?
 176     if [ ! $status -eq "0" ]; then
 177       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 178     fi
 179     ;;
 180 
 181   SunOS | Linux )
 182     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 183                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 184                          -Dawt.toolkit=sun.awt.X11.XToolkit \
 185                          TestWrapped sun.awt.X11.XToolkit
 186     status=$?
 187     if [ ! $status -eq "0" ]; then
 188       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit";
 189     fi
 190     AWT_TOOLKIT=XToolkit ${TESTJAVA}/bin/java ${TESTVMOPTS} \
 191                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 192                                               -Djava.awt.headless=true \
 193                                               TestWrapped sun.awt.X11.XToolkit
 194     status=$?
 195     if [ ! $status -eq "0" ]; then
 196       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit";
 197     fi
 198     ;;
 199 
 200   Darwin)
 201     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 202                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 203                          TestWrapped sun.lwawt.macosx.LWCToolkit
 204     status=$?
 205     if [ ! $status -eq "0" ]; then
 206       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit";
 207     fi
 208     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 209                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 210                          -Dawt.toolkit=sun.lwawt.macosx.LWCToolkit \
 211                          TestWrapped sun.lwawt.macosx.LWCToolkit
 212     status=$?
 213     if [ ! $status -eq "0" ]; then
 214       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit";
 215     fi
 216     ;;
 217 
 218 esac
 219 
 220 pass "All the tests are PASSED";
 221 
 222 #For additional examples of how to write platform independent KSH scripts,
 223 # see the jtreg file itself.  It is a KSH script for both Solaris and Win32