1 /*
2 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
37 * MixingOnDialog.java
38 *
39 * summary: Tests whether awt.Button and swing.JButton mix correctly
40 * when awt.Button's width got shrinked
41 */
42
43 import java.awt.*;
44 import java.awt.event.*;
45 import javax.swing.*;
46 import test.java.awt.regtesthelpers.Util;
47
48
49
50 public class MixingOnShrinkingHWButton
51 {
52 static volatile boolean heavyClicked = false;
53 static volatile boolean lightClicked = false;
54
55 private static void init()
56 {
57 //*** Create instructions for the user here ***
58
59 String[] instructions =
60 {
61 "This is an AUTOMATIC test, simply wait until it is done.",
62 "The result (passed or failed) will be shown in the",
63 "message window below."
64 };
65 Sysout.createDialog( );
66 Sysout.printInstructions( instructions );
67
68
69 // Create components
70 final Dialog d = new Dialog((Frame)null, "Button-JButton mix test");
71 final Button heavy = new Button(" Heavyweight Button ");
72 final JButton light = new JButton(" LW Button ");
73
74 // Actions for the buttons add appropriate number to the test sequence
75 heavy.addActionListener(new java.awt.event.ActionListener()
76 {
77 public void actionPerformed(java.awt.event.ActionEvent e) {
78 heavyClicked = true;
79 }
80 }
81 );
82
83 light.addActionListener(new java.awt.event.ActionListener()
84 {
85 public void actionPerformed(java.awt.event.ActionEvent e) {
86 lightClicked = true;
87 }
88 }
182 if( ! testGeneratedInterrupt ) throw e;
183
184 //reset flag in case hit this code more than once for some reason (just safety)
185 testGeneratedInterrupt = false;
186
187 if ( theTestPassed == false )
188 {
189 throw new RuntimeException( failureMessage );
190 }
191 }
192
193 }//main
194
195 public static synchronized void setTimeoutTo( int seconds )
196 {
197 sleepTime = seconds * 1000;
198 }
199
200 public static synchronized void pass()
201 {
202 Sysout.println( "The test passed." );
203 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
204 //first check if this is executing in main thread
205 if ( mainThread == Thread.currentThread() )
206 {
207 //Still in the main thread, so set the flag just for kicks,
208 // and throw a test passed exception which will be caught
209 // and end the test.
210 theTestPassed = true;
211 throw new TestPassedException();
212 }
213 theTestPassed = true;
214 testGeneratedInterrupt = true;
215 mainThread.interrupt();
216 }//pass()
217
218 public static synchronized void fail()
219 {
220 //test writer didn't specify why test failed, so give generic
221 fail( "it just plain failed! :-)" );
222 }
223
224 public static synchronized void fail( String whyFailed )
225 {
226 Sysout.println( "The test failed: " + whyFailed );
227 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
228 //check if this called from main thread
229 if ( mainThread == Thread.currentThread() )
230 {
231 //If main thread, fail now 'cause not sleeping
232 throw new RuntimeException( whyFailed );
233 }
234 theTestPassed = false;
235 testGeneratedInterrupt = true;
236 failureMessage = whyFailed;
237 mainThread.interrupt();
238 }//fail()
239
240 }// class MixingOnDialog
241
242 //This exception is used to exit from any level of call nesting
243 // when it's determined that the test has passed, and immediately
244 // end the test.
245 class TestPassedException extends RuntimeException
246 {
247 }
248
249 //*********** End Standard Test Machinery Section **********
250
251
252 //************ Begin classes defined for the test ****************
253
254 // if want to make listeners, here is the recommended place for them, then instantiate
255 // them in init()
256
257 /* Example of a class which may be written as part of a test
258 class NewClass implements anInterface
259 {
260 static int newVar = 0;
261
262 public void eventDispatched(AWTEvent e)
263 {
264 //Counting events to see if we get enough
265 eventCount++;
266
267 if( eventCount == 20 )
268 {
269 //got enough events, so pass
270
271 MixingOnDialog.pass();
272 }
273 else if( tries == 20 )
274 {
275 //tried too many times without getting enough events so fail
276
277 MixingOnDialog.fail();
278 }
279
280 }// eventDispatched()
281
282 }// NewClass class
283
284 */
285
286
287 //************** End classes defined for the test *******************
288
289
290
291
292 /****************************************************
293 Standard Test Machinery
294 DO NOT modify anything below -- it's a standard
295 chunk of code whose purpose is to make user
296 interaction uniform, and thereby make it simpler
297 to read and understand someone else's test.
298 ****************************************************/
299
300 /**
301 This is part of the standard test machinery.
302 It creates a dialog (with the instructions), and is the interface
303 for sending text messages to the user.
304 To print the instructions, send an array of strings to Sysout.createDialog
305 WithInstructions method. Put one line of instructions per array entry.
306 To display a message for the tester to see, simply call Sysout.println
307 with the string to be displayed.
308 This mimics System.out.println but works within the test harness as well
309 as standalone.
310 */
311
312 class Sysout
313 {
314 private static TestDialog dialog;
315
316 public static void createDialogWithInstructions( String[] instructions )
317 {
318 dialog = new TestDialog( new Frame(), "Instructions" );
319 dialog.printInstructions( instructions );
320 dialog.setVisible(true);
321 println( "Any messages for the tester will display here." );
322 }
323
324 public static void createDialog( )
325 {
326 dialog = new TestDialog( new Frame(), "Instructions" );
327 String[] defInstr = { "Instructions will appear here. ", "" } ;
328 dialog.printInstructions( defInstr );
329 dialog.setVisible(true);
330 println( "Any messages for the tester will display here." );
331 }
332
333
334 public static void printInstructions( String[] instructions )
335 {
336 dialog.printInstructions( instructions );
337 }
338
339
340 public static void println( String messageIn )
341 {
342 dialog.displayMessage( messageIn );
343 System.out.println(messageIn);
344 }
345
346 }// Sysout class
347
348 /**
349 This is part of the standard test machinery. It provides a place for the
350 test instructions to be displayed, and a place for interactive messages
351 to the user to be displayed.
352 To have the test instructions displayed, see Sysout.
353 To have a message to the user be displayed, see Sysout.
354 Do not call anything in this dialog directly.
355 */
356 class TestDialog extends Dialog
357 {
358
359 TextArea instructionsText;
360 TextArea messageText;
361 int maxStringLength = 80;
362
363 //DO NOT call this directly, go through Sysout
364 public TestDialog( Frame frame, String name )
365 {
366 super( frame, name );
367 int scrollBoth = TextArea.SCROLLBARS_BOTH;
368 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
369 add( "North", instructionsText );
370
371 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
372 add("Center", messageText);
373
374 pack();
375
376 setVisible(true);
377 }// TestDialog()
378
379 //DO NOT call this directly, go through Sysout
380 public void printInstructions( String[] instructions )
381 {
382 //Clear out any current instructions
383 instructionsText.setText( "" );
384
385 //Go down array of instruction strings
386
387 String printStr, remainingStr;
388 for( int i=0; i < instructions.length; i++ )
389 {
390 //chop up each into pieces maxSringLength long
391 remainingStr = instructions[ i ];
392 while( remainingStr.length() > 0 )
393 {
394 //if longer than max then chop off first max chars to print
395 if( remainingStr.length() >= maxStringLength )
396 {
397 //Try to chop on a word boundary
398 int posOfSpace = remainingStr.
399 lastIndexOf( ' ', maxStringLength - 1 );
400
401 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
402
403 printStr = remainingStr.substring( 0, posOfSpace + 1 );
404 remainingStr = remainingStr.substring( posOfSpace + 1 );
405 }
406 //else just print
407 else
408 {
409 printStr = remainingStr;
410 remainingStr = "";
411 }
412
413 instructionsText.append( printStr + "\n" );
414
415 }// while
416
417 }// for
418
419 }//printInstructions()
420
421 //DO NOT call this directly, go through Sysout
422 public void displayMessage( String messageIn )
423 {
424 messageText.append( messageIn + "\n" );
425 System.out.println(messageIn);
426 }
427
428 }// TestDialog class
|
1 /*
2 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
37 * MixingOnDialog.java
38 *
39 * summary: Tests whether awt.Button and swing.JButton mix correctly
40 * when awt.Button's width got shrinked
41 */
42
43 import java.awt.*;
44 import java.awt.event.*;
45 import javax.swing.*;
46 import test.java.awt.regtesthelpers.Util;
47
48
49
50 public class MixingOnShrinkingHWButton
51 {
52 static volatile boolean heavyClicked = false;
53 static volatile boolean lightClicked = false;
54
55 private static void init()
56 {
57 // Create components
58 final Dialog d = new Dialog((Frame)null, "Button-JButton mix test");
59 final Button heavy = new Button(" Heavyweight Button ");
60 final JButton light = new JButton(" LW Button ");
61
62 // Actions for the buttons add appropriate number to the test sequence
63 heavy.addActionListener(new java.awt.event.ActionListener()
64 {
65 public void actionPerformed(java.awt.event.ActionEvent e) {
66 heavyClicked = true;
67 }
68 }
69 );
70
71 light.addActionListener(new java.awt.event.ActionListener()
72 {
73 public void actionPerformed(java.awt.event.ActionEvent e) {
74 lightClicked = true;
75 }
76 }
170 if( ! testGeneratedInterrupt ) throw e;
171
172 //reset flag in case hit this code more than once for some reason (just safety)
173 testGeneratedInterrupt = false;
174
175 if ( theTestPassed == false )
176 {
177 throw new RuntimeException( failureMessage );
178 }
179 }
180
181 }//main
182
183 public static synchronized void setTimeoutTo( int seconds )
184 {
185 sleepTime = seconds * 1000;
186 }
187
188 public static synchronized void pass()
189 {
190 System.out.println( "The test passed." );
191 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
192 //first check if this is executing in main thread
193 if ( mainThread == Thread.currentThread() )
194 {
195 //Still in the main thread, so set the flag just for kicks,
196 // and throw a test passed exception which will be caught
197 // and end the test.
198 theTestPassed = true;
199 throw new TestPassedException();
200 }
201 theTestPassed = true;
202 testGeneratedInterrupt = true;
203 mainThread.interrupt();
204 }//pass()
205
206 public static synchronized void fail()
207 {
208 //test writer didn't specify why test failed, so give generic
209 fail( "it just plain failed! :-)" );
210 }
211
212 public static synchronized void fail( String whyFailed )
213 {
214 System.out.println( "The test failed: " + whyFailed );
215 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
216 //check if this called from main thread
217 if ( mainThread == Thread.currentThread() )
218 {
219 //If main thread, fail now 'cause not sleeping
220 throw new RuntimeException( whyFailed );
221 }
222 theTestPassed = false;
223 testGeneratedInterrupt = true;
224 failureMessage = whyFailed;
225 mainThread.interrupt();
226 }//fail()
227
228 }// class MixingOnDialog
229
230 //This exception is used to exit from any level of call nesting
231 // when it's determined that the test has passed, and immediately
232 // end the test.
233 class TestPassedException extends RuntimeException
234 {
235 }
|