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