0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * test
0N/A * @bug 6497426
0N/A * @summary Tests that pressing of Ctrl+ascii mostly fires KEY_TYPED with a Unicode control symbols
0N/A * @author Yuri.Nesterenko@... area=awt.keyboard
0N/A * @run applet CtrlASCII.html
0N/A */
0N/A
0N/A// Note there is no @ in front of test above. This is so that the
0N/A// harness will not mistake this file as a test file. It should
0N/A// only see the html file as a test file. (the harness runs all
0N/A// valid test files, so it would run this test twice if this file
0N/A// were valid as well as the html file.)
0N/A// Also, note the area= after Your Name in the author tag. Here, you
0N/A// should put which functional area the test falls in. See the
0N/A// AWT-core home page -> test areas and/or -> AWT team for a list of
0N/A// areas.
0N/A// Note also the 'RobotLWTest.html' in the run tag. This should
0N/A// be changed to the name of the test.
0N/A
0N/A
0N/A/**
0N/A * CtrlASCII.java
0N/A *
0N/A * @summary Tests that pressing of Ctrl+ascii mostly fires KEY_TYPED with a Unicode control symbols
0N/A */
0N/A
0N/Aimport java.applet.Applet;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.util.*;
0N/A
0N/A
0N/A//
0N/A// In this test, a key listener for KEY_TYPED checks if a character typed has
0N/A// a correspondent keycode in an initially filled hashtable.
0N/A// If it does not, test fails. If character was produced by
0N/A// pressing a wrong key still listed in the hashtable, test cannot detect it.
0N/A// Under MS Windows, unlike X Window, some Ctrl+Ascii keystrokes don't
0N/A// produce a unicode character, so there will be no KEY_TYPED and no problem.
0N/A// Test doesn't try to verify Ctrl+deadkey behavior.
0N/A//
0N/A
0N/Apublic class CtrlASCII extends Applet implements KeyListener
0N/A{
0N/A // Declare things used in the test, like buttons and labels here
0N/A static Hashtable<Character, Integer> keycharHash = new Hashtable<Character, Integer>();
0N/A static boolean testFailed = false;
0N/A //Frame frame;
0N/A TextField tf;
0N/A Robot robot;
0N/A
0N/A static void fillHash( boolean isMSWindows ) {
0N/A keycharHash.put( (char)0x20 , KeyEvent.VK_SPACE ); /*32,x20*/ /*' ' */
0N/A keycharHash.put( (char)0x21 , KeyEvent.VK_EXCLAMATION_MARK ); /*33,x21*/ /*'!' fr*/
0N/A keycharHash.put( (char)0x22 , KeyEvent.VK_QUOTEDBL ); /*34,x22*/ /*'"' fr*/
0N/A keycharHash.put( (char)0x23 , KeyEvent.VK_NUMBER_SIGN ); /*35,x23*/ /*'#' de*/
0N/A keycharHash.put( (char)0x24 , KeyEvent.VK_DOLLAR ); /*36,x24*/ /*'$', de_CH*/
0N/A //keycharHash.put('%', (char)0x25 ); /*37,x25*/ /*no VK, cannot test*/
0N/A keycharHash.put( (char)0x26 , KeyEvent.VK_AMPERSAND ); /*38,x26*/ /*'&', fr*/
0N/A keycharHash.put( (char)0x27 , KeyEvent.VK_QUOTE ); /*39,x27*/ /*''', fr*/
0N/A keycharHash.put( (char)0x28 , KeyEvent.VK_LEFT_PARENTHESIS ); /*40,x28*/ /*'(', fr*/
0N/A keycharHash.put( (char)0x29 , KeyEvent.VK_RIGHT_PARENTHESIS ); /*41,x29*/ /*')', fr*/
0N/A keycharHash.put( (char)0x2a , KeyEvent.VK_ASTERISK ); /*42,x2a*/ /*'*', fr*/
0N/A keycharHash.put( (char)0x2b , KeyEvent.VK_PLUS ); /*43,x2b*/ /*'+', de*/
0N/A keycharHash.put( (char)0x2c , KeyEvent.VK_COMMA ); /*44,x2c*/ /*','*/
0N/A keycharHash.put( (char)0x2d , KeyEvent.VK_MINUS ); /*45,x2d*/ /*'-'*/
0N/A keycharHash.put( (char)0x2e , KeyEvent.VK_PERIOD ); /*46,x2e*/ /*'.'*/
0N/A keycharHash.put( (char)0x2f , KeyEvent.VK_SLASH ); /*47,x2f*/ /*'/'*/
0N/A keycharHash.put( (char)0x30 , KeyEvent.VK_0 ); /*48,x30*/
0N/A keycharHash.put( (char)0x31 , KeyEvent.VK_1 ); /*49,x31*/
0N/A keycharHash.put( (char)0x32 , KeyEvent.VK_2 ); /*50,x32*/
0N/A keycharHash.put( (char)0x33 , KeyEvent.VK_3 ); /*51,x33*/
0N/A keycharHash.put( (char)0x34 , KeyEvent.VK_4 ); /*52,x34*/
0N/A keycharHash.put( (char)0x35 , KeyEvent.VK_5 ); /*53,x35*/
0N/A keycharHash.put( (char)0x36 , KeyEvent.VK_6 ); /*54,x36*/
0N/A keycharHash.put( (char)0x37 , KeyEvent.VK_7 ); /*55,x37*/
0N/A keycharHash.put( (char)0x38 , KeyEvent.VK_8 ); /*56,x38*/
0N/A keycharHash.put( (char)0x39 , KeyEvent.VK_9 ); /*57,x39*/
0N/A keycharHash.put( (char)0x3a , KeyEvent.VK_COLON ); /*58,x3a*/ /*':', fr*/
0N/A keycharHash.put( (char)0x3b , KeyEvent.VK_SEMICOLON ); /*59,x3b*/ /*';'*/
0N/A keycharHash.put( (char)0x3c , KeyEvent.VK_LESS ); /*60,x3c*/ /*'<' us 102*/
0N/A keycharHash.put( (char)0x3d , KeyEvent.VK_EQUALS ); /*61,x3d*/
0N/A keycharHash.put( (char)0x3e , KeyEvent.VK_GREATER ); /*62,x3e*/ /*'>' ?????? where???*/
0N/A // Javadoc says: "there is no keycode for the question mark because
0N/A // there is no keyboard for which it appears on the primary layer."
0N/A // Well, it's Lithuanian standard.
0N/A //keycharHash.put('?', (char)0x3f ); /*63,x3f*/ /*no VK, cannot test*/
0N/A keycharHash.put( (char)0x40 , KeyEvent.VK_AT ); /*64,x40*/ /*'@' ?????? where???*/
0N/A keycharHash.put( (char)0x1 , KeyEvent.VK_A ); /*65,x41*/
0N/A keycharHash.put( (char)0x2 , KeyEvent.VK_B ); /*66,x42*/
0N/A keycharHash.put( (char)0x3 , KeyEvent.VK_C ); /*67,x43*/
0N/A keycharHash.put( (char)0x4 , KeyEvent.VK_D ); /*68,x44*/
0N/A keycharHash.put( (char)0x5 , KeyEvent.VK_E ); /*69,x45*/
0N/A keycharHash.put( (char)0x6 , KeyEvent.VK_F ); /*70,x46*/
0N/A keycharHash.put( (char)0x7 , KeyEvent.VK_G ); /*71,x47*/
0N/A keycharHash.put( (char)0x8 , KeyEvent.VK_H ); /*72,x48*/
0N/A keycharHash.put( (char)0x9 , KeyEvent.VK_I ); /*73,x49*/
0N/A keycharHash.put( (char)0xa , KeyEvent.VK_J ); /*74,x4a*/
0N/A keycharHash.put( (char)0xb , KeyEvent.VK_K ); /*75,x4b*/
0N/A keycharHash.put( (char)0xc , KeyEvent.VK_L ); /*76,x4c*/
0N/A keycharHash.put( (char)0xd , KeyEvent.VK_M ); /*77,x4d*/
0N/A keycharHash.put( (char)0xe , KeyEvent.VK_N ); /*78,x4e*/
0N/A keycharHash.put( (char)0xf , KeyEvent.VK_O ); /*79,x4f*/
0N/A keycharHash.put( (char)0x10 , KeyEvent.VK_P ); /*80,x50*/
0N/A keycharHash.put( (char)0x11 , KeyEvent.VK_Q ); /*81,x51*/
0N/A keycharHash.put( (char)0x12 , KeyEvent.VK_R ); /*82,x52*/
0N/A keycharHash.put( (char)0x13 , KeyEvent.VK_S ); /*83,x53*/
0N/A keycharHash.put( (char)0x14 , KeyEvent.VK_T ); /*84,x54*/
0N/A keycharHash.put( (char)0x15 , KeyEvent.VK_U ); /*85,x55*/
0N/A keycharHash.put( (char)0x16 , KeyEvent.VK_V ); /*86,x56*/
0N/A keycharHash.put( (char)0x17 , KeyEvent.VK_W ); /*87,x57*/
0N/A keycharHash.put( (char)0x18 , KeyEvent.VK_X ); /*88,x58*/
0N/A keycharHash.put( (char)0x19 , KeyEvent.VK_Y ); /*89,x59*/
0N/A keycharHash.put( (char)0x1a , KeyEvent.VK_Z ); /*90,x5a*/
0N/A
0N/A keycharHash.put( (char)0x1b , KeyEvent.VK_OPEN_BRACKET ); /*91,x5b*/ /*'['*/
0N/A keycharHash.put( (char)0x1c , KeyEvent.VK_BACK_SLASH ); /*92,x5c*/ /*'\'*/
0N/A keycharHash.put( (char)0x1d , KeyEvent.VK_CLOSE_BRACKET ); /*93,x5d*/ /*']'*/
0N/A keycharHash.put( (char)0x5e , KeyEvent.VK_CIRCUMFLEX ); /*94,x5e*/ /*'^' ?? nodead fr, de??*/
0N/A keycharHash.put( (char)0x1f , KeyEvent.VK_UNDERSCORE ); /*95,x5f*/ /*'_' fr*/
0N/A keycharHash.put( (char)0x60 , KeyEvent.VK_BACK_QUOTE ); /*96,x60*/
0N/A /********* Same as uppercase*/
0N/A //keycharHash.put( (char)0x1 , KeyEvent.VK_a );/*97,x61*/
0N/A //keycharHash.put( (char)0x2 , KeyEvent.VK_b );/*98,x62*/
0N/A //keycharHash.put( (char)0x3 , KeyEvent.VK_c );/*99,x63*/
0N/A //keycharHash.put( (char)0x4 , KeyEvent.VK_d );/*100,x64*/
0N/A //keycharHash.put( (char)0x5 , KeyEvent.VK_e );/*101,x65*/
0N/A //keycharHash.put( (char)0x6 , KeyEvent.VK_f );/*102,x66*/
0N/A //keycharHash.put( (char)0x7 , KeyEvent.VK_g );/*103,x67*/
0N/A //keycharHash.put( (char)0x8 , KeyEvent.VK_h );/*104,x68*/
0N/A //keycharHash.put( (char)0x9 , KeyEvent.VK_i );/*105,x69*/
0N/A //keycharHash.put( (char)0xa , KeyEvent.VK_j );/*106,x6a*/
0N/A //keycharHash.put( (char)0xb , KeyEvent.VK_k );/*107,x6b*/
0N/A //keycharHash.put( (char)0xc , KeyEvent.VK_l );/*108,x6c*/
0N/A //keycharHash.put( (char)0xd , KeyEvent.VK_m );/*109,x6d*/
0N/A //keycharHash.put( (char)0xe , KeyEvent.VK_n );/*110,x6e*/
0N/A //keycharHash.put( (char)0xf , KeyEvent.VK_o );/*111,x6f*/
0N/A //keycharHash.put( (char)0x10 , KeyEvent.VK_p );/*112,x70*/
0N/A //keycharHash.put( (char)0x11 , KeyEvent.VK_q );/*113,x71*/
0N/A //keycharHash.put( (char)0x12 , KeyEvent.VK_r );/*114,x72*/
0N/A //keycharHash.put( (char)0x13 , KeyEvent.VK_s );/*115,x73*/
0N/A //keycharHash.put( (char)0x14 , KeyEvent.VK_t );/*116,x74*/
0N/A //keycharHash.put( (char)0x15 , KeyEvent.VK_u );/*117,x75*/
0N/A //keycharHash.put( (char)0x16 , KeyEvent.VK_v );/*118,x76*/
0N/A //keycharHash.put( (char)0x17 , KeyEvent.VK_w );/*119,x77*/
0N/A //keycharHash.put( (char)0x18 , KeyEvent.VK_x );/*120,x78*/
0N/A //keycharHash.put( (char)0x19 , KeyEvent.VK_y );/*121,x79*/
0N/A //keycharHash.put( (char)0x1a , KeyEvent.VK_z );/*122,x7a*/
0N/A
0N/A keycharHash.put( (char)0x7b , KeyEvent.VK_BRACELEFT ); /*123,x7b*/ /*'{' la (Latin American)*/
0N/A //keycharHash.put( (char)0x1c , KeyEvent.VK_| ); /*124,x7c*/ /* no VK, cannot test*/
0N/A keycharHash.put( (char)0x7d , KeyEvent.VK_BRACERIGHT ); /*125,x7d*/ /*'}' la */
0N/A //keycharHash.put( (char)0x1e , KeyEvent.VK_~ ); /*126,x7e*/ /* no VK, cannot test*/
0N/A
0N/A
0N/A }
0N/A public static void main(String[] args) {
0N/A CtrlASCII test = new CtrlASCII();
0N/A test.init();
0N/A test.start();
0N/A }
0N/A
0N/A public void init()
0N/A {
0N/A //Create instructions for the user here, as well as set up
0N/A // the environment -- set the layout manager, add buttons,
0N/A // etc.
0N/A // XXX test for MS Windows
0N/A fillHash( false );
0N/A this.setLayout (new BorderLayout ());
0N/A
0N/A String[] instructions =
0N/A {
0N/A "This is an AUTOMATIC test",
0N/A "simply wait until it is done"
0N/A };
0N/A Sysout.createDialog( );
0N/A Sysout.printInstructions( instructions );
0N/A
0N/A }//End init()
0N/A
0N/A public void start ()
0N/A {
0N/A //Get things going. Request focus, set size, et cetera
0N/A
0N/A setSize(400,300);
0N/A setVisible(true);
0N/A
0N/A //What would normally go into main() will probably go here.
0N/A //Use System.out.println for diagnostic messages that you want
0N/A //to read after the test is done.
0N/A //Use Sysout.println for messages you want the tester to read.
0N/A
0N/A String original = "0123456789";
0N/A tf = new TextField(original, 20);
0N/A this.add(tf);
0N/A tf.addKeyListener(this);
0N/A validate();
0N/A
0N/A try {
0N/A robot = new Robot();
0N/A robot.setAutoWaitForIdle(true);
0N/A robot.setAutoDelay(100);
0N/A
0N/A robot.waitForIdle();
0N/A
0N/A // wait for focus, etc. (Hack.)
0N/A robot.delay(2000);
0N/A this.requestFocus();
0N/A tf.requestFocusInWindow();
0N/A
0N/A Point pt = getLocationOnScreen();
0N/A robot.mouseMove( pt.x+100, pt.y+100 );
0N/A robot.delay(2000);
0N/A robot.mousePress( InputEvent.BUTTON1_MASK );
0N/A robot.mouseRelease( InputEvent.BUTTON1_MASK );
0N/A Enumeration<Integer> enuElem = keycharHash.elements();
0N/A
0N/A int kc;
0N/A while( enuElem.hasMoreElements()) {
0N/A kc = enuElem.nextElement();
0N/A punchCtrlKey( robot, kc );
0N/A }
0N/A robot.delay(500);
0N/A } catch (Exception e) {
0N/A throw new RuntimeException("The test was not completed.\n\n" + e);
0N/A }
0N/A if( testFailed ) {
0N/A throw new RuntimeException("The test failed.\n\n");
0N/A }
0N/A Sysout.println("Success\n");
0N/A
0N/A }// start()
0N/A public void punchCtrlKey( Robot ro, int keyCode ) {
0N/A ro.keyPress(KeyEvent.VK_CONTROL);
0N/A ro.keyPress(keyCode);
0N/A ro.keyRelease(keyCode);
0N/A ro.keyRelease(KeyEvent.VK_CONTROL);
0N/A ro.delay(200);
0N/A }
0N/A public void keyPressed(KeyEvent evt)
0N/A {
0N/A //printKey(evt);
0N/A }
0N/A
0N/A public void keyTyped(KeyEvent evt)
0N/A {
0N/A printKey(evt);
0N/A char keych = evt.getKeyChar();
0N/A if( !keycharHash.containsKey( keych ) ) {
0N/A System.out.println("Unexpected keychar: "+keych);
0N/A Sysout.println("Unexpected keychar: "+keych);
0N/A testFailed = true;
0N/A }
0N/A }
0N/A
0N/A public void keyReleased(KeyEvent evt)
0N/A {
0N/A //printKey(evt);
0N/A }
0N/A
0N/A protected void printKey(KeyEvent evt)
0N/A {
0N/A switch(evt.getID())
0N/A {
0N/A case KeyEvent.KEY_TYPED:
0N/A case KeyEvent.KEY_PRESSED:
0N/A case KeyEvent.KEY_RELEASED:
0N/A break;
0N/A default:
0N/A System.out.println("Other Event ");
0N/A Sysout.println("Other Event ");
0N/A return;
0N/A }
0N/A System.out.print(" 0x"+ Integer.toHexString(evt.getKeyChar()));
0N/A Sysout.println (" 0x"+ Integer.toHexString(evt.getKeyChar()));
0N/A }
0N/A
0N/A}// class CtrlASCII
0N/A
0N/A
0N/A/****************************************************
0N/A Standard Test Machinery
0N/A DO NOT modify anything below -- it's a standard
0N/A chunk of code whose purpose is to make user
0N/A interaction uniform, and thereby make it simpler
0N/A to read and understand someone else's test.
0N/A ****************************************************/
0N/A
0N/A/**
0N/A This is part of the standard test machinery.
0N/A It creates a dialog (with the instructions), and is the interface
0N/A for sending text messages to the user.
0N/A To print the instructions, send an array of strings to Sysout.createDialog
0N/A WithInstructions method. Put one line of instructions per array entry.
0N/A To display a message for the tester to see, simply call Sysout.println
0N/A with the string to be displayed.
0N/A This mimics System.out.println but works within the test harness as well
0N/A as standalone.
0N/A */
0N/A
0N/Aclass Sysout
0N/A {
0N/A private static TestDialog dialog;
0N/A
0N/A public static void createDialogWithInstructions( String[] instructions )
0N/A {
0N/A dialog = new TestDialog( new Frame(), "Instructions" );
0N/A dialog.printInstructions( instructions );
0N/A dialog.show();
0N/A println( "Any messages for the tester will display here." );
0N/A }
0N/A
0N/A public static void createDialog( )
0N/A {
0N/A dialog = new TestDialog( new Frame(), "Instructions" );
0N/A String[] defInstr = { "Instructions will appear here. ", "" } ;
0N/A dialog.printInstructions( defInstr );
0N/A dialog.show();
0N/A println( "Any messages for the tester will display here." );
0N/A }
0N/A
0N/A
0N/A public static void printInstructions( String[] instructions )
0N/A {
0N/A dialog.printInstructions( instructions );
0N/A }
0N/A
0N/A
0N/A public static void println( String messageIn )
0N/A {
0N/A dialog.displayMessage( messageIn );
0N/A }
0N/A
0N/A }// Sysout class
0N/A
0N/A/**
0N/A This is part of the standard test machinery. It provides a place for the
0N/A test instructions to be displayed, and a place for interactive messages
0N/A to the user to be displayed.
0N/A To have the test instructions displayed, see Sysout.
0N/A To have a message to the user be displayed, see Sysout.
0N/A Do not call anything in this dialog directly.
0N/A */
0N/Aclass TestDialog extends Dialog
0N/A {
0N/A
0N/A TextArea instructionsText;
0N/A TextArea messageText;
0N/A int maxStringLength = 80;
0N/A
0N/A //DO NOT call this directly, go through Sysout
0N/A public TestDialog( Frame frame, String name )
0N/A {
0N/A super( frame, name );
0N/A int scrollBoth = TextArea.SCROLLBARS_BOTH;
0N/A instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
0N/A add( "North", instructionsText );
0N/A
0N/A messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
0N/A add("South", messageText);
0N/A
0N/A pack();
0N/A
0N/A show();
0N/A }// TestDialog()
0N/A
0N/A //DO NOT call this directly, go through Sysout
0N/A public void printInstructions( String[] instructions )
0N/A {
0N/A //Clear out any current instructions
0N/A instructionsText.setText( "" );
0N/A
0N/A //Go down array of instruction strings
0N/A
0N/A String printStr, remainingStr;
0N/A for( int i=0; i < instructions.length; i++ )
0N/A {
0N/A //chop up each into pieces maxSringLength long
0N/A remainingStr = instructions[ i ];
0N/A while( remainingStr.length() > 0 )
0N/A {
0N/A //if longer than max then chop off first max chars to print
0N/A if( remainingStr.length() >= maxStringLength )
0N/A {
0N/A //Try to chop on a word boundary
0N/A int posOfSpace = remainingStr.
0N/A lastIndexOf( ' ', maxStringLength - 1 );
0N/A
0N/A if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
0N/A
0N/A printStr = remainingStr.substring( 0, posOfSpace + 1 );
0N/A remainingStr = remainingStr.substring( posOfSpace + 1 );
0N/A }
0N/A //else just print
0N/A else
0N/A {
0N/A printStr = remainingStr;
0N/A remainingStr = "";
0N/A }
0N/A
0N/A instructionsText.append( printStr + "\n" );
0N/A
0N/A }// while
0N/A
0N/A }// for
0N/A
0N/A }//printInstructions()
0N/A
0N/A //DO NOT call this directly, go through Sysout
0N/A public void displayMessage( String messageIn )
0N/A {
0N/A messageText.append( messageIn + "\n" );
0N/A }
0N/A
0N/A }// TestDialog class