< prev index next >

test/jdk/java/awt/event/KeyEvent/KeyTyped/CtrlASCII.java

Print this page




   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  */
  23 
  24 /*
  25  * test
  26  * @bug 6497426
  27  * @summary Tests that pressing of Ctrl+ascii mostly fires KEY_TYPED with a Unicode control symbols
  28  * @author Yuri.Nesterenko@... area=awt.keyboard
  29  * @run applet CtrlASCII.html
  30  */
  31 
  32 // Note there is no @ in front of test above.  This is so that the
  33 //  harness will not mistake this file as a test file.  It should
  34 //  only see the html file as a test file. (the harness runs all
  35 //  valid test files, so it would run this test twice if this file
  36 //  were valid as well as the html file.)
  37 // Also, note the area= after Your Name in the author tag.  Here, you
  38 //  should put which functional area the test falls in.  See the
  39 //  AWT-core home page -> test areas and/or -> AWT team  for a list of
  40 //  areas.
  41 // Note also the 'RobotLWTest.html' in the run tag.  This should
  42 //  be changed to the name of the test.
  43 
  44 
  45 /**
  46  * CtrlASCII.java
  47  *
  48  * @summary Tests that pressing of Ctrl+ascii mostly fires KEY_TYPED with a Unicode control symbols
  49  */
  50 
  51 import java.applet.Applet;
  52 import java.awt.*;
  53 import java.awt.event.*;
  54 import java.util.*;
  55 
  56 
  57 //
  58 // In this test, a key listener for KEY_TYPED checks if a character typed has
  59 // a correspondent keycode in an initially filled hashtable.
  60 // If it does not, test fails. If character was produced by
  61 // pressing a wrong key still listed in the hashtable, test cannot detect it.
  62 // Under MS Windows, unlike X Window, some Ctrl+Ascii keystrokes don't
  63 // produce a unicode character, so there will be no KEY_TYPED and no problem.
  64 // Test doesn't try to verify Ctrl+deadkey behavior.
  65 //
  66 
  67 public class CtrlASCII extends Applet implements KeyListener
  68 {
  69     // Declare things used in the test, like buttons and labels here
  70     static Hashtable<Character, Integer> keycharHash = new Hashtable<Character, Integer>();
  71     static boolean testFailed = false;
  72     //Frame frame;
  73     TextField tf;
  74     Robot robot;
  75 
  76     static void fillHash( boolean isMSWindows ) {
  77         keycharHash.put(    (char)0x20         , KeyEvent.VK_SPACE        );                      /*32,x20*/ /*' ' */
  78         keycharHash.put(    (char)0x21         , KeyEvent.VK_EXCLAMATION_MARK        );           /*33,x21*/ /*'!' fr*/
  79         keycharHash.put(    (char)0x22         , KeyEvent.VK_QUOTEDBL        );                   /*34,x22*/ /*'"' fr*/
  80         keycharHash.put(    (char)0x23         , KeyEvent.VK_NUMBER_SIGN        );                /*35,x23*/ /*'#' de*/
  81         keycharHash.put(    (char)0x24         , KeyEvent.VK_DOLLAR        );                      /*36,x24*/ /*'$', de_CH*/
  82         //keycharHash.put('%',                                  (char)0x25        );                                  /*37,x25*/ /*no VK, cannot test*/
  83         keycharHash.put(    (char)0x26    , KeyEvent.VK_AMPERSAND        );                  /*38,x26*/ /*'&', fr*/
  84         keycharHash.put(    (char)0x27    , KeyEvent.VK_QUOTE        );                      /*39,x27*/ /*''', fr*/
  85         keycharHash.put(    (char)0x28    , KeyEvent.VK_LEFT_PARENTHESIS        );           /*40,x28*/ /*'(', fr*/
  86         keycharHash.put(    (char)0x29    , KeyEvent.VK_RIGHT_PARENTHESIS        );           /*41,x29*/ /*')', fr*/
  87         keycharHash.put(    (char)0x2a    , KeyEvent.VK_ASTERISK        );                    /*42,x2a*/ /*'*', fr*/


 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 




   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  */
  23 
  24 /*
  25   @test
  26   @key headful
  27   @bug  6497426
  28   @summary ests that pressing of Ctrl+ascii mostly fires KEY_TYPED with a Unicode control symbols
  29   @run main CtrlASCII
  30  */
  31 




















  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.util.*;
  35 

  36 //
  37 // In this test, a key listener for KEY_TYPED checks if a character typed has
  38 // a correspondent keycode in an initially filled hashtable.
  39 // If it does not, test fails. If character was produced by
  40 // pressing a wrong key still listed in the hashtable, test cannot detect it.
  41 // Under MS Windows, unlike X Window, some Ctrl+Ascii keystrokes don't
  42 // produce a unicode character, so there will be no KEY_TYPED and no problem.
  43 // Test doesn't try to verify Ctrl+deadkey behavior.
  44 //
  45 public class CtrlASCII extends Frame implements KeyListener

  46 {
  47     // Declare things used in the test, like buttons and labels here
  48     static Hashtable<Character, Integer> keycharHash = new Hashtable<Character, Integer>();
  49     static boolean testFailed = false;
  50     //Frame frame;
  51     TextField tf;
  52     Robot robot;
  53 
  54     static void fillHash( boolean isMSWindows ) {
  55         keycharHash.put(    (char)0x20         , KeyEvent.VK_SPACE        );                      /*32,x20*/ /*' ' */
  56         keycharHash.put(    (char)0x21         , KeyEvent.VK_EXCLAMATION_MARK        );           /*33,x21*/ /*'!' fr*/
  57         keycharHash.put(    (char)0x22         , KeyEvent.VK_QUOTEDBL        );                   /*34,x22*/ /*'"' fr*/
  58         keycharHash.put(    (char)0x23         , KeyEvent.VK_NUMBER_SIGN        );                /*35,x23*/ /*'#' de*/
  59         keycharHash.put(    (char)0x24         , KeyEvent.VK_DOLLAR        );                      /*36,x24*/ /*'$', de_CH*/
  60         //keycharHash.put('%',                                  (char)0x25        );                                  /*37,x25*/ /*no VK, cannot test*/
  61         keycharHash.put(    (char)0x26    , KeyEvent.VK_AMPERSAND        );                  /*38,x26*/ /*'&', fr*/
  62         keycharHash.put(    (char)0x27    , KeyEvent.VK_QUOTE        );                      /*39,x27*/ /*''', fr*/
  63         keycharHash.put(    (char)0x28    , KeyEvent.VK_LEFT_PARENTHESIS        );           /*40,x28*/ /*'(', fr*/
  64         keycharHash.put(    (char)0x29    , KeyEvent.VK_RIGHT_PARENTHESIS        );           /*41,x29*/ /*')', fr*/
  65         keycharHash.put(    (char)0x2a    , KeyEvent.VK_ASTERISK        );                    /*42,x2a*/ /*'*', fr*/


 155         //keycharHash.put(  (char)0x1e        , KeyEvent.VK_~        );                   /*126,x7e*/ /* no VK, cannot test*/
 156 
 157 
 158     }
 159     public static void main(String[] args) {
 160         CtrlASCII test = new CtrlASCII();
 161         test.init();
 162         test.start();
 163     }
 164 
 165     public void init()
 166     {
 167         fillHash( false );
 168         this.setLayout (new BorderLayout ());
 169 
 170     }//End  init()
 171 
 172     public void start ()
 173     {
 174         setSize(400,300);
 175         setLocationRelativeTo(null);
 176         setVisible(true);
 177 
 178         String original = "0123456789";
 179         tf = new TextField(original, 20);
 180         this.add(tf);
 181         tf.addKeyListener(this);
 182         validate();
 183 
 184         try {
 185             robot = new Robot();
 186             robot.setAutoWaitForIdle(true);
 187             robot.setAutoDelay(100);
 188 
 189             robot.waitForIdle();
 190 
 191             // wait for focus, etc.  (Hack.)
 192             robot.delay(2000);
 193             this.requestFocus();
 194             tf.requestFocusInWindow();
 195 


< prev index next >