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