diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java (renamed from tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelTests.java) | 38 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java | 97 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java | 5 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java | 22 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java | 9 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java | 29 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/DistracterFilterTest.java | 65 |
7 files changed, 234 insertions, 31 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java index 06139b808..96f925554 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java @@ -29,9 +29,14 @@ import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @MediumTest -public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTestsBase { +public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetTestsBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } + private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, - final int elementId, final String label, final int iconId) { + final int elementId, final CharSequence label, final int iconId) { final Keyboard keyboard = layoutSet.getKeyboard(elementId); final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); @@ -39,7 +44,7 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); } - private void doTestActionLabel(final String tag, final InputMethodSubtype subtype, + protected void doTestActionLabel(final String tag, final InputMethodSubtype subtype, final int actionId, final int labelResId) { final EditorInfo editorInfo = new EditorInfo(); editorInfo.imeOptions = actionId; @@ -57,6 +62,11 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe } else { label = job.runInLocale(res, SubtypeLocaleUtils.getSubtypeLocale(subtype)); } + doTestActionLabel(tag, subtype, editorInfo, label); + } + + protected void doTestActionLabel(final String tag, final InputMethodSubtype subtype, + final EditorInfo editorInfo, final CharSequence label) { // Test text layouts. editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); @@ -82,7 +92,7 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe label, KeyboardIconsSet.ICON_UNDEFINED); } - private void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, + protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, final int actionId, final String iconName) { final int iconId = KeyboardIconsSet.getIconId(iconName); final EditorInfo editorInfo = new EditorInfo(); @@ -111,14 +121,16 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "unspecifiled " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, "enter_key"); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, + KeyboardIconsSet.NAME_ENTER_KEY); } } public void testActionNone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, "enter_key"); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, + KeyboardIconsSet.NAME_ENTER_KEY); } } @@ -132,7 +144,8 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe public void testActionSearch() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, "search_key"); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, + KeyboardIconsSet.NAME_SEARCH_KEY); } } @@ -164,4 +177,15 @@ public final class KeyboardLayoutSetActionLabelTests extends KeyboardLayoutSetTe tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); } } + + public void testActionCustom() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final CharSequence customLabel = "customLabel"; + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = customLabel; + doTestActionLabel(tag, subtype, editorInfo, customLabel); + } + } } diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java new file mode 100644 index 000000000..7747ac5f9 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2014 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.keyboard; + +import android.test.suitebuilder.annotation.MediumTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@MediumTest +public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetActionLabelKlpTests { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_LXX_DARK; + } + + @Override + public void testActionUnspecified() { + super.testActionUnspecified(); + } + + @Override + public void testActionNone() { + super.testActionNone(); + } + + @Override + public void testActionGo() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_GO, + KeyboardIconsSet.NAME_GO_KEY); + } + } + + @Override + public void testActionSearch() { + super.testActionSearch(); + } + + @Override + public void testActionSend() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEND, + KeyboardIconsSet.NAME_SEND_KEY); + } + } + + @Override + public void testActionNext() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NEXT, + KeyboardIconsSet.NAME_NEXT_KEY); + } + } + + @Override + public void testActionDone() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_DONE, + KeyboardIconsSet.NAME_DONE_KEY); + } + } + + @Override + public void testActionPrevious() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, + KeyboardIconsSet.NAME_PREVIOUS_KEY); + } + } + + @Override + public void testActionCustom() { + super.testActionCustom(); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java index 26402f8c7..bf19a8b46 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java @@ -29,6 +29,11 @@ public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsB private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 45; private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2; + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } + private static String toString(final ArrayList<InputMethodSubtype> subtypeList) { final StringBuilder sb = new StringBuilder(); for (int index = 0; index < subtypeList.size(); index++) { diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java index 1ccb58c0f..ab7d1b28d 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java @@ -18,9 +18,7 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.res.Resources; -import android.preference.PreferenceManager; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; import android.view.ContextThemeWrapper; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodInfo; @@ -38,8 +36,7 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.ArrayList; import java.util.Locale; -@SmallTest -public class KeyboardLayoutSetTestsBase extends AndroidTestCase { +public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { // All input method subtypes of LatinIME. private final ArrayList<InputMethodSubtype> mAllSubtypesList = new ArrayList<>(); private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList = new ArrayList<>(); @@ -48,13 +45,15 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase { private Context mThemeContext; private int mScreenMetrics; + protected abstract int getKeyboardThemeForTests(); + @Override protected void setUp() throws Exception { super.setUp(); mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics); - final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme( - PreferenceManager.getDefaultSharedPreferences(mContext)); + final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById( + getKeyboardThemeForTests()); mThemeContext = new ContextThemeWrapper(mContext, keyboardTheme.mStyleId); RichInputMethodManager.init(mThemeContext); final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); @@ -115,13 +114,13 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase { protected final KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo) { - return createKeyboardLayoutSet(subtype, editorInfo, false /* isShortcutImeEnabled */, - false /* showsVoiceInputKey */, false /* isLanguageSwitchKeyEnabled */); + return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */, + false /* languageSwitchKeyEnabled */); } protected final KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, - final EditorInfo editorInfo, final boolean isShortcutImeEnabled, - final boolean showsVoiceInputKey, final boolean isLanguageSwitchKeyEnabled) { + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled) { final Context context = mThemeContext; final Resources res = context.getResources(); final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); @@ -129,7 +128,8 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase { final Builder builder = new Builder(context, editorInfo); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight) .setSubtype(subtype) - .setOptions(isShortcutImeEnabled, showsVoiceInputKey, isLanguageSwitchKeyEnabled); + .setVoiceInputKeyEnabled(voiceInputKeyEnabled) + .setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled); return builder.build(); } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java index d4e8fb647..a22ed60ac 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java @@ -24,6 +24,7 @@ import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.keyboard.KeyboardLayoutSetTestsBase; +import com.android.inputmethod.keyboard.KeyboardTheme; import com.android.inputmethod.keyboard.layout.LayoutBase; import com.android.inputmethod.keyboard.layout.expected.AbstractLayoutBase; import com.android.inputmethod.keyboard.layout.expected.ActualKeyboardBuilder; @@ -53,8 +54,12 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase { + (isPhone() ? "phone" : "tablet"); // TODO: Test with language switch key enabled and disabled. mKeyboardLayoutSet = createKeyboardLayoutSet(mSubtype, null /* editorInfo */, - true /* isShortcutImeEnabled */, true /* showsVoiceInputKey */, - true /* isLanguageSwitchKeyEnabled */); + true /* voiceInputKeyEnabled */, true /* languageSwitchKeyEnabled */); + } + + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; } // Those helper methods have a lower case name to be readable when defining expected keyboard diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index ccede0e39..55b794c94 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -1472,4 +1472,33 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals(bigramProbability, binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "bbb")); } + + public void testGetMaxFrequencyOfExactMatches() { + for (final int formatVersion : DICT_FORMAT_VERSIONS) { + testGetMaxFrequencyOfExactMatches(formatVersion); + } + } + + private void testGetMaxFrequencyOfExactMatches(final int formatVersion) { + File dictFile = null; + try { + dictFile = createEmptyDictionaryAndGetFile("TestBinaryDictionary", formatVersion); + } catch (IOException e) { + fail("IOException while writing an initial dictionary : " + e); + } + final BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(), + 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, + Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); + addUnigramWord(binaryDictionary, "abc", 10); + addUnigramWord(binaryDictionary, "aBc", 15); + assertEquals(15, binaryDictionary.getMaxFrequencyOfExactMatches("abc")); + addUnigramWord(binaryDictionary, "ab'c", 20); + assertEquals(20, binaryDictionary.getMaxFrequencyOfExactMatches("abc")); + addUnigramWord(binaryDictionary, "a-b-c", 25); + assertEquals(25, binaryDictionary.getMaxFrequencyOfExactMatches("abc")); + addUnigramWord(binaryDictionary, "ab-'-'-'-c", 30); + assertEquals(30, binaryDictionary.getMaxFrequencyOfExactMatches("abc")); + addUnigramWord(binaryDictionary, "ab c", 255); + assertEquals(30, binaryDictionary.getMaxFrequencyOfExactMatches("abc")); + } } diff --git a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java index 406e9a9b8..b7f2271be 100644 --- a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java +++ b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java @@ -42,11 +42,6 @@ public class DistracterFilterTest extends InputTestsBase { final Locale localeEnUs = new Locale("en", "US"); String typedWord; - typedWord = "google"; - // For this test case, we consider "google" is a distracter to "Google". - assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( - EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); - typedWord = "Bill"; // For this test case, we consider "Bill" is a distracter to "bill". assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( @@ -83,15 +78,20 @@ public class DistracterFilterTest extends InputTestsBase { EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); typedWord = "cafe"; - // For this test case, we consider "café" is not a distracter to any word in dictionaries. + // For this test case, we consider "cafe" is not a distracter to any word in dictionaries. assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); - typedWord = "ill"; - // For this test case, we consider "ill" is not a distracter to any word in dictionaries. + typedWord = "I'll"; + // For this test case, we consider "I'll" is not a distracter to any word in dictionaries. assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); + typedWord = "ill"; + // For this test case, we consider "ill" is a distracter to "I'll" + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); + typedWord = "asdfd"; // For this test case, we consider "asdfd" is not a distracter to any word in dictionaries. assertFalse( @@ -101,8 +101,51 @@ public class DistracterFilterTest extends InputTestsBase { typedWord = "thank"; // For this test case, we consider "thank" is not a distracter to any other word // in dictionaries. - assertFalse( - mDistracterFilter.isDistracterToWordsInDictionaries( - EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); + assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); + + final Locale localeDeDe = new Locale("de", "DE"); + + typedWord = "fuer"; + // For this test case, we consider "fuer" is a distracter to "für". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); + + typedWord = "fUEr"; + // For this test case, we consider "fUEr" is a distracter to "für". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); + + typedWord = "fur"; + // For this test case, we consider "fur" is a distracter to "für". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); + + final Locale localeFrFr = new Locale("fr", "FR"); + + typedWord = "a"; + // For this test case, we consider "a" is a distracter to "à". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); + + typedWord = "à"; + // For this test case, we consider "à" is not a distracter to any word in dictionaries. + assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); + + typedWord = "etre"; + // For this test case, we consider "etre" is a distracter to "être". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); + + typedWord = "États-unis"; + // For this test case, we consider "États-unis" is a distracter to "États-Unis". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); + + typedWord = "ÉtatsUnis"; + // For this test case, we consider "ÉtatsUnis" is a distracter to "États-Unis". + assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( + EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); } } |