diff options
Diffstat (limited to 'tests')
13 files changed, 702 insertions, 269 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 210e81489..38a2ecfeb 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -22,8 +22,6 @@ <application> <uses-library android:name="android.test.runner" /> <!-- meta-data android:name="com.android.contacts.iconset" android:resource="@xml/iconset" /--> - <uses-permission android:name="android.permission.READ_CONTACTS" /> - </application> <instrumentation android:name="android.test.InstrumentationTestRunner" diff --git a/tests/data/bigramlist.xml b/tests/data/bigramlist.xml index dd3f2916e..d3d8bb801 100644 --- a/tests/data/bigramlist.xml +++ b/tests/data/bigramlist.xml @@ -25,7 +25,7 @@ <bi w1="about" count="3"> <w w2="part" p="117" /> <w w2="business" p="100" /> - <w w2="being" p="10" /> + <w w2="being" p="90" /> </bi> <bi w1="business" count="1"> <w w2="people" p="100" /> diff --git a/tests/res/raw/test.dict b/tests/res/raw/test.dict Binary files differindex 6a5d6d794..453fc9fce 100644 --- a/tests/res/raw/test.dict +++ b/tests/res/raw/test.dict diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java new file mode 100644 index 000000000..e3f0e0718 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java @@ -0,0 +1,430 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.keyboard.internal; + +import android.test.AndroidTestCase; + +public class KeyboardStateNonDistinctTests extends AndroidTestCase + implements MockKeyboardSwitcher.Constants { + protected MockKeyboardSwitcher mSwitcher; + + public boolean hasDistinctMultitouch() { + return false; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mSwitcher = new MockKeyboardSwitcher(); + + final String layoutSwitchBackSymbols = ""; + mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch()); + } + + public void assertAlphabetNormal() { + assertTrue(mSwitcher.assertAlphabetNormal()); + } + + public void assertAlphabetManualShifted() { + assertTrue(mSwitcher.assertAlphabetManualShifted()); + } + + public void assertAlphabetAutomaticShifted() { + assertTrue(mSwitcher.assertAlphabetAutomaticShifted()); + } + + public void assertAlphabetShiftLocked() { + assertTrue(mSwitcher.assertAlphabetShiftLocked()); + } + + public void assertSymbolsNormal() { + assertTrue(mSwitcher.assertSymbolsNormal()); + } + + public void assertSymbolsShifted() { + assertTrue(mSwitcher.assertSymbolsShifted()); + } + + // Initial state test. + public void testLoadKeyboard() { + assertAlphabetNormal(); + } + + // Shift key in alphabet mode. + public void testShift() { + // Press/release shift key, enter into shift state. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Press/release shift key, back to normal state. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetNormal(); + + // Press/release shift key, enter into shift state. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Press/release letter key, snap back to normal state. + mSwitcher.onPressKey('Z'); + mSwitcher.onCodeInput('Z'); + mSwitcher.onReleaseKey('Z'); + assertAlphabetNormal(); + } + + // Shift key sliding input. + public void testShiftSliding() { + // Press shift key. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Slide out shift key. + mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING); + assertAlphabetManualShifted(); + + // Enter into letter key. + mSwitcher.onPressKey('Z'); + assertAlphabetManualShifted(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('Z'); + mSwitcher.onReleaseKey('Z'); + assertAlphabetNormal(); + } + + public void enterSymbolsMode() { + // Press/release "?123" key. + mSwitcher.onPressKey(CODE_SYMBOL); + assertSymbolsNormal(); + mSwitcher.onCodeInput(CODE_SYMBOL); + mSwitcher.onReleaseKey(CODE_SYMBOL); + assertSymbolsNormal(); + } + + public void leaveSymbolsMode() { + // Press/release "ABC" key. + mSwitcher.onPressKey(CODE_SYMBOL); + assertAlphabetNormal(); + mSwitcher.onCodeInput(CODE_SYMBOL); + mSwitcher.onReleaseKey(CODE_SYMBOL); + assertAlphabetNormal(); + } + + // Switching between alphabet and symbols. + public void testAlphabetAndSymbols() { + enterSymbolsMode(); + leaveSymbolsMode(); + } + + // Switching between alphabet shift locked and symbols. + public void testAlphabetShiftLockedAndSymbols() { + enterShiftLockWithLongPressShift(); + enterSymbolsMode(); + + // Press/release "ABC" key, switch back to shift locked mode. + mSwitcher.onPressKey(CODE_SYMBOL); + assertAlphabetShiftLocked(); + mSwitcher.onCodeInput(CODE_SYMBOL); + mSwitcher.onReleaseKey(CODE_SYMBOL); + assertAlphabetShiftLocked(); + } + + // Symbols key sliding input. + public void testSymbolsSliding() { + // Press "123?" key. + mSwitcher.onPressKey(CODE_SYMBOL); + assertSymbolsNormal(); + // Slide out from "123?" key. + mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING); + assertSymbolsNormal(); + + // Enter into letter key. + mSwitcher.onPressKey('z'); + assertSymbolsNormal(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('z'); + mSwitcher.onReleaseKey('z'); + assertAlphabetNormal(); + } + + // Switching between symbols and symbols shifted. + public void testSymbolsAndSymbolsShifted() { + enterSymbolsMode(); + + // Press/release "=\<" key. + mSwitcher.onPressKey(CODE_SHIFT); + assertSymbolsShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertSymbolsShifted(); + + // Press/release "?123" key. + mSwitcher.onPressKey(CODE_SHIFT); + assertSymbolsNormal(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertSymbolsNormal(); + + leaveSymbolsMode(); + } + + // Symbols shift sliding input + public void testSymbolsShiftSliding() { + enterSymbolsMode(); + + // Press "=\<" key. + mSwitcher.onPressKey(CODE_SHIFT); + assertSymbolsShifted(); + // Slide out "=\<" key. + mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING); + assertSymbolsShifted(); + + // Enter into symbol shifted letter key. + mSwitcher.onPressKey('~'); + assertSymbolsShifted(); + // Release symbol shifted letter key, snap back to symbols. + mSwitcher.onCodeInput('~'); + mSwitcher.onReleaseKey('~'); + assertSymbolsNormal(); + } + + // Symbols shift sliding input from symbols shifted. + public void testSymbolsShiftSliding2() { + enterSymbolsMode(); + + // Press/release "=\<" key. + mSwitcher.onPressKey(CODE_SHIFT); + assertSymbolsShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertSymbolsShifted(); + + // Press "123?" key. + mSwitcher.onPressKey(CODE_SHIFT); + assertSymbolsNormal(); + // Slide out "123?" key. + mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING); + assertSymbolsNormal(); + + // Enter into symbol letter key. + mSwitcher.onPressKey('1'); + assertSymbolsNormal(); + // Release symbol letter key, snap back to symbols shift. + mSwitcher.onCodeInput('1'); + mSwitcher.onReleaseKey('1'); + assertSymbolsShifted(); + } + + // Automatic snap back to alphabet from symbols by space key. + public void testSnapBackBySpace() { + enterSymbolsMode(); + + // Enter a symbol letter. + mSwitcher.onPressKey('1'); + assertSymbolsNormal(); + mSwitcher.onCodeInput('1'); + mSwitcher.onReleaseKey('1'); + assertSymbolsNormal(); + // Enter space, snap back to alphabet. + mSwitcher.onPressKey(CODE_SPACE); + assertSymbolsNormal(); + mSwitcher.onCodeInput(CODE_SPACE); + mSwitcher.onReleaseKey(CODE_SPACE); + assertAlphabetNormal(); + } + + // TODO: Add automatic snap back to shift locked test. + + // Automatic snap back to alphabet from symbols by registered letters. + public void testSnapBack() { + final String snapBackChars = "'"; + final int snapBackCode = snapBackChars.codePointAt(0); + final boolean hasDistinctMultitouch = true; + mSwitcher.loadKeyboard(snapBackChars, hasDistinctMultitouch); + + enterSymbolsMode(); + + // Enter a symbol letter. + mSwitcher.onPressKey('1'); + assertSymbolsNormal(); + mSwitcher.onCodeInput('1'); + mSwitcher.onReleaseKey('1'); + assertSymbolsNormal(); + // Enter snap back letter, snap back to alphabet. + mSwitcher.onPressKey(snapBackCode); + assertSymbolsNormal(); + mSwitcher.onCodeInput(snapBackCode); + mSwitcher.onReleaseKey(snapBackCode); + assertAlphabetNormal(); + } + + // Automatic upper case test + public void testAutomaticUpperCase() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + + // Press shift key. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Release shift key. + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetNormal(); + } + + // Sliding from shift key in automatic upper case. + public void testAutomaticUpperCaseSliding() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + + // Press shift key. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Slide out shift key. + mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING); + assertAlphabetManualShifted(); + // Enter into letter key. + mSwitcher.onPressKey('Z'); + assertAlphabetManualShifted(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('Z'); + mSwitcher.onReleaseKey('Z'); + assertAlphabetNormal(); + } + + // Sliding from symbol key in automatic upper case. + public void testAutomaticUpperCaseSliding2() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + + // Press "123?" key. + mSwitcher.onPressKey(CODE_SYMBOL); + assertSymbolsNormal(); + // Slide out "123?" key. + mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING); + assertSymbolsNormal(); + // Enter into symbol letter keys. + mSwitcher.onPressKey('1'); + assertSymbolsNormal(); + // Release symbol letter key, snap back to alphabet. + mSwitcher.onCodeInput('1'); + mSwitcher.onReleaseKey('1'); + assertAlphabetNormal(); + } + + public void enterShiftLockWithLongPressShift() { + // Long press shift key + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Long press recognized in LatinKeyboardView.KeyTimerHandler. + mSwitcher.onCodeInput(CODE_CAPSLOCK); + assertAlphabetShiftLocked(); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetShiftLocked(); + } + + public void leaveShiftLockWithLongPressShift() { + // Press shift key. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Long press recognized in LatinKeyboardView.KeyTimerHandler. + mSwitcher.onCodeInput(CODE_CAPSLOCK); + assertAlphabetNormal(); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetNormal(); + } + + // Long press shift key. + // TODO: Move long press recognizing timer/logic into KeyboardState. + public void testLongPressShift() { + enterShiftLockWithLongPressShift(); + leaveShiftLockWithLongPressShift(); + } + + // Leave shift lock with single tap shift key. + public void testShiftInShiftLock() { + enterShiftLockWithLongPressShift(); + assertAlphabetShiftLocked(); + + // Tap shift key. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT, SINGLE); + assertAlphabetManualShifted(); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetNormal(); + } + + // Double tap shift key. + // TODO: Move double tap recognizing timer/logic into KeyboardState. + public void testDoubleTapShift() { + // First shift key tap. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetManualShifted(); + // Second shift key tap. + // Double tap recognized in LatinKeyboardView.KeyTimerHandler. + mSwitcher.onCodeInput(CODE_CAPSLOCK); + assertAlphabetShiftLocked(); + + // First shift key tap. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onCodeInput(CODE_SHIFT); + assertAlphabetManualShifted(); + mSwitcher.onReleaseKey(CODE_SHIFT); + assertAlphabetNormal(); + // Second shift key tap. + // Second tap is ignored in LatinKeyboardView.KeyTimerHandler. + } + + // Update shift state. + public void testUpdateShiftState() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + } + + // Update shift state when shift locked. + public void testUpdateShiftStateInShiftLocked() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + enterShiftLockWithLongPressShift(); + assertAlphabetShiftLocked(); + // Update shift state when shift locked + mSwitcher.updateShiftState(); + assertAlphabetShiftLocked(); + } + + // TODO: Change focus test. + + // TODO: Change orientation test. +} diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java index 1f6141e50..19339f72e 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java @@ -16,246 +16,102 @@ package com.android.inputmethod.keyboard.internal; -import android.test.AndroidTestCase; - -import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.internal.KeyboardState.SwitchActions; - -public class KeyboardStateTests extends AndroidTestCase { - private static final int ALPHABET_UNSHIFTED = 0; - private static final int ALPHABET_MANUAL_SHIFTED = 1; - private static final int ALPHABET_AUTOMATIC_SHIFTED = 2; - private static final int ALPHABET_SHIFT_LOCKED = 3; - private static final int SYMBOLS_UNSHIFTED = 4; - private static final int SYMBOLS_SHIFTED = 5; - - static class KeyboardSwitcher implements KeyboardState.SwitchActions { - public int mLayout = ALPHABET_UNSHIFTED; - - @Override - public void setAlphabetKeyboard() { - mLayout = ALPHABET_UNSHIFTED; - } - - @Override - public void setShifted(int shiftMode) { - if (shiftMode == SwitchActions.UNSHIFT) { - mLayout = ALPHABET_UNSHIFTED; - } else if (shiftMode == SwitchActions.MANUAL_SHIFT) { - mLayout = ALPHABET_MANUAL_SHIFTED; - } else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) { - mLayout = ALPHABET_AUTOMATIC_SHIFTED; - } - } - - @Override - public void setShiftLocked(boolean shiftLocked) { - if (shiftLocked) { - mLayout = ALPHABET_SHIFT_LOCKED; - } else { - mLayout = ALPHABET_UNSHIFTED; - } - } - - @Override - public void setSymbolsKeyboard() { - mLayout = SYMBOLS_UNSHIFTED; - } - - @Override - public void setSymbolsShiftedKeyboard() { - mLayout = SYMBOLS_SHIFTED; - } - } - - private KeyboardSwitcher mSwitcher; - private KeyboardState mState; - +public class KeyboardStateTests extends KeyboardStateNonDistinctTests { @Override - protected void setUp() throws Exception { - super.setUp(); - - mSwitcher = new KeyboardSwitcher(); - mState = new KeyboardState(mSwitcher); - - final String layoutSwitchBackCharacter = ""; - // TODO: Unit tests for non-distinct multi touch device. - final boolean hasDistinctMultitouch = true; - mState.onLoadKeyboard(layoutSwitchBackCharacter, hasDistinctMultitouch); - } - - // Argument for KeyboardState.onPressShift and onReleaseShift. - private static final boolean NOT_SLIDING = false; - private static final boolean SLIDING = true; - // Argument for KeyboardState.onCodeInput. - private static final boolean SINGLE = true; - private static final boolean MULTI = false; - private static final boolean NO_AUTO_CAPS = false; - private static final boolean AUTO_CAPS = true; - - private void assertAlphabetNormal() { - assertEquals(ALPHABET_UNSHIFTED, mSwitcher.mLayout); + public boolean hasDistinctMultitouch() { + return true; } - private void assertAlphabetManualShifted() { - assertEquals(ALPHABET_MANUAL_SHIFTED, mSwitcher.mLayout); - } - - private void assertAlphabetAutomaticShifted() { - assertEquals(ALPHABET_AUTOMATIC_SHIFTED, mSwitcher.mLayout); - } - - private void assertAlphabetShiftLocked() { - assertEquals(ALPHABET_SHIFT_LOCKED, mSwitcher.mLayout); - } - - private void assertSymbolsNormal() { - assertEquals(SYMBOLS_UNSHIFTED, mSwitcher.mLayout); - } - - private void assertSymbolsShifted() { - assertEquals(SYMBOLS_SHIFTED, mSwitcher.mLayout); - } - - // Initial state test. - public void testLoadKeyboard() { - assertAlphabetNormal(); - } + // Shift key chording input. + public void testShiftChording() { + // Press shift key and hold, enter into choring shift state. + mSwitcher.onPressKey(CODE_SHIFT); + assertAlphabetManualShifted(); - // Shift key in alphabet mode. - public void testShift() { - // Press/release shift key. - mState.onPressShift(NOT_SLIDING); + // Press/release letter keys. + mSwitcher.onPressKey('Z'); + mSwitcher.onCodeInput('Z', MULTI); + mSwitcher.onReleaseKey('Z'); assertAlphabetManualShifted(); - mState.onReleaseShift(NOT_SLIDING); + mSwitcher.onPressKey('X'); + mSwitcher.onCodeInput('X', MULTI); + mSwitcher.onReleaseKey('X'); assertAlphabetManualShifted(); - // Press/release shift key. - mState.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mState.onReleaseShift(NOT_SLIDING); + // Release shift key, snap back to normal state. + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); + mSwitcher.updateShiftState(); assertAlphabetNormal(); - - // TODO: Sliding test } - // Switching between alphabet and symbols. - public void testAlphabetAndSymbols() { - // Press/release "?123" key. - mState.onPressSymbol(); - assertSymbolsNormal(); - mState.onReleaseSymbol(); + // Symbols key chording input. + public void testSymbolsChording() { + // Press symbols key and hold, enter into choring shift state. + mSwitcher.onPressKey(CODE_SYMBOL); assertSymbolsNormal(); - // Press/release "ABC" key. - mState.onPressSymbol(); - assertAlphabetNormal(); - mState.onReleaseSymbol(); - assertAlphabetNormal(); - - // TODO: Sliding test - // TODO: Snap back test - } - - // Switching between symbols and symbols shifted. - public void testSymbolsAndSymbolsShifted() { - // Press/release "?123" key. - mState.onPressSymbol(); + // Press/release symbol letter keys. + mSwitcher.onPressKey('1'); + mSwitcher.onCodeInput('1', MULTI); + mSwitcher.onReleaseKey('1'); assertSymbolsNormal(); - mState.onReleaseSymbol(); + mSwitcher.onPressKey('2'); + mSwitcher.onCodeInput('2', MULTI); + mSwitcher.onReleaseKey('2'); assertSymbolsNormal(); - // Press/release "=\<" key. - mState.onPressShift(NOT_SLIDING); - assertSymbolsShifted(); - mState.onReleaseShift(NOT_SLIDING); - assertSymbolsShifted(); - - // Press/release "ABC" key. - mState.onPressSymbol(); + // Release shift key, snap back to normal state. + mSwitcher.onCodeInput(CODE_SYMBOL); + mSwitcher.onReleaseKey(CODE_SYMBOL); + mSwitcher.updateShiftState(); assertAlphabetNormal(); - mState.onReleaseSymbol(); - assertAlphabetNormal(); - - // TODO: Sliding test - // TODO: Snap back test } - // Automatic upper case test - public void testAutomaticUpperCase() { + // Chording shift key in automatic upper case. + public void testAutomaticUpperCaseChording() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); // Update shift state with auto caps enabled. - mState.onUpdateShiftState(true); + mSwitcher.updateShiftState(); assertAlphabetAutomaticShifted(); // Press shift key. - mState.onPressShift(NOT_SLIDING); + mSwitcher.onPressKey(CODE_SHIFT); assertAlphabetManualShifted(); - // Release shift key. - mState.onReleaseShift(NOT_SLIDING); + // Press/release letter keys. + mSwitcher.onPressKey('Z'); + mSwitcher.onCodeInput('Z', MULTI); + mSwitcher.onReleaseKey('Z'); + assertAlphabetManualShifted(); + // Release shift key, snap back to alphabet. + mSwitcher.onCodeInput(CODE_SHIFT); + mSwitcher.onReleaseKey(CODE_SHIFT); assertAlphabetNormal(); - - // TODO: Chording test. } - // TODO: UpdateShiftState with shift locked, etc. - - // TODO: Multitouch test - - // TODO: Change focus test. - - // TODO: Change orientation test. - - // Long press shift key. - // TODO: Move long press recognizing timer/logic into KeyboardState. - public void testLongPressShift() { - // Long press shift key - mState.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Long press recognized in LatinKeyboardView.KeyTimerHandler. - mState.onToggleCapsLock(); - assertAlphabetShiftLocked(); - mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS); - assertAlphabetShiftLocked(); - mState.onReleaseShift(NOT_SLIDING); - assertAlphabetShiftLocked(); + // Chording symbol key in automatic upper case. + public void testAutomaticUpperCaseChrding2() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); - // Long press shift key. - mState.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Long press recognized in LatinKeyboardView.KeyTimerHandler. - mState.onToggleCapsLock(); - assertAlphabetNormal(); - mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS); - assertAlphabetNormal(); - mState.onReleaseShift(NOT_SLIDING); + // Press "123?" key. + mSwitcher.onPressKey(CODE_SYMBOL); + assertSymbolsNormal(); + // Press/release symbol letter keys. + mSwitcher.onPressKey('1'); + assertSymbolsNormal(); + mSwitcher.onCodeInput('1', MULTI); + mSwitcher.onReleaseKey('1'); + assertSymbolsNormal(); + // Release "123?" key, snap back to alphabet. + mSwitcher.onCodeInput(CODE_SYMBOL); + mSwitcher.onReleaseKey(CODE_SYMBOL); assertAlphabetNormal(); } - // Double tap shift key. - // TODO: Move double tap recognizing timer/logic into KeyboardState. - public void testDoubleTapShift() { - // First shift key tap. - mState.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS); - assertAlphabetManualShifted(); - mState.onReleaseShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Second shift key tap. - // Double tap recognized in LatinKeyboardView.KeyTimerHandler. - mState.onToggleCapsLock(); - assertAlphabetShiftLocked(); - mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS); - assertAlphabetShiftLocked(); + // TODO: Multitouch test - // First shift key tap. - mState.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS); - assertAlphabetManualShifted(); - mState.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - // Second shift key tap. - // Second tap is ignored in LatinKeyboardView.KeyTimerHandler. - } + // TODO: n-Keys roll over test } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java new file mode 100644 index 000000000..1e294d179 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.keyboard.internal; + +import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.internal.KeyboardState.SwitchActions; + +public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { + public interface Constants { + // Argument for KeyboardState.onPressKey and onReleaseKey. + public static final boolean NOT_SLIDING = false; + public static final boolean SLIDING = true; + // Argument for KeyboardState.onCodeInput. + public static final boolean SINGLE = true; + public static final boolean MULTI = false; + public static final boolean NO_AUTO_CAPS = false; + public static final boolean AUTO_CAPS = true; + + public static final int CODE_SHIFT = Keyboard.CODE_SHIFT; + public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL; + public static final int CODE_CAPSLOCK = Keyboard.CODE_CAPSLOCK; + public static final int CODE_SPACE = Keyboard.CODE_SPACE; + } + + public static final String WORD_SEPARATORS = " ,."; + + private static final int ALPHABET_UNSHIFTED = 0; + private static final int ALPHABET_MANUAL_SHIFTED = 1; + private static final int ALPHABET_AUTOMATIC_SHIFTED = 2; + private static final int ALPHABET_SHIFT_LOCKED = 3; + private static final int SYMBOLS_UNSHIFTED = 4; + private static final int SYMBOLS_SHIFTED = 5; + + private int mLayout = ALPHABET_UNSHIFTED; + + private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS; + // Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS. + private boolean mAutoCapsState = true; + + private final KeyboardState mState = new KeyboardState(this); + + public boolean assertAlphabetNormal() { + return mLayout == ALPHABET_UNSHIFTED; + } + + public boolean assertAlphabetManualShifted() { + return mLayout == ALPHABET_MANUAL_SHIFTED; + } + + public boolean assertAlphabetAutomaticShifted() { + return mLayout == ALPHABET_AUTOMATIC_SHIFTED; + } + + public boolean assertAlphabetShiftLocked() { + return mLayout == ALPHABET_SHIFT_LOCKED; + } + + public boolean assertSymbolsNormal() { + return mLayout == SYMBOLS_UNSHIFTED; + } + + public boolean assertSymbolsShifted() { + return mLayout == SYMBOLS_SHIFTED; + } + + public void setAutoCapsMode(boolean autoCaps) { + mAutoCapsMode = autoCaps; + } + + @Override + public void setAlphabetKeyboard() { + mLayout = ALPHABET_UNSHIFTED; + } + + @Override + public void setShifted(int shiftMode) { + if (shiftMode == SwitchActions.UNSHIFT) { + mLayout = ALPHABET_UNSHIFTED; + } else if (shiftMode == SwitchActions.MANUAL_SHIFT) { + mLayout = ALPHABET_MANUAL_SHIFTED; + } else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) { + mLayout = ALPHABET_AUTOMATIC_SHIFTED; + } + } + + @Override + public void setShiftLocked(boolean shiftLocked) { + if (shiftLocked) { + mLayout = ALPHABET_SHIFT_LOCKED; + } else { + mLayout = ALPHABET_UNSHIFTED; + } + } + + @Override + public void setSymbolsKeyboard() { + mLayout = SYMBOLS_UNSHIFTED; + } + + @Override + public void setSymbolsShiftedKeyboard() { + mLayout = SYMBOLS_SHIFTED; + } + + @Override + public void requestUpdatingShiftState() { + mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); + } + + public void updateShiftState() { + mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); + } + + public void loadKeyboard(String layoutSwitchBackSymbols, + boolean hasDistinctMultitouch) { + mState.onLoadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch); + } + + public void onPressKey(int code) { + mState.onPressKey(code); + } + + public void onReleaseKey(int code) { + onReleaseKey(code, Constants.NOT_SLIDING); + } + + public void onReleaseKey(int code, boolean withSliding) { + mState.onReleaseKey(code, withSliding); + } + + public void onCodeInput(int code) { + onCodeInput(code, Constants.SINGLE); + } + + public void onCodeInput(int code, boolean isSinglePointer) { + mAutoCapsState = (WORD_SEPARATORS.indexOf(code) >= 0); + mState.onCodeInput(code, isSinglePointer, mAutoCapsMode && mAutoCapsState); + } + + public void onCancelInput(boolean isSinglePointer) { + mState.onCancelInput(isSinglePointer); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java index fec3e8ee1..7925d1a49 100644 --- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java @@ -16,10 +16,7 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.latin.LocaleUtils; - import android.content.Context; -import android.content.res.Resources; import android.test.AndroidTestCase; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; @@ -30,24 +27,22 @@ import java.util.List; import java.util.Locale; public class SubtypeLocaleTests extends AndroidTestCase { - private static final String PACKAGE = LatinIME.class.getPackage().getName(); - - private Resources mRes; - private List<InputMethodSubtype> mKeyboardSubtypes = new ArrayList<InputMethodSubtype>(); + private List<InputMethodSubtype> mKeyboardSubtypes; @Override protected void setUp() throws Exception { super.setUp(); final Context context = getContext(); - mRes = context.getResources(); + final String packageName = context.getApplicationInfo().packageName; SubtypeLocale.init(context); final InputMethodManager imm = (InputMethodManager) context.getSystemService( Context.INPUT_METHOD_SERVICE); for (final InputMethodInfo imi : imm.getInputMethodList()) { - if (imi.getPackageName().equals(PACKAGE)) { + if (imi.getPackageName().equals(packageName)) { + mKeyboardSubtypes = new ArrayList<InputMethodSubtype>(); final int subtypeCount = imi.getSubtypeCount(); for (int i = 0; i < subtypeCount; ++i) { InputMethodSubtype subtype = imi.getSubtypeAt(i); @@ -58,37 +53,29 @@ public class SubtypeLocaleTests extends AndroidTestCase { break; } } - assertNotNull("Can not find input method " + PACKAGE, mKeyboardSubtypes); + assertNotNull("Can not find input method " + packageName, mKeyboardSubtypes); assertTrue("Can not find keyboard subtype", mKeyboardSubtypes.size() > 0); } - private String getStringWithLocale(int resId, Locale locale) { - final Locale savedLocale = Locale.getDefault(); - try { - Locale.setDefault(locale); - return mRes.getString(resId); - } finally { - Locale.setDefault(savedLocale); - } - } - public void testSubtypeLocale() { final StringBuilder messages = new StringBuilder(); int failedCount = 0; for (final InputMethodSubtype subtype : mKeyboardSubtypes) { - final String localeCode = subtype.getLocale(); - final Locale locale = LocaleUtils.constructLocaleFromString(localeCode); - // The locale name which will be displayed on spacebar. For example 'English (US)' or - // 'Francais (Canada)'. (c=\u008d) - final String displayName = SubtypeLocale.getFullDisplayName(locale); - // The subtype name in its locale. For example 'English (US) Keyboard' or - // 'Clavier Francais (Canada)'. (c=\u008d) - final String subtypeName = getStringWithLocale(subtype.getNameResId(), locale); - if (subtypeName.contains(displayName)) { + final Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale()); + final String subtypeLocaleString = + subtype.containsExtraValueKey(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) + ? subtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) + : subtype.getLocale(); + final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtypeLocaleString); + // The subtype name in its locale. For example 'English (US)' or 'Deutsch (QWERTY)'. + final String subtypeName = SubtypeLocale.getFullDisplayName(subtypeLocale); + // The locale language name in its locale. + final String languageName = locale.getDisplayLanguage(locale); + if (!subtypeName.contains(languageName)) { failedCount++; messages.append(String.format( - "subtype name is '%s' and should contain locale '%s' name '%s'\n", - subtypeName, localeCode, displayName)); + "subtype name is '%s' and should contain locale '%s' language name '%s'\n", + subtypeName, subtypeLocale, languageName)); } } assertEquals(messages.toString(), 0, failedCount); diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java index cccd1a4a9..2e362458b 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java @@ -21,7 +21,7 @@ import android.text.TextUtils; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.keyboard.KeyboardSet; import java.io.File; import java.util.Locale; @@ -32,24 +32,20 @@ public class SuggestHelper { protected final Keyboard mKeyboard; private final KeyDetector mKeyDetector; - public static final int ALPHABET_KEYBOARD = com.android.inputmethod.latin.R.xml.kbd_qwerty; - - public SuggestHelper(Context context, int dictionaryId, KeyboardId keyboardId) { + public SuggestHelper(Context context, int dictionaryId, KeyboardSet keyboardSet) { // Use null as the locale for Suggest so as to force it to use the internal dictionary // (and not try to find a dictionary provider for a specified locale) mSuggest = new Suggest(context, dictionaryId, null); - mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params()) - .load(ALPHABET_KEYBOARD, keyboardId).build(); + mKeyboard = keyboardSet.getMainKeyboard(); mKeyDetector = new KeyDetector(0); init(); } protected SuggestHelper(final Context context, final File dictionaryPath, - final long startOffset, final long length, final KeyboardId keyboardId, + final long startOffset, final long length, final KeyboardSet keyboardSet, final Locale locale) { mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale); - mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params()) - .load(ALPHABET_KEYBOARD, keyboardId).build(); + mKeyboard = keyboardSet.getMainKeyboard(); mKeyDetector = new KeyDetector(0); init(); } diff --git a/tests/src/com/android/inputmethod/latin/SuggestTests.java b/tests/src/com/android/inputmethod/latin/SuggestTests.java index 4080f34be..e12ae58c4 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestTests.java +++ b/tests/src/com/android/inputmethod/latin/SuggestTests.java @@ -33,7 +33,7 @@ public class SuggestTests extends SuggestTestsBase { final Locale locale = Locale.US; mHelper = new SuggestHelper( getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(), - createKeyboardId(locale, Configuration.ORIENTATION_PORTRAIT), locale); + createKeyboardSet(locale, Configuration.ORIENTATION_PORTRAIT), locale); mHelper.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM); } @@ -183,7 +183,8 @@ public class SuggestTests extends SuggestTestsBase { "part", mHelper.getBigramAutoCorrection("about", "pa")); // TODO: The following test fails. // suggested("single: said", "said", mHelper.getAutoCorrection("sa")); - suggested("bigram: from sa[me]", - "same", mHelper.getBigramAutoCorrection("from", "sa")); + // TODO: The following test fails due to "transpose correction". + // suggested("bigram: from sa[me]", + // "same", mHelper.getBigramAutoCorrection("from", "sa")); } } diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java index 9dd61d78c..73e34ba6f 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java @@ -22,8 +22,9 @@ import android.test.AndroidTestCase; import android.text.InputType; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.view.inputmethod.EditorInfo; -import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.keyboard.KeyboardSet; import java.io.File; import java.io.InputStream; @@ -38,7 +39,12 @@ public class SuggestTestsBase extends AndroidTestCase { mTestPackageFile = new File(getTestContext().getApplicationInfo().sourceDir); } - protected KeyboardId createKeyboardId(Locale locale, int orientation) { + protected KeyboardSet createKeyboardSet(Locale locale, int orientation) { + return createKeyboardSet(locale, orientation, false); + } + + protected KeyboardSet createKeyboardSet(Locale locale, int orientation, + boolean touchPositionCorrectionEnabled) { final DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); final int width; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { @@ -50,8 +56,12 @@ public class SuggestTestsBase extends AndroidTestCase { + "orientation=" + orientation); return null; } - return new KeyboardId(KeyboardId.ELEMENT_ALPHABET, locale, orientation, width, - KeyboardId.MODE_TEXT, InputType.TYPE_CLASS_TEXT, 0, false, false, false, false); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.inputType = InputType.TYPE_CLASS_TEXT; + final KeyboardSet.Builder builder = new KeyboardSet.Builder(getContext(), editorInfo); + builder.setScreenGeometry(orientation, width); + builder.setSubtype(locale, true, touchPositionCorrectionEnabled); + return builder.build(); } protected InputStream openTestRawResource(int resIdInTest) { diff --git a/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java b/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java index 863c2b254..74fadf76b 100644 --- a/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java @@ -16,11 +16,11 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.KeyboardId; - import android.content.Context; import android.text.TextUtils; +import com.android.inputmethod.keyboard.KeyboardSet; + import java.io.File; import java.util.Locale; import java.util.StringTokenizer; @@ -31,8 +31,8 @@ public class UserBigramSuggestHelper extends SuggestHelper { public UserBigramSuggestHelper(final Context context, final File dictionaryPath, final long startOffset, final long length, final int userBigramMax, - final int userBigramDelete, final KeyboardId keyboardId, final Locale locale) { - super(context, dictionaryPath, startOffset, length, keyboardId, locale); + final int userBigramDelete, final KeyboardSet keyboardSet, final Locale locale) { + super(context, dictionaryPath, startOffset, length, keyboardSet, locale); mContext = context; mUserBigram = new UserBigramDictionary(context, null, locale.toString(), Suggest.DIC_USER); diff --git a/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java b/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java index 2bc0aabc0..2b88a7ca6 100644 --- a/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java +++ b/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java @@ -23,7 +23,7 @@ import com.android.inputmethod.latin.tests.R; import java.util.Locale; public class UserBigramSuggestTests extends SuggestTestsBase { - private static final int SUGGESTION_STARTS = 6; + private static final int SUGGESTION_STARTS = 1; private static final int MAX_DATA = 20; private static final int DELETE_DATA = 10; @@ -37,7 +37,7 @@ public class UserBigramSuggestTests extends SuggestTestsBase { mHelper = new UserBigramSuggestHelper( getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(), MAX_DATA, DELETE_DATA, - createKeyboardId(locale, Configuration.ORIENTATION_PORTRAIT), locale); + createKeyboardSet(locale, Configuration.ORIENTATION_PORTRAIT), locale); } /************************** Tests ************************/ diff --git a/tests/src/com/android/inputmethod/latin/UtilsTests.java b/tests/src/com/android/inputmethod/latin/UtilsTests.java index 5c0b03a0a..2ef4e2ff5 100644 --- a/tests/src/com/android/inputmethod/latin/UtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/UtilsTests.java @@ -18,8 +18,6 @@ package com.android.inputmethod.latin; import android.test.AndroidTestCase; -import com.android.inputmethod.latin.tests.R; - public class UtilsTests extends AndroidTestCase { // The following is meant to be a reasonable default for |