Merge "Cleanup KeyboardStateTests a bit"
This commit is contained in:
commit
327c6828a5
1 changed files with 85 additions and 40 deletions
|
@ -29,9 +29,13 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
private static final int SYMBOLS_UNSHIFTED = 4;
|
private static final int SYMBOLS_UNSHIFTED = 4;
|
||||||
private static final int SYMBOLS_SHIFTED = 5;
|
private static final int SYMBOLS_SHIFTED = 5;
|
||||||
|
|
||||||
static class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
static class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
public int mLayout = ALPHABET_UNSHIFTED;
|
public int mLayout = ALPHABET_UNSHIFTED;
|
||||||
|
|
||||||
|
public boolean mAutoCaps = NO_AUTO_CAPS;
|
||||||
|
|
||||||
|
final KeyboardState mState = new KeyboardState(this);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAlphabetKeyboard() {
|
public void setAlphabetKeyboard() {
|
||||||
mLayout = ALPHABET_UNSHIFTED;
|
mLayout = ALPHABET_UNSHIFTED;
|
||||||
|
@ -66,22 +70,62 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
public void setSymbolsShiftedKeyboard() {
|
public void setSymbolsShiftedKeyboard() {
|
||||||
mLayout = SYMBOLS_SHIFTED;
|
mLayout = SYMBOLS_SHIFTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleCapsLock() {
|
||||||
|
mState.onToggleCapsLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private KeyboardSwitcher mSwitcher;
|
public void updateShiftState() {
|
||||||
private KeyboardState mState;
|
mState.onUpdateShiftState(mAutoCaps);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadKeyboard(String layoutSwitchBackSymbols,
|
||||||
|
boolean hasDistinctMultitouch) {
|
||||||
|
mState.onLoadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPressShift(boolean withSliding) {
|
||||||
|
mState.onPressShift(withSliding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onReleaseShift(boolean withSliding) {
|
||||||
|
mState.onReleaseShift(withSliding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPressSymbol() {
|
||||||
|
mState.onPressSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onReleaseSymbol() {
|
||||||
|
mState.onReleaseSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onOtherKeyPressed() {
|
||||||
|
mState.onOtherKeyPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCodeInput(int code, boolean isSinglePointer) {
|
||||||
|
mState.onCodeInput(code, isSinglePointer, mAutoCaps);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCancelInput(boolean isSinglePointer) {
|
||||||
|
mState.onCancelInput(isSinglePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MockKeyboardSwitcher mSwitcher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
mSwitcher = new KeyboardSwitcher();
|
mSwitcher = new MockKeyboardSwitcher();
|
||||||
mState = new KeyboardState(mSwitcher);
|
|
||||||
|
|
||||||
final String layoutSwitchBackCharacter = "";
|
final String layoutSwitchBackSymbols = "";
|
||||||
// TODO: Unit tests for non-distinct multi touch device.
|
// TODO: Unit tests for non-distinct multi touch device.
|
||||||
final boolean hasDistinctMultitouch = true;
|
final boolean hasDistinctMultitouch = true;
|
||||||
mState.onLoadKeyboard(layoutSwitchBackCharacter, hasDistinctMultitouch);
|
mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Argument for KeyboardState.onPressShift and onReleaseShift.
|
// Argument for KeyboardState.onPressShift and onReleaseShift.
|
||||||
|
@ -125,15 +169,15 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Shift key in alphabet mode.
|
// Shift key in alphabet mode.
|
||||||
public void testShift() {
|
public void testShift() {
|
||||||
// Press/release shift key.
|
// Press/release shift key.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
|
|
||||||
// Press/release shift key.
|
// Press/release shift key.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
|
||||||
// TODO: Sliding test
|
// TODO: Sliding test
|
||||||
|
@ -142,15 +186,15 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Switching between alphabet and symbols.
|
// Switching between alphabet and symbols.
|
||||||
public void testAlphabetAndSymbols() {
|
public void testAlphabetAndSymbols() {
|
||||||
// Press/release "?123" key.
|
// Press/release "?123" key.
|
||||||
mState.onPressSymbol();
|
mSwitcher.onPressSymbol();
|
||||||
assertSymbolsNormal();
|
assertSymbolsNormal();
|
||||||
mState.onReleaseSymbol();
|
mSwitcher.onReleaseSymbol();
|
||||||
assertSymbolsNormal();
|
assertSymbolsNormal();
|
||||||
|
|
||||||
// Press/release "ABC" key.
|
// Press/release "ABC" key.
|
||||||
mState.onPressSymbol();
|
mSwitcher.onPressSymbol();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onReleaseSymbol();
|
mSwitcher.onReleaseSymbol();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
|
||||||
// TODO: Sliding test
|
// TODO: Sliding test
|
||||||
|
@ -160,21 +204,21 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Switching between symbols and symbols shifted.
|
// Switching between symbols and symbols shifted.
|
||||||
public void testSymbolsAndSymbolsShifted() {
|
public void testSymbolsAndSymbolsShifted() {
|
||||||
// Press/release "?123" key.
|
// Press/release "?123" key.
|
||||||
mState.onPressSymbol();
|
mSwitcher.onPressSymbol();
|
||||||
assertSymbolsNormal();
|
assertSymbolsNormal();
|
||||||
mState.onReleaseSymbol();
|
mSwitcher.onReleaseSymbol();
|
||||||
assertSymbolsNormal();
|
assertSymbolsNormal();
|
||||||
|
|
||||||
// Press/release "=\<" key.
|
// Press/release "=\<" key.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertSymbolsShifted();
|
assertSymbolsShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertSymbolsShifted();
|
assertSymbolsShifted();
|
||||||
|
|
||||||
// Press/release "ABC" key.
|
// Press/release "ABC" key.
|
||||||
mState.onPressSymbol();
|
mSwitcher.onPressSymbol();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onReleaseSymbol();
|
mSwitcher.onReleaseSymbol();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
|
||||||
// TODO: Sliding test
|
// TODO: Sliding test
|
||||||
|
@ -183,15 +227,16 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
|
|
||||||
// Automatic upper case test
|
// Automatic upper case test
|
||||||
public void testAutomaticUpperCase() {
|
public void testAutomaticUpperCase() {
|
||||||
|
mSwitcher.mAutoCaps = AUTO_CAPS;
|
||||||
// Update shift state with auto caps enabled.
|
// Update shift state with auto caps enabled.
|
||||||
mState.onUpdateShiftState(true);
|
mSwitcher.updateShiftState();
|
||||||
assertAlphabetAutomaticShifted();
|
assertAlphabetAutomaticShifted();
|
||||||
|
|
||||||
// Press shift key.
|
// Press shift key.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
// Release shift key.
|
// Release shift key.
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
|
||||||
// TODO: Chording test.
|
// TODO: Chording test.
|
||||||
|
@ -209,25 +254,25 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// TODO: Move long press recognizing timer/logic into KeyboardState.
|
// TODO: Move long press recognizing timer/logic into KeyboardState.
|
||||||
public void testLongPressShift() {
|
public void testLongPressShift() {
|
||||||
// Long press shift key
|
// Long press shift key
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mSwitcher.toggleCapsLock();
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS);
|
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
|
|
||||||
// Long press shift key.
|
// Long press shift key.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mSwitcher.toggleCapsLock();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS);
|
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,25 +280,25 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// TODO: Move double tap recognizing timer/logic into KeyboardState.
|
// TODO: Move double tap recognizing timer/logic into KeyboardState.
|
||||||
public void testDoubleTapShift() {
|
public void testDoubleTapShift() {
|
||||||
// First shift key tap.
|
// First shift key tap.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
// Second shift key tap.
|
// Second shift key tap.
|
||||||
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
|
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mSwitcher.toggleCapsLock();
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
|
|
||||||
// First shift key tap.
|
// First shift key tap.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mSwitcher.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
// Second shift key tap.
|
// Second shift key tap.
|
||||||
// Second tap is ignored in LatinKeyboardView.KeyTimerHandler.
|
// Second tap is ignored in LatinKeyboardView.KeyTimerHandler.
|
||||||
|
|
Loading…
Reference in a new issue