rev 9504 : need to fix test log and others

   1 /*
   2  * Copyright (c) 2014, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.robot.com.sun.glass.ui.monocle;
  27 
  28 import com.sun.glass.ui.monocle.TestLog;
  29 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  30 import org.junit.After;
  31 import org.junit.Assert;
  32 import org.junit.Before;
  33 import org.junit.Test;
  34 
  35 
  36 public class USKeyboardTest {
  37 
  38     private UInput ui;
  39     private Character [] bigChars;
  40     private Character [] smallChars;
  41     private Character [] digits;
  42     private Character [] digitsShift;
  43     private Character [] signs;
  44     private Character [] signsShift;
  45     private String [] signsKeyNames;
  46 
  47     @Before
  48     public void initDevice() {
  49         TestLog.reset();
  50         ui = new UInput();
  51     }
  52 
  53     @After
  54     public void destroyDevice() throws InterruptedException {
  55         ui.waitForQuiet();
  56         try {
  57             ui.processLine("DESTROY");
  58         } catch (RuntimeException e) { }
  59         ui.processLine("CLOSE");
  60         ui.dispose();
  61     }
  62 
  63     private void createUSKeyboard() {
  64         bigChars = new Character[26];
  65         for(int i = 65; i < 91; i++) {
  66             bigChars[i-65] = (char) i;
  67         }
  68         smallChars = new Character[26];
  69         for(int i = 97; i < 123; i++) {
  70             smallChars[i-97] = (char) i;
  71         }
  72         digits = new Character [] {'1','2','3','4','5','6','7','8','9','0'};
  73         digitsShift = new Character [] {'!','@','#','$','%','^','&','*','(',')'};
  74 
  75         signs =  new Character [] {'`','-','=','[',']',';','\'','\\',',','.','/'};
  76         signsShift = new Character [] {'~','_','+','{','}',':','"','|','<','>','?'};
  77         signsKeyNames = new String [] {"GRAVE", "MINUS","EQUAL","LEFTBRACE",
  78                                         "RIGHTBRACE","SEMICOLON","APOSTROPHE",
  79                                         "BACKSLASH","COMMA","DOT","SLASH"};
  80         ui.processLine("OPEN");
  81         ui.processLine("EVBIT EV_KEY");
  82         ui.processLine("EVBIT EV_SYN");
  83         for(int i = 0; i < 26; i++) {
  84             ui.processLine("KEYBIT KEY_" + bigChars[i]);
  85         }
  86         for(int i = 0; i < 10; i++) {
  87             ui.processLine("KEYBIT KEY_" + digits[i]);
  88         }
  89         for(int i = 0; i < 11; i++) {
  90             ui.processLine("KEYBIT KEY_" + signsKeyNames[i]);
  91         }
  92         ui.processLine("KEYBIT 0x0033");
  93         ui.processLine("KEYBIT KEY_LEFTSHIFT");
  94         ui.processLine("KEYBIT KEY_CAPSLOCK");
  95         ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
  96         ui.processLine("CREATE");
  97     }
  98 
  99     private void checkShift(String key, char unShifted, char shifted) throws Exception {
 100         checkKey(key, unShifted, false);
 101         checkKey(key, shifted, true);
 102     }
 103 
 104     private void checkKey(String key, char c, boolean shiftPressed) throws Exception {
 105         if (shiftPressed) {
 106             ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
 107             ui.processLine("EV_SYN");
 108         }
 109         ui.processLine("EV_KEY " + key + " 1");
 110         ui.processLine("EV_SYN");
 111         ui.processLine("EV_KEY " + key + " 0");
 112         ui.processLine("EV_SYN");
 113         if (shiftPressed) {
 114             ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
 115             ui.processLine("EV_SYN");
 116             TestLog.waitForLog("Key released: SHIFT");
 117         }
 118         TestLog.waitForLog("Key typed: %0$c", new Object[] { c });
 119     }
 120 
 121     /**
 122      * The test is checking the lookup of each key on board,
 123      * at first with Shift button unpressed and then with Shift button pressed.
 124      */
 125     @Test
 126     public void testShift() throws Exception {
 127         TestApplication.showFullScreenScene();
 128         TestApplication.addKeyListeners();
 129         createUSKeyboard();
 130 
 131         for(int i = 0; i < 26; i++) {
 132             checkShift("KEY_"+ bigChars[i], smallChars[i], bigChars[i]);
 133         }
 134         for(int i = 0; i < 10; i++) {
 135             checkShift("KEY_"+ digits[i], digits[i], digitsShift[i]);
 136         }
 137         for(int i = 0; i < 11; i++) {
 138             checkShift("KEY_"+ signsKeyNames[i], signs[i], signsShift[i]);
 139         }
 140     }
 141 
 142     /**
 143      * The test is checking the lookup of each key on board,
 144      * when Caps Lock only is pressed and then with both Shift
 145      * and Caps Lock buttons are pressed.
 146      */
 147     @Test
 148     public void testCapsLock() throws Exception {
 149         TestApplication.showFullScreenScene();
 150         TestApplication.addKeyListeners();
 151         createUSKeyboard();
 152 
 153         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 154         ui.processLine("EV_SYN");
 155         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 156         ui.processLine("EV_SYN");
 157 
 158         for(int i = 0; i < 26; i++) {
 159             checkShift("KEY_"+ bigChars[i], bigChars[i], smallChars[i]);
 160         }
 161         for(int i = 0; i < 10; i++) {
 162             checkShift("KEY_"+ digits[i], digits[i], digitsShift[i]);
 163         }
 164         for(int i = 0; i < 11; i++) {
 165             checkShift("KEY_"+ signsKeyNames[i], signs[i], signsShift[i]);
 166         }
 167 
 168         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 169         ui.processLine("EV_SYN");
 170         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 171         ui.processLine("EV_SYN");
 172         TestLog.waitForLog("Key released: CAPS");
 173     }
 174 
 175     /** Key presses and releases are allowed to overlap. RT-37425. */
 176     @Test
 177     public void testPressReleaseOrder() throws Exception {
 178         TestApplication.showFullScreenScene();
 179         TestApplication.addKeyListeners();
 180         ui.processLine("OPEN");
 181         ui.processLine("EVBIT EV_KEY");
 182         ui.processLine("EVBIT EV_SYN");
 183         ui.processLine("KEYBIT KEY_1");
 184         ui.processLine("KEYBIT KEY_2");
 185         ui.processLine("KEYBIT KEY_3");
 186         ui.processLine("KEYBIT KEY_4");
 187         ui.processLine("KEYBIT KEY_CAPSLOCK");
 188         ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
 189         ui.processLine("CREATE");
 190 
 191         ui.processLine("EV_KEY KEY_1 1");
 192         ui.processLine("EV_SYN");
 193         TestLog.waitForLog("Key pressed: DIGIT1");
 194         TestLog.waitForLog("Key typed: 1");
 195         ui.processLine("EV_KEY KEY_2 1");
 196         ui.processLine("EV_SYN");
 197         TestLog.waitForLog("Key pressed: DIGIT2");
 198         TestLog.waitForLog("Key typed: 2");
 199         ui.processLine("EV_KEY KEY_1 0");
 200         ui.processLine("EV_SYN");
 201         TestLog.waitForLog("Key released: DIGIT1");
 202         ui.processLine("EV_KEY KEY_3 1");
 203         ui.processLine("EV_SYN");
 204         TestLog.waitForLog("Key pressed: DIGIT3");
 205         TestLog.waitForLog("Key typed: 3");
 206         ui.processLine("EV_KEY KEY_2 0");
 207         ui.processLine("EV_SYN");
 208         TestLog.waitForLog("Key released: DIGIT2");
 209         ui.processLine("EV_KEY KEY_4 1");
 210         ui.processLine("EV_SYN");
 211         TestLog.waitForLog("Key pressed: DIGIT4");
 212         TestLog.waitForLog("Key typed: 4");
 213         ui.processLine("EV_KEY KEY_3 0");
 214         ui.processLine("EV_SYN");
 215         TestLog.waitForLog("Key released: DIGIT3");
 216         ui.processLine("EV_KEY KEY_4 0");
 217         ui.processLine("EV_SYN");
 218         TestLog.waitForLog("Key released: DIGIT3");
 219     }
 220 
 221     @Test
 222     public void testBackspace() throws Exception {
 223         TestApplication.showFullScreenScene();
 224         TestApplication.addKeyListeners();
 225         ui.processLine("OPEN");
 226         ui.processLine("EVBIT EV_KEY");
 227         ui.processLine("EVBIT EV_SYN");
 228         ui.processLine("KEYBIT KEY_BACKSPACE");
 229         ui.processLine("KEYBIT KEY_LEFTSHIFT");
 230         ui.processLine("KEYBIT KEY_CAPSLOCK");
 231         ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
 232         ui.processLine("CREATE");
 233 
 234         ui.processLine("EV_KEY KEY_BACKSPACE 1");
 235         ui.processLine("EV_SYN");
 236         TestLog.waitForLog("Key pressed: BACK_SPACE");
 237         ui.processLine("EV_KEY KEY_BACKSPACE 0");
 238         ui.processLine("EV_SYN");
 239         TestLog.waitForLog("Key released: BACK_SPACE");
 240         Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
 241 
 242         TestLog.reset();
 243         ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
 244         ui.processLine("EV_SYN");
 245         ui.processLine("EV_KEY KEY_BACKSPACE 1");
 246         ui.processLine("EV_SYN");
 247         TestLog.waitForLog("Key pressed: BACK_SPACE");
 248         ui.processLine("EV_KEY KEY_BACKSPACE 0");
 249         ui.processLine("EV_SYN");
 250         ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
 251         ui.processLine("EV_SYN");
 252         TestLog.waitForLog("Key released: BACK_SPACE");
 253         Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
 254 
 255         TestLog.reset();
 256         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 257         ui.processLine("EV_SYN");
 258         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 259         ui.processLine("EV_SYN");
 260         ui.processLine("EV_KEY KEY_BACKSPACE 1");
 261         ui.processLine("EV_SYN");
 262         TestLog.waitForLog("Key pressed: BACK_SPACE");
 263         ui.processLine("EV_KEY KEY_BACKSPACE 0");
 264         ui.processLine("EV_SYN");
 265         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 266         ui.processLine("EV_SYN");
 267         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 268         ui.processLine("EV_SYN");
 269         TestLog.waitForLog("Key released: BACK_SPACE");
 270         Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
 271 
 272         TestLog.reset();
 273         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 274         ui.processLine("EV_SYN");
 275         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 276         ui.processLine("EV_SYN");
 277         ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
 278         ui.processLine("EV_SYN");
 279         ui.processLine("EV_KEY KEY_BACKSPACE 1");
 280         ui.processLine("EV_SYN");
 281         TestLog.waitForLog("Key pressed: BACK_SPACE");
 282         ui.processLine("EV_KEY KEY_BACKSPACE 0");
 283         ui.processLine("EV_SYN");
 284         ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
 285         ui.processLine("EV_SYN");
 286         ui.processLine("EV_KEY KEY_CAPSLOCK 1");
 287         ui.processLine("EV_SYN");
 288         ui.processLine("EV_KEY KEY_CAPSLOCK 0");
 289         ui.processLine("EV_SYN");
 290         TestLog.waitForLog("Key released: BACK_SPACE");
 291         Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
 292     }
 293 }
--- EOF ---