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