aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java261
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java82
-rw-r--r--tests/src/com/android/inputmethod/latin/EditDistanceTests.java18
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestHelper.java54
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestTestsBase.java8
-rw-r--r--tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java5
6 files changed, 338 insertions, 90 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java
new file mode 100644
index 000000000..1f6141e50
--- /dev/null
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2011 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;
+
+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;
+
+ @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);
+ }
+
+ 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 in alphabet mode.
+ public void testShift() {
+ // Press/release shift key.
+ mState.onPressShift(NOT_SLIDING);
+ assertAlphabetManualShifted();
+ mState.onReleaseShift(NOT_SLIDING);
+ assertAlphabetManualShifted();
+
+ // Press/release shift key.
+ mState.onPressShift(NOT_SLIDING);
+ assertAlphabetManualShifted();
+ mState.onReleaseShift(NOT_SLIDING);
+ assertAlphabetNormal();
+
+ // TODO: Sliding test
+ }
+
+ // Switching between alphabet and symbols.
+ public void testAlphabetAndSymbols() {
+ // Press/release "?123" key.
+ mState.onPressSymbol();
+ assertSymbolsNormal();
+ mState.onReleaseSymbol();
+ 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();
+ assertSymbolsNormal();
+ mState.onReleaseSymbol();
+ assertSymbolsNormal();
+
+ // Press/release "=\<" key.
+ mState.onPressShift(NOT_SLIDING);
+ assertSymbolsShifted();
+ mState.onReleaseShift(NOT_SLIDING);
+ assertSymbolsShifted();
+
+ // Press/release "ABC" key.
+ mState.onPressSymbol();
+ assertAlphabetNormal();
+ mState.onReleaseSymbol();
+ assertAlphabetNormal();
+
+ // TODO: Sliding test
+ // TODO: Snap back test
+ }
+
+ // Automatic upper case test
+ public void testAutomaticUpperCase() {
+ // Update shift state with auto caps enabled.
+ mState.onUpdateShiftState(true);
+ assertAlphabetAutomaticShifted();
+
+ // Press shift key.
+ mState.onPressShift(NOT_SLIDING);
+ assertAlphabetManualShifted();
+ // Release shift key.
+ mState.onReleaseShift(NOT_SLIDING);
+ 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();
+
+ // 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);
+ 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();
+
+ // 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.
+ }
+}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
index 798fca0f5..0eb324234 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParserTests.java
@@ -89,78 +89,78 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
assertParser("Single escaped at", "\\@",
"@", null, ICON_UNDEFINED, '@');
assertParser("Single letter with outputText", "a|abc",
- "a", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with escaped outputText", "a|a\\|c",
- "a", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "a|c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with comma outputText", "a|a,b",
- "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with escaped comma outputText", "a|a\\,b",
- "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with outputText starts with at", "a|@bc",
- "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with outputText contains at", "a|a@c",
- "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with escaped at outputText", "a|\\@bc",
- "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single escaped escape with outputText", "\\\\|\\\\",
- "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "\\", "\\", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single escaped bar with outputText", "\\||\\|",
- "|", "|", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "|", "|", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Single letter with code", "a|" + CODE_SETTINGS,
"a", null, ICON_UNDEFINED, mCodeSettings);
}
public void testLabel() {
assertParser("Simple label", "abc",
- "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped bar", "a\\|c",
- "a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a|c", "a|c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped escape", "a\\\\c",
- "a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a\\c", "a\\c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with comma", "a,c",
- "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped comma", "a\\,c",
- "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label starts with at", "@bc",
- "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label contains at", "a@c",
- "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped at", "\\@bc",
- "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped letter", "\\abc",
- "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with outputText", "abc|def",
- "abc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with comma and outputText", "a,c|def",
- "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Escaped comma label with outputText", "a\\,c|def",
- "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a,c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Escaped label with outputText", "a\\|c|def",
- "a|c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a|c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped bar outputText", "abc|d\\|f",
- "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Escaped escape label with outputText", "a\\\\|def",
- "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label starts with at and outputText", "@bc|def",
- "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label contains at label and outputText", "a@c|def",
- "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Escaped at label with outputText", "\\@bc|def",
- "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with comma outputText", "abc|a,b",
- "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped comma outputText", "abc|a\\,b",
- "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with outputText starts with at", "abc|@bc",
- "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with outputText contains at", "abc|a@c",
- "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped at outputText", "abc|\\@bc",
- "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with escaped bar outputText", "abc|d\\|f",
- "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f",
- "a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ "a|c", "d|f", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParser("Label with code", "abc|" + CODE_SETTINGS,
"abc", null, ICON_UNDEFINED, mCodeSettings);
assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS,
@@ -169,13 +169,13 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
public void testIconAndCode() {
assertParser("Icon with outputText", ICON_SETTINGS + "|abc",
- null, "abc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY);
+ null, "abc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc",
- null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY);
+ null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c",
- null, "a@c", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY);
+ null, "a@c", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc",
- null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY);
+ null, "@bc", ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS,
"@bc", null, ICON_UNDEFINED, mCodeSettings);
assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS,
@@ -190,7 +190,7 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
assertParserError("Empty spec", "", null,
null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Empty label with outputText", "|a",
- null, "a", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ null, "a", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Empty label with code", "|" + CODE_SETTINGS,
null, null, ICON_UNDEFINED, mCodeSettings);
assertParserError("Empty outputText with label", "a|",
@@ -200,9 +200,9 @@ public class MoreKeySpecParserTests extends AndroidTestCase {
assertParserError("Empty icon and code", "|",
null, null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Icon without code", ICON_SETTINGS,
- null, null, ICON_SETTINGS_KEY, Keyboard.CODE_DUMMY);
+ null, null, ICON_SETTINGS_KEY, Keyboard.CODE_UNSPECIFIED);
assertParser("Non existing icon", ICON_NON_EXISTING + "|abc",
- null, "abc", ICON_UNDEFINED, Keyboard.CODE_DUMMY);
+ null, "abc", ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING,
"abc", null, ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED);
assertParserError("Third bar at end", "a|b|",
diff --git a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
index 75bd04938..c053a49e5 100644
--- a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
+++ b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
@@ -37,7 +37,7 @@ public class EditDistanceTests extends AndroidTestCase {
* sitting
*/
public void testExample1() {
- final int dist = Utils.editDistance("kitten", "sitting");
+ final int dist = BinaryDictionary.editDistance("kitten", "sitting");
assertEquals("edit distance between 'kitten' and 'sitting' is 3",
3, dist);
}
@@ -50,26 +50,26 @@ public class EditDistanceTests extends AndroidTestCase {
* S--unday
*/
public void testExample2() {
- final int dist = Utils.editDistance("Saturday", "Sunday");
+ final int dist = BinaryDictionary.editDistance("Saturday", "Sunday");
assertEquals("edit distance between 'Saturday' and 'Sunday' is 3",
3, dist);
}
public void testBothEmpty() {
- final int dist = Utils.editDistance("", "");
+ final int dist = BinaryDictionary.editDistance("", "");
assertEquals("when both string are empty, no edits are needed",
0, dist);
}
public void testFirstArgIsEmpty() {
- final int dist = Utils.editDistance("", "aaaa");
+ final int dist = BinaryDictionary.editDistance("", "aaaa");
assertEquals("when only one string of the arguments is empty,"
+ " the edit distance is the length of the other.",
4, dist);
}
public void testSecoondArgIsEmpty() {
- final int dist = Utils.editDistance("aaaa", "");
+ final int dist = BinaryDictionary.editDistance("aaaa", "");
assertEquals("when only one string of the arguments is empty,"
+ " the edit distance is the length of the other.",
4, dist);
@@ -78,27 +78,27 @@ public class EditDistanceTests extends AndroidTestCase {
public void testSameStrings() {
final String arg1 = "The quick brown fox jumps over the lazy dog.";
final String arg2 = "The quick brown fox jumps over the lazy dog.";
- final int dist = Utils.editDistance(arg1, arg2);
+ final int dist = BinaryDictionary.editDistance(arg1, arg2);
assertEquals("when same strings are passed, distance equals 0.",
0, dist);
}
public void testSameReference() {
final String arg = "The quick brown fox jumps over the lazy dog.";
- final int dist = Utils.editDistance(arg, arg);
+ final int dist = BinaryDictionary.editDistance(arg, arg);
assertEquals("when same string references are passed, the distance equals 0.",
0, dist);
}
public void testNullArg() {
try {
- Utils.editDistance(null, "aaa");
+ BinaryDictionary.editDistance(null, "aaa");
fail("IllegalArgumentException should be thrown.");
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
try {
- Utils.editDistance("aaa", null);
+ BinaryDictionary.editDistance("aaa", null);
fail("IllegalArgumentException should be thrown.");
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 464930f4c..cccd1a4a9 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -19,24 +19,27 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.text.TextUtils;
-import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
+import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
-import com.android.inputmethod.keyboard.LatinKeyboard;
import java.io.File;
import java.util.Locale;
public class SuggestHelper {
protected final Suggest mSuggest;
- protected final LatinKeyboard mKeyboard;
+ protected int mCorrectionMode;
+ 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) {
// 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 LatinKeyboard.Builder(context).load(keyboardId).build();
+ mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params())
+ .load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyDetector = new KeyDetector(0);
init();
}
@@ -45,46 +48,30 @@ public class SuggestHelper {
final long startOffset, final long length, final KeyboardId keyboardId,
final Locale locale) {
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale);
- mKeyboard = new LatinKeyboard.Builder(context).load(keyboardId).build();
+ mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params())
+ .load(ALPHABET_KEYBOARD, keyboardId).build();
mKeyDetector = new KeyDetector(0);
init();
}
private void init() {
- mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL);
+ setCorrectionMode(Suggest.CORRECTION_FULL);
mKeyDetector.setKeyboard(mKeyboard, 0, 0);
mKeyDetector.setProximityCorrectionEnabled(true);
mKeyDetector.setProximityThreshold(mKeyboard.mMostCommonKeyWidth);
}
public void setCorrectionMode(int correctionMode) {
- mSuggest.setCorrectionMode(correctionMode);
+ mCorrectionMode = correctionMode;
}
public boolean hasMainDictionary() {
return mSuggest.hasMainDictionary();
}
- private void addKeyInfo(WordComposer word, char c) {
- for (final Key key : mKeyboard.mKeys) {
- if (key.mCode == c) {
- final int x = key.mX + key.mWidth / 2;
- final int y = key.mY + key.mHeight / 2;
- final int[] codes = mKeyDetector.newCodeArray();
- mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes);
- word.add(c, codes, x, y);
- return;
- }
- }
- word.add(c, new int[] { c }, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
- }
-
protected WordComposer createWordComposer(CharSequence s) {
WordComposer word = new WordComposer();
- for (int i = 0; i < s.length(); i++) {
- final char c = s.charAt(i);
- addKeyInfo(word, c);
- }
+ word.setComposingWord(s, mKeyboard, mKeyDetector);
return word;
}
@@ -96,13 +83,13 @@ public class SuggestHelper {
// TODO: This may be slow, but is OK for test so far.
public SuggestedWords getSuggestions(CharSequence typed) {
return mSuggest.getSuggestions(createWordComposer(typed), null,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
}
public CharSequence getFirstSuggestion(CharSequence typed) {
WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed.
return suggestions.size() > 1 ? suggestions.getWord(1) : null;
}
@@ -110,7 +97,7 @@ public class SuggestHelper {
public CharSequence getAutoCorrection(CharSequence typed) {
WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed.
return (suggestions.size() > 1 && mSuggest.hasAutoCorrection())
? suggestions.getWord(1) : null;
@@ -119,7 +106,7 @@ public class SuggestHelper {
public int getSuggestIndex(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed.
for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected))
@@ -131,7 +118,8 @@ public class SuggestHelper {
private void getBigramSuggestions(CharSequence previous, CharSequence typed) {
if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) {
WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0)));
- mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo());
+ mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo(),
+ mCorrectionMode);
}
}
@@ -139,7 +127,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
return suggestions.size() > 1 ? suggestions.getWord(1) : null;
}
@@ -147,7 +135,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
return (suggestions.size() > 1 && mSuggest.hasAutoCorrection())
? suggestions.getWord(1) : null;
}
@@ -157,7 +145,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
- mKeyboard.getProximityInfo());
+ mKeyboard.getProximityInfo(), mCorrectionMode);
for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected))
return i;
diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
index 058a3e7c0..9dd61d78c 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
@@ -19,9 +19,9 @@ package com.android.inputmethod.latin;
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
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;
@@ -50,10 +50,8 @@ public class SuggestTestsBase extends AndroidTestCase {
+ "orientation=" + orientation);
return null;
}
- return new KeyboardId(locale.toString() + " keyboard",
- com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, orientation, width,
- KeyboardId.MODE_TEXT, new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE,
- false, false, false);
+ return new KeyboardId(KeyboardId.ELEMENT_ALPHABET, locale, orientation, width,
+ KeyboardId.MODE_TEXT, InputType.TYPE_CLASS_TEXT, 0, false, false, false, false);
}
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 023e20a10..863c2b254 100644
--- a/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/UserBigramSuggestHelper.java
@@ -38,7 +38,7 @@ public class UserBigramSuggestHelper extends SuggestHelper {
Suggest.DIC_USER);
mUserBigram.setDatabaseMax(userBigramMax);
mUserBigram.setDatabaseDelete(userBigramDelete);
- mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
+ setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
mSuggest.setUserBigramDictionary(mUserBigram);
}
@@ -59,7 +59,8 @@ public class UserBigramSuggestHelper extends SuggestHelper {
flushUserBigrams();
if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) {
WordComposer firstChar = createWordComposer(Character.toString(typed));
- mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo());
+ mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo(),
+ mCorrectionMode);
boolean reloading = mUserBigram.reloadDictionaryIfRequired();
if (reloading) mUserBigram.waitForDictionaryLoading();
mUserBigram.getBigrams(firstChar, previous, mSuggest);