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