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