KeyboardStateTestsBase.java revision 64e01baadeb624781d9d056b62679b25ea0fe5c0
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.android.inputmethod.keyboard.internal; 18 19import android.test.AndroidTestCase; 20 21public abstract class KeyboardStateTestsBase extends AndroidTestCase 22 implements MockKeyboardSwitcher.Constants { 23 protected MockKeyboardSwitcher mSwitcher; 24 25 public abstract boolean hasDistinctMultitouch(); 26 27 @Override 28 protected void setUp() throws Exception { 29 super.setUp(); 30 31 mSwitcher = new MockKeyboardSwitcher(); 32 mSwitcher.setAutoCapsMode(NO_AUTO_CAPS); 33 34 final String layoutSwitchBackSymbols = ""; 35 loadKeyboard(layoutSwitchBackSymbols, ALPHABET_UNSHIFTED); 36 } 37 38 public void setAutoCapsMode(boolean autoCaps) { 39 mSwitcher.setAutoCapsMode(autoCaps); 40 } 41 42 public void updateShiftState(int afterUpdate) { 43 mSwitcher.updateShiftState(); 44 assertEquals(afterUpdate, mSwitcher.getLayoutId()); 45 } 46 47 public void loadKeyboard(String layoutSwitchBackSymbols, int afterLoad) { 48 mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch()); 49 updateShiftState(afterLoad); 50 } 51 52 public void pressKey(int code, int afterPress) { 53 mSwitcher.onPressKey(code); 54 assertEquals(afterPress, mSwitcher.getLayoutId()); 55 } 56 57 public void releaseKey(int code, int afterRelease) { 58 mSwitcher.onCodeInput(code, SINGLE); 59 mSwitcher.onReleaseKey(code, NOT_SLIDING); 60 assertEquals(afterRelease, mSwitcher.getLayoutId()); 61 } 62 63 public void pressAndReleaseKey(int code, int afterPress, int afterRelease) { 64 pressKey(code, afterPress); 65 releaseKey(code, afterRelease); 66 } 67 68 public void chordingPressKey(int code, int afterPress) { 69 pressKey(code, afterPress); 70 } 71 72 public void chordingReleaseKey(int code, int afterRelease) { 73 mSwitcher.onCodeInput(code, MULTI); 74 mSwitcher.onReleaseKey(code, NOT_SLIDING); 75 assertEquals(afterRelease, mSwitcher.getLayoutId()); 76 } 77 78 public void chordingPressAndReleaseKey(int code, int afterPress, int afterRelease) { 79 chordingPressKey(code, afterPress); 80 chordingReleaseKey(code, afterRelease); 81 } 82 83 public void pressAndSlideFromKey(int code, int afterPress, int afterSlide) { 84 pressKey(code, afterPress); 85 mSwitcher.onReleaseKey(code, SLIDING); 86 assertEquals(afterSlide, mSwitcher.getLayoutId()); 87 } 88 89 public void longPressShiftKey(int afterPress, int afterLongPress) { 90 // Long press shift key 91 mSwitcher.onPressKey(CODE_SHIFT); 92 assertEquals(afterPress, mSwitcher.getLayoutId()); 93 // Long press recognized in LatinKeyboardView.KeyTimerHandler. 94 mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE); 95 assertEquals(afterLongPress, mSwitcher.getLayoutId()); 96 mSwitcher.onReleaseKey(CODE_SHIFT, NOT_SLIDING); 97 assertEquals(afterLongPress, mSwitcher.getLayoutId()); 98 } 99 100 public void secondTapShiftKey(int afterTap) { 101 mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE); 102 assertEquals(afterTap, mSwitcher.getLayoutId()); 103 } 104} 105