aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java59
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java5
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java4
3 files changed, 43 insertions, 25 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index b1b48135f..eb94e2266 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -16,17 +16,33 @@
package com.android.inputmethod.latin;
-import android.test.MoreAsserts;
+import static android.test.MoreAsserts.assertNotEqual;
+
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.settings.Settings;
@LargeTest
public class InputLogicTests extends InputTestsBase {
+ private boolean mNextWordPrediction;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mNextWordPrediction = getBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, true);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mNextWordPrediction, true);
+ super.tearDown();
+ }
+
public void testTypeWord() {
final String WORD_TO_TYPE = "abcd";
type(WORD_TO_TYPE);
@@ -494,24 +510,19 @@ public class InputLogicTests extends InputTestsBase {
public void testPredictionsWithDoubleSpaceToPeriod() {
mLatinIME.clearPersonalizedDictionariesForTest();
- final String WORD_TO_TYPE = "Barack ";
+ final String WORD_TO_TYPE = "Barack ";
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- // No need to test here, testPredictionsAfterSpace is testing it already
- type(" ");
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
- runMessages();
- // Test the predictions have been cleared
- SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
- assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0);
+
type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- // Test the first prediction is displayed
+
+ SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("predictions after cancel double-space-to-period", "Obama",
- suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
+ mLatinIME.getSuggestedWordsForTest().getWord(0));
}
public void testPredictionsAfterManualPick() {
@@ -533,15 +544,9 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
- SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
- assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size());
- type(WORD_TO_TYPE);
- sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
- runMessages();
- suggestedWords = mLatinIME.getSuggestedWordsForTest();
- assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
- suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
+ SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
+ assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty());
}
public void testPredictionsAfterRecorrection() {
@@ -668,8 +673,11 @@ public class InputLogicTests extends InputTestsBase {
type(Constants.CODE_DELETE);
assertEquals("gesture then backspace", "", mEditText.getText().toString());
gesture("this");
- MoreAsserts.assertNotEqual("gesture twice the same thing", "this",
- mEditText.getText().toString());
+ if (DecoderSpecificConstants.SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION) {
+ assertNotEqual("this", mEditText.getText().toString());
+ } else {
+ assertEquals("this", mEditText.getText().toString());
+ }
}
private void typeOrGestureWordAndPutCursorInside(final boolean gesture, final String word,
@@ -736,12 +744,13 @@ public class InputLogicTests extends InputTestsBase {
ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1);
}
+ // TODO: Verify this works when we return FIGS language models to the APK.
public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq ";
- final String EXPECTED_RESULT = "ira ";
- changeLanguage("fr");
+ final String EXPECTED_RESULT = "ir a ";
+ changeLanguage("es");
type(STRING_TO_TYPE);
- assertEquals("simple auto-correct for French", EXPECTED_RESULT,
+ assertEquals("simple auto-correct for Spanish", EXPECTED_RESULT,
mEditText.getText().toString());
}
@@ -771,6 +780,8 @@ public class InputLogicTests extends InputTestsBase {
}
public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
+ setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, false, true);
+
final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!";
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index 6ae38c615..ab4060a86 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -164,6 +164,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
return previousSetting;
}
+ protected boolean getBooleanPreference(final String key, final boolean defaultValue) {
+ return PreferenceManager.getDefaultSharedPreferences(mLatinIME)
+ .getBoolean(key, defaultValue);
+ }
+
protected String setStringPreference(final String key, final String value,
final String defaultValue) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
index 94105aa12..4b7b9bc36 100644
--- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
+++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.personalization;
import android.content.Context;
+import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.common.FileUtils;
@@ -98,7 +99,8 @@ public class UserHistoryDictionaryTestsHelper {
private static void addWordsToDictionary(final UserHistoryDictionary dict,
final List<String> words, final int timestamp) {
- NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
+ NgramContext ngramContext = NgramContext.getEmptyPrevWordsContext(
+ BinaryDictionary.MAX_PREV_WORD_COUNT_FOR_N_GRAM);
for (final String word : words) {
UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp);
ngramContext = ngramContext.getNextNgramContext(new WordInfo(word));