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