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