aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/inputmethod/latin/ArbitrarySubtype.java54
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java102
2 files changed, 141 insertions, 15 deletions
diff --git a/tests/src/com/android/inputmethod/latin/ArbitrarySubtype.java b/tests/src/com/android/inputmethod/latin/ArbitrarySubtype.java
new file mode 100644
index 000000000..1e3482ca7
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/ArbitrarySubtype.java
@@ -0,0 +1,54 @@
+/*
+ * 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.latin;
+
+import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
+
+public class ArbitrarySubtype extends InputMethodSubtypeCompatWrapper {
+ final String mLocale;
+ final String mExtraValue;
+
+ public ArbitrarySubtype(final String locale, final String extraValue) {
+ super(locale);
+ mLocale = locale;
+ mExtraValue = extraValue;
+ }
+
+ public String getLocale() {
+ return mLocale;
+ }
+
+ public String getExtraValue() {
+ return mExtraValue;
+ }
+
+ public String getMode() {
+ return "keyboard";
+ }
+
+ public String getExtraValueOf(final String key) {
+ if (LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key)) {
+ return "";
+ } else {
+ return null;
+ }
+ }
+
+ public boolean containsExtraValueKey(final String key) {
+ return LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key);
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index e3911f22f..a6a4d9343 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -95,20 +95,7 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
mLatinIME.onStartInputView(ei, false);
mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
mInputConnection = ic;
- // Wait for the main dictionary to be loaded (we need it for auto-correction tests)
- int remainingAttempts = 10;
- while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- // Don't do much
- } finally {
- --remainingAttempts;
- }
- }
- if (!mLatinIME.mSuggest.hasMainDictionary()) {
- throw new RuntimeException("Can't initialize the main dictionary");
- }
+ changeLanguage("en_US");
}
// We need to run the messages added to the handler from LatinIME. The only way to do
@@ -177,6 +164,29 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
}
}
+ private void waitForDictionaryToBeLoaded() {
+ int remainingAttempts = 10;
+ while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ // Don't do much
+ } finally {
+ --remainingAttempts;
+ }
+ }
+ if (!mLatinIME.mSuggest.hasMainDictionary()) {
+ throw new RuntimeException("Can't initialize the main dictionary");
+ }
+ }
+
+ private void changeLanguage(final String locale) {
+ SubtypeSwitcher.getInstance().updateSubtype(
+ new ArbitrarySubtype(locale, LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
+ waitForDictionaryToBeLoaded();
+ }
+
+
// Helper to avoid writing the try{}catch block each time
private static void sleep(final int milliseconds) {
try {
@@ -273,6 +283,15 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
assertEquals("simple auto-correct", EXPECTED_RESULT, mTextView.getText().toString());
}
+ public void testAutoCorrectForFrench() {
+ final String STRING_TO_TYPE = "irq ";
+ final String EXPECTED_RESULT = "ira ";
+ changeLanguage("fr");
+ type(STRING_TO_TYPE);
+ assertEquals("simple auto-correct for French", EXPECTED_RESULT,
+ mTextView.getText().toString());
+ }
+
public void testAutoCorrectWithPeriod() {
final String STRING_TO_TYPE = "tgis.";
final String EXPECTED_RESULT = "this.";
@@ -375,6 +394,34 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
mTextView.getText().toString());
}
+ public void testManualPickThenSeparatorForFrench() {
+ final String WORD1_TO_TYPE = "test";
+ final String WORD2_TO_TYPE = "!";
+ final String EXPECTED_RESULT = "test !";
+ changeLanguage("fr");
+ type(WORD1_TO_TYPE);
+ mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
+ type(WORD2_TO_TYPE);
+ assertEquals("manual pick then separator for French", EXPECTED_RESULT,
+ mTextView.getText().toString());
+ }
+
+ public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
+ final String WORD_TO_TYPE = "test ";
+ final String PUNCTUATION_FROM_STRIP = "!";
+ final String EXPECTED_RESULT = "test !!";
+ changeLanguage("fr");
+ type(WORD_TO_TYPE);
+ sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
+ runMessages();
+ assertTrue("type word then type space should display punctuation strip",
+ mLatinIME.isShowingPunctuationList());
+ mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
+ mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
+ assertEquals("type word then type space then punctuation from strip twice for French",
+ EXPECTED_RESULT, mTextView.getText().toString());
+ }
+
public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {
final String WORD_TO_TYPE = "this !!";
final String EXPECTED_RESULT = "this !!";
@@ -404,7 +451,32 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
type(WORD1_TO_TYPE);
mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
type(WORD2_TO_TYPE);
- assertEquals("manual pick then space then type", WORD1_TO_TYPE + WORD2_TO_TYPE,
+ assertEquals("manual pick then space then type", EXPECTED_RESULT,
+ mTextView.getText().toString());
+ }
+
+ public void testManualPickThenManualPick() {
+ final String WORD1_TO_TYPE = "this";
+ final String WORD2_TO_PICK = "is";
+ final String EXPECTED_RESULT = "this is";
+ type(WORD1_TO_TYPE);
+ mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
+ // Here we fake picking a word through bigram prediction. This test is taking
+ // advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually
+ // to actually pass the right string.
+ mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK);
+ assertEquals("manual pick then manual pick", EXPECTED_RESULT,
+ mTextView.getText().toString());
+ }
+
+ public void testManualPickThenManualPickWithPunctAtStart() {
+ final String WORD1_TO_TYPE = "this";
+ final String WORD2_TO_PICK = "!is";
+ final String EXPECTED_RESULT = "this!is";
+ type(WORD1_TO_TYPE);
+ mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
+ mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK);
+ assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
mTextView.getText().toString());
}