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     Darwin)
  81       VAR="Lets not forget about Mac"
  82       DEFAULT_JDK=$(/usr/libexec/java_home)
  83       FILESEP="/"
  84       ;;
  85 
  86    # catch all other OSs
  87    * )
  88       echo "Unrecognized system!  $OS"
  89       fail "Unrecognized system!  $OS"
  90       ;;
  91 esac
  92 
  93 # check that some executable or other file you need is available, abort if not
  94 #  note that the name of the executable is in the fail string as well.
  95 # this is how to check for presence of the compiler, etc.
  96 #RESOURCE=`whence SomeProgramOrFileNeeded`
  97 #if [ "${RESOURCE}" = "" ] ; 
  98 #   then fail "Need SomeProgramOrFileNeeded to perform the test" ; 
  99 #fi
 100 
 101 # Want this test to run standalone as well as in the harness, so do the 
 102 #  following to copy the test's directory into the harness's scratch directory 
 103 #  and set all appropriate variables:
 104 
 105 if [ -z "${TESTJAVA}" ] ; then
 106    # TESTJAVA is not set, so the test is running stand-alone.
 107    # TESTJAVA holds the path to the root directory of the build of the JDK
 108    # to be tested.  That is, any java files run explicitly in this shell
 109    # should use TESTJAVA in the path to the java interpreter.
 110    # So, we'll set this to the JDK spec'd on the command line.  If none
 111    # is given on the command line, tell the user that and use a cheesy
 112    # default.
 113    # THIS IS THE JDK BEING TESTED.
 114    if [ -n "$1" ] ;
 115       then TESTJAVA=$1
 116       else echo "no JDK specified on command line so using default!"
 117      TESTJAVA=$DEFAULT_JDK
 118    fi
 119    TESTSRC=.
 120    TESTCLASSES=.
 121    STANDALONE=1;
 122 fi
 123 echo "JDK under test is: $TESTJAVA"
 124 
 125 #Deal with .class files:
 126 if [ -n "${STANDALONE}" ] ; then
 127    # then compile all .java files (if there are any) into .class files
 128    if [ -a *.java ]; then
 129       ${TESTJAVA}/bin/javac$ ./*.java ;
 130    fi
 131    # else in harness so copy all the class files from where jtreg put them
 132    # over to the scratch directory this test is running in. 
 133    else cp ${TESTCLASSES}/*.class . ;
 134 fi
 135 
 136 #if in test harness, then copy the entire directory that the test is in over 
 137 # to the scratch directory.  This catches any support files needed by the test.
 138 if [ -z "${STANDALONE}" ] ; 
 139    then cp ${TESTSRC}/* . 
 140 fi
 141 
 142 #Just before executing anything, make sure it has executable permission!
 143 chmod 777 ./*
 144 
 145 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 146 
 147 case "$OS" in
 148   Windows* | CYGWIN* )
 149     ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 150                          TestWrapped sun.awt.windows.WToolkit
 151     status=$?
 152     if [ ! $status -eq "0" ]; then
 153       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 154     fi
 155     ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 156                          -Dawt.toolkit=sun.awt.windows.WToolkit \
 157                          TestWrapped sun.awt.windows.WToolkit
 158     status=$?
 159     if [ ! $status -eq "0" ]; then
 160       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.windows.WToolkit";
 161     fi
 162     ;;
 163 
 164   SunOS | Linux )
 165     ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 166                          -Dawt.toolkit=sun.awt.X11.XToolkit \
 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     AWT_TOOLKIT=XToolkit ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 173                                               TestWrapped sun.awt.X11.XToolkit
 174     status=$?
 175     if [ ! $status -eq "0" ]; then
 176       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.awt.xawt.XToolkit";
 177     fi
 178     ;;
 179 
 180   Darwin)
 181     ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 182                          TestWrapped sun.lwawt.macosx.LWCToolkit
 183     status=$?
 184     if [ ! $status -eq "0" ]; then
 185       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit";
 186     fi
 187     ${TESTJAVA}/bin/java -Djava.awt.headless=true \
 188                          -Dawt.toolkit=sun.lwawt.macosx.LWCToolkit \
 189                          TestWrapped sun.lwawt.macosx.LWCToolkit
 190     status=$?
 191     if [ ! $status -eq "0" ]; then
 192       fail "Test FAILED: toolkit wrapped into HeadlessToolkit is not an instance of sun.lwawt.macosx.LWCToolkit";
 193     fi
 194     ;;
 195 
 196 esac
 197 
 198 pass "All the tests are PASSED";
 199 
 200 #For additional examples of how to write platform independent KSH scripts,
 201 # see the jtreg file itself.  It is a KSH script for both Solaris and Win32