1 /*
2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
169 //keycharHash.put( (char)0x17 , KeyEvent.VK_w );/*119,x77*/
170 //keycharHash.put( (char)0x18 , KeyEvent.VK_x );/*120,x78*/
171 //keycharHash.put( (char)0x19 , KeyEvent.VK_y );/*121,x79*/
172 //keycharHash.put( (char)0x1a , KeyEvent.VK_z );/*122,x7a*/
173
174 keycharHash.put( (char)0x7b , KeyEvent.VK_BRACELEFT ); /*123,x7b*/ /*'{' la (Latin American)*/
175 //keycharHash.put( (char)0x1c , KeyEvent.VK_| ); /*124,x7c*/ /* no VK, cannot test*/
176 keycharHash.put( (char)0x7d , KeyEvent.VK_BRACERIGHT ); /*125,x7d*/ /*'}' la */
177 //keycharHash.put( (char)0x1e , KeyEvent.VK_~ ); /*126,x7e*/ /* no VK, cannot test*/
178
179
180 }
181 public static void main(String[] args) {
182 CtrlASCII test = new CtrlASCII();
183 test.init();
184 test.start();
185 }
186
187 public void init()
188 {
189 //Create instructions for the user here, as well as set up
190 // the environment -- set the layout manager, add buttons,
191 // etc.
192 // XXX test for MS Windows
193 fillHash( false );
194 this.setLayout (new BorderLayout ());
195
196 String[] instructions =
197 {
198 "This is an AUTOMATIC test",
199 "simply wait until it is done"
200 };
201 Sysout.createDialog( );
202 Sysout.printInstructions( instructions );
203
204 }//End init()
205
206 public void start ()
207 {
208 //Get things going. Request focus, set size, et cetera
209
210 setSize(400,300);
211 setVisible(true);
212
213 //What would normally go into main() will probably go here.
214 //Use System.out.println for diagnostic messages that you want
215 //to read after the test is done.
216 //Use Sysout.println for messages you want the tester to read.
217
218 String original = "0123456789";
219 tf = new TextField(original, 20);
220 this.add(tf);
221 tf.addKeyListener(this);
222 validate();
223
224 try {
225 robot = new Robot();
226 robot.setAutoWaitForIdle(true);
227 robot.setAutoDelay(100);
228
229 robot.waitForIdle();
230
231 // wait for focus, etc. (Hack.)
232 robot.delay(2000);
233 this.requestFocus();
234 tf.requestFocusInWindow();
235
236 Point pt = getLocationOnScreen();
237 robot.mouseMove( pt.x+100, pt.y+100 );
238 robot.delay(2000);
239 robot.mousePress( InputEvent.BUTTON1_MASK );
240 robot.mouseRelease( InputEvent.BUTTON1_MASK );
241 Enumeration<Integer> enuElem = keycharHash.elements();
242
243 int kc;
244 while( enuElem.hasMoreElements()) {
245 kc = enuElem.nextElement();
246 punchCtrlKey( robot, kc );
247 }
248 robot.delay(500);
249 } catch (Exception e) {
250 throw new RuntimeException("The test was not completed.\n\n" + e);
251 }
252 if( testFailed ) {
253 throw new RuntimeException("The test failed.\n\n");
254 }
255 Sysout.println("Success\n");
256
257 }// start()
258 public void punchCtrlKey( Robot ro, int keyCode ) {
259 ro.keyPress(KeyEvent.VK_CONTROL);
260 try {
261 ro.keyPress(keyCode);
262 ro.keyRelease(keyCode);
263 }catch(IllegalArgumentException iae) {
264 System.err.println("skip probably invalid keyCode "+keyCode);
265 }
266 ro.keyRelease(KeyEvent.VK_CONTROL);
267 ro.delay(200);
268 }
269 public void keyPressed(KeyEvent evt)
270 {
271 //printKey(evt);
272 }
273
274 public void keyTyped(KeyEvent evt)
275 {
276 printKey(evt);
277 char keych = evt.getKeyChar();
278 if( !keycharHash.containsKey( keych ) ) {
279 System.out.println("Unexpected keychar: "+keych);
280 Sysout.println("Unexpected keychar: "+keych);
281 testFailed = true;
282 }
283 }
284
285 public void keyReleased(KeyEvent evt)
286 {
287 //printKey(evt);
288 }
289
290 protected void printKey(KeyEvent evt)
291 {
292 switch(evt.getID())
293 {
294 case KeyEvent.KEY_TYPED:
295 case KeyEvent.KEY_PRESSED:
296 case KeyEvent.KEY_RELEASED:
297 break;
298 default:
299 System.out.println("Other Event ");
300 Sysout.println("Other Event ");
301 return;
302 }
303 System.out.print(" 0x"+ Integer.toHexString(evt.getKeyChar()));
304 Sysout.println (" 0x"+ Integer.toHexString(evt.getKeyChar()));
305 }
306
307 }// class CtrlASCII
308
309
310 /****************************************************
311 Standard Test Machinery
312 DO NOT modify anything below -- it's a standard
313 chunk of code whose purpose is to make user
314 interaction uniform, and thereby make it simpler
315 to read and understand someone else's test.
316 ****************************************************/
317
318 /**
319 This is part of the standard test machinery.
320 It creates a dialog (with the instructions), and is the interface
321 for sending text messages to the user.
322 To print the instructions, send an array of strings to Sysout.createDialog
323 WithInstructions method. Put one line of instructions per array entry.
324 To display a message for the tester to see, simply call Sysout.println
325 with the string to be displayed.
326 This mimics System.out.println but works within the test harness as well
327 as standalone.
328 */
329
330 class Sysout
331 {
332 private static TestDialog dialog;
333
334 public static void createDialogWithInstructions( String[] instructions )
335 {
336 dialog = new TestDialog( new Frame(), "Instructions" );
337 dialog.printInstructions( instructions );
338 dialog.show();
339 println( "Any messages for the tester will display here." );
340 }
341
342 public static void createDialog( )
343 {
344 dialog = new TestDialog( new Frame(), "Instructions" );
345 String[] defInstr = { "Instructions will appear here. ", "" } ;
346 dialog.printInstructions( defInstr );
347 dialog.show();
348 println( "Any messages for the tester will display here." );
349 }
350
351
352 public static void printInstructions( String[] instructions )
353 {
354 dialog.printInstructions( instructions );
355 }
356
357
358 public static void println( String messageIn )
359 {
360 dialog.displayMessage( messageIn );
361 }
362
363 }// Sysout class
364
365 /**
366 This is part of the standard test machinery. It provides a place for the
367 test instructions to be displayed, and a place for interactive messages
368 to the user to be displayed.
369 To have the test instructions displayed, see Sysout.
370 To have a message to the user be displayed, see Sysout.
371 Do not call anything in this dialog directly.
372 */
373 class TestDialog extends Dialog
374 {
375
376 TextArea instructionsText;
377 TextArea messageText;
378 int maxStringLength = 80;
379
380 //DO NOT call this directly, go through Sysout
381 public TestDialog( Frame frame, String name )
382 {
383 super( frame, name );
384 int scrollBoth = TextArea.SCROLLBARS_BOTH;
385 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
386 add( "North", instructionsText );
387
388 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
389 add("South", messageText);
390
391 pack();
392
393 show();
394 }// TestDialog()
395
396 //DO NOT call this directly, go through Sysout
397 public void printInstructions( String[] instructions )
398 {
399 //Clear out any current instructions
400 instructionsText.setText( "" );
401
402 //Go down array of instruction strings
403
404 String printStr, remainingStr;
405 for( int i=0; i < instructions.length; i++ )
406 {
407 //chop up each into pieces maxSringLength long
408 remainingStr = instructions[ i ];
409 while( remainingStr.length() > 0 )
410 {
411 //if longer than max then chop off first max chars to print
412 if( remainingStr.length() >= maxStringLength )
413 {
414 //Try to chop on a word boundary
415 int posOfSpace = remainingStr.
416 lastIndexOf( ' ', maxStringLength - 1 );
417
418 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
419
420 printStr = remainingStr.substring( 0, posOfSpace + 1 );
421 remainingStr = remainingStr.substring( posOfSpace + 1 );
422 }
423 //else just print
424 else
425 {
426 printStr = remainingStr;
427 remainingStr = "";
428 }
429
430 instructionsText.append( printStr + "\n" );
431
432 }// while
433
434 }// for
435
436 }//printInstructions()
437
438 //DO NOT call this directly, go through Sysout
439 public void displayMessage( String messageIn )
440 {
441 messageText.append( messageIn + "\n" );
442 }
443
444 }// TestDialog class
|
1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
169 //keycharHash.put( (char)0x17 , KeyEvent.VK_w );/*119,x77*/
170 //keycharHash.put( (char)0x18 , KeyEvent.VK_x );/*120,x78*/
171 //keycharHash.put( (char)0x19 , KeyEvent.VK_y );/*121,x79*/
172 //keycharHash.put( (char)0x1a , KeyEvent.VK_z );/*122,x7a*/
173
174 keycharHash.put( (char)0x7b , KeyEvent.VK_BRACELEFT ); /*123,x7b*/ /*'{' la (Latin American)*/
175 //keycharHash.put( (char)0x1c , KeyEvent.VK_| ); /*124,x7c*/ /* no VK, cannot test*/
176 keycharHash.put( (char)0x7d , KeyEvent.VK_BRACERIGHT ); /*125,x7d*/ /*'}' la */
177 //keycharHash.put( (char)0x1e , KeyEvent.VK_~ ); /*126,x7e*/ /* no VK, cannot test*/
178
179
180 }
181 public static void main(String[] args) {
182 CtrlASCII test = new CtrlASCII();
183 test.init();
184 test.start();
185 }
186
187 public void init()
188 {
189 fillHash( false );
190 this.setLayout (new BorderLayout ());
191
192 }//End init()
193
194 public void start ()
195 {
196 setSize(400,300);
197 setVisible(true);
198
199 String original = "0123456789";
200 tf = new TextField(original, 20);
201 this.add(tf);
202 tf.addKeyListener(this);
203 validate();
204
205 try {
206 robot = new Robot();
207 robot.setAutoWaitForIdle(true);
208 robot.setAutoDelay(100);
209
210 robot.waitForIdle();
211
212 // wait for focus, etc. (Hack.)
213 robot.delay(2000);
214 this.requestFocus();
215 tf.requestFocusInWindow();
216
217 Point pt = getLocationOnScreen();
218 robot.mouseMove( pt.x+100, pt.y+100 );
219 robot.delay(2000);
220 robot.mousePress( InputEvent.BUTTON1_MASK );
221 robot.mouseRelease( InputEvent.BUTTON1_MASK );
222 Enumeration<Integer> enuElem = keycharHash.elements();
223
224 int kc;
225 while( enuElem.hasMoreElements()) {
226 kc = enuElem.nextElement();
227 punchCtrlKey( robot, kc );
228 }
229 robot.delay(500);
230 } catch (Exception e) {
231 throw new RuntimeException("The test was not completed.\n\n" + e);
232 }
233 if( testFailed ) {
234 throw new RuntimeException("The test failed.\n\n");
235 }
236 System.out.println("Success\n");
237
238 }// start()
239 public void punchCtrlKey( Robot ro, int keyCode ) {
240 ro.keyPress(KeyEvent.VK_CONTROL);
241 try {
242 ro.keyPress(keyCode);
243 ro.keyRelease(keyCode);
244 }catch(IllegalArgumentException iae) {
245 System.err.println("skip probably invalid keyCode "+keyCode);
246 }
247 ro.keyRelease(KeyEvent.VK_CONTROL);
248 ro.delay(200);
249 }
250 public void keyPressed(KeyEvent evt)
251 {
252 //printKey(evt);
253 }
254
255 public void keyTyped(KeyEvent evt)
256 {
257 printKey(evt);
258 char keych = evt.getKeyChar();
259 if( !keycharHash.containsKey( keych ) ) {
260 System.out.println("Unexpected keychar: "+keych);
261 System.out.println("Unexpected keychar: "+keych);
262 testFailed = true;
263 }
264 }
265
266 public void keyReleased(KeyEvent evt)
267 {
268 //printKey(evt);
269 }
270
271 protected void printKey(KeyEvent evt)
272 {
273 switch(evt.getID())
274 {
275 case KeyEvent.KEY_TYPED:
276 case KeyEvent.KEY_PRESSED:
277 case KeyEvent.KEY_RELEASED:
278 break;
279 default:
280 System.out.println("Other Event ");
281 System.out.println("Other Event ");
282 return;
283 }
284 System.out.print(" 0x"+ Integer.toHexString(evt.getKeyChar()));
285 System.out.println (" 0x"+ Integer.toHexString(evt.getKeyChar()));
286 }
287
288 }// class CtrlASCII
|