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:
35status=1
36
37#Call this from anywhere to fail the test with an error message
38# usage: fail "reason why the test failed"
39fail() 
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"
48pass() 
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
60OS=`uname -s`
61case "$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      ;;
75esac
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
89if [ -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;
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