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