1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.cts; 18 19 import dalvik.annotation.TestLevel; 20 import dalvik.annotation.TestTargetClass; 21 import dalvik.annotation.TestTargetNew; 22 import dalvik.annotation.TestTargets; 23 24 import android.test.AndroidTestCase; 25 import android.text.TextUtils; 26 import android.view.KeyCharacterMap; 27 import android.view.KeyEvent; 28 import android.view.KeyCharacterMap.KeyData; 29 30 @TestTargetClass(KeyCharacterMap.class) 31 public class KeyCharacterMapTest extends AndroidTestCase { 32 33 private KeyCharacterMap mKeyCharacterMap; 34 private final char[] chars = {'A', 'B', 'C'}; 35 36 @Override 37 protected void setUp() throws Exception { 38 super.setUp(); 39 mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); 40 } 41 42 @TestTargetNew( 43 level = TestLevel.COMPLETE, 44 method = "isPrintingKey", 45 args = {int.class} 46 ) 47 public void testIsPrintingKey() throws Exception { 48 49 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_UNKNOWN)); 50 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SOFT_LEFT)); 51 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SOFT_RIGHT)); 52 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_HOME)); 53 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BACK)); 54 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CALL)); 55 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENDCALL)); 56 57 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_0)); 58 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_1)); 59 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_2)); 60 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_3)); 61 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_4)); 62 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_5)); 63 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_6)); 64 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_7)); 65 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_8)); 66 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_9)); 67 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STAR)); 68 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_POUND)); 69 70 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_UP)); 71 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_DOWN)); 72 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_LEFT)); 73 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_RIGHT)); 74 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_CENTER)); 75 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_UP)); 76 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_DOWN)); 77 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_POWER)); 78 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAMERA)); 79 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CLEAR)); 80 81 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_A)); 82 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_B)); 83 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_C)); 84 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_D)); 85 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_E)); 86 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F)); 87 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_G)); 88 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_H)); 89 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_I)); 90 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_J)); 91 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_K)); 92 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_L)); 93 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_M)); 94 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_N)); 95 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_O)); 96 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_P)); 97 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Q)); 98 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_R)); 99 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_S)); 100 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_T)); 101 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_U)); 102 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_V)); 103 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_W)); 104 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_X)); 105 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Y)); 106 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Z)); 107 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_COMMA)); 108 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PERIOD)); 109 110 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ALT_LEFT)); 111 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ALT_RIGHT)); 112 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SHIFT_LEFT)); 113 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SHIFT_RIGHT)); 114 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TAB)); 115 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SPACE)); 116 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYM)); 117 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM)); 118 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_EXPLORER)); 119 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENVELOPE)); 120 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENTER)); 121 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DEL)); 122 123 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_GRAVE)); 124 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MINUS)); 125 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_EQUALS)); 126 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_LEFT_BRACKET)); 127 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_RIGHT_BRACKET)); 128 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BACKSLASH)); 129 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SEMICOLON)); 130 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_APOSTROPHE)); 131 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SLASH)); 132 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AT)); 133 134 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM)); 135 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_HEADSETHOOK)); 136 137 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FOCUS)); 138 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PLUS)); 139 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MENU)); 140 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NOTIFICATION)); 141 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SEARCH)); 142 143 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); 144 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_STOP)); 145 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_NEXT)); 146 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PREVIOUS)); 147 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_REWIND)); 148 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD)); 149 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MUTE)); 150 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_UP)); 151 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_DOWN)); 152 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PICTSYMBOLS)); 153 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SWITCH_CHARSET)); 154 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_A)); 155 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_B)); 156 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_C)); 157 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_X)); 158 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Y)); 159 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Z)); 160 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L1)); 161 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R1)); 162 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L2)); 163 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R2)); 164 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBL)); 165 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBR)); 166 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_START)); 167 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_SELECT)); 168 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_MODE)); 169 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ESCAPE)); 170 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD_DEL)); 171 172 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_LEFT)); 173 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_RIGHT)); 174 175 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPS_LOCK)); 176 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SCROLL_LOCK)); 177 178 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_LEFT)); 179 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_RIGHT)); 180 181 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FUNCTION)); 182 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYSRQ)); 183 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BREAK)); 184 185 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_HOME)); 186 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_END)); 187 188 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INSERT)); 189 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD)); 190 191 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY)); 192 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PAUSE)); 193 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_CLOSE)); 194 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_EJECT)); 195 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_RECORD)); 196 197 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F1)); 198 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F2)); 199 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F3)); 200 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F4)); 201 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F5)); 202 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F6)); 203 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F7)); 204 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F8)); 205 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F9)); 206 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F10)); 207 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F11)); 208 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F12)); 209 210 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM_LOCK)); 211 212 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_0)); 213 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_1)); 214 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_2)); 215 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_3)); 216 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_4)); 217 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_5)); 218 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_6)); 219 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_7)); 220 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_8)); 221 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_9)); 222 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DIVIDE)); 223 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_MULTIPLY)); 224 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_SUBTRACT)); 225 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ADD)); 226 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DOT)); 227 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_COMMA)); 228 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ENTER)); 229 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_EQUALS)); 230 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN)); 231 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN)); 232 233 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_MUTE)); 234 235 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INFO)); 236 237 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_UP)); 238 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_DOWN)); 239 240 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_IN)); 241 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_OUT)); 242 243 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV)); 244 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_WINDOW)); 245 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_GUIDE)); 246 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DVR)); 247 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BOOKMARK)); 248 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPTIONS)); 249 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SETTINGS)); 250 251 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_POWER)); 252 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_INPUT)); 253 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_POWER)); 254 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_INPUT)); 255 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_POWER)); 256 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_INPUT)); 257 258 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_RED)); 259 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_GREEN)); 260 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_YELLOW)); 261 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_BLUE)); 262 } 263 264 @TestTargetNew( 265 level = TestLevel.COMPLETE, 266 method = "load", 267 args = {int.class} 268 ) 269 public void testLoad() throws Exception { 270 mKeyCharacterMap = null; 271 mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD); 272 assertNotNull(mKeyCharacterMap); 273 } 274 275 @TestTargetNew( 276 level = TestLevel.COMPLETE, 277 method = "getNumber", 278 args = {int.class} 279 ) 280 public void testGetNumber() throws Exception { 281 assertEquals('0', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_0)); 282 assertEquals('1', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_1)); 283 assertEquals('2', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_2)); 284 assertEquals('3', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_3)); 285 assertEquals('4', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_4)); 286 assertEquals('5', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_5)); 287 assertEquals('6', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_6)); 288 assertEquals('7', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_7)); 289 assertEquals('8', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_8)); 290 assertEquals('9', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_9)); 291 assertEquals('*', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_STAR)); 292 assertEquals('#', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_POUND)); 293 } 294 295 @TestTargetNew( 296 level = TestLevel.COMPLETE, 297 method = "getMatch", 298 args = {int.class, char[].class} 299 ) 300 public void testGetMatch1() throws Exception { 301 try { 302 mKeyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null); 303 fail("should throw exception"); 304 } catch (Exception e) { 305 } 306 307 assertEquals('\0', mKeyCharacterMap.getMatch(getCharacterKeyCode('E'), chars)); 308 assertEquals('A', mKeyCharacterMap.getMatch(getCharacterKeyCode('A'), chars)); 309 assertEquals('B', mKeyCharacterMap.getMatch(getCharacterKeyCode('B'), chars)); 310 } 311 312 private int getCharacterKeyCode(char oneChar) { 313 // Lowercase the character to avoid getting modifiers in the KeyEvent array. 314 char[] chars = new char[] {Character.toLowerCase(oneChar)}; 315 KeyEvent[] events = mKeyCharacterMap.getEvents(chars); 316 return events[0].getKeyCode(); 317 } 318 319 @TestTargetNew( 320 level = TestLevel.COMPLETE, 321 method = "getMatch", 322 args = {int.class, char[].class, int.class} 323 ) 324 public void testGetMatch2() throws Exception { 325 try { 326 mKeyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null, 1); 327 fail("should throw exception"); 328 } catch (Exception e) { 329 } 330 assertEquals('\0', mKeyCharacterMap.getMatch(1000, chars, 2)); 331 assertEquals('\0', mKeyCharacterMap.getMatch(10000, chars, 2)); 332 assertEquals('\0', mKeyCharacterMap.getMatch(getCharacterKeyCode('E'), chars)); 333 assertEquals('A', mKeyCharacterMap.getMatch(getCharacterKeyCode('A'), chars)); 334 assertEquals('B', mKeyCharacterMap.getMatch(getCharacterKeyCode('B'), chars)); 335 } 336 337 @TestTargetNew( 338 level = TestLevel.COMPLETE, 339 method = "getKeyboardType", 340 args = {} 341 ) 342 public void testGetKeyboardType() throws Exception { 343 mKeyCharacterMap.getKeyboardType(); 344 } 345 346 @TestTargets({ 347 @TestTargetNew( 348 level = TestLevel.COMPLETE, 349 method = "getEvents", 350 args = {char[].class} 351 ), 352 @TestTargetNew( 353 level = TestLevel.NOT_FEASIBLE, 354 method = "getDisplayLabel", 355 args = {int.class} 356 ) 357 }) 358 public void testGetEvents() { 359 try { 360 mKeyCharacterMap.getEvents(null); 361 fail("should throw exception"); 362 } catch (Exception e) { 363 } 364 CharSequence mCharSequence = "TestMessage123"; 365 int len = mCharSequence.length(); 366 char[] charsArray = new char[len]; 367 TextUtils.getChars(mCharSequence, 1, len, charsArray, 0); 368 mKeyCharacterMap.getEvents(charsArray); 369 } 370 371 @TestTargets({ 372 @TestTargetNew( 373 level = TestLevel.COMPLETE, 374 method = "getKeyData", 375 args = {int.class, android.view.KeyCharacterMap.KeyData.class} 376 ), 377 @TestTargetNew( 378 level = TestLevel.NOT_FEASIBLE, 379 method = "get", 380 args = {int.class, int.class} 381 ), 382 @TestTargetNew( 383 level = TestLevel.NOT_FEASIBLE, 384 method = "finalize", 385 args = {} 386 ), 387 @TestTargetNew( 388 level = TestLevel.NOT_FEASIBLE, 389 method = "getDeadChar", 390 args = {int.class, int.class} 391 ), 392 @TestTargetNew( 393 level = TestLevel.SUFFICIENT, 394 method = "deviceHasKey", 395 args = {int.class} 396 ), 397 @TestTargetNew( 398 level = TestLevel.SUFFICIENT, 399 method = "deviceHasKeys", 400 args = {int[].class} 401 ) 402 }) 403 public void testGetKeyData() throws Exception { 404 KeyData result = new KeyData(); 405 result.meta = new char[2]; 406 try { 407 mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_HOME, result); 408 fail("should throw exception"); 409 } catch (Exception e) { 410 } 411 result.meta = new char[4]; 412 assertFalse(mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_HOME, result)); 413 assertTrue(mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_0, result)); 414 assertEquals(48, result.meta[0]); 415 416 // here just call deviceHasKey and deviceHasKeys. 417 KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_0); 418 final int[] keyChar = new int[] { 419 KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_1, KeyEvent.KEYCODE_3 420 }; 421 boolean[] keys = KeyCharacterMap.deviceHasKeys(keyChar); 422 assertEquals(keyChar.length, keys.length); 423 } 424 425 } 426