diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin')
9 files changed, 290 insertions, 74 deletions
diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java index 7275d3afa..c4fd5a0c4 100644 --- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java +++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java @@ -30,7 +30,7 @@ public class BlueUnderlineTests extends InputTestsBase { type(STRING_TO_TYPE); sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); - final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertEquals("show blue underline, span start", EXPECTED_SPAN_START, span.mStart); assertEquals("show blue underline, span end", EXPECTED_SPAN_END, span.mEnd); assertEquals("show blue underline, span color", true, span.isAutoCorrectionIndicator()); @@ -47,7 +47,7 @@ public class BlueUnderlineTests extends InputTestsBase { type(STRING_2_TO_TYPE); // We haven't have time to look into the dictionary yet, so the line should still be // blue to avoid any flicker. - final SpanGetter spanBefore = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart); assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd); assertEquals("extend blue underline, span color", true, @@ -55,7 +55,7 @@ public class BlueUnderlineTests extends InputTestsBase { sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span - final SpanGetter spanAfter = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter spanAfter = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertNull("hide blue underline", spanAfter.mSpan); } @@ -76,10 +76,10 @@ public class BlueUnderlineTests extends InputTestsBase { type(Constants.CODE_DELETE); sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); - final SpanGetter suggestionSpan = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertEquals("show no blue underline after backspace, span start should be -1", EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart); - final SpanGetter underlineSpan = new SpanGetter(mTextView.getText(), UnderlineSpan.class); + final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class); assertEquals("should be composing, so should have an underline span", EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); assertEquals("should be composing, so should have an underline span", @@ -103,7 +103,7 @@ public class BlueUnderlineTests extends InputTestsBase { NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); - final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertNull("blue underline removed when cursor is moved", span.mSpan); } @@ -117,7 +117,7 @@ public class BlueUnderlineTests extends InputTestsBase { // Here the blue underline has been set. testBlueUnderline() is testing for this already, // so let's not test it here again. // Now simulate the user moving the cursor. - SpanGetter span = new SpanGetter(mTextView.getText(), UnderlineSpan.class); + SpanGetter span = new SpanGetter(mEditText.getText(), UnderlineSpan.class); assertNull("should not be composing, so should not have an underline span", span.mSpan); } } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 72c8d9c2f..91401970a 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -24,7 +24,7 @@ public class InputLogicTests extends InputTestsBase { public void testTypeWord() { final String WORD_TO_TYPE = "abcd"; type(WORD_TO_TYPE); - assertEquals("type word", WORD_TO_TYPE, mTextView.getText().toString()); + assertEquals("type word", WORD_TO_TYPE, mEditText.getText().toString()); } public void testPickSuggestionThenBackspace() { @@ -35,7 +35,7 @@ public class InputLogicTests extends InputTestsBase { mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); type(Constants.CODE_DELETE); assertEquals("press suggestion then backspace", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testPickAutoCorrectionThenBackspace() { @@ -48,10 +48,10 @@ public class InputLogicTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK, - mTextView.getText().toString()); + mEditText.getText().toString()); type(Constants.CODE_DELETE); assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testPickTypedWordOverAutoCorrectionThenBackspace() { @@ -63,10 +63,10 @@ public class InputLogicTests extends InputTestsBase { pickSuggestionManually(1, WORD_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE, - mTextView.getText().toString()); + mEditText.getText().toString()); type(Constants.CODE_DELETE); assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testPickDifferentSuggestionThenBackspace() { @@ -79,10 +79,10 @@ public class InputLogicTests extends InputTestsBase { pickSuggestionManually(2, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick different suggestion then backspace", WORD_TO_PICK, - mTextView.getText().toString()); + mEditText.getText().toString()); type(Constants.CODE_DELETE); assertEquals("pick different suggestion then backspace", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testDeleteSelection() { @@ -102,7 +102,7 @@ public class InputLogicTests extends InputTestsBase { mLatinIME.onUpdateSelection(typedLength, typedLength, SELECTION_START, SELECTION_END, -1, -1); type(Constants.CODE_DELETE); - assertEquals("delete selection", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("delete selection", EXPECTED_RESULT, mEditText.getText().toString()); } public void testDeleteSelectionTwice() { @@ -123,21 +123,21 @@ public class InputLogicTests extends InputTestsBase { SELECTION_START, SELECTION_END, -1, -1); type(Constants.CODE_DELETE); type(Constants.CODE_DELETE); - assertEquals("delete selection twice", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("delete selection twice", EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrect() { final String STRING_TO_TYPE = "tgis "; final String EXPECTED_RESULT = "this "; type(STRING_TO_TYPE); - assertEquals("simple auto-correct", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("simple auto-correct", EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrectWithPeriod() { final String STRING_TO_TYPE = "tgis."; final String EXPECTED_RESULT = "this."; type(STRING_TO_TYPE); - assertEquals("auto-correct with period", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("auto-correct with period", EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrectWithPeriodThenRevert() { @@ -147,7 +147,7 @@ public class InputLogicTests extends InputTestsBase { mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); type(Constants.CODE_DELETE); assertEquals("auto-correct with period then revert", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testAutoCorrectWithSpaceThenRevert() { @@ -157,7 +157,7 @@ public class InputLogicTests extends InputTestsBase { mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); type(Constants.CODE_DELETE); assertEquals("auto-correct with space then revert", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testAutoCorrectToSelfDoesNotRevert() { @@ -167,14 +167,14 @@ public class InputLogicTests extends InputTestsBase { mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); type(Constants.CODE_DELETE); assertEquals("auto-correct with space does not revert", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testDoubleSpace() { final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this. "; type(STRING_TO_TYPE); - assertEquals("double space make a period", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); } public void testCancelDoubleSpace() { @@ -182,7 +182,7 @@ public class InputLogicTests extends InputTestsBase { final String EXPECTED_RESULT = "this "; type(STRING_TO_TYPE); type(Constants.CODE_DELETE); - assertEquals("double space make a period", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); } public void testBackspaceAtStartAfterAutocorrect() { @@ -197,7 +197,7 @@ public class InputLogicTests extends InputTestsBase { NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); type(Constants.CODE_DELETE); assertEquals("auto correct then move cursor to start of line then backspace", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrectThenMoveCursorThenBackspace() { @@ -212,7 +212,7 @@ public class InputLogicTests extends InputTestsBase { NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1); type(Constants.CODE_DELETE); assertEquals("auto correct then move cursor then backspace", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testNoSpaceAfterManualPick() { @@ -221,7 +221,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); pickSuggestionManually(0, WORD_TO_TYPE); assertEquals("no space after manual pick", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenType() { @@ -231,7 +231,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD1_TO_TYPE); pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); - assertEquals("manual pick then type", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("manual pick then type", EXPECTED_RESULT, mEditText.getText().toString()); } public void testManualPickThenSeparator() { @@ -241,7 +241,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD1_TO_TYPE); pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); - assertEquals("manual pick then separator", EXPECTED_RESULT, mTextView.getText().toString()); + assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString()); } public void testManualPickThenStripperThenPick() { @@ -254,7 +254,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); pickSuggestionManually(0, WORD_TO_TYPE); assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenSpaceThenType() { @@ -265,7 +265,7 @@ public class InputLogicTests extends InputTestsBase { pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then space then type", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenManualPick() { @@ -279,7 +279,7 @@ public class InputLogicTests extends InputTestsBase { // to actually pass the right string. pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testDeleteWholeComposingWord() { @@ -288,7 +288,7 @@ public class InputLogicTests extends InputTestsBase { for (int i = 0; i < WORD_TO_TYPE.length(); ++i) { type(Constants.CODE_DELETE); } - assertEquals("delete whole composing word", "", mTextView.getText().toString()); + assertEquals("delete whole composing word", "", mEditText.getText().toString()); } // TODO: Add some tests for non-BMP characters } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java index 333b60277..2d736e338 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java @@ -30,7 +30,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { changeLanguage("fr"); type(STRING_TO_TYPE); assertEquals("simple auto-correct for French", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenSeparatorForFrench() { @@ -42,7 +42,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then separator for French", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() { @@ -64,7 +64,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice for French", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } finally { setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, defaultNextWordPredictionOption); @@ -98,7 +98,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { changeLanguage("de"); type(STRING_TO_TYPE); assertEquals("simple auto-correct for German", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testAutoCorrectWithUmlautForGerman() { @@ -107,6 +107,6 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { changeLanguage("de"); type(STRING_TO_TYPE); assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } } diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 9e107a49c..aec4aaca1 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; import android.os.Looper; -import android.os.MessageQueue; import android.preference.PreferenceManager; import android.test.ServiceTestCase; import android.text.InputType; @@ -31,8 +30,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; +import android.widget.EditText; import android.widget.FrameLayout; -import android.widget.TextView; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; @@ -40,7 +39,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.Locale; -public class InputTestsBase extends ServiceTestCase<LatinIME> { +public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { private static final String PREF_DEBUG_MODE = "debug_mode"; @@ -49,7 +48,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { protected LatinIME mLatinIME; protected Keyboard mKeyboard; - protected MyTextView mTextView; + protected MyEditText mEditText; protected View mInputView; protected InputConnection mInputConnection; @@ -88,26 +87,41 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { } } - // A helper class to increase control over the TextView - public static class MyTextView extends TextView { + // A helper class to increase control over the EditText + public static class MyEditText extends EditText { public Locale mCurrentLocale; - public MyTextView(final Context c) { + public MyEditText(final Context c) { super(c); } + + @Override public void onAttachedToWindow() { + // Make onAttachedToWindow "public" super.onAttachedToWindow(); } + + // overriding hidden API in EditText public Locale getTextServicesLocale() { - // This method is necessary because TextView is asking this method for the language + // This method is necessary because EditText is asking this method for the language // to check the spell in. If we don't override this, the spell checker will run in // whatever language the keyboard is currently set on the test device, ignoring any // settings we do inside the tests. return mCurrentLocale; } + + // overriding hidden API in EditText + public Locale getSpellCheckerLocale() { + // This method is necessary because EditText is asking this method for the language + // to check the spell in. If we don't override this, the spell checker will run in + // whatever language the keyboard is currently set on the test device, ignoring any + // settings we do inside the tests. + return mCurrentLocale; + } + } public InputTestsBase() { - super(LatinIME.class); + super(LatinIMEForTests.class); } // TODO: Isn't there a way to make this generic somehow? We can take a <T> and return a <T> @@ -130,18 +144,18 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { @Override protected void setUp() throws Exception { super.setUp(); - mTextView = new MyTextView(getContext()); + mEditText = new MyEditText(getContext()); final int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_MULTI_LINE; - mTextView.setInputType(inputType); - mTextView.setEnabled(true); + mEditText.setInputType(inputType); + mEditText.setEnabled(true); setupService(); mLatinIME = getService(); final boolean previousDebugSetting = setDebugMode(true); mLatinIME.onCreate(); setDebugMode(previousDebugSetting); final EditorInfo ei = new EditorInfo(); - final InputConnection ic = mTextView.onCreateInputConnection(ei); + final InputConnection ic = mEditText.onCreateInputConnection(ei); final LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ViewGroup vg = new FrameLayout(getContext()); @@ -225,8 +239,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { } protected void changeLanguage(final String locale) { - mTextView.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); - SubtypeSwitcher.getInstance().forceLocale(mTextView.mCurrentLocale); + mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); + SubtypeSwitcher.getInstance().forceLocale(mEditText.mCurrentLocale); mLatinIME.loadKeyboard(); mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); waitForDictionaryToBeLoaded(); diff --git a/tests/src/com/android/inputmethod/latin/LatinIMEForTests.java b/tests/src/com/android/inputmethod/latin/LatinIMEForTests.java new file mode 100644 index 000000000..e47c55736 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/LatinIMEForTests.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2013 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; + +public class LatinIMEForTests extends LatinIME { + @Override + public boolean isInputViewShown() { + return true; + } +} diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index 1b2f0e679..84ff6b307 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -44,7 +44,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } finally { setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, defaultNextWordPredictionOption); @@ -56,7 +56,7 @@ public class PunctuationTests extends InputTestsBase { final String EXPECTED_RESULT = "this !!"; type(WORD_TO_TYPE); assertEquals("manual pick then space then punctuation from keyboard twice", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenPunctuationFromStripTwiceThenType() { @@ -70,7 +70,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); type(WORD2_TO_TYPE); assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManualPickThenManualPickWithPunctAtStart() { @@ -81,7 +81,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD1_TO_TYPE); pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT, - mTextView.getText().toString()); + mEditText.getText().toString()); } public void testManuallyPickedWordThenColon() { @@ -92,7 +92,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then colon", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testManuallyPickedWordThenOpenParen() { @@ -103,7 +103,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then open paren", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testManuallyPickedWordThenCloseParen() { @@ -114,7 +114,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then close paren", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testManuallyPickedWordThenSmiley() { @@ -125,7 +125,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the smiley key", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testManuallyPickedWordThenDotCom() { @@ -136,7 +136,7 @@ public class PunctuationTests extends InputTestsBase { pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the .com key", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testTypeWordTypeDotThenPressDotCom() { @@ -146,7 +146,7 @@ public class PunctuationTests extends InputTestsBase { type(WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("type word type dot then press the .com key", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrectionWithSingleQuoteInside() { @@ -154,7 +154,7 @@ public class PunctuationTests extends InputTestsBase { final String EXPECTED_RESULT = "you'd "; type(WORD_TO_TYPE); assertEquals("auto-correction with single quote inside", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } public void testAutoCorrectionWithSingleQuotesAround() { @@ -162,6 +162,6 @@ public class PunctuationTests extends InputTestsBase { final String EXPECTED_RESULT = "'this' "; type(WORD_TO_TYPE); assertEquals("auto-correction with single quotes around", - EXPECTED_RESULT, mTextView.getText().toString()); + EXPECTED_RESULT, mEditText.getText().toString()); } } diff --git a/tests/src/com/android/inputmethod/latin/ResourceUtilsTests.java b/tests/src/com/android/inputmethod/latin/ResourceUtilsTests.java new file mode 100644 index 000000000..ed16846b9 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/ResourceUtilsTests.java @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2013 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 android.test.suitebuilder.annotation.SmallTest; + +import java.util.HashMap; + +@SmallTest +public class ResourceUtilsTests extends AndroidTestCase { + public void testFindDefaultConstant() { + final String[] nullArray = null; + assertNull(ResourceUtils.findDefaultConstant(nullArray)); + + final String[] emptyArray = {}; + assertNull(ResourceUtils.findDefaultConstant(emptyArray)); + + final String[] array = { + "HARDWARE=grouper,0.3", + "HARDWARE=mako,0.4", + ",defaultValue1", + "HARDWARE=manta,0.2", + ",defaultValue2", + }; + assertEquals(ResourceUtils.findDefaultConstant(array), "defaultValue1"); + } + + public void testFindConstantForKeyValuePairsSimple() { + final HashMap<String,String> anyKeyValue = CollectionUtils.newHashMap(); + anyKeyValue.put("anyKey", "anyValue"); + final HashMap<String,String> nullKeyValue = null; + final HashMap<String,String> emptyKeyValue = CollectionUtils.newHashMap(); + + final String[] nullArray = null; + assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, nullArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, nullArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(nullKeyValue, nullArray)); + + final String[] emptyArray = {}; + assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, emptyArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(emptyKeyValue, emptyArray)); + assertNull(ResourceUtils.findConstantForKeyValuePairs(nullKeyValue, emptyArray)); + + final String HARDWARE_KEY = "HARDWARE"; + final String[] array = { + ",defaultValue", + "HARDWARE=grouper,0.3", + "HARDWARE=mako,0.4", + "HARDWARE=manta,0.2", + "HARDWARE=mako,0.5", + }; + + final HashMap<String,String> keyValues = CollectionUtils.newHashMap(); + keyValues.put(HARDWARE_KEY, "grouper"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.3"); + keyValues.put(HARDWARE_KEY, "mako"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.4"); + keyValues.put(HARDWARE_KEY, "manta"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.2"); + + try { + keyValues.clear(); + keyValues.put("hardware", "grouper"); + final String constant = ResourceUtils.findConstantForKeyValuePairs(keyValues, array); + fail("condition without HARDWARE must fail: constant=" + constant); + } catch (final RuntimeException e) { + assertEquals(e.getMessage(), "Found unknown key: HARDWARE=grouper"); + } + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "MAKO"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + + try { + final String constant = ResourceUtils.findConstantForKeyValuePairs( + emptyKeyValue, array); + fail("emptyCondition shouldn't match: constant=" + constant); + } catch (final RuntimeException e) { + assertEquals(e.getMessage(), "Found unknown key: HARDWARE=grouper"); + } + } + + public void testFindConstantForKeyValuePairsCombined() { + final String HARDWARE_KEY = "HARDWARE"; + final String MODEL_KEY = "MODEL"; + final String MANUFACTURER_KEY = "MANUFACTURER"; + final String[] array = { + ",defaultValue", + "HARDWARE=grouper:MANUFACTURER=asus,0.3", + "HARDWARE=mako:MODEL=Nexus 4,0.4", + "HARDWARE=manta:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + final String[] failArray = { + ",defaultValue", + "HARDWARE=grouper:MANUFACTURER=ASUS,0.3", + "HARDWARE=mako:MODEL=Nexus_4,0.4", + "HARDWARE=mantaray:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + + final HashMap<String,String> keyValues = CollectionUtils.newHashMap(); + keyValues.put(HARDWARE_KEY, "grouper"); + keyValues.put(MODEL_KEY, "Nexus 7"); + keyValues.put(MANUFACTURER_KEY, "asus"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.3"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "mako"); + keyValues.put(MODEL_KEY, "Nexus 4"); + keyValues.put(MANUFACTURER_KEY, "LGE"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.4"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "manta"); + keyValues.put(MODEL_KEY, "Nexus 10"); + keyValues.put(MANUFACTURER_KEY, "samsung"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.2"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray)); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertNull(ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, failArray), "0.2"); + } + + public void testFindConstantForKeyValuePairsRegexp() { + final String HARDWARE_KEY = "HARDWARE"; + final String MODEL_KEY = "MODEL"; + final String MANUFACTURER_KEY = "MANUFACTURER"; + final String[] array = { + ",defaultValue", + "HARDWARE=grouper|tilapia:MANUFACTURER=asus,0.3", + "HARDWARE=[mM][aA][kK][oO]:MODEL=Nexus 4,0.4", + "HARDWARE=manta.*:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" + }; + + final HashMap<String,String> keyValues = CollectionUtils.newHashMap(); + keyValues.put(HARDWARE_KEY, "grouper"); + keyValues.put(MODEL_KEY, "Nexus 7"); + keyValues.put(MANUFACTURER_KEY, "asus"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.3"); + keyValues.put(HARDWARE_KEY, "tilapia"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.3"); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "mako"); + keyValues.put(MODEL_KEY, "Nexus 4"); + keyValues.put(MANUFACTURER_KEY, "LGE"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.4"); + keyValues.put(HARDWARE_KEY, "MAKO"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.4"); + + keyValues.clear(); + keyValues.put(HARDWARE_KEY, "manta"); + keyValues.put(MODEL_KEY, "Nexus 10"); + keyValues.put(MANUFACTURER_KEY, "samsung"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.2"); + keyValues.put(HARDWARE_KEY, "mantaray"); + assertEquals(ResourceUtils.findConstantForKeyValuePairs(keyValues, array), "0.2"); + } +} diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java index 1e3cc8ad4..29e790a7d 100644 --- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java @@ -178,7 +178,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue(StringUtils.isIdenticalAfterDowncase("")); } - private void checkCapitalize(final String src, final String dst, final String separators, + private static void checkCapitalize(final String src, final String dst, final String separators, final Locale locale) { assertEquals(dst, StringUtils.capitalizeEachWord(src, separators, locale)); assert(src.equals(dst) diff --git a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java index 879cc4664..995d7f07b 100644 --- a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java +++ b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java @@ -24,14 +24,15 @@ import com.android.inputmethod.latin.InputTestsBase; @LargeTest public class AndroidSpellCheckerServiceTest extends InputTestsBase { public void testSpellchecker() { - mTextView.onAttachedToWindow(); - mTextView.setText("tgis"); - type(" "); + changeLanguage("en_US"); + mEditText.setText("tgis "); + mEditText.setSelection(mEditText.getText().length()); + mEditText.onAttachedToWindow(); sleep(1000); runMessages(); sleep(1000); - final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); // If no span, the following will crash final String[] suggestions = span.getSuggestions(); // For this test we consider "tgis" should yield at least 2 suggestions (at this moment @@ -43,14 +44,15 @@ public class AndroidSpellCheckerServiceTest extends InputTestsBase { public void testRussianSpellchecker() { changeLanguage("ru"); - mTextView.onAttachedToWindow(); - mTextView.setText("годп"); - type(" "); + mEditText.onAttachedToWindow(); + mEditText.setText("годп "); + mEditText.setSelection(mEditText.getText().length()); + mEditText.onAttachedToWindow(); sleep(1000); runMessages(); sleep(1000); - final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class); + final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); // If no span, the following will crash final String[] suggestions = span.getSuggestions(); // For this test we consider "годп" should yield at least 2 suggestions (at this moment |