diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputLogicTests.java | 32 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java | 78 |
2 files changed, 97 insertions, 13 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 1c714e7de..ab9751380 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -351,6 +351,38 @@ public class InputLogicTests extends InputTestsBase { } // TODO: Add some tests for non-BMP characters + public void testAutoCorrectByUserHistory() { + final String WORD_TO_BE_CORRECTED = "qpmx"; + final String NOT_CORRECTED_RESULT = "qpmx "; + final String DESIRED_WORD = "qpmz"; + final String CORRECTED_RESULT = "qpmz "; + final int typeCountNotToAutocorrect = 3; + final int typeCountToAutoCorrect = 16; + int startIndex = 0; + int endIndex = 0; + + for (int i = 0; i < typeCountNotToAutocorrect; i++) { + type(DESIRED_WORD); + type(Constants.CODE_SPACE); + } + startIndex = mEditText.getText().length(); + type(WORD_TO_BE_CORRECTED); + type(Constants.CODE_SPACE); + endIndex = mEditText.getText().length(); + assertEquals("not auto-corrected by user history", NOT_CORRECTED_RESULT, + mEditText.getText().subSequence(startIndex, endIndex).toString()); + for (int i = typeCountNotToAutocorrect; i < typeCountToAutoCorrect; i++) { + type(DESIRED_WORD); + type(Constants.CODE_SPACE); + } + startIndex = mEditText.getText().length(); + type(WORD_TO_BE_CORRECTED); + type(Constants.CODE_SPACE); + endIndex = mEditText.getText().length(); + assertEquals("auto-corrected by user history", + CORRECTED_RESULT, mEditText.getText().subSequence(startIndex, endIndex).toString()); + } + public void testPredictionsAfterSpace() { final String WORD_TO_TYPE = "Barack "; type(WORD_TO_TYPE); diff --git a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java index 24af09484..2cc22fae4 100644 --- a/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java +++ b/tests/src/com/android/inputmethod/latin/settings/SpacingAndPunctuationsTests.java @@ -20,6 +20,8 @@ import android.content.res.Resources; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.utils.RunInLocale; @@ -32,6 +34,18 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { private static final int ARMENIAN_FULL_STOP = '\u0589'; private static final int ARMENIAN_COMMA = '\u055D'; + private int mScreenMetrics; + + private boolean isPhone() { + return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_PHONE + || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_PHONE; + } + + private boolean isTablet() { + return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET + || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET; + } + private SpacingAndPunctuations ENGLISH; private SpacingAndPunctuations FRENCH; private SpacingAndPunctuations GERMAN; @@ -56,6 +70,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); + mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics); + // Language only ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH); FRENCH = getSpacingAndPunctuations(Locale.FRENCH); @@ -373,23 +389,39 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { assertTrue(SWISS_GERMAN.mUsesGermanRules); } - private static final String[] PUNCTUATION_LABELS_LTR = { + // Punctuations for phone. + private static final String[] PUNCTUATION_LABELS_PHONE = { "!", "?", ",", ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" }; - private static final String[] PUNCTUATION_WORDS_LTR = PUNCTUATION_LABELS_LTR; - private static final String[] PUNCTUATION_WORDS_HEBREW = { + private static final String[] PUNCTUATION_WORDS_PHONE_LTR = PUNCTUATION_LABELS_PHONE; + private static final String[] PUNCTUATION_WORDS_PHONE_HEBREW = { "!", "?", ",", ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" }; // U+061F: "؟" ARABIC QUESTION MARK // U+060C: "،" ARABIC COMMA // U+061B: "؛" ARABIC SEMICOLON - private static final String[] PUNCTUATION_LABELS_ARABIC_PERSIAN = { + private static final String[] PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN = { "!", "\u061F", "\u060C", ":", "\u061B", "\"", "(", ")", "'", "-", "/", "@", "_" }; - private static final String[] PUNCTUATION_WORDS_ARABIC_PERSIAN = { + private static final String[] PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN = { "!", "\u061F", "\u060C", ":", "\u061B", "\"", ")", "(", "'", "-", "/", "@", "_" }; + // Punctuations for tablet. + private static final String[] PUNCTUATION_LABELS_TABLET = { + ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_TABLET_LTR = PUNCTUATION_LABELS_TABLET; + private static final String[] PUNCTUATION_WORDS_TABLET_HEBREW = { + ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN = { + "!", "\u061F", ":", "\u061B", "\"", "'", "(", ")", "-", "/", "@", "_" + }; + private static final String[] PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN = { + "!", "\u061F", ":", "\u061B", "\"", "'", ")", "(", "-", "/", "@", "_" + }; + private static void testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp, final String[] punctuationLabels, final String[] punctuationWords) { final SuggestedWords suggestedWords = sp.mSuggestPuncList; @@ -407,19 +439,39 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase { } } - // TODO: Add tests for tablet as well - public void testPunctuationSuggestions() { + public void testPhonePunctuationSuggestions() { + if (!isPhone()) { + return; + } + testingStandardPunctuationSuggestions(ENGLISH, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(FRENCH, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(GERMAN, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); + testingStandardPunctuationSuggestions(ARABIC, + PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(PERSIAN, + PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); + testingStandardPunctuationSuggestions(HEBREW, + PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW); + } + + public void testTabletPunctuationSuggestions() { + if (!isTablet()) { + return; + } testingStandardPunctuationSuggestions(ENGLISH, - PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR); + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); testingStandardPunctuationSuggestions(FRENCH, - PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR); + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); testingStandardPunctuationSuggestions(GERMAN, - PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_LTR); + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); testingStandardPunctuationSuggestions(ARABIC, - PUNCTUATION_LABELS_ARABIC_PERSIAN, PUNCTUATION_WORDS_ARABIC_PERSIAN); + PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); testingStandardPunctuationSuggestions(PERSIAN, - PUNCTUATION_LABELS_ARABIC_PERSIAN, PUNCTUATION_WORDS_ARABIC_PERSIAN); + PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); testingStandardPunctuationSuggestions(HEBREW, - PUNCTUATION_LABELS_LTR, PUNCTUATION_WORDS_HEBREW); + PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_HEBREW); } } |