aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestHelper.java17
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestTestsBase.java7
-rw-r--r--tests/src/com/android/inputmethod/latin/UtilsTests.java67
4 files changed, 83 insertions, 12 deletions
diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
index d128cb3fa..d102aa4d1 100644
--- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
+++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.latin.Utils;
+
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
@@ -75,7 +77,7 @@ public class SubtypeLocaleTests extends AndroidTestCase {
int failedCount = 0;
for (final InputMethodSubtype subtype : mKeyboardSubtypes) {
final String localeCode = subtype.getLocale();
- final Locale locale = new Locale(localeCode);
+ final Locale locale = Utils.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);
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 5930ea36e..87ea011fa 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -20,7 +20,6 @@ import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.LatinKeyboard;
-import com.android.inputmethod.keyboard.ProximityKeyDetector;
import android.content.Context;
import android.text.TextUtils;
@@ -34,17 +33,19 @@ public class SuggestHelper {
private final KeyDetector mKeyDetector;
public SuggestHelper(Context context, int dictionaryId, KeyboardId keyboardId) {
- mSuggest = new Suggest(context, dictionaryId);
- mKeyboard = new LatinKeyboard(context, keyboardId);
- mKeyDetector = new ProximityKeyDetector();
+ // 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(context, keyboardId, keyboardId.mWidth);
+ mKeyDetector = new KeyDetector();
init();
}
protected SuggestHelper(Context context, File dictionaryPath, long startOffset, long length,
KeyboardId keyboardId) {
- mSuggest = new Suggest(dictionaryPath, startOffset, length);
- mKeyboard = new LatinKeyboard(context, keyboardId);
- mKeyDetector = new ProximityKeyDetector();
+ mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null);
+ mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth);
+ mKeyDetector = new KeyDetector();
init();
}
@@ -53,7 +54,7 @@ public class SuggestHelper {
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL);
mKeyDetector.setKeyboard(mKeyboard, 0, 0);
mKeyDetector.setProximityCorrectionEnabled(true);
- mKeyDetector.setProximityThreshold(KeyDetector.getMostCommonKeyWidth(mKeyboard));
+ mKeyDetector.setProximityThreshold(mKeyboard.getMostCommonKeyWidth());
}
public void setCorrectionMode(int correctionMode) {
diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
index 48d169f6a..28766c21f 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
@@ -38,11 +38,12 @@ public class SuggestTestsBase extends AndroidTestCase {
mTestPackageFile = new File(getTestContext().getApplicationInfo().sourceDir);
}
- protected static KeyboardId createKeyboardId(Locale locale) {
+ protected KeyboardId createKeyboardId(Locale locale) {
+ final int displayWidth = getContext().getResources().getDisplayMetrics().widthPixels;
return new KeyboardId(locale.toString() + " keyboard",
com.android.inputmethod.latin.R.xml.kbd_qwerty, KeyboardView.COLOR_SCHEME_WHITE,
- locale, Configuration.ORIENTATION_LANDSCAPE, KeyboardId.MODE_TEXT,
- new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false, false);
+ locale, Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT,
+ new EditorInfo(), false, false, false, false);
}
protected InputStream openTestRawResource(int resIdInTest) {
diff --git a/tests/src/com/android/inputmethod/latin/UtilsTests.java b/tests/src/com/android/inputmethod/latin/UtilsTests.java
new file mode 100644
index 000000000..5c0b03a0a
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/UtilsTests.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010,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.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
+ // the "word_separators" resource.
+ private static final String sSeparators = ".,:;!?-";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /************************** Tests ************************/
+
+ /**
+ * Test for getting previous word (for bigram suggestions)
+ */
+ public void testGetPreviousWord() {
+ // If one of the following cases breaks, the bigram suggestions won't work.
+ assertEquals(EditingUtils.getPreviousWord("abc def", sSeparators), "abc");
+ assertNull(EditingUtils.getPreviousWord("abc", sSeparators));
+ assertNull(EditingUtils.getPreviousWord("abc. def", sSeparators));
+
+ // The following tests reflect the current behavior of the function
+ // EditingUtils#getPreviousWord.
+ // TODO: However at this time, the code does never go
+ // into such a path, so it should be safe to change the behavior of
+ // this function if needed - especially since it does not seem very
+ // logical. These tests are just there to catch any unintentional
+ // changes in the behavior of the EditingUtils#getPreviousWord method.
+ assertEquals(EditingUtils.getPreviousWord("abc def ", sSeparators), "abc");
+ assertEquals(EditingUtils.getPreviousWord("abc def.", sSeparators), "abc");
+ assertEquals(EditingUtils.getPreviousWord("abc def .", sSeparators), "def");
+ assertNull(EditingUtils.getPreviousWord("abc ", sSeparators));
+ }
+
+ /**
+ * Test for getting the word before the cursor (for bigram)
+ */
+ public void testGetThisWord() {
+ assertEquals(EditingUtils.getThisWord("abc def", sSeparators), "def");
+ assertEquals(EditingUtils.getThisWord("abc def ", sSeparators), "def");
+ assertNull(EditingUtils.getThisWord("abc def.", sSeparators));
+ assertNull(EditingUtils.getThisWord("abc def .", sSeparators));
+ }
+}