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 20 import android.test.AndroidTestCase; 21 import android.text.TextUtils; 22 import android.view.KeyCharacterMap; 23 import android.view.KeyEvent; 24 import android.view.KeyCharacterMap.KeyData; 25 26 public class KeyCharacterMapTest extends AndroidTestCase { 27 28 private KeyCharacterMap mKeyCharacterMap; 29 private final char[] chars = {'A', 'B', 'C'}; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); 35 } 36 37 public void testIsPrintingKey() throws Exception { 38 39 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_UNKNOWN)); 40 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SOFT_LEFT)); 41 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SOFT_RIGHT)); 42 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_HOME)); 43 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BACK)); 44 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CALL)); 45 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENDCALL)); 46 47 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_0)); 48 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_1)); 49 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_2)); 50 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_3)); 51 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_4)); 52 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_5)); 53 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_6)); 54 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_7)); 55 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_8)); 56 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_9)); 57 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STAR)); 58 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_POUND)); 59 60 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_UP)); 61 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_DOWN)); 62 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_LEFT)); 63 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_RIGHT)); 64 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DPAD_CENTER)); 65 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_UP)); 66 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_DOWN)); 67 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_POWER)); 68 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAMERA)); 69 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CLEAR)); 70 71 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_A)); 72 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_B)); 73 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_C)); 74 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_D)); 75 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_E)); 76 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F)); 77 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_G)); 78 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_H)); 79 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_I)); 80 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_J)); 81 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_K)); 82 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_L)); 83 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_M)); 84 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_N)); 85 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_O)); 86 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_P)); 87 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Q)); 88 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_R)); 89 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_S)); 90 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_T)); 91 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_U)); 92 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_V)); 93 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_W)); 94 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_X)); 95 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Y)); 96 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_Z)); 97 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_COMMA)); 98 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PERIOD)); 99 100 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ALT_LEFT)); 101 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ALT_RIGHT)); 102 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SHIFT_LEFT)); 103 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SHIFT_RIGHT)); 104 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TAB)); 105 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SPACE)); 106 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYM)); 107 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM)); 108 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_EXPLORER)); 109 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENVELOPE)); 110 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENTER)); 111 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DEL)); 112 113 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_GRAVE)); 114 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MINUS)); 115 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_EQUALS)); 116 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_LEFT_BRACKET)); 117 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_RIGHT_BRACKET)); 118 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BACKSLASH)); 119 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SEMICOLON)); 120 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_APOSTROPHE)); 121 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SLASH)); 122 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AT)); 123 124 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM)); 125 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_HEADSETHOOK)); 126 127 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FOCUS)); 128 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PLUS)); 129 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MENU)); 130 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NOTIFICATION)); 131 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SEARCH)); 132 133 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); 134 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_STOP)); 135 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_NEXT)); 136 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PREVIOUS)); 137 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_REWIND)); 138 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD)); 139 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MUTE)); 140 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_UP)); 141 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_DOWN)); 142 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PICTSYMBOLS)); 143 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SWITCH_CHARSET)); 144 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_A)); 145 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_B)); 146 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_C)); 147 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_X)); 148 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Y)); 149 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Z)); 150 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L1)); 151 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R1)); 152 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L2)); 153 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R2)); 154 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBL)); 155 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBR)); 156 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_START)); 157 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_SELECT)); 158 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_MODE)); 159 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ESCAPE)); 160 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD_DEL)); 161 162 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_LEFT)); 163 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_RIGHT)); 164 165 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPS_LOCK)); 166 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SCROLL_LOCK)); 167 168 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_LEFT)); 169 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_RIGHT)); 170 171 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FUNCTION)); 172 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYSRQ)); 173 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BREAK)); 174 175 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_HOME)); 176 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_END)); 177 178 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INSERT)); 179 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD)); 180 181 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY)); 182 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PAUSE)); 183 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_CLOSE)); 184 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_EJECT)); 185 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_RECORD)); 186 187 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F1)); 188 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F2)); 189 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F3)); 190 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F4)); 191 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F5)); 192 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F6)); 193 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F7)); 194 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F8)); 195 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F9)); 196 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F10)); 197 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F11)); 198 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F12)); 199 200 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM_LOCK)); 201 202 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_0)); 203 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_1)); 204 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_2)); 205 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_3)); 206 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_4)); 207 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_5)); 208 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_6)); 209 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_7)); 210 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_8)); 211 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_9)); 212 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DIVIDE)); 213 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_MULTIPLY)); 214 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_SUBTRACT)); 215 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ADD)); 216 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DOT)); 217 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_COMMA)); 218 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ENTER)); 219 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_EQUALS)); 220 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN)); 221 assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN)); 222 223 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_MUTE)); 224 225 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INFO)); 226 227 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_UP)); 228 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_DOWN)); 229 230 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_IN)); 231 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_OUT)); 232 233 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV)); 234 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_WINDOW)); 235 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_GUIDE)); 236 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DVR)); 237 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BOOKMARK)); 238 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPTIONS)); 239 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SETTINGS)); 240 241 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_POWER)); 242 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_INPUT)); 243 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_POWER)); 244 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_INPUT)); 245 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_POWER)); 246 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_INPUT)); 247 248 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_RED)); 249 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_GREEN)); 250 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_YELLOW)); 251 assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_BLUE)); 252 } 253 254 public void testLoad() throws Exception { 255 mKeyCharacterMap = null; 256 mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD); 257 assertNotNull(mKeyCharacterMap); 258 } 259 260 public void testGetNumber() throws Exception { 261 assertEquals('0', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_0)); 262 assertEquals('1', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_1)); 263 assertEquals('2', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_2)); 264 assertEquals('3', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_3)); 265 assertEquals('4', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_4)); 266 assertEquals('5', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_5)); 267 assertEquals('6', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_6)); 268 assertEquals('7', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_7)); 269 assertEquals('8', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_8)); 270 assertEquals('9', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_9)); 271 assertEquals('*', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_STAR)); 272 assertEquals('#', mKeyCharacterMap.getNumber(KeyEvent.KEYCODE_POUND)); 273 } 274 275 public void testGetMatch1() throws Exception { 276 try { 277 mKeyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null); 278 fail("should throw exception"); 279 } catch (Exception e) { 280 } 281 282 assertEquals('\0', mKeyCharacterMap.getMatch(getCharacterKeyCode('E'), chars)); 283 assertEquals('A', mKeyCharacterMap.getMatch(getCharacterKeyCode('A'), chars)); 284 assertEquals('B', mKeyCharacterMap.getMatch(getCharacterKeyCode('B'), chars)); 285 } 286 287 private int getCharacterKeyCode(char oneChar) { 288 // Lowercase the character to avoid getting modifiers in the KeyEvent array. 289 char[] chars = new char[] {Character.toLowerCase(oneChar)}; 290 KeyEvent[] events = mKeyCharacterMap.getEvents(chars); 291 return events[0].getKeyCode(); 292 } 293 294 public void testGetMatch2() throws Exception { 295 try { 296 mKeyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null, 1); 297 fail("should throw exception"); 298 } catch (Exception e) { 299 } 300 assertEquals('\0', mKeyCharacterMap.getMatch(1000, chars, 2)); 301 assertEquals('\0', mKeyCharacterMap.getMatch(10000, chars, 2)); 302 assertEquals('\0', mKeyCharacterMap.getMatch(getCharacterKeyCode('E'), chars)); 303 assertEquals('A', mKeyCharacterMap.getMatch(getCharacterKeyCode('A'), chars)); 304 assertEquals('B', mKeyCharacterMap.getMatch(getCharacterKeyCode('B'), chars)); 305 } 306 307 public void testGetKeyboardType() throws Exception { 308 mKeyCharacterMap.getKeyboardType(); 309 } 310 311 public void testGetEvents() { 312 try { 313 mKeyCharacterMap.getEvents(null); 314 fail("should throw exception"); 315 } catch (Exception e) { 316 } 317 CharSequence mCharSequence = "TestMessage123"; 318 int len = mCharSequence.length(); 319 char[] charsArray = new char[len]; 320 TextUtils.getChars(mCharSequence, 1, len, charsArray, 0); 321 mKeyCharacterMap.getEvents(charsArray); 322 } 323 324 public void testGetKeyData() throws Exception { 325 KeyData result = new KeyData(); 326 result.meta = new char[2]; 327 try { 328 mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_HOME, result); 329 fail("should throw exception"); 330 } catch (Exception e) { 331 } 332 result.meta = new char[4]; 333 assertFalse(mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_HOME, result)); 334 assertTrue(mKeyCharacterMap.getKeyData(KeyEvent.KEYCODE_0, result)); 335 assertEquals(48, result.meta[0]); 336 337 // here just call deviceHasKey and deviceHasKeys. 338 KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_0); 339 final int[] keyChar = new int[] { 340 KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_1, KeyEvent.KEYCODE_3 341 }; 342 boolean[] keys = KeyCharacterMap.deviceHasKeys(keyChar); 343 assertEquals(keyChar.length, keys.length); 344 } 345 346 } 347