47 |
47 |
48 static volatile boolean clickPassed = false; |
48 static volatile boolean clickPassed = false; |
49 |
49 |
50 private static void init() |
50 private static void init() |
51 { |
51 { |
52 //*** Create instructions for the user here *** |
|
53 |
|
54 String[] instructions = |
|
55 { |
|
56 "This is an AUTOMATIC test, simply wait until it is done.", |
|
57 "The result (passed or failed) will be shown in the", |
|
58 "message window below." |
|
59 }; |
|
60 Sysout.createDialog( ); |
|
61 Sysout.printInstructions( instructions ); |
|
62 |
|
63 |
|
64 // Create the frame and the button |
52 // Create the frame and the button |
65 Frame f = new Frame(); |
53 Frame f = new Frame(); |
66 f.setBounds(100, 100, 400, 300); |
54 f.setBounds(100, 100, 400, 300); |
67 |
55 |
68 Button b = new Button("OK"); |
56 Button b = new Button("OK"); |
227 // when it's determined that the test has passed, and immediately |
215 // when it's determined that the test has passed, and immediately |
228 // end the test. |
216 // end the test. |
229 class TestPassedException extends RuntimeException |
217 class TestPassedException extends RuntimeException |
230 { |
218 { |
231 } |
219 } |
232 |
|
233 //*********** End Standard Test Machinery Section ********** |
|
234 |
|
235 |
|
236 //************ Begin classes defined for the test **************** |
|
237 |
|
238 // if want to make listeners, here is the recommended place for them, then instantiate |
|
239 // them in init() |
|
240 |
|
241 /* Example of a class which may be written as part of a test |
|
242 class NewClass implements anInterface |
|
243 { |
|
244 static int newVar = 0; |
|
245 |
|
246 public void eventDispatched(AWTEvent e) |
|
247 { |
|
248 //Counting events to see if we get enough |
|
249 eventCount++; |
|
250 |
|
251 if( eventCount == 20 ) |
|
252 { |
|
253 //got enough events, so pass |
|
254 |
|
255 ValidBounds.pass(); |
|
256 } |
|
257 else if( tries == 20 ) |
|
258 { |
|
259 //tried too many times without getting enough events so fail |
|
260 |
|
261 ValidBounds.fail(); |
|
262 } |
|
263 |
|
264 }// eventDispatched() |
|
265 |
|
266 }// NewClass class |
|
267 |
|
268 */ |
|
269 |
|
270 |
|
271 //************** End classes defined for the test ******************* |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 /**************************************************** |
|
277 Standard Test Machinery |
|
278 DO NOT modify anything below -- it's a standard |
|
279 chunk of code whose purpose is to make user |
|
280 interaction uniform, and thereby make it simpler |
|
281 to read and understand someone else's test. |
|
282 ****************************************************/ |
|
283 |
|
284 /** |
|
285 This is part of the standard test machinery. |
|
286 It creates a dialog (with the instructions), and is the interface |
|
287 for sending text messages to the user. |
|
288 To print the instructions, send an array of strings to Sysout.createDialog |
|
289 WithInstructions method. Put one line of instructions per array entry. |
|
290 To display a message for the tester to see, simply call Sysout.println |
|
291 with the string to be displayed. |
|
292 This mimics System.out.println but works within the test harness as well |
|
293 as standalone. |
|
294 */ |
|
295 |
|
296 class Sysout |
|
297 { |
|
298 private static TestDialog dialog; |
|
299 |
|
300 public static void createDialogWithInstructions( String[] instructions ) |
|
301 { |
|
302 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
303 dialog.printInstructions( instructions ); |
|
304 dialog.setVisible(true); |
|
305 println( "Any messages for the tester will display here." ); |
|
306 } |
|
307 |
|
308 public static void createDialog( ) |
|
309 { |
|
310 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
311 String[] defInstr = { "Instructions will appear here. ", "" } ; |
|
312 dialog.printInstructions( defInstr ); |
|
313 dialog.setVisible(true); |
|
314 println( "Any messages for the tester will display here." ); |
|
315 } |
|
316 |
|
317 |
|
318 public static void printInstructions( String[] instructions ) |
|
319 { |
|
320 dialog.printInstructions( instructions ); |
|
321 } |
|
322 |
|
323 |
|
324 public static void println( String messageIn ) |
|
325 { |
|
326 dialog.displayMessage( messageIn ); |
|
327 System.out.println(messageIn); |
|
328 } |
|
329 |
|
330 }// Sysout class |
|
331 |
|
332 /** |
|
333 This is part of the standard test machinery. It provides a place for the |
|
334 test instructions to be displayed, and a place for interactive messages |
|
335 to the user to be displayed. |
|
336 To have the test instructions displayed, see Sysout. |
|
337 To have a message to the user be displayed, see Sysout. |
|
338 Do not call anything in this dialog directly. |
|
339 */ |
|
340 class TestDialog extends Dialog |
|
341 { |
|
342 |
|
343 TextArea instructionsText; |
|
344 TextArea messageText; |
|
345 int maxStringLength = 80; |
|
346 |
|
347 //DO NOT call this directly, go through Sysout |
|
348 public TestDialog( Frame frame, String name ) |
|
349 { |
|
350 super( frame, name ); |
|
351 int scrollBoth = TextArea.SCROLLBARS_BOTH; |
|
352 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); |
|
353 add( "North", instructionsText ); |
|
354 |
|
355 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); |
|
356 add("Center", messageText); |
|
357 |
|
358 pack(); |
|
359 |
|
360 setVisible(true); |
|
361 }// TestDialog() |
|
362 |
|
363 //DO NOT call this directly, go through Sysout |
|
364 public void printInstructions( String[] instructions ) |
|
365 { |
|
366 //Clear out any current instructions |
|
367 instructionsText.setText( "" ); |
|
368 |
|
369 //Go down array of instruction strings |
|
370 |
|
371 String printStr, remainingStr; |
|
372 for( int i=0; i < instructions.length; i++ ) |
|
373 { |
|
374 //chop up each into pieces maxSringLength long |
|
375 remainingStr = instructions[ i ]; |
|
376 while( remainingStr.length() > 0 ) |
|
377 { |
|
378 //if longer than max then chop off first max chars to print |
|
379 if( remainingStr.length() >= maxStringLength ) |
|
380 { |
|
381 //Try to chop on a word boundary |
|
382 int posOfSpace = remainingStr. |
|
383 lastIndexOf( ' ', maxStringLength - 1 ); |
|
384 |
|
385 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; |
|
386 |
|
387 printStr = remainingStr.substring( 0, posOfSpace + 1 ); |
|
388 remainingStr = remainingStr.substring( posOfSpace + 1 ); |
|
389 } |
|
390 //else just print |
|
391 else |
|
392 { |
|
393 printStr = remainingStr; |
|
394 remainingStr = ""; |
|
395 } |
|
396 |
|
397 instructionsText.append( printStr + "\n" ); |
|
398 |
|
399 }// while |
|
400 |
|
401 }// for |
|
402 |
|
403 }//printInstructions() |
|
404 |
|
405 //DO NOT call this directly, go through Sysout |
|
406 public void displayMessage( String messageIn ) |
|
407 { |
|
408 messageText.append( messageIn + "\n" ); |
|
409 System.out.println(messageIn); |
|
410 } |
|
411 |
|
412 }// TestDialog class |
|