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 */
28 @summary api/java_awt/Component/index.html#PaintUpdate fails randomly
29 @author dmitry.cherepanov@...: area=awt.painting
30 @run main NoUpdateUponShow
31 */
32
33 /**
34 * NoUpdateUponShow.java
35 *
36 * summary: System-level painting operations shouldn't make call to update()
37 */
38
39 import java.awt.*;
40
41 public class NoUpdateUponShow
42 {
43
44 static volatile boolean wasUpdate = false;
45
46 private static void init()
47 {
48 //*** Create instructions for the user here ***
49
50 String[] instructions =
51 {
52 "This is an AUTOMATIC test, simply wait until it is done.",
53 "The result (passed or failed) will be shown in the",
54 "message window below."
55 };
56 Sysout.createDialog( );
57 Sysout.printInstructions( instructions );
58
59
60 // Create the frame and the button
61 Frame f = new Frame();
62 f.setBounds(100, 100, 200, 200);
63 f.setLayout(new FlowLayout());
64 f.add(new Button() {
65 @Override
66 public void update(Graphics g) {
67 wasUpdate = true;
68 super.update(g);
69 }
70 });
71 f.setVisible(true);
72
73 try {
74 Robot robot = new Robot();
75 robot.waitForIdle();
76 }catch(Exception ex) {
77 ex.printStackTrace();
78 throw new RuntimeException("Unexpected failure");
79 }
141 if( ! testGeneratedInterrupt ) throw e;
142
143 //reset flag in case hit this code more than once for some reason (just safety)
144 testGeneratedInterrupt = false;
145
146 if ( theTestPassed == false )
147 {
148 throw new RuntimeException( failureMessage );
149 }
150 }
151
152 }//main
153
154 public static synchronized void setTimeoutTo( int seconds )
155 {
156 sleepTime = seconds * 1000;
157 }
158
159 public static synchronized void pass()
160 {
161 Sysout.println( "The test passed." );
162 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
163 //first check if this is executing in main thread
164 if ( mainThread == Thread.currentThread() )
165 {
166 //Still in the main thread, so set the flag just for kicks,
167 // and throw a test passed exception which will be caught
168 // and end the test.
169 theTestPassed = true;
170 throw new TestPassedException();
171 }
172 theTestPassed = true;
173 testGeneratedInterrupt = true;
174 mainThread.interrupt();
175 }//pass()
176
177 public static synchronized void fail()
178 {
179 //test writer didn't specify why test failed, so give generic
180 fail( "it just plain failed! :-)" );
181 }
182
183 public static synchronized void fail( String whyFailed )
184 {
185 Sysout.println( "The test failed: " + whyFailed );
186 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
187 //check if this called from main thread
188 if ( mainThread == Thread.currentThread() )
189 {
190 //If main thread, fail now 'cause not sleeping
191 throw new RuntimeException( whyFailed );
192 }
193 theTestPassed = false;
194 testGeneratedInterrupt = true;
195 failureMessage = whyFailed;
196 mainThread.interrupt();
197 }//fail()
198
199 }// class ValidBounds
200
201 //This exception is used to exit from any level of call nesting
202 // when it's determined that the test has passed, and immediately
203 // end the test.
204 class TestPassedException extends RuntimeException
205 {
206 }
207
208 //*********** End Standard Test Machinery Section **********
209
210
211 //************ Begin classes defined for the test ****************
212
213 // if want to make listeners, here is the recommended place for them, then instantiate
214 // them in init()
215
216 /* Example of a class which may be written as part of a test
217 class NewClass implements anInterface
218 {
219 static int newVar = 0;
220
221 public void eventDispatched(AWTEvent e)
222 {
223 //Counting events to see if we get enough
224 eventCount++;
225
226 if( eventCount == 20 )
227 {
228 //got enough events, so pass
229
230 ValidBounds.pass();
231 }
232 else if( tries == 20 )
233 {
234 //tried too many times without getting enough events so fail
235
236 ValidBounds.fail();
237 }
238
239 }// eventDispatched()
240
241 }// NewClass class
242
243 */
244
245
246 //************** End classes defined for the test *******************
247
248
249
250
251 /****************************************************
252 Standard Test Machinery
253 DO NOT modify anything below -- it's a standard
254 chunk of code whose purpose is to make user
255 interaction uniform, and thereby make it simpler
256 to read and understand someone else's test.
257 ****************************************************/
258
259 /**
260 This is part of the standard test machinery.
261 It creates a dialog (with the instructions), and is the interface
262 for sending text messages to the user.
263 To print the instructions, send an array of strings to Sysout.createDialog
264 WithInstructions method. Put one line of instructions per array entry.
265 To display a message for the tester to see, simply call Sysout.println
266 with the string to be displayed.
267 This mimics System.out.println but works within the test harness as well
268 as standalone.
269 */
270
271 class Sysout
272 {
273 private static TestDialog dialog;
274
275 public static void createDialogWithInstructions( String[] instructions )
276 {
277 dialog = new TestDialog( new Frame(), "Instructions" );
278 dialog.printInstructions( instructions );
279 dialog.setVisible(true);
280 println( "Any messages for the tester will display here." );
281 }
282
283 public static void createDialog( )
284 {
285 dialog = new TestDialog( new Frame(), "Instructions" );
286 String[] defInstr = { "Instructions will appear here. ", "" } ;
287 dialog.printInstructions( defInstr );
288 dialog.setVisible(true);
289 println( "Any messages for the tester will display here." );
290 }
291
292
293 public static void printInstructions( String[] instructions )
294 {
295 dialog.printInstructions( instructions );
296 }
297
298
299 public static void println( String messageIn )
300 {
301 dialog.displayMessage( messageIn );
302 System.out.println(messageIn);
303 }
304
305 }// Sysout class
306
307 /**
308 This is part of the standard test machinery. It provides a place for the
309 test instructions to be displayed, and a place for interactive messages
310 to the user to be displayed.
311 To have the test instructions displayed, see Sysout.
312 To have a message to the user be displayed, see Sysout.
313 Do not call anything in this dialog directly.
314 */
315 class TestDialog extends Dialog
316 {
317
318 TextArea instructionsText;
319 TextArea messageText;
320 int maxStringLength = 80;
321
322 //DO NOT call this directly, go through Sysout
323 public TestDialog( Frame frame, String name )
324 {
325 super( frame, name );
326 int scrollBoth = TextArea.SCROLLBARS_BOTH;
327 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
328 add( "North", instructionsText );
329
330 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
331 add("Center", messageText);
332
333 pack();
334
335 setVisible(true);
336 }// TestDialog()
337
338 //DO NOT call this directly, go through Sysout
339 public void printInstructions( String[] instructions )
340 {
341 //Clear out any current instructions
342 instructionsText.setText( "" );
343
344 //Go down array of instruction strings
345
346 String printStr, remainingStr;
347 for( int i=0; i < instructions.length; i++ )
348 {
349 //chop up each into pieces maxSringLength long
350 remainingStr = instructions[ i ];
351 while( remainingStr.length() > 0 )
352 {
353 //if longer than max then chop off first max chars to print
354 if( remainingStr.length() >= maxStringLength )
355 {
356 //Try to chop on a word boundary
357 int posOfSpace = remainingStr.
358 lastIndexOf( ' ', maxStringLength - 1 );
359
360 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
361
362 printStr = remainingStr.substring( 0, posOfSpace + 1 );
363 remainingStr = remainingStr.substring( posOfSpace + 1 );
364 }
365 //else just print
366 else
367 {
368 printStr = remainingStr;
369 remainingStr = "";
370 }
371
372 instructionsText.append( printStr + "\n" );
373
374 }// while
375
376 }// for
377
378 }//printInstructions()
379
380 //DO NOT call this directly, go through Sysout
381 public void displayMessage( String messageIn )
382 {
383 messageText.append( messageIn + "\n" );
384 System.out.println(messageIn);
385 }
386
387 }// 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 */
28 @summary api/java_awt/Component/index.html#PaintUpdate fails randomly
29 @author dmitry.cherepanov@...: area=awt.painting
30 @run main NoUpdateUponShow
31 */
32
33 /**
34 * NoUpdateUponShow.java
35 *
36 * summary: System-level painting operations shouldn't make call to update()
37 */
38
39 import java.awt.*;
40
41 public class NoUpdateUponShow
42 {
43
44 static volatile boolean wasUpdate = false;
45
46 private static void init()
47 {
48 // Create the frame and the button
49 Frame f = new Frame();
50 f.setBounds(100, 100, 200, 200);
51 f.setLayout(new FlowLayout());
52 f.add(new Button() {
53 @Override
54 public void update(Graphics g) {
55 wasUpdate = true;
56 super.update(g);
57 }
58 });
59 f.setVisible(true);
60
61 try {
62 Robot robot = new Robot();
63 robot.waitForIdle();
64 }catch(Exception ex) {
65 ex.printStackTrace();
66 throw new RuntimeException("Unexpected failure");
67 }
129 if( ! testGeneratedInterrupt ) throw e;
130
131 //reset flag in case hit this code more than once for some reason (just safety)
132 testGeneratedInterrupt = false;
133
134 if ( theTestPassed == false )
135 {
136 throw new RuntimeException( failureMessage );
137 }
138 }
139
140 }//main
141
142 public static synchronized void setTimeoutTo( int seconds )
143 {
144 sleepTime = seconds * 1000;
145 }
146
147 public static synchronized void pass()
148 {
149 System.out.println( "The test passed." );
150 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
151 //first check if this is executing in main thread
152 if ( mainThread == Thread.currentThread() )
153 {
154 //Still in the main thread, so set the flag just for kicks,
155 // and throw a test passed exception which will be caught
156 // and end the test.
157 theTestPassed = true;
158 throw new TestPassedException();
159 }
160 theTestPassed = true;
161 testGeneratedInterrupt = true;
162 mainThread.interrupt();
163 }//pass()
164
165 public static synchronized void fail()
166 {
167 //test writer didn't specify why test failed, so give generic
168 fail( "it just plain failed! :-)" );
169 }
170
171 public static synchronized void fail( String whyFailed )
172 {
173 System.out.println( "The test failed: " + whyFailed );
174 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
175 //check if this called from main thread
176 if ( mainThread == Thread.currentThread() )
177 {
178 //If main thread, fail now 'cause not sleeping
179 throw new RuntimeException( whyFailed );
180 }
181 theTestPassed = false;
182 testGeneratedInterrupt = true;
183 failureMessage = whyFailed;
184 mainThread.interrupt();
185 }//fail()
186
187 }// class ValidBounds
188
189 //This exception is used to exit from any level of call nesting
190 // when it's determined that the test has passed, and immediately
191 // end the test.
192 class TestPassedException extends RuntimeException
193 {
194 }
|