diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/InputLogicTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputLogicTests.java | 102 |
1 files changed, 87 insertions, 15 deletions
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()); } |