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 #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.
 110 if [ -z "${STANDALONE}" ] ; 
 111    then cp ${TESTSRC}/* . 
 112 fi
 113 case "$OS" in
 114   Windows* | CYGWIN* )
 115     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 116                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 117                          *.java
 118     status=$?
 119     if [ ! $status -eq "0" ]; then
 120       fail "Compilation failed";
 121     fi
 122     ;;
 123 
 124   SunOS | Linux )
 125     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 126                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 127                          *.java
 128     status=$?
 129     if [ ! $status -eq "0" ]; then
 130       fail "Compilation failed";
 131     fi
 132     ;;
 133 
 134   Darwin)
 135     ${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} \
 136                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 137                          *.java
 138     status=$?
 139     if [ ! $status -eq "0" ]; then
 140       fail "Compilation failed";
 141     fi
 142     ;;
 143 
 144 esac
 145 
 146 #Just before executing anything, make sure it has executable permission!
 147 chmod 777 ./*
 148 
 149 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 150 
 151 case "$OS" in
 152   Windows* | CYGWIN* )
 153     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 154                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 155                          TestWrapped sun.awt.windows.WToolkit
 156     status=$?
 157     if [ ! $status -eq "0" ]; then
 158       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 159     fi
 160     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 161                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.windows=ALL-UNNAMED ${CP} \
 162                          -Dawt.toolkit=sun.awt.windows.WToolkit \
 163                          TestWrapped sun.awt.windows.WToolkit
 164     status=$?
 165     if [ ! $status -eq "0" ]; then
 166       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 167     fi
 168     ;;
 169 
 170   SunOS | Linux )
 171     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 172                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 173                          -Dawt.toolkit=sun.awt.X11.XToolkit \
 174                          TestWrapped sun.awt.X11.XToolkit
 175     status=$?
 176     if [ ! $status -eq "0" ]; then
 177       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit";
 178     fi
 179     AWT_TOOLKIT=XToolkit ${TESTJAVA}/bin/java ${TESTVMOPTS} \
 180                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.awt.X11=ALL-UNNAMED ${CP} \
 181                                               -Djava.awt.headless=true \
 182                                               TestWrapped sun.awt.X11.XToolkit
 183     status=$?
 184     if [ ! $status -eq "0" ]; then
 185       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit";
 186     fi
 187     ;;
 188 
 189   Darwin)
 190     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 191                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 192                          TestWrapped sun.lwawt.macosx.LWCToolkit
 193     status=$?
 194     if [ ! $status -eq "0" ]; then
 195       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit";
 196     fi
 197     ${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.awt.headless=true \
 198                          -XaddExports:java.desktop/sun.awt=ALL-UNNAMED,java.desktop/sun.lwawt.macosx=ALL-UNNAMED ${CP} \
 199                          -Dawt.toolkit=sun.lwawt.macosx.LWCToolkit \
 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     ;;
 206 
 207 esac
 208 
 209 pass "All the tests are PASSED";
 210 
 211 #For additional examples of how to write platform independent KSH scripts,
 212 # see the jtreg file itself.  It is a KSH script for both Solaris and Win32