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