blob: d2e16b35ce12cb35472141036c690153db3da027 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright (c) 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 @test
26 @bug 5045936 5055171
27 @summary Tests that there is no ClassCastException thrown in printing
28 checkbox and scrollbar with XAWT
29 @author art@sparc.spb.su
30 @run applet/manual=yesno PrintCheckboxManualTest.html
31*/
32
33// Note there is no @ in front of test above. This is so that the
34// harness will not mistake this file as a test file. It should
35// only see the html file as a test file. (the harness runs all
36// valid test files, so it would run this test twice if this file
37// were valid as well as the html file.)
38// Also, note the area= after Your Name in the author tag. Here, you
39// should put which functional area the test falls in. See the
40// AWT-core home page -> test areas and/or -> AWT team for a list of
41// areas.
42
43
44
45import java.awt.*;
46import java.awt.event.*;
47
48
49//Manual tests should run as applet tests if possible because they
50// get their environments cleaned up, including AWT threads, any
51// test created threads, and any system resources used by the test
52// such as file descriptors. (This is normally not a problem as
53// main tests usually run in a separate VM, however on some platforms
54// such as the Mac, separate VMs are not possible and non-applet
55// tests will cause problems). Also, you don't have to worry about
56// synchronisation stuff in Applet tests the way you do in main
57// tests...
58
59
60public class PrintCheckboxManualTest extends Panel
61{
62 //Declare things used in the test, like buttons and labels here
63 Frame f;
64
65 public static void main(String[] args) {
66 PrintCheckboxManualTest a = new PrintCheckboxManualTest();
67
68 a.init();
69 a.start();
70 }
71
72 public void init()
73 {
74 //Create instructions for the user here, as well as set up
75 // the environment -- set the layout manager, add buttons,
76 // etc.
77 this.setLayout (new BorderLayout ());
78
79 String[] instructions =
80 {
81 "Linux or Solaris with XToolkit ONLY!",
82 "1. Click the 'Print' button on the frame",
83 "2. Select a printer in the print dialog and proceed",
84 "3. If the frame with checkbox and button on it is printed successfully test PASSED else FAILED"
85 };
86 Sysout.createDialogWithInstructions( instructions );
87
88 }//End init()
89
90 public void start ()
91 {
92 //Get things going. Request focus, set size, et cetera
93 setSize (200,200);
94 setVisible(true);
95 validate();
96
97 //What would normally go into main() will probably go here.
98 //Use System.out.println for diagnostic messages that you want
99 // to read after the test is done.
100 //Use Sysout.println for messages you want the tester to read.
101
102 f = new Frame("Print checkbox");
103 f.setLayout(new GridLayout(2, 2));
104 f.setSize(200, 100);
105
106 Checkbox ch = new Checkbox("123");
107 ch.setState(true);
108 f.add(ch);
109
110 Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL);
111 f.add(sb);
112
113 Button b = new Button("Print");
114 b.addActionListener(new ActionListener()
115 {
116 public void actionPerformed(ActionEvent ev)
117 {
118 PrintJob pj = Toolkit.getDefaultToolkit().getPrintJob(f, "PrintCheckboxManualTest", null);
119 if (pj != null)
120 {
121 try
122 {
123 Graphics g = pj.getGraphics();
124 f.printAll(g);
125 g.dispose();
126 pj.end();
127 Sysout.println("Test PASSED");
128 }
129 catch (ClassCastException cce)
130 {
131 Sysout.println("Test FAILED: ClassCastException");
132// throw new RuntimeException("Test FAILED: ClassCastException", cce);
133 }
134 catch (Exception e)
135 {
136 Sysout.println("Test FAILED: unknown Exception");
137// throw new Error("Test FAILED: unknown exception", e);
138 }
139 }
140 }
141 });
142 f.add(b);
143
144 f.setVisible(true);
145 }// start()
146
147 //The rest of this class is the actions which perform the test...
148
149 //Use Sysout.println to communicate with the user NOT System.out!!
150 //Sysout.println ("Something Happened!");
151
152}
153
154/* Place other classes related to the test after this line */
155
156
157
158
159
160/****************************************************
161 Standard Test Machinery
162 DO NOT modify anything below -- it's a standard
163 chunk of code whose purpose is to make user
164 interaction uniform, and thereby make it simpler
165 to read and understand someone else's test.
166 ****************************************************/
167
168/**
169 This is part of the standard test machinery.
170 It creates a dialog (with the instructions), and is the interface
171 for sending text messages to the user.
172 To print the instructions, send an array of strings to Sysout.createDialog
173 WithInstructions method. Put one line of instructions per array entry.
174 To display a message for the tester to see, simply call Sysout.println
175 with the string to be displayed.
176 This mimics System.out.println but works within the test harness as well
177 as standalone.
178 */
179
180class Sysout
181{
182 private static TestDialog dialog;
183
184 public static void createDialogWithInstructions( String[] instructions )
185 {
186 dialog = new TestDialog( new Frame(), "Instructions" );
187 dialog.printInstructions( instructions );
188 dialog.setVisible(true);
189 println( "Any messages for the tester will display here." );
190 }
191
192 public static void createDialog( )
193 {
194 dialog = new TestDialog( new Frame(), "Instructions" );
195 String[] defInstr = { "Instructions will appear here. ", "" } ;
196 dialog.printInstructions( defInstr );
197 dialog.setVisible(true);
198 println( "Any messages for the tester will display here." );
199 }
200
201
202 public static void printInstructions( String[] instructions )
203 {
204 dialog.printInstructions( instructions );
205 }
206
207
208 public static void println( String messageIn )
209 {
210 dialog.displayMessage( messageIn );
211 }
212
213}// Sysout class
214
215/**
216 This is part of the standard test machinery. It provides a place for the
217 test instructions to be displayed, and a place for interactive messages
218 to the user to be displayed.
219 To have the test instructions displayed, see Sysout.
220 To have a message to the user be displayed, see Sysout.
221 Do not call anything in this dialog directly.
222 */
223class TestDialog extends Dialog
224{
225
226 TextArea instructionsText;
227 TextArea messageText;
228 int maxStringLength = 80;
229
230 //DO NOT call this directly, go through Sysout
231 public TestDialog( Frame frame, String name )
232 {
233 super( frame, name );
234 int scrollBoth = TextArea.SCROLLBARS_BOTH;
235 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
236 add( "North", instructionsText );
237
238 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
239 add("Center", messageText);
240
241 pack();
242
243 setVisible(true);
244 }// TestDialog()
245
246 //DO NOT call this directly, go through Sysout
247 public void printInstructions( String[] instructions )
248 {
249 //Clear out any current instructions
250 instructionsText.setText( "" );
251
252 //Go down array of instruction strings
253
254 String printStr, remainingStr;
255 for( int i=0; i < instructions.length; i++ )
256 {
257 //chop up each into pieces maxSringLength long
258 remainingStr = instructions[ i ];
259 while( remainingStr.length() > 0 )
260 {
261 //if longer than max then chop off first max chars to print
262 if( remainingStr.length() >= maxStringLength )
263 {
264 //Try to chop on a word boundary
265 int posOfSpace = remainingStr.
266 lastIndexOf( ' ', maxStringLength - 1 );
267
268 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
269
270 printStr = remainingStr.substring( 0, posOfSpace + 1 );
271 remainingStr = remainingStr.substring( posOfSpace + 1 );
272 }
273 //else just print
274 else
275 {
276 printStr = remainingStr;
277 remainingStr = "";
278 }
279
280 instructionsText.append( printStr + "\n" );
281
282 }// while
283
284 }// for
285
286 }//printInstructions()
287
288 //DO NOT call this directly, go through Sysout
289 public void displayMessage( String messageIn )
290 {
291 messageText.append( messageIn + "\n" );
292 System.out.println(messageIn);
293 }
294
295}// TestDialog class