diff options
Diffstat (limited to 'tests/src')
99 files changed, 4998 insertions, 1661 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java deleted file mode 100644 index a25d6d6e7..000000000 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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.content.res.Resources; -import android.text.InputType; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodSubtype; - -import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; -import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.RunInLocale; -import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; - -import java.util.Locale; - -abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase { - public void testActionUnspecified() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "unspecifiled " - + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - 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, - KeyboardIconsSet.NAME_ENTER_KEY); - } - } - - public void testActionSearch() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, - KeyboardIconsSet.NAME_SEARCH_KEY); - } - } - - public abstract void testActionGo(); - public abstract void testActionSend(); - public abstract void testActionNext(); - public abstract void testActionDone(); - public abstract void testActionPrevious(); - - 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; - doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); - } - } - - private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, - 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); - assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); - assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); - } - - protected void doTestActionKeyLabelResId(final String tag, final InputMethodSubtype subtype, - final int actionId, final int labelResId) { - final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) - ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); - doTestActionKeyLabelResIdInLocale(tag, subtype, actionId, labelLocale, labelResId); - } - - protected void doTestActionKeyLabelResIdInLocale(final String tag, - final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, - final int labelResId) { - final EditorInfo editorInfo = new EditorInfo(); - editorInfo.imeOptions = actionId; - final RunInLocale<String> job = new RunInLocale<String>() { - @Override - protected String job(final Resources res) { - return res.getString(labelResId); - } - }; - final String label = job.runInLocale(getContext().getResources(), labelLocale); - doTestActionKeyLabel(tag, subtype, editorInfo, label); - } - - protected void doTestActionKeyLabel(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); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test phone number layouts. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test normal number layout. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test number password layouts. - editorInfo.inputType = - InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; - final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, - label, KeyboardIconsSet.ICON_UNDEFINED); - } - - 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(); - editorInfo.imeOptions = actionId; - // Test text layouts. - editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; - final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); - doTestActionKey( - tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); - // Test phone number layouts. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); - doTestActionKey( - tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); - // Test normal number layout. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); - // Test number password layout. - editorInfo.inputType = - InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; - final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java deleted file mode 100644 index 322a344ff..000000000 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.content.res.Resources; -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.R; -import com.android.inputmethod.latin.RichInputMethodManager; -import com.android.inputmethod.latin.utils.RunInLocale; -import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; - -import java.util.Locale; - -@MediumTest -public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase { - @Override - protected int getKeyboardThemeForTests() { - return KeyboardTheme.THEME_ID_KLP; - } - - @Override - public void testActionGo() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO, - R.string.label_go_key); - } - } - - @Override - public void testActionSend() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND, - R.string.label_send_key); - } - } - - @Override - public void testActionNext() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT, - R.string.label_next_key); - } - } - - @Override - public void testActionDone() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE, - R.string.label_done_key); - } - } - - @Override - public void testActionPrevious() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, - R.string.label_previous_key); - } - } - - // Working variable to simulate system locale changing. - private Locale mSystemLocale = Locale.getDefault(); - - private void doTestActionLabelInLocale(final InputMethodSubtype subtype, - final Locale labelLocale, final Locale systemLocale) { - // Simulate system locale changing, see {@link SystemBroadcastReceiver}. - if (!systemLocale.equals(mSystemLocale)) { - KeyboardLayoutSet.onSystemLocaleChanged(); - mSystemLocale = systemLocale; - } - final String tag = "label=" + labelLocale + " system=" + systemLocale - + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - final RunInLocale<Void> job = new RunInLocale<Void>() { - @Override - public Void job(final Resources res) { - doTestActionKeyIcon(tag + " unspecified", subtype, - EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); - doTestActionKeyIcon(tag + " none", subtype, - EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); - doTestActionKeyLabelResIdInLocale(tag + " go", subtype, - EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key); - doTestActionKeyIcon(tag + " search", subtype, - EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); - doTestActionKeyLabelResIdInLocale(tag + " send", subtype, - EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key); - doTestActionKeyLabelResIdInLocale(tag + " next", subtype, - EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key); - doTestActionKeyLabelResIdInLocale(tag + " done", subtype, - EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key); - doTestActionKeyLabelResIdInLocale(tag + " previous", subtype, - EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key); - return null; - } - }; - job.runInLocale(getContext().getResources(), systemLocale); - } - - public void testActionLabelInOtherLocale() { - final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); - final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY); - // An action label should be displayed in subtype's locale regardless of the system locale. - doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.US); - doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.FRENCH); - doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.ITALIAN); - doTestActionLabelInLocale(italian, Locale.ITALIAN, Locale.JAPANESE); - } - - public void testNoLanguageSubtypeActionLabel() { - final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); - final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( - SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY); - // An action label of no language keyboard should be displayed in the system locale. - doTestActionLabelInLocale(noLanguage, Locale.US, Locale.US); - doTestActionLabelInLocale(noLanguage, Locale.FRENCH, Locale.FRENCH); - doTestActionLabelInLocale(noLanguage, Locale.ITALIAN, Locale.ITALIAN); - doTestActionLabelInLocale(noLanguage, Locale.JAPANESE, Locale.JAPANESE); - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java deleted file mode 100644 index 028b3e400..000000000 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 KeyboardLayoutSetActionLabelBase { - @Override - protected int getKeyboardThemeForTests() { - return KeyboardTheme.THEME_ID_LXX_LIGHT; - } - - @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 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); - } - } -} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java index 6b0652c59..25bac9dd4 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java @@ -25,8 +25,8 @@ import java.util.ArrayList; @SmallTest public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsBase { - private static final int NUMBER_OF_SUBTYPES = 76; - private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 45; + private static final int NUMBER_OF_SUBTYPES = 81; + private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 49; private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2; @Override @@ -52,13 +52,14 @@ public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsB public final void testAsciiCapableSubtypesCount() { final ArrayList<InputMethodSubtype> asciiCapableSubtypesList = - getAsciiCapableSubtypesList(); + getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE); assertEquals(toString(asciiCapableSubtypesList), NUMBER_OF_ASCII_CAPABLE_SUBTYPES, asciiCapableSubtypesList.size()); } public final void testAdditionalSubtypesCount() { - final ArrayList<InputMethodSubtype> additionalSubtypesList = getAdditionalSubtypesList(); + final ArrayList<InputMethodSubtype> additionalSubtypesList = + getSubtypesFilteredBy(FILTER_IS_ADDITIONAL_SUBTYPE); assertEquals(toString(additionalSubtypesList), NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES, additionalSubtypesList.size()); } diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java index a002bbe48..71bbdba1a 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java @@ -17,7 +17,9 @@ package com.android.inputmethod.keyboard; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; +import android.preference.PreferenceManager; import android.test.AndroidTestCase; import android.view.ContextThemeWrapper; import android.view.inputmethod.EditorInfo; @@ -29,6 +31,8 @@ import com.android.inputmethod.keyboard.KeyboardLayoutSet.Builder; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.RichInputMethodSubtype; +import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -39,9 +43,27 @@ import java.util.Locale; 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<>(); - private final ArrayList<InputMethodSubtype> mAdditionalSubtypesList = new ArrayList<>(); + public interface SubtypeFilter { + public boolean accept(final InputMethodSubtype subtype); + } + + public static final SubtypeFilter FILTER_IS_ASCII_CAPABLE = new SubtypeFilter() { + @Override + public boolean accept(InputMethodSubtype subtype) { + return InputMethodSubtypeCompatUtils.isAsciiCapable(subtype); + } + }; + + public static final SubtypeFilter FILTER_IS_ADDITIONAL_SUBTYPE = new SubtypeFilter() { + @Override + public boolean accept(InputMethodSubtype subtype) { + return AdditionalSubtypeUtils.isAdditionalSubtype(subtype); + } + }; + + private SharedPreferences mSharedPreferences; + private String mSavedAdditionalSubtypes; private int mScreenMetrics; protected abstract int getKeyboardThemeForTests(); @@ -49,41 +71,53 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); + final Context context = getContext(); + mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final Resources res = context.getResources(); + + // Save additional subtypes preference. + mSavedAdditionalSubtypes = Settings.readPrefAdditionalSubtypes(mSharedPreferences, res); + final String predefinedSubtypes = AdditionalSubtypeUtils.createPrefSubtypes( + res.getStringArray(R.array.predefined_subtypes)); + // Reset additional subtypes to predefined ones. + Settings.writePrefAdditionalSubtypes(mSharedPreferences, predefinedSubtypes); + final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById( - getKeyboardThemeForTests()); + getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES); setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId)); KeyboardLayoutSet.onKeyboardThemeChanged(); - final Context context = getContext(); - mScreenMetrics = context.getResources().getInteger(R.integer.config_screen_metrics); + mScreenMetrics = res.getInteger(R.integer.config_screen_metrics); RichInputMethodManager.init(context); final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme(); final int subtypeCount = imi.getSubtypeCount(); for (int index = 0; index < subtypeCount; index++) { - final InputMethodSubtype subtype = imi.getSubtypeAt(index); - if (AdditionalSubtypeUtils.isAdditionalSubtype(subtype)) { - mAdditionalSubtypesList.add(subtype); - continue; - } - mAllSubtypesList.add(subtype); - if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) { - mAsciiCapableSubtypesList.add(subtype); - } + mAllSubtypesList.add(imi.getSubtypeAt(index)); } } - protected final ArrayList<InputMethodSubtype> getAllSubtypesList() { - return mAllSubtypesList; + @Override + protected void tearDown() throws Exception { + // Restore additional subtypes preference. + Settings.writePrefAdditionalSubtypes(mSharedPreferences, mSavedAdditionalSubtypes); + super.tearDown(); } - protected final ArrayList<InputMethodSubtype> getAsciiCapableSubtypesList() { - return mAsciiCapableSubtypesList; + protected final ArrayList<InputMethodSubtype> getAllSubtypesList() { + return mAllSubtypesList; } - protected final ArrayList<InputMethodSubtype> getAdditionalSubtypesList() { - return mAdditionalSubtypesList; + protected final ArrayList<InputMethodSubtype> getSubtypesFilteredBy( + final SubtypeFilter filter) { + final ArrayList<InputMethodSubtype> list = new ArrayList<>(); + for (final InputMethodSubtype subtype : mAllSubtypesList) { + if (filter.accept(subtype)) { + list.add(subtype); + } + } + return list; } protected final boolean isPhone() { @@ -101,7 +135,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { return subtype; } } - for (final InputMethodSubtype subtype : mAsciiCapableSubtypesList) { + for (final InputMethodSubtype subtype : getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE)) { final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype); if (locale.equals(subtypeLocale)) { // Create additional subtype. @@ -116,21 +150,22 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo) { return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */, - false /* languageSwitchKeyEnabled */); + false /* languageSwitchKeyEnabled */, false /* splitLayoutEnabled */); } protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, - final boolean languageSwitchKeyEnabled) { + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final Context context = getContext(); final Resources res = context.getResources(); final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final Builder builder = new Builder(context, editorInfo); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight) - .setSubtype(subtype) + .setSubtype(new RichInputMethodSubtype(subtype)) .setVoiceInputKeyEnabled(voiceInputKeyEnabled) - .setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled); + .setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled) + .setSplitLayoutEnabledByUser(splitLayoutEnabled); return builder.build(); } } diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java index c20954f81..34cf4072f 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardThemeTests.java @@ -28,6 +28,8 @@ import android.preference.PreferenceManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; +import java.util.Arrays; + @SmallTest public class KeyboardThemeTests extends AndroidTestCase { private SharedPreferences mPrefs; @@ -77,7 +79,9 @@ public class KeyboardThemeTests extends AndroidTestCase { } private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) { - assertEquals(expectedThemeId, KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion).mThemeId); + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); + assertEquals(expectedThemeId, actualTheme.mThemeId); } /* @@ -139,8 +143,8 @@ public class KeyboardThemeTests extends AndroidTestCase { final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY; setKeyboardThemePreference(oldPrefKey, previousThemeId); - final KeyboardTheme defaultTheme = - KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion); + final KeyboardTheme defaultTheme = KeyboardTheme.getDefaultKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); assertNotNull(defaultTheme); assertEquals(expectedThemeId, defaultTheme.mThemeId); @@ -194,7 +198,8 @@ public class KeyboardThemeTests extends AndroidTestCase { // Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard". setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); - final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion); + final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES); assertNotNull(theme); assertEquals(expectedThemeId, theme.mThemeId); @@ -341,4 +346,60 @@ public class KeyboardThemeTests extends AndroidTestCase { assertUpgradePlatformFromTo( oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT); } + + /* + * Test for missing selected theme. + */ + private static KeyboardTheme[] LIMITED_THEMES = { + KeyboardTheme.searchKeyboardThemeById(THEME_ID_ICS, KeyboardTheme.KEYBOARD_THEMES), + KeyboardTheme.searchKeyboardThemeById(THEME_ID_KLP, KeyboardTheme.KEYBOARD_THEMES) + }; + static { + Arrays.sort(LIMITED_THEMES); + } + + public void testMissingSelectedThemeIcs() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = VERSION_CODES.ICE_CREAM_SANDWICH; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_LIGHT is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } + + public void testMissingSelectedThemeKlp() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = VERSION_CODES.KITKAT; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_LIGHT is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } + + public void testMissingSelectedThemeLxx() { + // Clean up preferences. + setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL); + setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL); + + final int sdkVersion = VERSION_CODES_LXX; + final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion); + setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_DARK); + + final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme( + mPrefs, sdkVersion, LIMITED_THEMES); + // LXX_DARK is missing, fall-back to KLP. + assertEquals(THEME_ID_KLP, actualTheme.mThemeId); + } } diff --git a/tests/src/com/android/inputmethod/keyboard/action/ActionTestsBase.java b/tests/src/com/android/inputmethod/keyboard/action/ActionTestsBase.java new file mode 100644 index 000000000..41b545aa8 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/ActionTestsBase.java @@ -0,0 +1,115 @@ +/* + * 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.action; + +import android.content.Context; +import android.content.res.Resources; +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.Key; +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.internal.KeyboardIconsSet; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyVisual; +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.utils.LocaleUtils; +import com.android.inputmethod.latin.utils.RunInLocale; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; + +abstract class ActionTestsBase extends KeyboardLayoutSetTestsBase { + static class ExpectedActionKey { + static ExpectedActionKey newIconKey(final String iconName) { + final int iconId = KeyboardIconsSet.getIconId(iconName); + return new ExpectedActionKey(ExpectedKeyVisual.newInstance(iconId)); + } + + static ExpectedActionKey newLabelKey(final String label) { + return new ExpectedActionKey(ExpectedKeyVisual.newInstance(label)); + } + + static ExpectedActionKey newLabelKey(final int labelResId, + final Locale labelLocale, final Context context) { + final RunInLocale<String> getString = new RunInLocale<String>() { + @Override + protected String job(final Resources res) { + return res.getString(labelResId); + } + }; + return newLabelKey(getString.runInLocale(context.getResources(), labelLocale)); + } + + private final ExpectedKeyVisual mVisual; + + private ExpectedActionKey(final ExpectedKeyVisual visual) { + mVisual = visual; + } + + public int getIconId() { return mVisual.getIconId(); } + + public String getLabel() { return mVisual.getLabel(); } + } + + protected static Locale getLabelLocale(final InputMethodSubtype subtype) { + final String localeString = subtype.getLocale(); + if (localeString.equals(SubtypeLocaleUtils.NO_LANGUAGE)) { + return null; + } + return LocaleUtils.constructLocaleFromString(localeString); + } + + private static void assertActionKey(final String tag, final KeyboardLayoutSet layoutSet, + final int elementId, final ExpectedActionKey expectedKey) { + final Keyboard keyboard = layoutSet.getKeyboard(elementId); + final Key actualKey = keyboard.getKey(Constants.CODE_ENTER); + assertNotNull(tag + " enter key on " + keyboard.mId, actualKey); + assertEquals(tag + " label " + expectedKey, expectedKey.getLabel(), actualKey.getLabel()); + assertEquals(tag + " icon " + expectedKey, expectedKey.getIconId(), actualKey.getIconId()); + } + + protected void doTestActionKey(final String tag, final InputMethodSubtype subtype, + final int actionId, final ExpectedActionKey expectedKey) { + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = actionId; + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + + protected void doTestActionKey(final String tag, final InputMethodSubtype subtype, + final EditorInfo editorInfo, final ExpectedActionKey expectedKey) { + // Test text layouts. + editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, expectedKey); + // Test phone number layouts. + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, expectedKey); + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, expectedKey); + // Test normal number layout. + assertActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, expectedKey); + // Test number password layout. + editorInfo.inputType = + InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; + final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); + assertActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, expectedKey); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionCustomTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionCustomTests.java new file mode 100644 index 000000000..cb1c6ad1f --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionCustomTests.java @@ -0,0 +1,37 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionCustomTests extends KlpActionTestsBase { + public void testActionCustom() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = "customLabel"; + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel"); + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionDoneTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionDoneTests.java new file mode 100644 index 000000000..e0a87a70d --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionDoneTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionDoneTests extends KlpActionTestsBase { + public void testActionDone() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_done_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionGoTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionGoTests.java new file mode 100644 index 000000000..865b598d6 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionGoTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionGoTests extends KlpActionTestsBase { + public void testActionGo() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_go_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionLabelTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionLabelTests.java new file mode 100644 index 000000000..74343cb6a --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionLabelTests.java @@ -0,0 +1,172 @@ +/* + * 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.action; + +import android.content.res.Resources; +import android.test.suitebuilder.annotation.MediumTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.KeyboardLayoutSet; +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.keyboard.internal.KeyboardTextsSet; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.utils.RunInLocale; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; + +@MediumTest +public class KlpActionLabelTests extends KlpActionTestsBase { + void doTestActionKeys(final InputMethodSubtype subtype, final String tag, + final ExpectedActionKey unspecifiedKey, final ExpectedActionKey noneKey, + final ExpectedActionKey goKey, final ExpectedActionKey searchKey, + final ExpectedActionKey sendKey, final ExpectedActionKey nextKey, + final ExpectedActionKey doneKey, final ExpectedActionKey previousKey) { + doTestActionKey( + tag + " unspecified", subtype, EditorInfo.IME_ACTION_UNSPECIFIED, unspecifiedKey); + doTestActionKey(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, noneKey); + doTestActionKey(tag + " go", subtype, EditorInfo.IME_ACTION_GO, goKey); + doTestActionKey(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, searchKey); + doTestActionKey(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, sendKey); + doTestActionKey(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, nextKey); + doTestActionKey(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, doneKey); + doTestActionKey(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, previousKey); + } + + // Working variable to simulate system locale changing. + private Locale mSystemLocale = Locale.getDefault(); + + private void doTestActionKeysInLocaleWithStringResources(final InputMethodSubtype subtype, + final Locale labelLocale, final Locale systemLocale) { + // Simulate system locale changing, see {@link SystemBroadcastReceiver}. + if (!systemLocale.equals(mSystemLocale)) { + KeyboardLayoutSet.onSystemLocaleChanged(); + mSystemLocale = systemLocale; + } + final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + final ExpectedActionKey goKey = ExpectedActionKey.newLabelKey( + R.string.label_go_key, labelLocale, getContext()); + final ExpectedActionKey searchKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + final ExpectedActionKey sendKey = ExpectedActionKey.newLabelKey( + R.string.label_send_key, labelLocale, getContext()); + final ExpectedActionKey nextKey = ExpectedActionKey.newLabelKey( + R.string.label_next_key, labelLocale, getContext()); + final ExpectedActionKey doneKey = ExpectedActionKey.newLabelKey( + R.string.label_done_key, labelLocale, getContext()); + final ExpectedActionKey previousKey = ExpectedActionKey.newLabelKey( + R.string.label_previous_key, labelLocale, getContext()); + final String tag = "label=" + labelLocale + " system=" + systemLocale + + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final RunInLocale<Void> job = new RunInLocale<Void>() { + @Override + public Void job(final Resources res) { + doTestActionKeys(subtype, tag, enterKey, enterKey, goKey, searchKey, sendKey, + nextKey, doneKey, previousKey); + return null; + } + }; + job.runInLocale(getContext().getResources(), systemLocale); + } + + public void testActionLabelInOtherLocale() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY); + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.US); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.FRENCH); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.ITALIAN); + doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.JAPANESE); + } + + public void testNoLanguageSubtypeActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype noLanguage = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY); + // An action label of no language keyboard should be displayed in the system locale. + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.US, Locale.US); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.FRENCH, Locale.FRENCH); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.ITALIAN, Locale.ITALIAN); + doTestActionKeysInLocaleWithStringResources(noLanguage, Locale.JAPANESE, Locale.JAPANESE); + } + + private void doTestActionKeysInLocaleWithKeyboardTextsSet(final InputMethodSubtype subtype, + final Locale labelLocale, final Locale systemLocale) { + // Simulate system locale changing, see {@link SystemBroadcastReceiver}. + if (!systemLocale.equals(mSystemLocale)) { + KeyboardLayoutSet.onSystemLocaleChanged(); + mSystemLocale = systemLocale; + } + final KeyboardTextsSet textsSet = new KeyboardTextsSet(); + textsSet.setLocale(labelLocale, getContext()); + final ExpectedActionKey enterKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + final ExpectedActionKey goKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_go_key")); + final ExpectedActionKey searchKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + final ExpectedActionKey sendKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_send_key")); + final ExpectedActionKey nextKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_next_key")); + final ExpectedActionKey doneKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_done_key")); + final ExpectedActionKey previousKey = ExpectedActionKey.newLabelKey( + textsSet.getText("label_previous_key")); + final String tag = "label=hi_ZZ system=" + systemLocale + + " " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final RunInLocale<Void> job = new RunInLocale<Void>() { + @Override + public Void job(final Resources res) { + doTestActionKeys(subtype, tag, enterKey, enterKey, goKey, searchKey, sendKey, + nextKey, doneKey, previousKey); + return null; + } + }; + job.runInLocale(getContext().getResources(), systemLocale); + } + + public void testHinglishActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final Locale hi_ZZ = new Locale("hi", "ZZ"); + final InputMethodSubtype hinglish = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + hi_ZZ.toString(), SubtypeLocaleUtils.QWERTY); + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, hi_ZZ, hi_ZZ); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, hi_ZZ, Locale.US); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, hi_ZZ, Locale.FRENCH); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, hi_ZZ, Locale.ITALIAN); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, hi_ZZ, Locale.JAPANESE); + } + + public void testSerbianLatinActionLabel() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final Locale sr_ZZ = new Locale("sr", "ZZ"); + final InputMethodSubtype hinglish = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + sr_ZZ.toString(), "serbian_qwertz"); + // An action label should be displayed in subtype's locale regardless of the system locale. + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, sr_ZZ, sr_ZZ); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, sr_ZZ, Locale.US); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, sr_ZZ, Locale.FRENCH); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, sr_ZZ, Locale.ITALIAN); + doTestActionKeysInLocaleWithKeyboardTextsSet(hinglish, sr_ZZ, Locale.JAPANESE); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionNextTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionNextTests.java new file mode 100644 index 000000000..c67740cac --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionNextTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionNextTests extends KlpActionTestsBase { + public void testActionNext() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_next_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionNoneTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionNoneTests.java new file mode 100644 index 000000000..0be2ecb93 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionNoneTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionNoneTests extends KlpActionTestsBase { + public void testActionNone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionPreviousTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionPreviousTests.java new file mode 100644 index 000000000..af6a15400 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionPreviousTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionPreviousTests extends KlpActionTestsBase { + public void testActionPrevious() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_previous_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionSearchTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionSearchTests.java new file mode 100644 index 000000000..adc3feee7 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionSearchTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionSearchTests extends KlpActionTestsBase { + public void testActionSearch() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionSendTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionSendTests.java new file mode 100644 index 000000000..82f97a2ae --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionSendTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionSendTests extends KlpActionTestsBase { + public void testActionSend() { + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey( + R.string.label_send_key, getLabelLocale(subtype), getContext()); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionTestsBase.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionTestsBase.java new file mode 100644 index 000000000..511f9950b --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionTestsBase.java @@ -0,0 +1,55 @@ +/* + * 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.action; + +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.KeyboardTheme; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.ArrayList; +import java.util.Locale; + +abstract class KlpActionTestsBase extends ActionTestsBase { + // Filter a subtype whose name should be displayed using {@link Locale#ROOT}, such like + // Hinglish (hi_ZZ) and Serbian-Latn (sr_ZZ). + static final SubtypeFilter SUBTYPE_FILTER_NAME_IN_BASE_LOCALE = new SubtypeFilter() { + @Override + public boolean accept(final InputMethodSubtype subtype) { + return Locale.ROOT.equals( + SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale(subtype.getLocale())); + } + }; + + protected ArrayList<InputMethodSubtype> mSubtypesWhoseNameIsDisplayedInItsLocale; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mSubtypesWhoseNameIsDisplayedInItsLocale = getSubtypesFilteredBy(new SubtypeFilter() { + @Override + public boolean accept(final InputMethodSubtype subtype) { + return !SUBTYPE_FILTER_NAME_IN_BASE_LOCALE.accept(subtype); + } + }); + } + + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java b/tests/src/com/android/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java new file mode 100644 index 000000000..307e273e8 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/KlpActionUnspecifiedTests.java @@ -0,0 +1,37 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class KlpActionUnspecifiedTests extends KlpActionTestsBase { + public void testActionUnspecified() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : mSubtypesWhoseNameIsDisplayedInItsLocale) { + final String tag = "unspecifiled " + + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionCustomTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionCustomTests.java new file mode 100644 index 000000000..d561f457d --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionCustomTests.java @@ -0,0 +1,37 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionCustomTests extends LxxActionTestsBase { + public void testActionCustom() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = "customLabel"; + final ExpectedActionKey expectedKey = ExpectedActionKey.newLabelKey("customLabel"); + doTestActionKey(tag, subtype, editorInfo, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionDoneTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionDoneTests.java new file mode 100644 index 000000000..b818bb1ce --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionDoneTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionDoneTests extends LxxActionTestsBase { + public void testActionDone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_DONE_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_DONE, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionGoTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionGoTests.java new file mode 100644 index 000000000..8001f7105 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionGoTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionGoTests extends LxxActionTestsBase { + public void testActionGo() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_GO_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_GO, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionNextTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionNextTests.java new file mode 100644 index 000000000..09a8c87ec --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionNextTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionNextTests extends LxxActionTestsBase { + public void testActionNext() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_NEXT_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NEXT, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionNoneTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionNoneTests.java new file mode 100644 index 000000000..98595e976 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionNoneTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionNoneTests extends LxxActionTestsBase { + public void testActionNone() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_NONE, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionPreviousTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionPreviousTests.java new file mode 100644 index 000000000..2327889ae --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionPreviousTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionPreviousTests extends LxxActionTestsBase { + public void testActionPrevious() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_PREVIOUS_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionSearchTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionSearchTests.java new file mode 100644 index 000000000..7e1d86b2e --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionSearchTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionSearchTests extends LxxActionTestsBase { + public void testActionSearch() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEARCH_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEARCH, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionSendTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionSendTests.java new file mode 100644 index 000000000..fa0134f0d --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionSendTests.java @@ -0,0 +1,36 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionSendTests extends LxxActionTestsBase { + public void testActionSend() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_SEND_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_SEND, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionTestsBase.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionTestsBase.java new file mode 100644 index 000000000..70de9a6b8 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionTestsBase.java @@ -0,0 +1,26 @@ +/* + * 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.action; + +import com.android.inputmethod.keyboard.KeyboardTheme; + +abstract class LxxActionTestsBase extends ActionTestsBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_LXX_LIGHT; + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java b/tests/src/com/android/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java new file mode 100644 index 000000000..711ca2614 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/action/LxxActionUnspecifiedTests.java @@ -0,0 +1,37 @@ +/* + * 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.action; + +import android.test.suitebuilder.annotation.LargeTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +@LargeTest +public class LxxActionUnspecifiedTests extends LxxActionTestsBase { + public void testActionUnspecified() { + final ExpectedActionKey expectedKey = ExpectedActionKey.newIconKey( + KeyboardIconsSet.NAME_ENTER_KEY); + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "unspecifiled " + + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKey(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, expectedKey); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelperTests.java b/tests/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelperTests.java index 6ea27588e..e6198015a 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelperTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelperTests.java @@ -26,6 +26,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.RichInputMethodSubtype; import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -40,14 +41,14 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { private RichInputMethodManager mRichImm; - InputMethodSubtype EN_US_QWERTY; - InputMethodSubtype EN_GB_QWERTY; - InputMethodSubtype FR_AZERTY; - InputMethodSubtype FR_CA_QWERTY; - InputMethodSubtype FR_CH_SWISS; - InputMethodSubtype FR_CH_QWERTY; - InputMethodSubtype FR_CH_QWERTZ; - InputMethodSubtype ZZ_QWERTY; + RichInputMethodSubtype EN_US_QWERTY; + RichInputMethodSubtype EN_GB_QWERTY; + RichInputMethodSubtype FR_AZERTY; + RichInputMethodSubtype FR_CA_QWERTY; + RichInputMethodSubtype FR_CH_SWISS; + RichInputMethodSubtype FR_CH_QWERTY; + RichInputMethodSubtype FR_CH_QWERTZ; + RichInputMethodSubtype ZZ_QWERTY; @Override protected void setUp() throws Exception { @@ -57,22 +58,22 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { mRichImm = RichInputMethodManager.getInstance(); SubtypeLocaleUtils.init(context); - EN_US_QWERTY = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.US.toString(), "qwerty"); - EN_GB_QWERTY = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.UK.toString(), "qwerty"); - FR_AZERTY = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.FRENCH.toString(), "azerty"); - FR_CA_QWERTY = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.CANADA_FRENCH.toString(), "qwerty"); - FR_CH_SWISS = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - "fr_CH", "swiss"); - FR_CH_QWERTZ = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - "fr_CH", "qwertz"); - FR_CH_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - "fr_CH", "qwerty"); - ZZ_QWERTY = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"); + EN_US_QWERTY = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), "qwerty")); + EN_GB_QWERTY = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.UK.toString(), "qwerty")); + FR_AZERTY = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.FRENCH.toString(), "azerty")); + FR_CA_QWERTY = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.CANADA_FRENCH.toString(), "qwerty")); + FR_CH_SWISS = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "fr_CH", "swiss")); + FR_CH_QWERTZ = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwertz")); + FR_CH_QWERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwerty")); + ZZ_QWERTY = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + SubtypeLocaleUtils.NO_LANGUAGE, "qwerty")); } private static List<InputMethodSubtype> asList(final InputMethodSubtype ... subtypes) { @@ -80,14 +81,14 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { } public void testOneSubtype() { - mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(EN_US_QWERTY)); + mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(EN_US_QWERTY.getRawSubtype())); mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(true /* isSame */); assertEquals("one same English (US)", FORMAT_TYPE_NONE, mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(EN_US_QWERTY)); assertEquals("one same NoLanguage", FORMAT_TYPE_FULL_LOCALE, mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(ZZ_QWERTY)); - mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(FR_AZERTY)); + mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(FR_AZERTY.getRawSubtype())); mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(false /* isSame */); assertEquals("one diff English (US)", FORMAT_TYPE_LANGUAGE_ONLY, mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(EN_US_QWERTY)); @@ -96,8 +97,8 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { } public void testTwoSubtypes() { - mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(EN_US_QWERTY, FR_AZERTY)); - + mLanguageOnSpacebarHelper.updateEnabledSubtypes(asList(EN_US_QWERTY.getRawSubtype(), + FR_AZERTY.getRawSubtype())); mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(true /* isSame */); assertEquals("two same English (US)", FORMAT_TYPE_LANGUAGE_ONLY, mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(EN_US_QWERTY)); @@ -117,7 +118,8 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { public void testSameLanuageSubtypes() { mLanguageOnSpacebarHelper.updateEnabledSubtypes( - asList(EN_US_QWERTY, EN_GB_QWERTY, FR_AZERTY, ZZ_QWERTY)); + asList(EN_US_QWERTY.getRawSubtype(), EN_GB_QWERTY.getRawSubtype(), + FR_AZERTY.getRawSubtype(), ZZ_QWERTY.getRawSubtype())); mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(true /* isSame */); assertEquals("two same English (US)", FORMAT_TYPE_FULL_LOCALE, @@ -138,7 +140,9 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase { public void testMultiSameLanuageSubtypes() { mLanguageOnSpacebarHelper.updateEnabledSubtypes( - asList(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTY, FR_CH_QWERTZ)); + asList(FR_AZERTY.getRawSubtype(), FR_CA_QWERTY.getRawSubtype(), + FR_CH_SWISS.getRawSubtype(), FR_CH_QWERTY.getRawSubtype(), + FR_CH_QWERTZ.getRawSubtype())); mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(true /* isSame */); assertEquals("multi same French", FORMAT_TYPE_LANGUAGE_ONLY, diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java index a353e5a35..986a233c1 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java @@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard.internal; import android.text.TextUtils; +import com.android.inputmethod.event.Event; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.RecapitalizeStatus; @@ -26,7 +27,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { // Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}. public static final boolean NOT_SLIDING = false; public static final boolean SLIDING = true; - // Argument for {@link KeyboardState#onCodeInput}. + // Argument for {@link KeyboardState#onEvent}. public static final boolean SINGLE = true; public static final boolean MULTI = false; public static final int CAP_MODE_OFF = Constants.TextUtils.CAP_MODE_OFF; @@ -183,7 +184,11 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { } else { mAutoCapsState = mAutoCapsMode; } - mState.onCodeInput(code, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); + final Event event = + Event.createSoftwareKeypressEvent(code /* codePoint */, code /* keyCode */, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */); + mState.onEvent(event, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE); } public void onFinishSlidingInput() { diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java index 922d2a8c8..8f4648c52 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java @@ -16,52 +16,33 @@ package com.android.inputmethod.keyboard.internal; -import android.app.Instrumentation; import android.content.Context; import android.content.res.Resources; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.MediumTest; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.latin.R; -import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; -@MediumTest -public class MoreKeySpecSplitTests extends InstrumentationTestCase { +@SmallTest +public class MoreKeySpecSplitTests extends AndroidTestCase { private static final Locale TEST_LOCALE = Locale.ENGLISH; - final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); + private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); @Override protected void setUp() throws Exception { super.setUp(); - final Instrumentation instrumentation = getInstrumentation(); - final Context targetContext = instrumentation.getTargetContext(); - mTextsSet.setLocale(TEST_LOCALE, targetContext); - final String[] testResourceNames = getAllResourceIdNames( - com.android.inputmethod.latin.tests.R.string.class); - final Context testContext = instrumentation.getContext(); - final Resources testRes = testContext.getResources(); - final String testResPackageName = testRes.getResourcePackageName( - // This dummy raw resource is needed to be able to load string resources from a test - // APK successfully. - com.android.inputmethod.latin.tests.R.raw.dummy_resource_for_testing); - mTextsSet.loadStringResourcesInternal(testRes, testResourceNames, testResPackageName); - } - - private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) { - final ArrayList<String> names = new ArrayList<>(); - for (final Field field : resourceIdClass.getFields()) { - if (field.getType() == int.class) { - names.add(field.getName()); - } - } - return names.toArray(new String[names.size()]); + final Context targetContext = getContext(); + final Resources targetRes = targetContext.getResources(); + final String targetPackageName = targetRes.getResourcePackageName( + R.string.english_ime_name); + mTextsSet.setLocale(TEST_LOCALE, targetRes, targetPackageName); } - private static <T> void assertArrayEquals(final String message, final T[] expected, - final T[] actual) { + static <T> void assertArrayEquals(final String message, final T[] expected, final T[] actual) { if (expected == actual) { return; } @@ -109,14 +90,6 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { private static final String SURROGATE1 = PAIR1 + PAIR2; private static final String SURROGATE2 = PAIR1 + PAIR2 + PAIR3; - public void testResolveNullText() { - assertNull("resolve null", mTextsSet.resolveTextReference(null)); - } - - public void testResolveEmptyText() { - assertNull("resolve empty text", mTextsSet.resolveTextReference("!text/empty_string")); - } - public void testSplitZero() { assertTextArray("Empty string", ""); assertTextArray("Empty entry", ","); @@ -224,132 +197,14 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { "\\!", "\\!TEXT/EMPTY_STRING"); } - public void testSplitResourceError() { - assertError("Incomplete resource name", "!text/", "!text/"); - assertError("Non existing resource", "!text/non_existing"); - } - - public void testSplitResourceZero() { - assertTextArray("Empty string", - "!text/empty_string"); - } - - public void testSplitResourceSingle() { - assertTextArray("Single char", - "!text/single_char", "a"); - assertTextArray("Space", - "!text/space", " "); - assertTextArray("Single label", - "!text/single_label", "abc"); - assertTextArray("Spaces", - "!text/spaces", " "); - assertTextArray("Spaces in label", - "!text/spaces_in_label", "a b c"); - assertTextArray("Spaces at beginning of label", - "!text/spaces_at_beginning_of_label", " abc"); - assertTextArray("Spaces at end of label", - "!text/spaces_at_end_of_label", "abc "); - assertTextArray("label surrounded by spaces", - "!text/label_surrounded_by_spaces", " abc "); - - assertTextArray("Escape and single char", - "\\\\!text/single_char", "\\\\a"); - } - - public void testSplitResourceSingleEscaped() { - assertTextArray("Escaped char", - "!text/escaped_char", "\\a"); - assertTextArray("Escaped comma", - "!text/escaped_comma", "\\,"); - assertTextArray("Escaped comma escape", - "!text/escaped_comma_escape", "a\\,\\"); - assertTextArray("Escaped escape", - "!text/escaped_escape", "\\\\"); - assertTextArray("Escaped label", - "!text/escaped_label", "a\\bc"); - assertTextArray("Escaped label at beginning", - "!text/escaped_label_at_beginning", "\\abc"); - assertTextArray("Escaped label at end", - "!text/escaped_label_at_end", "abc\\"); - assertTextArray("Escaped label with comma", - "!text/escaped_label_with_comma", "a\\,c"); - assertTextArray("Escaped label with comma at beginning", - "!text/escaped_label_with_comma_at_beginning", "\\,bc"); - assertTextArray("Escaped label with comma at end", - "!text/escaped_label_with_comma_at_end", "ab\\,"); - assertTextArray("Escaped label with successive", - "!text/escaped_label_with_successive", "\\,\\\\bc"); - assertTextArray("Escaped label with escape", - "!text/escaped_label_with_escape", "a\\\\c"); + public void testSplitTextReferenceError() { + assertError("Incomplete text name", "!text/", "!text/"); + assertError("Non existing text", "!text/non_existing"); } - public void testSplitResourceMulti() { - assertTextArray("Multiple chars", - "!text/multiple_chars", "a", "b", "c"); - assertTextArray("Multiple chars surrounded by spaces", - "!text/multiple_chars_surrounded_by_spaces", - " a ", " b ", " c "); - assertTextArray("Multiple labels", - "!text/multiple_labels", "abc", "def", "ghi"); - assertTextArray("Multiple labels surrounded by spaces", - "!text/multiple_labels_surrounded_by_spaces", " abc ", " def ", " ghi "); - } - - public void testSplitResourcetMultiEscaped() { - assertTextArray("Multiple chars with comma", - "!text/multiple_chars_with_comma", - "a", "\\,", "c"); - assertTextArray("Multiple chars with comma surrounded by spaces", - "!text/multiple_chars_with_comma_surrounded_by_spaces", - " a ", " \\, ", " c "); - assertTextArray("Multiple labels with escape", - "!text/multiple_labels_with_escape", - "\\abc", "d\\ef", "gh\\i"); - assertTextArray("Multiple labels with escape surrounded by spaces", - "!text/multiple_labels_with_escape_surrounded_by_spaces", - " \\abc ", " d\\ef ", " gh\\i "); - assertTextArray("Multiple labels with comma and escape", - "!text/multiple_labels_with_comma_and_escape", - "ab\\\\", "d\\\\\\,", "g\\,i"); - assertTextArray("Multiple labels with comma and escape surrounded by spaces", - "!text/multiple_labels_with_comma_and_escape_surrounded_by_spaces", - " ab\\\\ ", " d\\\\\\, ", " g\\,i "); - } - - public void testSplitMultipleResources() { - assertTextArray("Literals and resources", - "1,!text/multiple_chars,z", "1", "a", "b", "c", "z"); - assertTextArray("Literals and resources and escape at end", - "\\1,!text/multiple_chars,z\\", "\\1", "a", "b", "c", "z\\"); - assertTextArray("Multiple single resource chars and labels", - "!text/single_char,!text/single_label,!text/escaped_comma", - "a", "abc", "\\,"); - assertTextArray("Multiple single resource chars and labels 2", - "!text/single_char,!text/single_label,!text/escaped_comma_escape", - "a", "abc", "a\\,\\"); - assertTextArray("Multiple multiple resource chars and labels", - "!text/multiple_chars,!text/multiple_labels,!text/multiple_chars_with_comma", - "a", "b", "c", "abc", "def", "ghi", "a", "\\,", "c"); - assertTextArray("Concatenated resources", - "!text/multiple_chars!text/multiple_labels!text/multiple_chars_with_comma", - "a", "b", "cabc", "def", "ghia", "\\,", "c"); - assertTextArray("Concatenated resource and literal", - "abc!text/multiple_labels", - "abcabc", "def", "ghi"); - } - - public void testSplitIndirectReference() { - assertTextArray("Indirect", - "!text/indirect_string", "a", "b", "c"); - assertTextArray("Indirect with literal", - "1,!text/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2"); - assertTextArray("Indirect2", - "!text/indirect2_string", "a", "b", "c"); - } - - public void testSplitInfiniteIndirectReference() { - assertError("Infinite indirection", - "1,!text/infinite_indirection,2", "1", "infinite", "<infinite>", "loop", "2"); + public void testSplitEmptyTextReference() { + // Note that morekeys_q of English locale is empty. + assertTextArray("Empty string", "!text/morekeys_q"); } public void testLabelReferece() { @@ -360,12 +215,6 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { assertTextArray("Settings as more key", "!text/keyspec_settings", "!icon/settings_key|!code/key_settings"); - - assertTextArray("Indirect naviagte actions as more key", - "!text/keyspec_indirect_navigate_actions", - "!fixedColumnOrder!2", - "!hasLabels!", "Prev|!code/key_action_previous", - "!hasLabels!", "Next|!code/key_action_next"); } public void testUselessUpperCaseSpecifier() { @@ -394,14 +243,6 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { assertTextArray("INDIRECT2", "!TEXT/INDIRECT2_STRING", "!TEXT/INDIRECT2_STRING"); - assertTextArray("Upper indirect", - "!text/upper_indirect_string", "!TEXT/MULTIPLE_CHARS"); - assertTextArray("Upper indirect with literal", - "1,!text/upper_indirect_string_with_literal,2", - "1", "x", "!TEXT/MULTIPLE_CHARS", "y", "2"); - assertTextArray("Upper indirect2", - "!text/upper_indirect2_string", "!TEXT/UPPER_INDIRECT_STRING"); - assertTextArray("UPPER INDIRECT", "!TEXT/upper_INDIRECT_STRING", "!TEXT/upper_INDIRECT_STRING"); assertTextArray("Upper INDIRECT with literal", @@ -413,9 +254,6 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { assertTextArray("INFINITE INDIRECTION", "1,!TEXT/INFINITE_INDIRECTION,2", "1", "!TEXT/INFINITE_INDIRECTION", "2"); - assertTextArray("Upper infinite indirection", - "1,!text/upper_infinite_indirection,2", - "1", "infinite", "!TEXT/INFINITE_INDIRECTION", "loop", "2"); assertTextArray("Upper INFINITE INDIRECTION", "1,!TEXT/UPPER_INFINITE_INDIRECTION,2", "1", "!TEXT/UPPER_INFINITE_INDIRECTION", "2"); diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java new file mode 100644 index 000000000..e06ecaedf --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecStringReferenceTests.java @@ -0,0 +1,284 @@ +/* + * 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.internal; + +import android.app.Instrumentation; +import android.content.Context; +import android.content.res.Resources; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.latin.tests.R; + +import java.util.Locale; + +@SmallTest +public class MoreKeySpecStringReferenceTests extends InstrumentationTestCase { + private static final Locale TEST_LOCALE = Locale.ENGLISH; + private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); + + @Override + protected void setUp() throws Exception { + super.setUp(); + + final Instrumentation instrumentation = getInstrumentation(); + final Context testContext = instrumentation.getContext(); + final Resources testRes = testContext.getResources(); + final String testPackageName = testRes.getResourcePackageName(R.string.empty_string); + mTextsSet.setLocale(TEST_LOCALE, testRes, testPackageName); + } + + private void assertTextArray(final String message, final String value, + final String ... expectedArray) { + final String resolvedActual = mTextsSet.resolveTextReference(value); + final String[] actual = MoreKeySpec.splitKeySpecs(resolvedActual); + final String[] expected = (expectedArray.length == 0) ? null : expectedArray; + MoreKeySpecSplitTests.assertArrayEquals(message, expected, actual); + } + + private void assertError(final String message, final String value, final String ... expected) { + try { + assertTextArray(message, value, expected); + fail(message); + } catch (Exception pcpe) { + // success. + } + } + + public void testResolveNullText() { + assertEquals("resolve null", + mTextsSet.resolveTextReference(null), null); + } + + public void testResolveEmptyText() { + assertEquals("resolve empty text", + mTextsSet.resolveTextReference("!string/empty_string"), null); + } + + public void testSplitSingleEscaped() { + assertTextArray("Escaped !string", "\\!string", + "\\!string"); + assertTextArray("Escaped !string/", "\\!string/", + "\\!string/"); + assertTextArray("Escaped !STRING/", "\\!STRING/", + "\\!STRING/"); + assertTextArray("Escaped !string/name", "\\!string/empty_string", + "\\!string/empty_string"); + assertTextArray("Escaped !STRING/NAME", "\\!STRING/EMPTY_STRING", + "\\!STRING/EMPTY_STRING"); + } + + public void testSplitMultiEscaped() { + assertTextArray("Multiple escaped !string", "\\!,\\!string/empty_string", + "\\!", "\\!string/empty_string"); + assertTextArray("Multiple escaped !STRING", "\\!,\\!STRING/EMPTY_STRING", + "\\!", "\\!STRING/EMPTY_STRING"); + } + + public void testSplitStringReferenceError() { + assertError("Incomplete resource name", "!string/", "!string/"); + assertError("Non existing resource", "!string/non_existing"); + } + + public void testSplitEmptyStringReference() { + assertTextArray("Empty string", "!string/empty_string"); + } + + public void testSplitResourceSingle() { + assertTextArray("Single char", "!string/single_char", + "a"); + assertTextArray("Space", "!string/space", + " "); + assertTextArray("Single label", "!string/single_label", + "abc"); + assertTextArray("Spaces", "!string/spaces", + " "); + assertTextArray("Spaces in label", "!string/spaces_in_label", + "a b c"); + assertTextArray("Spaces at beginning of label", "!string/spaces_at_beginning_of_label", + " abc"); + assertTextArray("Spaces at end of label", "!string/spaces_at_end_of_label", + "abc "); + assertTextArray("label surrounded by spaces", "!string/label_surrounded_by_spaces", + " abc "); + assertTextArray("Escape and single char", "\\\\!string/single_char", + "\\\\a"); + } + + public void testSplitResourceSingleEscaped() { + assertTextArray("Escaped char", + "!string/escaped_char", "\\a"); + assertTextArray("Escaped comma", + "!string/escaped_comma", "\\,"); + assertTextArray("Escaped comma escape", + "!string/escaped_comma_escape", "a\\,\\"); + assertTextArray("Escaped escape", + "!string/escaped_escape", "\\\\"); + assertTextArray("Escaped label", + "!string/escaped_label", "a\\bc"); + assertTextArray("Escaped label at beginning", + "!string/escaped_label_at_beginning", "\\abc"); + assertTextArray("Escaped label at end", + "!string/escaped_label_at_end", "abc\\"); + assertTextArray("Escaped label with comma", + "!string/escaped_label_with_comma", "a\\,c"); + assertTextArray("Escaped label with comma at beginning", + "!string/escaped_label_with_comma_at_beginning", "\\,bc"); + assertTextArray("Escaped label with comma at end", + "!string/escaped_label_with_comma_at_end", "ab\\,"); + assertTextArray("Escaped label with successive", + "!string/escaped_label_with_successive", "\\,\\\\bc"); + assertTextArray("Escaped label with escape", + "!string/escaped_label_with_escape", "a\\\\c"); + } + + public void testSplitResourceMulti() { + assertTextArray("Multiple chars", + "!string/multiple_chars", "a", "b", "c"); + assertTextArray("Multiple chars surrounded by spaces", + "!string/multiple_chars_surrounded_by_spaces", + " a ", " b ", " c "); + assertTextArray("Multiple labels", + "!string/multiple_labels", "abc", "def", "ghi"); + assertTextArray("Multiple labels surrounded by spaces", + "!string/multiple_labels_surrounded_by_spaces", " abc ", " def ", " ghi "); + } + + public void testSplitResourcetMultiEscaped() { + assertTextArray("Multiple chars with comma", + "!string/multiple_chars_with_comma", + "a", "\\,", "c"); + assertTextArray("Multiple chars with comma surrounded by spaces", + "!string/multiple_chars_with_comma_surrounded_by_spaces", + " a ", " \\, ", " c "); + assertTextArray("Multiple labels with escape", + "!string/multiple_labels_with_escape", + "\\abc", "d\\ef", "gh\\i"); + assertTextArray("Multiple labels with escape surrounded by spaces", + "!string/multiple_labels_with_escape_surrounded_by_spaces", + " \\abc ", " d\\ef ", " gh\\i "); + assertTextArray("Multiple labels with comma and escape", + "!string/multiple_labels_with_comma_and_escape", + "ab\\\\", "d\\\\\\,", "g\\,i"); + assertTextArray("Multiple labels with comma and escape surrounded by spaces", + "!string/multiple_labels_with_comma_and_escape_surrounded_by_spaces", + " ab\\\\ ", " d\\\\\\, ", " g\\,i "); + } + + public void testSplitMultipleResources() { + assertTextArray("Literals and resources", + "1,!string/multiple_chars,z", + "1", "a", "b", "c", "z"); + assertTextArray("Literals and resources and escape at end", + "\\1,!string/multiple_chars,z\\", + "\\1", "a", "b", "c", "z\\"); + assertTextArray("Multiple single resource chars and labels", + "!string/single_char,!string/single_label,!string/escaped_comma", + "a", "abc", "\\,"); + assertTextArray("Multiple single resource chars and labels 2", + "!string/single_char,!string/single_label,!string/escaped_comma_escape", + "a", "abc", "a\\,\\"); + assertTextArray("Multiple multiple resource chars and labels", + "!string/multiple_chars,!string/multiple_labels,!string/multiple_chars_with_comma", + "a", "b", "c", "abc", "def", "ghi", "a", "\\,", "c"); + assertTextArray("Concatenated resources", + "!string/multiple_chars!string/multiple_labels!string/multiple_chars_with_comma", + "a", "b", "cabc", "def", "ghia", "\\,", "c"); + assertTextArray("Concatenated resource and literal", + "abc!string/multiple_labels", + "abcabc", "def", "ghi"); + } + + public void testSplitIndirectReference() { + assertTextArray("Indirect", + "!string/indirect_string", "a", "b", "c"); + assertTextArray("Indirect with literal", + "1,!string/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2"); + assertTextArray("Indirect2", + "!string/indirect2_string", "a", "b", "c"); + } + + public void testSplitInfiniteIndirectReference() { + assertError("Infinite indirection", + "1,!string/infinite_indirection,2", "1", "infinite", "<infinite>", "loop", "2"); + } + + public void testLabelReferece() { + assertTextArray("Indirect naviagte actions as more key", + "!string/keyspec_indirect_navigate_actions", + "!fixedColumnOrder!2", + "!hasLabels!", "ActionPrevious|!code/key_action_previous", + "!hasLabels!", "ActionNext|!code/key_action_next"); + } + + public void testUselessUpperCaseSpecifier() { + assertTextArray("EMPTY STRING", + "!STRING/EMPTY_STRING", "!STRING/EMPTY_STRING"); + + assertTextArray("SINGLE CHAR", + "!STRING/SINGLE_CHAR", "!STRING/SINGLE_CHAR"); + assertTextArray("Escape and SINGLE CHAR", + "\\\\!STRING/SINGLE_CHAR", "\\\\!STRING/SINGLE_CHAR"); + + assertTextArray("MULTIPLE CHARS", + "!STRING/MULTIPLE_CHARS", "!STRING/MULTIPLE_CHARS"); + + assertTextArray("Literals and RESOURCES", + "1,!STRING/MULTIPLE_CHARS,z", "1", "!STRING/MULTIPLE_CHARS", "z"); + assertTextArray("Multiple single RESOURCE chars and LABELS 2", + "!STRING/SINGLE_CHAR,!STRING/SINGLE_LABEL,!STRING/ESCAPED_COMMA_ESCAPE", + "!STRING/SINGLE_CHAR", "!STRING/SINGLE_LABEL", "!STRING/ESCAPED_COMMA_ESCAPE"); + + assertTextArray("INDIRECT", + "!STRING/INDIRECT_STRING", "!STRING/INDIRECT_STRING"); + assertTextArray("INDIRECT with literal", + "1,!STRING/INDIRECT_STRING_WITH_LITERAL,2", + "1", "!STRING/INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("INDIRECT2", + "!STRING/INDIRECT2_STRING", "!STRING/INDIRECT2_STRING"); + + assertTextArray("Upper indirect", + "!string/upper_indirect_string", "!STRING/MULTIPLE_CHARS"); + assertTextArray("Upper indirect with literal", + "1,!string/upper_indirect_string_with_literal,2", + "1", "x", "!STRING/MULTIPLE_CHARS", "y", "2"); + assertTextArray("Upper indirect2", + "!string/upper_indirect2_string", "!STRING/UPPER_INDIRECT_STRING"); + + assertTextArray("UPPER INDIRECT", + "!STRING/upper_INDIRECT_STRING", "!STRING/upper_INDIRECT_STRING"); + assertTextArray("Upper INDIRECT with literal", + "1,!STRING/upper_INDIRECT_STRING_WITH_LITERAL,2", + "1", "!STRING/upper_INDIRECT_STRING_WITH_LITERAL", "2"); + assertTextArray("Upper INDIRECT2", + "!STRING/upper_INDIRECT2_STRING", "!STRING/upper_INDIRECT2_STRING"); + + assertTextArray("INFINITE INDIRECTION", + "1,!STRING/INFINITE_INDIRECTION,2", "1", "!STRING/INFINITE_INDIRECTION", "2"); + + assertTextArray("Upper infinite indirection", + "1,!string/upper_infinite_indirection,2", + "1", "infinite", "!STRING/INFINITE_INDIRECTION", "loop", "2"); + assertTextArray("Upper INFINITE INDIRECTION", + "1,!STRING/UPPER_INFINITE_INDIRECTION,2", + "1", "!STRING/UPPER_INFINITE_INDIRECTION", "2"); + + assertTextArray("INDIRECT NAVIGATE ACTIONS AS MORE KEY", + "!STRING/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY", + "!STRING/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY"); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Dvorak.java b/tests/src/com/android/inputmethod/keyboard/layout/Dvorak.java index ba94c8dee..66fce014b 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/Dvorak.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/Dvorak.java @@ -18,9 +18,8 @@ package com.android.inputmethod.keyboard.layout; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import com.android.inputmethod.keyboard.layout.expected.ExpectedKey.ExpectedAdditionalMoreKey; -import com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; diff --git a/tests/src/com/android/inputmethod/keyboard/layout/LayoutBase.java b/tests/src/com/android/inputmethod/keyboard/layout/LayoutBase.java index b05789b73..b714ec794 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/LayoutBase.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/LayoutBase.java @@ -51,6 +51,24 @@ public abstract class LayoutBase extends AbstractLayoutBase { } /** + * Set accented letters to a specific keyboard element. + * @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard + * layout. + * @param elementId the element id of keyboard + * @return the {@link ExpectedKeyboardBuilder} object that contains accented letters as + * "more keys". + */ + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder, + final int elementId) { + // This method can be overridden by an extended class to provide customized expected + // accented letters depending on the shift state of keyboard. + // This is a default behavior to call a shift-state-independent + // {@link #setAccentedLetters(ExpectedKeyboardBuilder)} implementation, so that + // <code>elementId</code> is ignored here. + return setAccentedLetters(builder); + } + + /** * Set accented letters to common layout. * @param builder the {@link ExpectedKeyboardBuilder} object that contains common keyboard * layout. @@ -310,7 +328,7 @@ public abstract class LayoutBase extends AbstractLayoutBase { // U+00A1: "¡" INVERTED EXCLAMATION MARK // U+00BF: "¿" INVERTED QUESTION MARK - static final ExpectedKey[] EXCLAMATION_AND_QUESTION_MARKS = joinKeys( + public static final ExpectedKey[] EXCLAMATION_AND_QUESTION_MARKS = joinKeys( key("!", moreKey("\u00A1")), key("?", moreKey("\u00BF"))); // U+200C: ZERO WIDTH NON-JOINER // U+200D: ZERO WIDTH JOINER @@ -386,7 +404,7 @@ public abstract class LayoutBase extends AbstractLayoutBase { ExpectedKey[][] getCommonAlphabetShiftLayout(final boolean isPhone, final int elementId) { final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( getCommonAlphabetLayout(isPhone)); - getCustomizer().setAccentedLetters(builder); + getCustomizer().setAccentedLetters(builder, elementId); builder.toUpperCase(getLocale()); return builder.build(); } @@ -411,7 +429,7 @@ public abstract class LayoutBase extends AbstractLayoutBase { final ExpectedKeyboardBuilder builder; if (elementId == KeyboardId.ELEMENT_ALPHABET) { builder = new ExpectedKeyboardBuilder(getCommonAlphabetLayout(isPhone)); - getCustomizer().setAccentedLetters(builder); + getCustomizer().setAccentedLetters(builder, elementId); } else { final ExpectedKey[][] commonLayout = getCommonAlphabetShiftLayout(isPhone, elementId); if (commonLayout == null) { diff --git a/tests/src/com/android/inputmethod/keyboard/layout/SerbianQwertz.java b/tests/src/com/android/inputmethod/keyboard/layout/SerbianQwertz.java new file mode 100644 index 000000000..b23fe768e --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/SerbianQwertz.java @@ -0,0 +1,57 @@ +/* + * 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.layout; + +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +public final class SerbianQwertz extends LayoutBase { + private static final String LAYOUT_NAME = "serbian_qwertz"; + + public SerbianQwertz(final LayoutCustomizer customizer) { + super(customizer, Symbols.class, SymbolsShifted.class); + } + + @Override + public String getName() { return LAYOUT_NAME; } + + @Override + ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; } + + public static final String ROW1_11 = "ROW1_11"; + public static final String ROW2_10 = "ROW2_10"; + public static final String ROW2_11 = "ROW2_11"; + public static final String ROW3_8 = "ROW3_8"; + public static final String ROW3_9 = "ROW3_9"; + + private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder() + .setKeysOfRow(1, + key("q", additionalMoreKey("1")), + key("w", additionalMoreKey("2")), + key("e", additionalMoreKey("3")), + key("r", additionalMoreKey("4")), + key("t", additionalMoreKey("5")), + key("z", additionalMoreKey("6")), + key("u", additionalMoreKey("7")), + key("i", additionalMoreKey("8")), + key("o", additionalMoreKey("9")), + key("p", additionalMoreKey("0")), + ROW1_11) + .setKeysOfRow(2, "a", "s", "d", "f", "g", "h", "j", "k", "l", ROW2_10, ROW2_11) + .setKeysOfRow(3, "y", "x", "c", "v", "b", "n", "m", ROW3_8, ROW3_9) + .build(); +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java index 2674a6a69..5c147a3b6 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java @@ -105,11 +105,11 @@ public class ExpectedKey { // The expected output of this key. private final ExpectedKeyOutput mOutput; - public final ExpectedKeyVisual getVisual() { + protected final ExpectedKeyVisual getVisual() { return mVisual; } - public final ExpectedKeyOutput getOutput() { + protected final ExpectedKeyOutput getOutput() { return mOutput; } @@ -162,18 +162,19 @@ public class ExpectedKey { public boolean equalsTo(final Key key) { // This key has no "more keys". - return mVisual.equalsTo(key) && mOutput.equalsTo(key) && key.getMoreKeys() == null; + return mVisual.hasSameKeyVisual(key) && mOutput.hasSameKeyOutput(key) + && key.getMoreKeys() == null; } public boolean equalsTo(final MoreKeySpec moreKeySpec) { - return mVisual.equalsTo(moreKeySpec) && mOutput.equalsTo(moreKeySpec); + return mVisual.hasSameKeyVisual(moreKeySpec) && mOutput.hasSameKeyOutput(moreKeySpec); } @Override public boolean equals(final Object object) { if (object instanceof ExpectedKey) { final ExpectedKey key = (ExpectedKey) object; - return mVisual.equalsTo(key.mVisual) && mOutput.equalsTo(key.mOutput) + return mVisual.hasSameKeyVisual(key.mVisual) && mOutput.hasSameKeyOutput(key.mOutput) && Arrays.equals(getMoreKeys(), key.getMoreKeys()); } return false; @@ -190,7 +191,7 @@ public class ExpectedKey { @Override public String toString() { - if (mVisual.equalsTo(mOutput)) { + if (mVisual.hasSameKeyVisual(mOutput)) { return mVisual.toString(); } return mVisual + "|" + mOutput; @@ -274,7 +275,7 @@ public class ExpectedKey { @Override public boolean equalsTo(final Key key) { - if (getVisual().equalsTo(key) && getOutput().equalsTo(key)) { + if (getVisual().hasSameKeyVisual(key) && getOutput().hasSameKeyOutput(key)) { final MoreKeySpec[] moreKeySpecs = key.getMoreKeys(); final ExpectedKey[] moreKeys = getMoreKeys(); // This key should have at least one "more key". diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java index 737d1695b..5c1a70fa3 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java @@ -43,10 +43,10 @@ abstract class ExpectedKeyOutput { abstract ExpectedKeyOutput toUpperCase(final Locale locale); abstract ExpectedKeyOutput preserveCase(); - abstract boolean equalsTo(final String text); - abstract boolean equalsTo(final Key key); - abstract boolean equalsTo(final MoreKeySpec moreKeySpec); - abstract boolean equalsTo(final ExpectedKeyOutput output); + abstract boolean hasSameKeyOutput(final String text); + abstract boolean hasSameKeyOutput(final Key key); + abstract boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec); + abstract boolean hasSameKeyOutput(final ExpectedKeyOutput output); /** * This class represents an integer code point. @@ -75,22 +75,22 @@ abstract class ExpectedKeyOutput { } @Override - boolean equalsTo(final String text) { + boolean hasSameKeyOutput(final String text) { return StringUtils.codePointCount(text) == 1 && text.codePointAt(0) == mCode; } @Override - boolean equalsTo(final Key key) { + boolean hasSameKeyOutput(final Key key) { return mCode == key.getCode(); } @Override - boolean equalsTo(final MoreKeySpec moreKeySpec) { + boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) { return mCode == moreKeySpec.mCode; } @Override - boolean equalsTo(final ExpectedKeyOutput output) { + boolean hasSameKeyOutput(final ExpectedKeyOutput output) { return (output instanceof Code) && mCode == ((Code)output).mCode; } @@ -130,24 +130,24 @@ abstract class ExpectedKeyOutput { } @Override - boolean equalsTo(final String text) { + boolean hasSameKeyOutput(final String text) { return text.equals(text); } @Override - boolean equalsTo(final Key key) { + boolean hasSameKeyOutput(final Key key) { return key.getCode() == Constants.CODE_OUTPUT_TEXT && mText.equals(key.getOutputText()); } @Override - boolean equalsTo(final MoreKeySpec moreKeySpec) { + boolean hasSameKeyOutput(final MoreKeySpec moreKeySpec) { return moreKeySpec.mCode == Constants.CODE_OUTPUT_TEXT && mText.equals(moreKeySpec.mOutputText); } @Override - boolean equalsTo(final ExpectedKeyOutput output) { + boolean hasSameKeyOutput(final ExpectedKeyOutput output) { return (output instanceof Text) && mText == ((Text)output).mText; } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java index facdf7043..2f3a0c15f 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java @@ -27,22 +27,24 @@ import java.util.Locale; * * There are two types of expected visual, an integer icon id and a string label. */ -abstract class ExpectedKeyVisual { - static ExpectedKeyVisual newInstance(final String label) { +public abstract class ExpectedKeyVisual { + public static ExpectedKeyVisual newInstance(final String label) { return new Label(label); } - static ExpectedKeyVisual newInstance(final int iconId) { + public static ExpectedKeyVisual newInstance(final int iconId) { return new Icon(iconId); } + public abstract int getIconId(); + public abstract String getLabel(); abstract ExpectedKeyVisual toUpperCase(final Locale locale); abstract ExpectedKeyVisual preserveCase(); - abstract boolean equalsTo(final String text); - abstract boolean equalsTo(final Key key); - abstract boolean equalsTo(final MoreKeySpec moreKeySpec); - abstract boolean equalsTo(final ExpectedKeyOutput output); - abstract boolean equalsTo(final ExpectedKeyVisual visual); + abstract boolean hasSameKeyVisual(final String text); + abstract boolean hasSameKeyVisual(final Key key); + abstract boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec); + abstract boolean hasSameKeyVisual(final ExpectedKeyOutput output); + abstract boolean hasSameKeyVisual(final ExpectedKeyVisual visual); /** * This class represents an integer icon id. @@ -55,6 +57,16 @@ abstract class ExpectedKeyVisual { } @Override + public int getIconId() { + return mIconId; + } + + @Override + public String getLabel() { + return null; + } + + @Override ExpectedKeyVisual toUpperCase(final Locale locale) { return this; } @@ -65,27 +77,32 @@ abstract class ExpectedKeyVisual { } @Override - boolean equalsTo(final String text) { + boolean hasSameKeyVisual(final String text) { return false; } @Override - boolean equalsTo(final Key key) { - return mIconId == key.getIconId(); + boolean hasSameKeyVisual(final Key key) { + // If the actual key has an icon as its visual, a label has to be null. + // See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams). + return mIconId == key.getIconId() && key.getLabel() == null; } @Override - boolean equalsTo(final MoreKeySpec moreKeySpec) { - return mIconId == moreKeySpec.mIconId; + boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) { + // If the actual more key has an icon as its visual, a label has to be null. + // See {@link KeySpecParser#getIconId(String)} and + // {@link KeySpecParser#getLabel(String)}. + return mIconId == moreKeySpec.mIconId && moreKeySpec.mLabel == null; } @Override - boolean equalsTo(final ExpectedKeyOutput output) { + boolean hasSameKeyVisual(final ExpectedKeyOutput output) { return false; } @Override - boolean equalsTo(final ExpectedKeyVisual visual) { + boolean hasSameKeyVisual(final ExpectedKeyVisual visual) { return (visual instanceof Icon) && mIconId == ((Icon)visual).mIconId; } @@ -101,7 +118,19 @@ abstract class ExpectedKeyVisual { private static class Label extends ExpectedKeyVisual { private final String mLabel; - Label(final String label) { mLabel = label; } + Label(final String label) { + mLabel = label; + } + + @Override + public int getIconId() { + return KeyboardIconsSet.ICON_UNDEFINED; + } + + @Override + public String getLabel() { + return mLabel; + } @Override ExpectedKeyVisual toUpperCase(final Locale locale) { @@ -114,27 +143,34 @@ abstract class ExpectedKeyVisual { } @Override - boolean equalsTo(final String text) { + boolean hasSameKeyVisual(final String text) { return mLabel.equals(text); } @Override - boolean equalsTo(final Key key) { - return mLabel.equals(key.getLabel()); + boolean hasSameKeyVisual(final Key key) { + // If the actual key has a label as its visual, an icon has to be undefined. + // See {@link KeyboardView#onDrawKeyTopVisuals(Key,Canvas,Paint,KeyDrawParams). + return mLabel.equals(key.getLabel()) + && key.getIconId() == KeyboardIconsSet.ICON_UNDEFINED; } @Override - boolean equalsTo(final MoreKeySpec moreKeySpec) { - return mLabel.equals(moreKeySpec.mLabel); + boolean hasSameKeyVisual(final MoreKeySpec moreKeySpec) { + // If the actual more key has a label as its visual, an icon has to be undefined. + // See {@link KeySpecParser#getIconId(String)} and + // {@link KeySpecParser#getLabel(String)}. + return mLabel.equals(moreKeySpec.mLabel) + && moreKeySpec.mIconId == KeyboardIconsSet.ICON_UNDEFINED; } @Override - boolean equalsTo(final ExpectedKeyOutput output) { - return output.equalsTo(mLabel); + boolean hasSameKeyVisual(final ExpectedKeyOutput output) { + return output.hasSameKeyOutput(mLabel); } @Override - boolean equalsTo(final ExpectedKeyVisual visual) { + boolean hasSameKeyVisual(final ExpectedKeyVisual visual) { return (visual instanceof Label) && mLabel.equals(((Label)visual).mLabel); } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java index 9b7de88ea..f5531c9e3 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java @@ -91,7 +91,7 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec ExpectedKey[] keys = getRowAt(row); for (int columnIndex = 0; columnIndex < keys.length; /* nothing */) { final ExpectedKey currentKey = keys[columnIndex]; - if (!currentKey.getVisual().equalsTo(visual)) { + if (!currentKey.getVisual().hasSameKeyVisual(visual)) { columnIndex++; continue; } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/DanishCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/DanishCustomizer.java new file mode 100644 index 000000000..2c5df6045 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/DanishCustomizer.java @@ -0,0 +1,113 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.Nordic; +import com.android.inputmethod.keyboard.layout.Symbols; +import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class DanishCustomizer extends EuroCustomizer { + public DanishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00E6") + .setMoreKeysOf("\u00E6", "\u00E4") + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00F8") + .setMoreKeysOf("\u00F8", "\u00F6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E1", "\u00E4", "\u00E0", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F3", "\u00F4", "\u00F2", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + .setMoreKeysOf("e", "\u00E9", "\u00EB") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00FB", "\u00F9", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + .setMoreKeysOf("i", "\u00ED", "\u00EF") + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u00DF", "\u015B", "\u0161") + // U+00F0: "ð" LATIN SMALL LETTER ETH + .setMoreKeysOf("d", "\u00F0") + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u0142") + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u00F1", "\u0144"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/EstonianEECustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/EstonianEECustomizer.java new file mode 100644 index 000000000..d0b87726f --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/EstonianEECustomizer.java @@ -0,0 +1,170 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; +import com.android.inputmethod.keyboard.layout.Nordic; +import com.android.inputmethod.keyboard.layout.Symbols; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class EstonianEECustomizer extends EuroCustomizer { + public EstonianEECustomizer(final Locale locale) { + super(locale); + } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00FC") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6", "\u00F5") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u00E5", + "\u00E6", "\u0105"); + } + + protected void setMoreKeysOfI(final ExpectedKeyboardBuilder builder, final int elementId) { + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + if (elementId == KeyboardId.ELEMENT_ALPHABET) { + builder.setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF", "\u0131"); + } else { + // The upper-case letter of "ı" in Estonian locale is "I". It should be omitted + // from the more keys of "I". + builder.setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF"); + } + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", "\u0151", + "\u00F8"); + } + + protected void setMoreKeysOfU(final ExpectedKeyboardBuilder builder) { + builder + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", "\u016F", + "\u0171"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder, + final int elementId) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfI(builder, elementId); + setMoreKeysOfO(builder); + setMoreKeysOfU(builder); + return builder + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + .setMoreKeysOf("e", + "\u0113", "\u00E8", "\u0117", "\u00E9", "\u00EA", "\u00EB", "\u0119", + "\u011B") + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + .setMoreKeysOf("r", "\u0157", "\u0159", "\u0155") + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + .setMoreKeysOf("t", "\u0163", "\u0165") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u010F") + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u0123", "\u011F") + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + .setMoreKeysOf("k", "\u0137") + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + .setMoreKeysOf("l", "\u013C", "\u0142", "\u013A", "\u013E") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + .setMoreKeysOf("n", "\u0146", "\u00F1", "\u0144"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/FinnishCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/FinnishCustomizer.java new file mode 100644 index 000000000..912aec4a0 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/FinnishCustomizer.java @@ -0,0 +1,83 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.Nordic; +import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class FinnishCustomizer extends EuroCustomizer { + public FinnishCustomizer(final Locale locale) { super(locale); } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6","\u00F8") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4") + .setMoreKeysOf("\u00E4", "\u00E6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E6", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + .setMoreKeysOf("u", "\u00FC") + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017E", "\u017A", "\u017C"); + } +}
\ No newline at end of file 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 a22ed60ac..a8c4ac8fa 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java @@ -54,7 +54,8 @@ abstract class LayoutTestsBase extends KeyboardLayoutSetTestsBase { + (isPhone() ? "phone" : "tablet"); // TODO: Test with language switch key enabled and disabled. mKeyboardLayoutSet = createKeyboardLayoutSet(mSubtype, null /* editorInfo */, - true /* voiceInputKeyEnabled */, true /* languageSwitchKeyEnabled */); + true /* voiceInputKeyEnabled */, true /* languageSwitchKeyEnabled */, + false /* splitLayoutEnabled */); } @Override diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/NorwegianCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/NorwegianCustomizer.java new file mode 100644 index 000000000..4be7a57c5 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/NorwegianCustomizer.java @@ -0,0 +1,96 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.Nordic; +import com.android.inputmethod.keyboard.layout.Symbols; +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class NorwegianCustomizer extends LayoutCustomizer { + public NorwegianCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } + + @Override + public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F8") + .setMoreKeysOf("\u00F8", "\u00F6") + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E6") + .setMoreKeysOf("\u00E6", "\u00E4"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E4", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u0101"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + .setMoreKeysOf("e", + "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/SerbianLatinCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/SerbianLatinCustomizer.java new file mode 100644 index 000000000..3660ce4b7 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/SerbianLatinCustomizer.java @@ -0,0 +1,82 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.SerbianQwertz; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class SerbianLatinCustomizer extends LayoutCustomizer { + public SerbianLatinCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS : LayoutBase.EXCLAMATION_AND_QUESTION_MARKS; + } + + protected void setSerbianKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW1_11, "\u0161") + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW2_10, "\u010D") + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .replaceKeyOfLabel(SerbianQwertz.ROW2_11, "\u0107") + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .replaceKeyOfLabel(SerbianQwertz.ROW3_8, "\u0111") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .replaceKeyOfLabel(SerbianQwertz.ROW3_9, "\u017E"); + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfS(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "š" key. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfC(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "č" and "ć" keys. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfD(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "đ" key. + } + + @SuppressWarnings("unused") + protected void setMoreKeysOfZ(final ExpectedKeyboardBuilder builder) { + // Serbian QWERTZ has a dedicated "ž" key. + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setSerbianKeys(builder); + setMoreKeysOfS(builder); + setMoreKeysOfC(builder); + setMoreKeysOfD(builder); + setMoreKeysOfZ(builder); + return builder + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + .setMoreKeysOf("e", "\u00E8") + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + .setMoreKeysOf("i", "\u00EC"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/SwedishCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/SwedishCustomizer.java new file mode 100644 index 000000000..af4a971bd --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/SwedishCustomizer.java @@ -0,0 +1,145 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.Nordic; +import com.android.inputmethod.keyboard.layout.Symbols; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +class SwedishCustomizer extends LayoutCustomizer { + private final LayoutCustomizer mEuroCustomizer; + + public SwedishCustomizer(final Locale locale) { + super(locale); + mEuroCustomizer = new EuroCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { + return mEuroCustomizer.getCurrencyKey(); + } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mEuroCustomizer.getOtherCurrencyKeys(); + } + + @Override + public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } + + @Override + public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } + + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + .replaceKeyOfLabel(Nordic.ROW2_10, "\u00F6") + .setMoreKeysOf("\u00F6", "\u00F8", "\u0153") + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4") + .setMoreKeysOf("\u00E4", "\u00E6"); + } + + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + .setMoreKeysOf("a", "\u00E6", "\u00E1", "\u00E0", "\u00E2", "\u0105", "\u00E3"); + } + + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u0153", "\u00F3", "\u00F2", "\u00F4", "\u00F5", + "\u014D"); + } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + setNordicKeys(builder); + setMoreKeysOfA(builder); + setMoreKeysOfO(builder); + return builder + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + .setMoreKeysOf("e", "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119") + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + .setMoreKeysOf("r", "\u0159") + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+00FE: "þ" LATIN SMALL LETTER THORN + .setMoreKeysOf("t", "\u0165", "\u00FE") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + .setMoreKeysOf("y", "\u00FD", "\u00FF") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FA", "\u00F9", "\u00FB", "\u016B") + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + .setMoreKeysOf("i", "\u00ED", "\u00EC", "\u00EE", "\u00EF") + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + .setMoreKeysOf("s", "\u015B", "\u0161", "\u015F", "\u00DF") + // U+00F0: "ð" LATIN SMALL LETTER ETH + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + .setMoreKeysOf("d", "\u00F0", "\u010F") + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + .setMoreKeysOf("l", "\u0142") + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + .setMoreKeysOf("z", "\u017A", "\u017E", "\u017C") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + .setMoreKeysOf("n", "\u0144", "\u00F1", "\u0148"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java index f5317e269..8e0e2bbbd 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsAzerbaijaniAZ.java @@ -19,9 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; import com.android.inputmethod.keyboard.layout.Qwerty; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -31,58 +29,8 @@ import java.util.Locale; @SmallTest public final class TestsAzerbaijaniAZ extends LayoutTestsBase { private static final Locale LOCALE = new Locale("az", "AZ"); - private static final LayoutBase LAYOUT = new Qwerty(new AzerbaijaniAZCustomizer(LOCALE)); + private static final LayoutBase LAYOUT = new Qwerty(new TurkicCustomizer(LOCALE)); @Override LayoutBase getLayout() { return LAYOUT; } - - private static final class AzerbaijaniAZCustomizer extends LayoutCustomizer { - public AzerbaijaniAZCustomizer(final Locale locale) { super(locale); } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+0259: "ə" LATIN SMALL LETTER SCHWA - .setMoreKeysOf("e", "\u0259") - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") - // U+0131: "ı" LATIN SMALL LETTER DOTLESS I - // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX - // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE - // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK - // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON - .setMoreKeysOf("i", - "\u0131", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", - "\u00F6", "\u00F4", "\u0153", "\u00F2", "\u00F3", "\u00F5", "\u00F8", - "\u014D") - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - .setMoreKeysOf("a", "\u00E2") - // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - .setMoreKeysOf("s", "\u015F", "\u00DF", "\u015B", "\u0161") - // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA - // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE - // U+010D: "č" LATIN SMALL LETTER C WITH CARON - .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") - // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE - .setMoreKeysOf("g", "\u011F"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanish.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanish.java index 85c63a128..bf43e5296 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanish.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanish.java @@ -19,11 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; import com.android.inputmethod.keyboard.layout.Nordic; -import com.android.inputmethod.keyboard.layout.Symbols; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -37,73 +33,4 @@ public final class TestsDanish extends LayoutTestsBase { @Override LayoutBase getLayout() { return LAYOUT; } - - private static class DanishCustomizer extends EuroCustomizer { - public DanishCustomizer(final Locale locale) { super(locale); } - - @Override - public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } - - @Override - public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } - - @Override - public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } - - @Override - public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE - // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS - .setMoreKeysOf("e", "\u00E9", "\u00EB") - // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE - // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS - .setMoreKeysOf("y", "\u00FD", "\u00FF") - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - .setMoreKeysOf("u", "\u00FA", "\u00FC", "\u00FB", "\u00F9", "\u016B") - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE - // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - .setMoreKeysOf("i", "\u00ED", "\u00EF") - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", "\u00F3", "\u00F4", "\u00F2", "\u00F5", "\u0153", "\u014D") - // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE - .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") - // U+00E6: "æ" LATIN SMALL LETTER AE - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW2_10, key("\u00E6", moreKey("\u00E4"))) - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW2_11, key("\u00F8", moreKey("\u00F6"))) - // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON - .setMoreKeysOf("a", "\u00E1", "\u00E4", "\u00E0", "\u00E2", "\u00E3", "\u0101") - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - .setMoreKeysOf("s", "\u00DF", "\u015B", "\u0161") - // U+00F0: "ð" LATIN SMALL LETTER ETH - .setMoreKeysOf("d", "\u00F0") - // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE - .setMoreKeysOf("l", "\u0142") - // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE - // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE - .setMoreKeysOf("n", "\u00F1", "\u0144"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java new file mode 100644 index 000000000..886b3de7e --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDanishQwertz.java @@ -0,0 +1,78 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.Qwertz; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * da: Danish/qwertz + */ +@SmallTest +public final class TestsDanishQwertz extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("da"); + private static final LayoutBase LAYOUT = new Qwertz(new DanishQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class DanishQwertyCustomizer extends DanishCustomizer { + public DanishQwertyCustomizer(final Locale locale) { + super(locale); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTZ layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E5", "\u00E6", "\u00E1", "\u00E4", "\u00E0", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F6", "\u00F3", "\u00F4", "\u00F2", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java index 37ca09238..b25b84674 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakEmail.java @@ -44,12 +44,13 @@ public class TestsDvorakEmail extends LayoutTestsBase { @Override protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, - final boolean languageSwitchKeyEnabled) { + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final EditorInfo emailField = new EditorInfo(); emailField.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; return super.createKeyboardLayoutSet( - subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled); + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); } private static class DvorakEmailCustomizer extends EnglishDvorakCustomizer { diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java index 3bcae0ce4..ba22f375d 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsDvorakUrl.java @@ -44,12 +44,13 @@ public class TestsDvorakUrl extends LayoutTestsBase { @Override protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, - final boolean languageSwitchKeyEnabled) { + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final EditorInfo emailField = new EditorInfo(); emailField.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; return super.createKeyboardLayoutSet( - subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled); + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); } private static class DvorakUrlCustomizer extends EnglishDvorakCustomizer { diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEE.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEE.java index 865e9ea17..28c2eb301 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEE.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEE.java @@ -19,11 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; import com.android.inputmethod.keyboard.layout.Nordic; -import com.android.inputmethod.keyboard.layout.Symbols; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -37,121 +33,4 @@ public final class TestsEstonianEE extends LayoutTestsBase { @Override LayoutBase getLayout() { return LAYOUT; } - - private static class EstonianEECustomizer extends EuroCustomizer { - public EstonianEECustomizer(final Locale locale) { - super(locale); - } - - @Override - public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_R9L; } - - @Override - public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_R9L; } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON - // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE - // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE - // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE - // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX - // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS - // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK - // U+011B: "ě" LATIN SMALL LETTER E WITH CARON - .setMoreKeysOf("e", - "\u0113", "\u00E8", "\u0117", "\u00E9", "\u00EA", "\u00EB", "\u0119", - "\u011B") - // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA - // U+0159: "ř" LATIN SMALL LETTER R WITH CARON - // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE - .setMoreKeysOf("r", "\u0157", "\u0159", "\u0155") - // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA - // U+0165: "ť" LATIN SMALL LETTER T WITH CARON - .setMoreKeysOf("t", "\u0163", "\u0165") - // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE - // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS - .setMoreKeysOf("y", "\u00FD", "\u00FF") - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE - // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE - .setMoreKeysOf("u", - "\u00FC", "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", "\u016F", - "\u0171") - // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON - // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE - // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX - // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - // U+0131: "ı" LATIN SMALL LETTER DOTLESS I - .setMoreKeysOf("i", - "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF", "\u0131") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - .setMoreKeysOf("o", - "\u00F6", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", "\u0151", - "\u00F8") - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW1_11, "\u00FC") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - .replaceKeyOfLabel(Nordic.ROW2_10, key("\u00F6", moreKey("\u00F5"))) - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW2_11, "\u00E4") - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON - // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE - // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE - // U+00E6: "æ" LATIN SMALL LETTER AE - // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK - .setMoreKeysOf("a", - "\u00E4", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u00E5", - "\u00E6", "\u0105") - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA - .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B", "\u015F") - // U+010F: "ď" LATIN SMALL LETTER D WITH CARON - .setMoreKeysOf("d", "\u010F") - // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA - // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE - .setMoreKeysOf("g", "\u0123", "\u011F") - // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA - .setMoreKeysOf("k", "\u0137") - // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA - // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE - // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE - // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON - .setMoreKeysOf("l", "\u013C", "\u0142", "\u013A", "\u013E") - // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON - // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE - // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE - .setMoreKeysOf("z", "\u017E", "\u017C", "\u017A") - // U+010D: "č" LATIN SMALL LETTER C WITH CARON - // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA - // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE - .setMoreKeysOf("c", "\u010D", "\u00E7", "\u0107") - // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA - // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE - // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE - .setMoreKeysOf("n", "\u0146", "\u00F1", "\u0144"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java new file mode 100644 index 000000000..ab8960b66 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEstonianEEQwerty.java @@ -0,0 +1,110 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.Qwerty; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * et_EE: Estonian (Estonia)/qwerty + */ +@SmallTest +public final class TestsEstonianEEQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("et", "EE"); + private static final LayoutBase LAYOUT = new Qwerty(new EstonianEEQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EstonianEEQwertyCustomizer extends EstonianEECustomizer { + public EstonianEEQwertyCustomizer(final Locale locale) { + super(locale); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + .setMoreKeysOf("a", "\u00E4", "\u0101", "\u00E0", "\u00E1", "\u00E2", "\u00E3", + "\u00E5", "\u00E6", "\u0105"); + } + + @Override + protected void setMoreKeysOfI(final ExpectedKeyboardBuilder builder, final int elementId) { + // TODO: The upper-case letter of "ı" in Estonian locale is "I". It should be omitted + // from the more keys of "I". + builder + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + .setMoreKeysOf("i", + "\u012B", "\u00EC", "\u012F", "\u00ED", "\u00EE", "\u00EF", "\u0131"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + .setMoreKeysOf("o", "\u00F6", "\u00F5", "\u00F2", "\u00F3", "\u00F4", "\u0153", + "\u0151", "\u00F8"); + } + + @Override + protected void setMoreKeysOfU(final ExpectedKeyboardBuilder builder) { + builder + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + .setMoreKeysOf("u", "\u00FC", "\u016B", "\u0173", "\u00F9", "\u00FA", "\u00FB", + "\u016F", "\u0171"); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnish.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnish.java index ff32da117..05def96be 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnish.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnish.java @@ -19,9 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; import com.android.inputmethod.keyboard.layout.Nordic; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -35,47 +33,4 @@ public final class TestsFinnish extends LayoutTestsBase { @Override LayoutBase getLayout() { return LAYOUT; } - - private static class FinnishCustomizer extends EuroCustomizer { - public FinnishCustomizer(final Locale locale) { super(locale); } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - .setMoreKeysOf("u", "\u00FC") - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", - "\u00F8", "\u00F4", "\u00F2", "\u00F3", "\u00F5", "\u0153", "\u014D") - // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE - .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - .replaceKeyOfLabel(Nordic.ROW2_10, key("\u00F6", moreKey("\u00F8"))) - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - // U+00E6: "æ" LATIN SMALL LETTER AE - .replaceKeyOfLabel(Nordic.ROW2_11, key("\u00E4", moreKey("\u00E6"))) - // U+00E6: "æ" LATIN SMALL LETTER AE - // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE - // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON - .setMoreKeysOf("a", "\u00E6", "\u00E0", "\u00E1", "\u00E2", "\u00E3", "\u0101") - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - .setMoreKeysOf("s", "\u0161", "\u00DF", "\u015B") - // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON - // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE - // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE - .setMoreKeysOf("z", "\u017E", "\u017A", "\u017C"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java new file mode 100644 index 000000000..c3df9d115 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsFinnishQwerty.java @@ -0,0 +1,78 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.Qwerty; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * fi: Finnish/qwerty + */ +@SmallTest +public final class TestsFinnishQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("fi"); + private static final LayoutBase LAYOUT = new Qwerty(new FinnishQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class FinnishQwertyCustomizer extends FinnishCustomizer { + public FinnishQwertyCustomizer(final Locale locale) { + super(locale); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E4", "\u00E5", "\u00E6", "\u00E0", "\u00E1", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F8", "\u00F4", "\u00F2", "\u00F3", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsHinglish.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsHinglish.java new file mode 100644 index 000000000..2a6e46f96 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsHinglish.java @@ -0,0 +1,56 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.Qwerty; +import com.android.inputmethod.keyboard.layout.Symbols; +import com.android.inputmethod.keyboard.layout.SymbolsShifted; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/* + * hi_ZZ: Hinglish/qwerty + */ +@SmallTest +public final class TestsHinglish extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("hi", "ZZ"); + private static final LayoutBase LAYOUT = new Qwerty(new HinglishCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class HinglishCustomizer extends LayoutCustomizer { + public HinglishCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return SymbolsShifted.CURRENCIES_OTHER_GENERIC; + } + + // U+20B9: "₹" INDIAN RUPEE SIGN + private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9", + Symbols.CURRENCY_GENERIC_MORE_KEYS); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsMyanmarMM.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsMyanmarMM.java index a0bd50c9a..e6d3b3b92 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsMyanmarMM.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsMyanmarMM.java @@ -16,7 +16,7 @@ package com.android.inputmethod.keyboard.layout.tests; -import android.test.suitebuilder.annotation.Suppress; +import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; import com.android.inputmethod.keyboard.layout.Myanmar; @@ -27,7 +27,7 @@ import java.util.Locale; /** * my_MM: Myanmar (Myanmar)/myanmar */ -@Suppress +@SmallTest public final class TestsMyanmarMM extends LayoutTestsBase { private static final Locale LOCALE = new Locale("my", "MM"); private static final LayoutBase LAYOUT = new Myanmar(new MyanmarCustomizer(LOCALE)); diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegian.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegian.java index 5d220dfa1..6c1921ab4 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegian.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegian.java @@ -19,11 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; import com.android.inputmethod.keyboard.layout.Nordic; -import com.android.inputmethod.keyboard.layout.Symbols; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -37,58 +33,4 @@ public final class TestsNorwegian extends LayoutTestsBase { @Override LayoutBase getLayout() { return LAYOUT; } - - private static class NorwegianCustomizer extends LayoutCustomizer { - public NorwegianCustomizer(final Locale locale) { super(locale); } - - @Override - public ExpectedKey[] getDoubleQuoteMoreKeys() { return Symbols.DOUBLE_QUOTES_L9R; } - - @Override - public ExpectedKey[] getSingleQuoteMoreKeys() { return Symbols.SINGLE_QUOTES_L9R; } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE - // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE - // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX - // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS - // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK - // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE - // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON - .setMoreKeysOf("e", - "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119", "\u0117", "\u0113") - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", - "\u00F4", "\u00F2", "\u00F3", "\u00F6", "\u00F5", "\u0153", "\u014D") - // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE - .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW2_10, key("\u00F8", moreKey("\u00F6"))) - // U+00E6: "æ" LATIN SMALL LETTER AE - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - .replaceKeyOfLabel(Nordic.ROW2_11, key("\u00E6", moreKey("\u00E4"))) - // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON - .setMoreKeysOf("a", "\u00E0", "\u00E4", "\u00E1", "\u00E2", "\u00E3", "\u0101"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java new file mode 100644 index 000000000..a481796ed --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsNorwegianColemak.java @@ -0,0 +1,79 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.Colemak; +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * nb: Norwegian Bokmål/colemak + */ +@SmallTest +public final class TestsNorwegianColemak extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("nb"); + private static final LayoutBase LAYOUT = new Colemak(new NorwegianColemakCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class NorwegianColemakCustomizer extends NorwegianCustomizer { + public NorwegianColemakCustomizer(final Locale locale) { + super(locale); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // Colemak layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + .setMoreKeysOf("a", "\u00E5", "\u00E6", "\u00E4", "\u00E0", "\u00E1", "\u00E2", + "\u00E3", "\u0101"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F8", "\u00F6", "\u00F4", "\u00F2", "\u00F3", "\u00F5", + "\u0153", "\u014D"); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java index 8563d6933..f89863279 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyEmail.java @@ -42,12 +42,13 @@ public class TestsQwertyEmail extends LayoutTestsBase { @Override protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, - final boolean languageSwitchKeyEnabled) { + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final EditorInfo emailField = new EditorInfo(); emailField.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; return super.createKeyboardLayoutSet( - subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled); + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); } private static class EnglishEmailCustomizer extends EnglishCustomizer { diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java index 1c1a2bbbd..0b69c7bc2 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsQwertyUrl.java @@ -42,12 +42,13 @@ public class TestsQwertyUrl extends LayoutTestsBase { @Override protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, - final boolean languageSwitchKeyEnabled) { + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final EditorInfo emailField = new EditorInfo(); emailField.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; return super.createKeyboardLayoutSet( - subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled); + subtype, emailField, voiceInputKeyEnabled, languageSwitchKeyEnabled, + splitLayoutEnabled); } private static class EnglishUrlCustomizer extends EnglishCustomizer { diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsRomanian.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsRomanian.java index 0207f1c22..d7b858ea5 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsRomanian.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsRomanian.java @@ -59,9 +59,9 @@ public final class TestsRomanian extends LayoutTestsBase { // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON .setMoreKeysOf("i", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS @@ -69,7 +69,7 @@ public final class TestsRomanian extends LayoutTestsBase { // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON .setMoreKeysOf("a", - "\u00E2", "\u00E3", "\u0103", "\u00E0", "\u00E1", "\u00E4", "\u00E6", + "\u0103", "\u00E2", "\u00E3", "\u00E0", "\u00E1", "\u00E4", "\u00E6", "\u00E5", "\u0101") // U+0219: "ș" LATIN SMALL LETTER S WITH COMMA BELOW // U+00DF: "ß" LATIN SMALL LETTER SHARP S diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java new file mode 100644 index 000000000..70f4bcefd --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatin.java @@ -0,0 +1,36 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.SerbianQwertz; + +import java.util.Locale; + +/** + * sr_ZZ: Serbian (Latin)/serbian_qwertz + */ +@SmallTest +public final class TestsSerbianLatin extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sr", "ZZ"); + private static final LayoutBase LAYOUT = new SerbianQwertz(new SerbianLatinCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java new file mode 100644 index 000000000..d8ef51b45 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSerbianLatinQwerty.java @@ -0,0 +1,88 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.Qwerty; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sr_ZZ: Serbian (Latin)/qwerty + */ +@SmallTest +public final class TestsSerbianLatinQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sr", "ZZ"); + private static final LayoutBase LAYOUT = new Qwerty(new SerbianLatinQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SerbianLatinQwertyCustomizer extends SerbianLatinCustomizer { + public SerbianLatinQwertyCustomizer(final Locale locale) { + super(locale); + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return isPhone ? EMPTY_KEYS + : joinKeys(LayoutBase.EXCLAMATION_AND_QUESTION_MARKS, LayoutBase.SHIFT_KEY); + } + + @Override + protected void setSerbianKeys(final ExpectedKeyboardBuilder builder) { + // QWERTY layout doesn't have Serbian Latin Keys. + } + + @Override + protected void setMoreKeysOfS(final ExpectedKeyboardBuilder builder) { + builder + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u0161") + .setAdditionalMoreKeysPositionOf("s", 2); + } + + @Override + protected void setMoreKeysOfC(final ExpectedKeyboardBuilder builder) { + builder + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + .setMoreKeysOf("c", "\u010D", "\u0107") + .setAdditionalMoreKeysPositionOf("c", 3); + } + + @Override + protected void setMoreKeysOfD(final ExpectedKeyboardBuilder builder) { + builder + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + .setMoreKeysOf("d", "\u0111") + .setAdditionalMoreKeysPositionOf("d", 2); + } + + @Override + protected void setMoreKeysOfZ(final ExpectedKeyboardBuilder builder) { + builder + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017E") + .setAdditionalMoreKeysPositionOf("z", 2); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java new file mode 100644 index 000000000..b3340aace --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSplitLayoutQwertyEnglishUS.java @@ -0,0 +1,64 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.KeyboardLayoutSet; +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.Qwerty; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; + +import java.util.Locale; + +/** + * en_US: English (United States)/qwerty - split layout + */ +@SmallTest +public class TestsSplitLayoutQwertyEnglishUS extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("en", "US"); + private static final LayoutBase LAYOUT = new Qwerty(new EnglishSplitCustomizer(LOCALE)); + + @Override + protected KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype, + final EditorInfo editorInfo, final boolean voiceInputKeyEnabled, + final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { + return super.createKeyboardLayoutSet(subtype, editorInfo, voiceInputKeyEnabled, + languageSwitchKeyEnabled, true /* splitLayoutEnabled */); + } + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class EnglishSplitCustomizer extends EnglishCustomizer { + EnglishSplitCustomizer(Locale locale) { + super(locale); + } + + @Override + public ExpectedKey[] getSpaceKeys(final boolean isPhone) { + if (isPhone) { + return super.getSpaceKeys(isPhone); + } else { + return LayoutBase.joinKeys( + LayoutBase.LANGUAGE_SWITCH_KEY, LayoutBase.SPACE_KEY, LayoutBase.SPACE_KEY); + } + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedish.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedish.java index 9b58914a2..79cb3dcc7 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedish.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedish.java @@ -19,11 +19,7 @@ package com.android.inputmethod.keyboard.layout.tests; import android.test.suitebuilder.annotation.SmallTest; import com.android.inputmethod.keyboard.layout.LayoutBase; -import com.android.inputmethod.keyboard.layout.LayoutBase.EuroCustomizer; import com.android.inputmethod.keyboard.layout.Nordic; -import com.android.inputmethod.keyboard.layout.Symbols; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; -import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; import java.util.Locale; @@ -37,88 +33,4 @@ public final class TestsSwedish extends LayoutTestsBase { @Override LayoutBase getLayout() { return LAYOUT; } - - private static class SwedishCustomizer extends EuroCustomizer { - public SwedishCustomizer(final Locale locale) { super(locale); } - - @Override - public ExpectedKey[] getDoubleAngleQuoteKeys() { return Symbols.DOUBLE_ANGLE_QUOTES_RL; } - - @Override - public ExpectedKey[] getSingleAngleQuoteKeys() { return Symbols.SINGLE_ANGLE_QUOTES_RL; } - - @Override - public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE - // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE - // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX - // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS - // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK - .setMoreKeysOf("e", "\u00E9", "\u00E8", "\u00EA", "\u00EB", "\u0119") - // U+0159: "ř" LATIN SMALL LETTER R WITH CARON - .setMoreKeysOf("r", "\u0159") - // U+0165: "ť" LATIN SMALL LETTER T WITH CARON - // U+00FE: "þ" LATIN SMALL LETTER THORN - .setMoreKeysOf("t", "\u0165", "\u00FE") - // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE - // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS - .setMoreKeysOf("y", "\u00FD", "\u00FF") - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - .setMoreKeysOf("u", "\u00FC", "\u00FA", "\u00F9", "\u00FB", "\u016B") - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE - // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX - // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - .setMoreKeysOf("i", "\u00ED", "\u00EC", "\u00EE", "\u00EF") - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", "\u00F3", "\u00F2", "\u00F4", "\u00F5", "\u014D") - // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE - .replaceKeyOfLabel(Nordic.ROW1_11, "\u00E5") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+0153: "œ" LATIN SMALL LIGATURE OE - .replaceKeyOfLabel(Nordic.ROW2_10, - key("\u00F6", joinMoreKeys("\u00F8", "\u0153"))) - // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS - // U+00E6: "æ" LATIN SMALL LETTER AE - .replaceKeyOfLabel(Nordic.ROW2_11, key("\u00E4", moreKey("\u00E6"))) - // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE - // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK - // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE - .setMoreKeysOf("a", "\u00E1", "\u00E0", "\u00E2", "\u0105", "\u00E3") - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - .setMoreKeysOf("s", "\u015B", "\u0161", "\u015F", "\u00DF") - // U+00F0: "ð" LATIN SMALL LETTER ETH - // U+010F: "ď" LATIN SMALL LETTER D WITH CARON - .setMoreKeysOf("d", "\u00F0", "\u010F") - // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE - .setMoreKeysOf("l", "\u0142") - // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE - // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON - // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE - .setMoreKeysOf("z", "\u017A", "\u017E", "\u017C") - // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA - // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE - // U+010D: "č" LATIN SMALL LETTER C WITH CARON - .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") - // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE - // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE - // U+0148: "ň" LATIN SMALL LETTER N WITH CARON - .setMoreKeysOf("n", "\u0144", "\u00F1", "\u0148"); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java new file mode 100644 index 000000000..ed74d6d74 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsSwedishPcQwerty.java @@ -0,0 +1,120 @@ +/* + * 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.layout.tests; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.keyboard.layout.LayoutBase; +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.PcQwerty; +import com.android.inputmethod.keyboard.layout.PcQwerty.PcQwertyCustomizer; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKey; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * sv: Swedish/pcqwerty + */ +@SmallTest +public final class TestsSwedishPcQwerty extends LayoutTestsBase { + private static final Locale LOCALE = new Locale("sv"); + private static final LayoutBase LAYOUT = new PcQwerty(new SwedishPcQwertyCustomizer(LOCALE)); + + @Override + LayoutBase getLayout() { return LAYOUT; } + + private static class SwedishPcQwertyCustomizer extends SwedishCustomizer { + private final LayoutCustomizer mPcQwertyCustomizer; + + public SwedishPcQwertyCustomizer(final Locale locale) { + super(locale); + mPcQwertyCustomizer = new PcQwertyCustomizer(locale); + } + + @Override + public ExpectedKey getCurrencyKey() { + return mPcQwertyCustomizer.getCurrencyKey(); + } + + @Override + public ExpectedKey[] getOtherCurrencyKeys() { + return mPcQwertyCustomizer.getOtherCurrencyKeys(); + } + + @Override + public int getNumberOfRows() { + return mPcQwertyCustomizer.getNumberOfRows(); + } + + @Override + public ExpectedKey[] getLeftShiftKeys(final boolean isPhone) { + return mPcQwertyCustomizer.getLeftShiftKeys(isPhone); + } + + @Override + public ExpectedKey[] getRightShiftKeys(final boolean isPhone) { + return mPcQwertyCustomizer.getRightShiftKeys(isPhone); + } + + @Override + public ExpectedKey[] getKeysLeftToSpacebar(final boolean isPhone) { + return mPcQwertyCustomizer.getKeysLeftToSpacebar(isPhone); + } + + @Override + public ExpectedKey[] getKeysRightToSpacebar(final boolean isPhone) { + return mPcQwertyCustomizer.getKeysRightToSpacebar(isPhone); + } + + @Override + protected void setNordicKeys(final ExpectedKeyboardBuilder builder) { + // PC QWERTY layout doesn't have Nordic keys. + } + + @Override + protected void setMoreKeysOfA(final ExpectedKeyboardBuilder builder) { + builder + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + .setMoreKeysOf("a", "\u00E4", "\u00E5", "\u00E6", "\u00E1", "\u00E0", "\u00E2", + "\u0105", "\u00E3"); + } + + @Override + protected void setMoreKeysOfO(final ExpectedKeyboardBuilder builder) { + builder + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", "\u00F6", "\u00F8", "\u0153", "\u00F3", "\u00F2", "\u00F4", + "\u00F5", "\u014D"); + } + + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTurkish.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTurkish.java index b35f8850a..bf427cdb0 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTurkish.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsTurkish.java @@ -37,50 +37,16 @@ public final class TestsTurkish extends LayoutTestsBase { LayoutBase getLayout() { return LAYOUT; } private static class TurkishCustomizer extends EuroCustomizer { - public TurkishCustomizer(final Locale locale) { super(locale); } + private final TurkicCustomizer mTurkicCustomizer; + + public TurkishCustomizer(final Locale locale) { + super(locale); + mTurkicCustomizer = new TurkicCustomizer(locale); + } @Override public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { - return builder - // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS - // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX - // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE - // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE - // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON - .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") - // U+0131: "ı" LATIN SMALL LETTER DOTLESS I - // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX - // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS - // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE - // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE - // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK - // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON - .setMoreKeysOf("i", - "\u0131", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") - // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS - // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX - // U+0153: "œ" LATIN SMALL LIGATURE OE - // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE - // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE - // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE - // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE - // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON - .setMoreKeysOf("o", - "\u00F6", "\u00F4", "\u0153", "\u00F2", "\u00F3", "\u00F5", "\u00F8", - "\u014D") - // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX - .setMoreKeysOf("a", "\u00E2") - // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA - // U+00DF: "ß" LATIN SMALL LETTER SHARP S - // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE - // U+0161: "š" LATIN SMALL LETTER S WITH CARON - .setMoreKeysOf("s", "\u015F", "\u00DF", "\u015B", "\u0161") - // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE - .setMoreKeysOf("g", "\u011F") - // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA - // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE - // U+010D: "č" LATIN SMALL LETTER C WITH CARON - .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D"); + return mTurkicCustomizer.setAccentedLetters(builder); } } } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TurkicCustomizer.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TurkicCustomizer.java new file mode 100644 index 000000000..1a98f6ccf --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TurkicCustomizer.java @@ -0,0 +1,85 @@ +/* + * 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.layout.tests; + +import com.android.inputmethod.keyboard.layout.LayoutBase.LayoutCustomizer; +import com.android.inputmethod.keyboard.layout.expected.ExpectedKeyboardBuilder; + +import java.util.Locale; + +/** + * Turkic languages layout customizer. + */ +class TurkicCustomizer extends LayoutCustomizer { + public TurkicCustomizer(final Locale locale) { super(locale); } + + @Override + public ExpectedKeyboardBuilder setAccentedLetters(final ExpectedKeyboardBuilder builder) { + return builder + // U+0259: "ə" LATIN SMALL LETTER SCHWA + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + .setMoreKeysOf("e", "\u0259", "\u00E9") + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + .setMoreKeysOf("y", "\u00FD") + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + .setMoreKeysOf("u", "\u00FC", "\u00FB", "\u00F9", "\u00FA", "\u016B") + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + .setMoreKeysOf("i", + "\u0131", "\u00EE", "\u00EF", "\u00EC", "\u00ED", "\u012F", "\u012B") + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + .setMoreKeysOf("o", + "\u00F6", "\u00F4", "\u0153", "\u00F2", "\u00F3", "\u00F5", "\u00F8", + "\u014D") + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + .setMoreKeysOf("a", "\u00E2", "\u00E4", "\u00E1") + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + .setMoreKeysOf("s", "\u015F", "\u00DF", "\u015B", "\u0161") + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + .setMoreKeysOf("g", "\u011F") + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + .setMoreKeysOf("z", "\u017E") + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + .setMoreKeysOf("c", "\u00E7", "\u0107", "\u010D") + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + .setMoreKeysOf("n", "\u0148", "\u00F1"); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index ae184268c..8d5d6ccec 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -20,7 +20,7 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Pair; -import com.android.inputmethod.latin.PrevWordsInfo.WordInfo; +import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.CodePointUtils; import com.android.inputmethod.latin.makedict.DictDecoder; @@ -78,13 +78,13 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { private void addBigramWords(final BinaryDictionary binaryDictionary, final String word0, final String word1, final int probability) { - binaryDictionary.addNgramEntry(new PrevWordsInfo(new WordInfo(word0)), word1, probability, + binaryDictionary.addNgramEntry(new NgramContext(new WordInfo(word0)), word1, probability, mCurrentTime /* timestamp */); } private static boolean isValidBigram(final BinaryDictionary binaryDictionary, final String word0, final String word1) { - return binaryDictionary.isValidNgram(new PrevWordsInfo(new WordInfo(word0)), word1); + return binaryDictionary.isValidNgram(new NgramContext(new WordInfo(word0)), word1); } private void forcePassingShortTime(final BinaryDictionary binaryDictionary) { @@ -342,31 +342,31 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { } final int maxUnigramCount = Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.MAX_UNIGRAM_COUNT_QUERY)); + binaryDictionary.getPropertyForGettingStats(BinaryDictionary.MAX_UNIGRAM_COUNT_QUERY)); for (int i = 0; i < unigramTypedCount; i++) { final String word = words.get(random.nextInt(words.size())); addUnigramWord(binaryDictionary, word, DUMMY_PROBABILITY); if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { final int unigramCountBeforeGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)); while (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { forcePassingShortTime(binaryDictionary); } final int unigramCountAfterGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)); assertTrue(unigramCountBeforeGC > unigramCountAfterGC); } } - assertTrue(Integer.parseInt(binaryDictionary.getPropertyForTest( + assertTrue(Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)) > 0); - assertTrue(Integer.parseInt(binaryDictionary.getPropertyForTest( + assertTrue(Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)) <= maxUnigramCount); forcePassingLongTime(binaryDictionary); - assertEquals(0, Integer.parseInt(binaryDictionary.getPropertyForTest( + assertEquals(0, Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY))); } @@ -415,13 +415,13 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { } if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { final int unigramCountBeforeGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)); assertTrue(binaryDictionary.isValidWord(strong)); assertTrue(binaryDictionary.isValidWord(weak)); binaryDictionary.flushWithGC(); final int unigramCountAfterGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.UNIGRAM_COUNT_QUERY)); assertTrue(unigramCountBeforeGC > unigramCountAfterGC); assertFalse(binaryDictionary.isValidWord(weak)); @@ -477,7 +477,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { } final int maxBigramCount = Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.MAX_BIGRAM_COUNT_QUERY)); + binaryDictionary.getPropertyForGettingStats(BinaryDictionary.MAX_BIGRAM_COUNT_QUERY)); for (int i = 0; i < bigramTypedCount; ++i) { final Pair<String, String> bigram = bigrams.get(random.nextInt(bigrams.size())); addUnigramWord(binaryDictionary, bigram.first, DUMMY_PROBABILITY); @@ -486,24 +486,24 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { final int bigramCountBeforeGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)); while (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { forcePassingShortTime(binaryDictionary); } final int bigramCountAfterGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)); assertTrue(bigramCountBeforeGC > bigramCountAfterGC); } } - assertTrue(Integer.parseInt(binaryDictionary.getPropertyForTest( + assertTrue(Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)) > 0); - assertTrue(Integer.parseInt(binaryDictionary.getPropertyForTest( + assertTrue(Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)) <= maxBigramCount); forcePassingLongTime(binaryDictionary); - assertEquals(0, Integer.parseInt(binaryDictionary.getPropertyForTest( + assertEquals(0, Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY))); } @@ -574,11 +574,11 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { } if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { final int bigramCountBeforeGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)); binaryDictionary.flushWithGC(); final int bigramCountAfterGC = - Integer.parseInt(binaryDictionary.getPropertyForTest( + Integer.parseInt(binaryDictionary.getPropertyForGettingStats( BinaryDictionary.BIGRAM_COUNT_QUERY)); assertTrue(bigramCountBeforeGC > bigramCountAfterGC); assertTrue(isValidBigram(binaryDictionary, strong, target)); @@ -661,31 +661,63 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */, true /* isBeginningOfSentence */, true /* isNotAWord */, false /* isBlacklisted */, mCurrentTime); - final PrevWordsInfo prevWordsInfoStartOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE; + final NgramContext beginningOfSentenceContext = NgramContext.BEGINNING_OF_SENTENCE; addUnigramWord(binaryDictionary, "aaa", DUMMY_PROBABILITY); - binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", DUMMY_PROBABILITY, mCurrentTime); - assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa")); - binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY, + assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", DUMMY_PROBABILITY, mCurrentTime); addUnigramWord(binaryDictionary, "bbb", DUMMY_PROBABILITY); - binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", DUMMY_PROBABILITY, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "bbb", DUMMY_PROBABILITY, mCurrentTime); - assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa")); - assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb")); + assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); + assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "bbb")); forcePassingLongTime(binaryDictionary); - assertFalse(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa")); - assertFalse(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb")); + assertFalse(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); + assertFalse(binaryDictionary.isValidNgram(beginningOfSentenceContext, "bbb")); addUnigramWord(binaryDictionary, "aaa", DUMMY_PROBABILITY); - binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", DUMMY_PROBABILITY, mCurrentTime); addUnigramWord(binaryDictionary, "bbb", DUMMY_PROBABILITY); - binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", DUMMY_PROBABILITY, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "bbb", DUMMY_PROBABILITY, mCurrentTime); - assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa")); - assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb")); + assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "aaa")); + assertTrue(binaryDictionary.isValidNgram(beginningOfSentenceContext, "bbb")); + binaryDictionary.close(); + dictFile.delete(); + } + + public void testRemoveUnigrams() { + for (final int formatVersion : DICT_FORMAT_VERSIONS) { + testRemoveUnigrams(formatVersion); + } + } + + private void testRemoveUnigrams(final int formatVersion) { + final int unigramInputCount = 20; + setCurrentTimeForTestMode(mCurrentTime); + 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, "aaa", Dictionary.NOT_A_PROBABILITY); + assertFalse(binaryDictionary.isValidWord("aaa")); + for (int i = 0; i < unigramInputCount; i++) { + addUnigramWord(binaryDictionary, "aaa", Dictionary.NOT_A_PROBABILITY); + } + assertTrue(binaryDictionary.isValidWord("aaa")); + assertTrue(binaryDictionary.removeUnigramEntry("aaa")); + assertFalse(binaryDictionary.isValidWord("aaa")); + binaryDictionary.close(); dictFile.delete(); } diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index 6ba18d665..e6f00b668 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -21,7 +21,7 @@ import android.test.suitebuilder.annotation.LargeTest; import android.text.TextUtils; import android.util.Pair; -import com.android.inputmethod.latin.PrevWordsInfo.WordInfo; +import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.makedict.CodePointUtils; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.WeightedString; @@ -55,6 +55,10 @@ public class BinaryDictionaryTests extends AndroidTestCase { return formatVersion > FormatSpec.VERSION401; } + private static boolean supportsNgram(final int formatVersion) { + return formatVersion >= FormatSpec.VERSION4_DEV; + } + private File createEmptyDictionaryAndGetFile(final String dictId, final int formatVersion) throws IOException { if (formatVersion == FormatSpec.VERSION4 @@ -204,23 +208,45 @@ public class BinaryDictionaryTests extends AndroidTestCase { private static void addBigramWords(final BinaryDictionary binaryDictionary, final String word0, final String word1, final int probability) { - binaryDictionary.addNgramEntry(new PrevWordsInfo(new WordInfo(word0)), word1, probability, + binaryDictionary.addNgramEntry(new NgramContext(new WordInfo(word0)), word1, probability, + BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); + } + + private static void addTrigramEntry(final BinaryDictionary binaryDictionary, final String word0, + final String word1, final String word2, final int probability) { + final NgramContext ngramContext = + new NgramContext(new WordInfo[] { new WordInfo(word1), new WordInfo(word0) } ); + binaryDictionary.addNgramEntry(ngramContext, word2, probability, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); } private static boolean isValidBigram(final BinaryDictionary binaryDictionary, final String word0, final String word1) { - return binaryDictionary.isValidNgram(new PrevWordsInfo(new WordInfo(word0)), word1); + return binaryDictionary.isValidNgram(new NgramContext(new WordInfo(word0)), word1); } private static void removeBigramEntry(final BinaryDictionary binaryDictionary, final String word0, final String word1) { - binaryDictionary.removeNgramEntry(new PrevWordsInfo(new WordInfo(word0)), word1); + binaryDictionary.removeNgramEntry(new NgramContext(new WordInfo(word0)), word1); + } + + private static void removeTrigramEntry(final BinaryDictionary binaryDictionary, + final String word0, final String word1, final String word2) { + final NgramContext ngramContext = + new NgramContext(new WordInfo[] { new WordInfo(word1), new WordInfo(word0) } ); + binaryDictionary.removeNgramEntry(ngramContext, word2); } private static int getBigramProbability(final BinaryDictionary binaryDictionary, final String word0, final String word1) { - return binaryDictionary.getNgramProbability(new PrevWordsInfo(new WordInfo(word0)), word1); + return binaryDictionary.getNgramProbability(new NgramContext(new WordInfo(word0)), word1); + } + + private static int getTrigramProbability(final BinaryDictionary binaryDictionary, + final String word0, final String word1, final String word2) { + final NgramContext ngramContext = + new NgramContext(new WordInfo[] { new WordInfo(word1), new WordInfo(word0) } ); + return binaryDictionary.getNgramProbability(ngramContext, word2); } public void testAddUnigramWord() { @@ -500,6 +526,56 @@ public class BinaryDictionaryTests extends AndroidTestCase { dictFile.delete(); } + public void testAddTrigramWords() { + for (final int formatVersion : DICT_FORMAT_VERSIONS) { + if (supportsNgram(formatVersion)) { + testAddTrigramWords(formatVersion); + } + } + } + + private void testAddTrigramWords(final int formatVersion) { + File dictFile = null; + try { + dictFile = createEmptyDictionaryAndGetFile("TestBinaryDictionary", formatVersion); + } catch (IOException e) { + fail("IOException while writing an initial dictionary : " + e); + } + BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(), + 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, + Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); + + final int unigramProbability = 100; + final int trigramProbability = 150; + final int updatedTrigramProbability = 200; + addUnigramWord(binaryDictionary, "aaa", unigramProbability); + addUnigramWord(binaryDictionary, "abb", unigramProbability); + addUnigramWord(binaryDictionary, "bcc", unigramProbability); + + addBigramWords(binaryDictionary, "abb", "bcc", 10); + addBigramWords(binaryDictionary, "abb", "aaa", 10); + + addTrigramEntry(binaryDictionary, "aaa", "abb", "bcc", trigramProbability); + addTrigramEntry(binaryDictionary, "bcc", "abb", "aaa", trigramProbability); + + assertEquals(trigramProbability, + getTrigramProbability(binaryDictionary, "aaa", "abb", "bcc")); + assertEquals(trigramProbability, + getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); + assertFalse(isValidBigram(binaryDictionary, "aaa", "abb")); + + addTrigramEntry(binaryDictionary, "bcc", "abb", "aaa", updatedTrigramProbability); + assertEquals(updatedTrigramProbability, + getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); + + removeTrigramEntry(binaryDictionary, "aaa", "abb", "bcc"); + assertEquals(Dictionary.NOT_A_PROBABILITY, + getTrigramProbability(binaryDictionary, "aaa", "abb", "bcc")); + assertTrue(isValidBigram(binaryDictionary, "abb", "bcc")); + + dictFile.delete(); + } + public void testFlushDictionary() { for (final int formatVersion : DICT_FORMAT_VERSIONS) { testFlushDictionary(formatVersion); @@ -892,14 +968,18 @@ public class BinaryDictionaryTests extends AndroidTestCase { addBigramWords(binaryDictionary, word0, word1, bigramProbability); } assertEquals(new HashSet<>(words).size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.UNIGRAM_COUNT_QUERY))); assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.BIGRAM_COUNT_QUERY))); binaryDictionary.flushWithGC(); assertEquals(new HashSet<>(words).size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.UNIGRAM_COUNT_QUERY))); assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats( + BinaryDictionary.BIGRAM_COUNT_QUERY))); binaryDictionary.close(); } @@ -1342,7 +1422,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.addUnigramEntry("ddd", unigramProbability, null /* shortcutTarget */, Dictionary.NOT_A_PROBABILITY, false /* isBeginningOfSentence */, true /* isNotAWord */, true /* isBlacklisted */, 0 /* timestamp */); - binaryDictionary.addNgramEntry(PrevWordsInfo.BEGINNING_OF_SENTENCE, + binaryDictionary.addNgramEntry(NgramContext.BEGINNING_OF_SENTENCE, "aaa", bigramProbability, 0 /* timestamp */); assertEquals(unigramProbability, binaryDictionary.getFrequency("aaa")); assertEquals(unigramProbability, binaryDictionary.getFrequency("bbb")); @@ -1356,7 +1436,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { if (canCheckBigramProbability(toFormatVersion)) { assertEquals(bigramProbability, getBigramProbability(binaryDictionary, "aaa", "bbb")); assertEquals(bigramProbability, binaryDictionary.getNgramProbability( - PrevWordsInfo.BEGINNING_OF_SENTENCE, "aaa")); + NgramContext.BEGINNING_OF_SENTENCE, "aaa")); } assertTrue(isValidBigram(binaryDictionary, "aaa", "bbb")); WordProperty wordProperty = binaryDictionary.getWordProperty("ccc", @@ -1434,7 +1514,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertEquals((int)unigramProbabilities.get(word), binaryDictionary.getFrequency(word)); } assertEquals(unigramProbabilities.size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats(BinaryDictionary.UNIGRAM_COUNT_QUERY))); for (final Pair<String, String> bigram : bigrams) { if (canCheckBigramProbability(toFormatVersion)) { @@ -1444,7 +1524,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { assertTrue(isValidBigram(binaryDictionary, bigram.first, bigram.second)); } assertEquals(bigramProbabilities.size(), Integer.parseInt( - binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY))); + binaryDictionary.getPropertyForGettingStats(BinaryDictionary.BIGRAM_COUNT_QUERY))); } public void testBeginningOfSentence() { @@ -1466,23 +1546,23 @@ public class BinaryDictionaryTests extends AndroidTestCase { 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); final int dummyProbability = 0; - final PrevWordsInfo prevWordsInfoBeginningOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE; + final NgramContext beginningOfSentenceContext = NgramContext.BEGINNING_OF_SENTENCE; final int bigramProbability = 200; addUnigramWord(binaryDictionary, "aaa", dummyProbability); - binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "aaa", bigramProbability, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", bigramProbability, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); assertEquals(bigramProbability, - binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "aaa")); - binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "aaa", bigramProbability, + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "aaa")); + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "aaa", bigramProbability, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); addUnigramWord(binaryDictionary, "bbb", dummyProbability); - binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "bbb", bigramProbability, + binaryDictionary.addNgramEntry(beginningOfSentenceContext, "bbb", bigramProbability, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */); binaryDictionary.flushWithGC(); assertEquals(bigramProbability, - binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "aaa")); + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "aaa")); assertEquals(bigramProbability, - binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "bbb")); + binaryDictionary.getNgramProbability(beginningOfSentenceContext, "bbb")); } public void testGetMaxFrequencyOfExactMatches() { diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java index 6e894decf..30b088137 100644 --- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java +++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java @@ -63,7 +63,7 @@ public class BlueUnderlineTests extends InputTestsBase { final int typedLength = STRING_TO_TYPE.length(); final int EXPECTED_SUGGESTION_SPAN_START = -1; final int EXPECTED_UNDERLINE_SPAN_START = 0; - final int EXPECTED_UNDERLINE_SPAN_END = 4; + final int EXPECTED_UNDERLINE_SPAN_END = 3; type(STRING_TO_TYPE); sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); diff --git a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java new file mode 100644 index 000000000..5af30e5b0 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java @@ -0,0 +1,81 @@ +/* + * 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.latin; + +import java.util.Locale; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.LargeTest; + +@LargeTest +public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase { + static final int MAX_CACHE_SIZE = 2; + static final int MAX_CACHE_SIZE_LARGE = 5; + + public void testCacheSize() { + final DictionaryFacilitatorLruCache cache = + new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, ""); + + assertEquals(0, cache.getCachedLocalesForTesting().size()); + assertNotNull(cache.get(Locale.US)); + assertEquals(1, cache.getCachedLocalesForTesting().size()); + assertNotNull(cache.get(Locale.UK)); + assertEquals(2, cache.getCachedLocalesForTesting().size()); + assertNotNull(cache.get(Locale.FRENCH)); + assertEquals(2, cache.getCachedLocalesForTesting().size()); + cache.evictAll(); + assertEquals(0, cache.getCachedLocalesForTesting().size()); + } + + public void testGetFacilitator() { + testGetFacilitator(new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, "")); + testGetFacilitator(new DictionaryFacilitatorLruCache( + getContext(), MAX_CACHE_SIZE_LARGE, "")); + } + + private void testGetFacilitator(final DictionaryFacilitatorLruCache cache) { + final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US); + assertNotNull(dictionaryFacilitatorEnUs); + assertEquals(Locale.US, dictionaryFacilitatorEnUs.getLocale()); + + final DictionaryFacilitator dictionaryFacilitatorFr = cache.get(Locale.FRENCH); + assertNotNull(dictionaryFacilitatorEnUs); + assertEquals(Locale.FRENCH, dictionaryFacilitatorFr.getLocale()); + + final DictionaryFacilitator dictionaryFacilitatorDe = cache.get(Locale.GERMANY); + assertNotNull(dictionaryFacilitatorDe); + assertEquals(Locale.GERMANY, dictionaryFacilitatorDe.getLocale()); + } + + public void testSetUseContactsDictionary() { + testSetUseContactsDictionary(new DictionaryFacilitatorLruCache( + getContext(), MAX_CACHE_SIZE, "")); + testSetUseContactsDictionary(new DictionaryFacilitatorLruCache( + getContext(), MAX_CACHE_SIZE_LARGE, "")); + } + + private void testSetUseContactsDictionary(final DictionaryFacilitatorLruCache cache) { + assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + cache.setUseContactsDictionary(true /* useContactsDictionary */); + assertNotNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + assertNotNull(cache.get(Locale.FRENCH).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + assertNotNull(cache.get(Locale.GERMANY).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + cache.setUseContactsDictionary(false /* useContactsDictionary */); + assertNull(cache.get(Locale.GERMANY).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); + } +} diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 59b858dbd..ec249dab3 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -159,8 +159,11 @@ public class InputLogicTests extends InputTestsBase { } public void testAutoCorrectWithSpaceThenRevert() { + // Backspacing to cancel the "tgis"->"this" autocorrection should result in + // a "phantom space": if the user presses space immediately after, + // only one space will be inserted in total. final String STRING_TO_TYPE = "tgis "; - final String EXPECTED_RESULT = "tgis "; + final String EXPECTED_RESULT = "tgis"; type(STRING_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); type(Constants.CODE_DELETE); @@ -168,6 +171,24 @@ public class InputLogicTests extends InputTestsBase { mEditText.getText().toString()); } + public void testAutoCorrectWithSpaceThenRevertThenTypeMore() { + final String STRING_TO_TYPE_FIRST = "tgis "; + final String STRING_TO_TYPE_SECOND = "a"; + final String EXPECTED_RESULT = "tgis a"; + type(STRING_TO_TYPE_FIRST); + mLatinIME.onUpdateSelection(0, 0, + STRING_TO_TYPE_FIRST.length(), STRING_TO_TYPE_FIRST.length(), -1, -1); + type(Constants.CODE_DELETE); + + type(STRING_TO_TYPE_SECOND); + mLatinIME.onUpdateSelection(STRING_TO_TYPE_FIRST.length(), STRING_TO_TYPE_FIRST.length(), + STRING_TO_TYPE_FIRST.length() - 1 + STRING_TO_TYPE_SECOND.length(), + STRING_TO_TYPE_FIRST.length() - 1 + STRING_TO_TYPE_SECOND.length(), + -1, -1); + assertEquals("auto-correct with space then revert then type more", EXPECTED_RESULT, + mEditText.getText().toString()); + } + public void testAutoCorrectToSelfDoesNotRevert() { final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this"; diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsDeadKeys.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsDeadKeys.java new file mode 100644 index 000000000..afe7dbe70 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsDeadKeys.java @@ -0,0 +1,215 @@ +/* + * 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.latin; + +import android.test.suitebuilder.annotation.LargeTest; + +import com.android.inputmethod.event.Event; + +import java.util.ArrayList; + +@LargeTest +public class InputLogicTestsDeadKeys extends InputTestsBase { + // A helper class for readability + private static class EventList extends ArrayList<Event> { + public EventList addCodePoint(final int codePoint, final boolean isDead) { + final Event event; + if (isDead) { + event = Event.createDeadEvent(codePoint, Event.NOT_A_KEY_CODE, null /* next */); + } else { + event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */); + } + add(event); + return this; + } + + public EventList addKey(final int keyCode) { + add(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT, keyCode, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */)); + return this; + } + } + + public void testDeadCircumflexSimple() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "aê"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint('e', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("simple dead circumflex", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testDeadCircumflexBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "ae"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('e', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex backspace", EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testDeadCircumflexFeedback() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final String EXPECTED_RESULT = "a\u02C6"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex gives feedback", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadDiaeresisSpace() { + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "a\u00A8e\u00A8i"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(Constants.CODE_SPACE, false) + .addCodePoint('e', false) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(Constants.CODE_ENTER, false) + .addCodePoint('i', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead diaeresis space commits the dead char", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadAcuteLetterBackspace() { + final int MODIFIER_LETTER_ACUTE = 0xB4; + final String EXPECTED_RESULT1 = "aá"; + final String EXPECTED_RESULT2 = "a"; + final EventList events = new EventList() + .addCodePoint('a', false) + .addCodePoint(MODIFIER_LETTER_ACUTE, true) + .addCodePoint('a', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead acute on a typed", EXPECTED_RESULT1, mEditText.getText().toString()); + mLatinIME.onEvent(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT, + Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, + false /* isKeyRepeat */)); + assertEquals("a with acute deleted", EXPECTED_RESULT2, mEditText.getText().toString()); + } + + public void testFinnishStroke() { + final int MODIFIER_LETTER_STROKE = '-'; + final String EXPECTED_RESULT = "x\u0110\u0127"; + final EventList events = new EventList() + .addCodePoint('x', false) + .addCodePoint(MODIFIER_LETTER_STROKE, true) + .addCodePoint('D', false) + .addCodePoint(MODIFIER_LETTER_STROKE, true) + .addCodePoint('h', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("Finnish dead stroke", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDoubleDeadOgonek() { + final int MODIFIER_LETTER_OGONEK = 0x02DB; + final String EXPECTED_RESULT = "txǫs\u02DBfk"; + final EventList events = new EventList() + .addCodePoint('t', false) + .addCodePoint('x', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint('o', false) + .addCodePoint('s', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint('f', false) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addCodePoint(MODIFIER_LETTER_OGONEK, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('k', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("double dead ogonek, and backspace", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDeadDiaeresis() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "r̂̈"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint('r', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("both circumflex and diaeresis on r", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDeadDiaeresisBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "û"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('u', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex, dead diaeresis, backspace, u", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testDeadCircumflexDoubleDeadDiaeresisBackspace() { + final int MODIFIER_LETTER_CIRCUMFLEX_ACCENT = 0x02C6; + final int MODIFIER_LETTER_DIAERESIS = 0xA8; + final String EXPECTED_RESULT = "\u02C6u"; + + final EventList events = new EventList() + .addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addCodePoint(MODIFIER_LETTER_DIAERESIS, true) + .addKey(Constants.CODE_DELETE) + .addCodePoint('u', false); + for (final Event event : events) { + mLatinIME.onEvent(event); + } + assertEquals("dead circumflex, double dead diaeresis, backspace, u", EXPECTED_RESULT, + mEditText.getText().toString()); + } +} diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java index 866f8894c..715d449a0 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java @@ -18,6 +18,8 @@ package com.android.inputmethod.latin; import android.test.suitebuilder.annotation.LargeTest; +import com.android.inputmethod.latin.settings.Settings; + @LargeTest public class InputLogicTestsNonEnglish extends InputTestsBase { final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; @@ -121,4 +123,32 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, mEditText.getText().toString()); } + + // Corresponds to InputLogicTests#testDoubleSpace + public void testDoubleSpaceHindi() { + changeLanguage("hi"); + // Set default pref just in case + setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); + // U+1F607 is an emoji + final String[] STRINGS_TO_TYPE = + new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; + final String[] EXPECTED_RESULTS = + new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; + for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { + mEditText.setText(""); + type(STRINGS_TO_TYPE[i]); + assertEquals("double space processing", EXPECTED_RESULTS[i], + mEditText.getText().toString()); + } + } + + // Corresponds to InputLogicTests#testCancelDoubleSpace + public void testCancelDoubleSpaceHindi() { + changeLanguage("hi"); + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + type(Constants.CODE_DELETE); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); + } } diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 986fb1097..6860bea45 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -36,6 +36,7 @@ import android.widget.EditText; import android.widget.FrameLayout; import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils; +import com.android.inputmethod.event.Event; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -182,6 +183,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { | InputType.TYPE_TEXT_FLAG_MULTI_LINE; mEditText.setInputType(inputType); mEditText.setEnabled(true); + if (null == Looper.myLooper()) { + Looper.prepare(); + } setupService(); mLatinIME = getService(); setDebugMode(true); @@ -263,14 +267,16 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { // but keep them in mind if something breaks. Commenting them out as is should work. //mLatinIME.onPressKey(codePoint, 0 /* repeatCount */, true /* isSinglePointer */); final Key key = mKeyboard.getKey(codePoint); + final Event event; if (key == null) { - mLatinIME.onCodeInput(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, - isKeyRepeat); + event = Event.createSoftwareKeypressEvent(codePoint, Event.NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, isKeyRepeat); } else { final int x = key.getX() + key.getWidth() / 2; final int y = key.getY() + key.getHeight() / 2; - mLatinIME.onCodeInput(codePoint, x, y, isKeyRepeat); + event = mLatinIME.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat); } + mLatinIME.onEvent(event); // Also see the comment at the top of this function about onReleaseKey //mLatinIME.onReleaseKey(codePoint, false /* withSliding */); } diff --git a/tests/src/com/android/inputmethod/latin/NgramContextTests.java b/tests/src/com/android/inputmethod/latin/NgramContextTests.java new file mode 100644 index 000000000..ecc2c634d --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/NgramContextTests.java @@ -0,0 +1,66 @@ +/* + * 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.latin; + +import com.android.inputmethod.latin.NgramContext.WordInfo; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +@SmallTest +public class NgramContextTests extends AndroidTestCase { + public void testConstruct() { + assertEquals(new NgramContext(new WordInfo("a")), new NgramContext(new WordInfo("a"))); + assertEquals(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE), + new NgramContext(WordInfo.BEGINNING_OF_SENTENCE)); + assertEquals(new NgramContext(WordInfo.EMPTY_WORD_INFO), + new NgramContext(WordInfo.EMPTY_WORD_INFO)); + assertEquals(new NgramContext(WordInfo.EMPTY_WORD_INFO), + new NgramContext(WordInfo.EMPTY_WORD_INFO)); + } + + public void testIsBeginningOfSentenceContext() { + assertFalse(new NgramContext().isBeginningOfSentenceContext()); + assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE) + .isBeginningOfSentenceContext()); + assertTrue(NgramContext.BEGINNING_OF_SENTENCE.isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("a")).isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("")).isBeginningOfSentenceContext()); + assertFalse(new NgramContext(WordInfo.EMPTY_WORD_INFO).isBeginningOfSentenceContext()); + assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE, new WordInfo("a")) + .isBeginningOfSentenceContext()); + assertFalse(new NgramContext(new WordInfo("a"), WordInfo.BEGINNING_OF_SENTENCE) + .isBeginningOfSentenceContext()); + assertFalse(new NgramContext(WordInfo.EMPTY_WORD_INFO, WordInfo.BEGINNING_OF_SENTENCE) + .isBeginningOfSentenceContext()); + } + + public void testGetNextNgramContext() { + final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); + final NgramContext ngramContext_b_a = + ngramContext_a.getNextNgramContext(new WordInfo("b")); + assertEquals("b", ngramContext_b_a.getNthPrevWord(1)); + assertEquals("a", ngramContext_b_a.getNthPrevWord(2)); + final NgramContext ngramContext_bos_b = + ngramContext_b_a.getNextNgramContext(WordInfo.BEGINNING_OF_SENTENCE); + assertTrue(ngramContext_bos_b.isBeginningOfSentenceContext()); + assertEquals("b", ngramContext_bos_b.getNthPrevWord(2)); + final NgramContext ngramContext_c_bos = + ngramContext_b_a.getNextNgramContext(new WordInfo("c")); + assertEquals("c", ngramContext_c_bos.getNthPrevWord(1)); + } +} diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java index f9d72269e..7a3233625 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java @@ -30,9 +30,8 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnectionWrapper; -import com.android.inputmethod.latin.PrevWordsInfo.WordInfo; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; -import com.android.inputmethod.latin.utils.PrevWordsInfoUtils; +import com.android.inputmethod.latin.utils.NgramContextUtils; import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -158,26 +157,25 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { */ public void testGetPreviousWord() { // If one of the following cases breaks, the bigram suggestions won't work. - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc. def", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE); - - assertFalse(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mIsBeginningOfSentence); - assertTrue(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mIsBeginningOfSentence); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc. def", mSpacingAndPunctuations, 2), NgramContext.BEGINNING_OF_SENTENCE); + + assertFalse(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); // For n-gram - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[1].mWord, "abc"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[1], - WordInfo.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(2), "abc"); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 2).isNthPrevWordBeginningOfSontence(2)); // The following tests reflect the current behavior of the function // RichInputConnection#getNthPreviousWord. @@ -186,33 +184,33 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { // this function if needed - especially since it does not seem very // logical. These tests are just there to catch any unintentional // changes in the behavior of the RichInputConnection#getPreviousWord method. - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def ", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def.", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def .", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "def"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc ", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE); - - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def ", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc 'def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "'def"); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def.", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc def .", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc, def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc? def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc! def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO); - assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord( - "abc 'def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def ", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def.", mSpacingAndPunctuations, 2).getNthPrevWord(1), "abc"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def .", mSpacingAndPunctuations, 2).getNthPrevWord(1), "def"); + assertTrue(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc ", mSpacingAndPunctuations, 2).isBeginningOfSentenceContext()); + + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def ", mSpacingAndPunctuations, 1).getNthPrevWord(1), "def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc 'def", mSpacingAndPunctuations, 1).getNthPrevWord(1), "'def"); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def.", mSpacingAndPunctuations, 1), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc def .", mSpacingAndPunctuations, 1), NgramContext.BEGINNING_OF_SENTENCE); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc, def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc? def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc! def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); + assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( + "abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); } public void testGetWordRangeAtCursor() { diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java index 869c550e0..563261f8f 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java +++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java @@ -147,7 +147,7 @@ public class SuggestedWordsTests extends AndroidTestCase { assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull()); // Make sure getTypedWordInfoOrNull() returns null. - assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull()); + assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull()); final SuggestedWords emptySuggestedWords = new SuggestedWords( new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */, @@ -157,6 +157,6 @@ public class SuggestedWordsTests extends AndroidTestCase { SuggestedWords.INPUT_STYLE_NONE); assertNull(emptySuggestedWords.getTypedWordInfoOrNull()); - assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull()); + assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull()); } } diff --git a/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java new file mode 100644 index 000000000..00857e54e --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/accounts/AccountsChangedReceiverTests.java @@ -0,0 +1,111 @@ +/* + * 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.latin.accounts; + +import android.accounts.AccountManager; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.test.AndroidTestCase; + +import com.android.inputmethod.latin.settings.Settings; + +/** + * Tests for {@link AccountsChangedReceiver}. + */ +public class AccountsChangedReceiverTests extends AndroidTestCase { + private static final String ACCOUNT_1 = "account1@example.com"; + private static final String ACCOUNT_2 = "account2@example.com"; + + private SharedPreferences mPrefs; + private String mLastKnownAccount = null; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + // Keep track of the current account so that we restore it when the test finishes. + mLastKnownAccount = mPrefs.getString(Settings.PREF_ACCOUNT_NAME, null); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + // Restore the account that was present before running the test. + updateAccountName(mLastKnownAccount); + } + + public void testUnknownIntent() { + updateAccountName(ACCOUNT_1); + AccountsChangedReceiver reciever = new AccountsChangedReceiver(); + reciever.onReceive(getContext(), new Intent("some-random-action")); + // Account should *not* be removed from preferences. + assertAccountName(ACCOUNT_1); + } + + public void testAccountRemoved() { + updateAccountName(ACCOUNT_1); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[] {ACCOUNT_2}; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should be removed from preferences. + assertAccountName(null); + } + + public void testAccountRemoved_noAccounts() { + updateAccountName(ACCOUNT_2); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[0]; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should be removed from preferences. + assertAccountName(null); + } + + public void testAccountNotRemoved() { + updateAccountName(ACCOUNT_2); + AccountsChangedReceiver reciever = new AccountsChangedReceiver() { + @Override + protected String[] getAccountsForLogin(Context context) { + return new String[] {ACCOUNT_1, ACCOUNT_2}; + } + }; + reciever.onReceive(getContext(), new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)); + // Account should *not* be removed from preferences. + assertAccountName(ACCOUNT_2); + } + + private void updateAccountName(String accountName) { + if (accountName == null) { + mPrefs.edit().remove(Settings.PREF_ACCOUNT_NAME).apply(); + } else { + mPrefs.edit().putString(Settings.PREF_ACCOUNT_NAME, accountName).apply(); + } + } + + private void assertAccountName(String expectedAccountName) { + assertEquals(expectedAccountName, mPrefs.getString(Settings.PREF_ACCOUNT_NAME, null)); + } +} diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java index eabd8d722..12290e6aa 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java @@ -27,6 +27,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; /** * Encodes binary files for a FusionDictionary. @@ -548,28 +550,6 @@ public class BinaryDictEncoderUtils { } /** - * Helper method to write a signed children position to a file. - * - * @param buffer the buffer to write to. - * @param index the index in the buffer to write the address to. - * @param position the position to write. - * @return the size in bytes the address actually took. - */ - /* package */ static int writeSignedChildrenPosition(final byte[] buffer, int index, - final int position) { - if (!BinaryDictIOUtils.hasChildrenAddress(position)) { - buffer[index] = buffer[index + 1] = buffer[index + 2] = 0; - } else { - final int absPosition = Math.abs(position); - buffer[index++] = - (byte)((position < 0 ? FormatSpec.MSB8 : 0) | (0xFF & (absPosition >> 16))); - buffer[index++] = (byte)(0xFF & (absPosition >> 8)); - buffer[index++] = (byte)(0xFF & absPosition); - } - return 3; - } - - /** * Makes the flag value for a PtNode. * * @param hasMultipleChars whether the PtNode has multiple chars. @@ -734,10 +714,6 @@ public class BinaryDictEncoderUtils { final int ptNodeCount = ptNodeArray.mData.size(); dictEncoder.writePtNodeCount(ptNodeCount); - final int parentPosition = - (ptNodeArray.mCachedParentAddress == FormatSpec.NO_PARENT_ADDRESS) - ? FormatSpec.NO_PARENT_ADDRESS - : ptNodeArray.mCachedParentAddress + ptNodeArray.mCachedAddressAfterUpdate; for (int i = 0; i < ptNodeCount; ++i) { final PtNode ptNode = ptNodeArray.mData.get(i); if (dictEncoder.getPosition() != ptNode.mCachedAddressAfterUpdate) { @@ -817,10 +793,12 @@ public class BinaryDictEncoderUtils { * @param destination the stream to write the file header to. * @param dict the dictionary to write. * @param formatOptions file format options. + * @param codePointOccurrenceArray code points ordered by occurrence count. * @return the size of the header. */ /* package */ static int writeDictionaryHeader(final OutputStream destination, - final FusionDictionary dict, final FormatOptions formatOptions) + final FusionDictionary dict, final FormatOptions formatOptions, + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray) throws IOException, UnsupportedFormatException { final int version = formatOptions.mVersion; if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION @@ -859,6 +837,9 @@ public class BinaryDictEncoderUtils { CharEncoding.writeString(headerBuffer, key); CharEncoding.writeString(headerBuffer, value); } + + // TODO: Write out the code point table. + final int size = headerBuffer.size(); final byte[] bytes = headerBuffer.toByteArray(); // Write out the header size. @@ -871,4 +852,15 @@ public class BinaryDictEncoderUtils { headerBuffer.close(); return size; } + + static final class CodePointTable { + final HashMap<Integer, Integer> mCodePointToOneByteCodeMap; + final ArrayList<Entry<Integer, Integer>> mCodePointOccurrenceArray; + + CodePointTable(final HashMap<Integer, Integer> codePointToOneByteCodeMap, + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray) { + mCodePointToOneByteCodeMap = codePointToOneByteCodeMap; + mCodePointOccurrenceArray = codePointOccurrenceArray; + } + } } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java index 5a3eba801..965479d73 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java @@ -69,7 +69,7 @@ public class BinaryDictUtils { } return new Ver4DictEncoder(file); } else if (formatOptions.mVersion == FormatSpec.VERSION2) { - return new Ver2DictEncoder(file); + return new Ver2DictEncoder(file, Ver2DictEncoder.CODE_POINT_TABLE_OFF); } else { throw new RuntimeException("The format option has a wrong version : " + formatOptions.mVersion); diff --git a/tests/src/com/android/inputmethod/latin/makedict/DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/DictEncoder.java index 678c5ca6b..645fd5c02 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/DictEncoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/DictEncoder.java @@ -33,6 +33,5 @@ public interface DictEncoder { public void setPosition(final int position); public int getPosition(); public void writePtNodeCount(final int ptNodeCount); - public void writeForwardLinkAddress(final int forwardLinkAddress); public void writePtNode(final PtNode ptNode, final FusionDictionary dict); } diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java index a286190cb..c47190190 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding; +import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils.CodePointTable; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; @@ -28,7 +29,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map.Entry; /** * An implementation of DictEncoder for version 2 binary dictionary. @@ -40,12 +45,16 @@ public class Ver2DictEncoder implements DictEncoder { private OutputStream mOutStream; private byte[] mBuffer; private int mPosition; + private final int mCodePointTableMode; + public static final int CODE_POINT_TABLE_OFF = 0; + public static final int CODE_POINT_TABLE_ON = 1; @UsedForTesting - public Ver2DictEncoder(final File dictFile) { + public Ver2DictEncoder(final File dictFile, final int codePointTableMode) { mDictFile = dictFile; mOutStream = null; mBuffer = null; + mCodePointTableMode = codePointTableMode; } // This constructor is used only by BinaryDictOffdeviceUtilsTests. @@ -55,6 +64,7 @@ public class Ver2DictEncoder implements DictEncoder { public Ver2DictEncoder(final OutputStream outStream) { mDictFile = null; mOutStream = outStream; + mCodePointTableMode = CODE_POINT_TABLE_OFF; } private void openStream() throws FileNotFoundException { @@ -68,6 +78,49 @@ public class Ver2DictEncoder implements DictEncoder { } } + // Package for testing + static CodePointTable makeCodePointTable(final FusionDictionary dict) { + final HashMap<Integer, Integer> codePointOccurrenceCounts = new HashMap<>(); + for (final WordProperty word : dict) { + // Store per code point occurrence + final String wordString = word.mWord; + for (int i = 0; i < wordString.length(); ++i) { + final int codePoint = Character.codePointAt(wordString, i); + if (codePointOccurrenceCounts.containsKey(codePoint)) { + codePointOccurrenceCounts.put(codePoint, + codePointOccurrenceCounts.get(codePoint) + 1); + } else { + codePointOccurrenceCounts.put(codePoint, 1); + } + } + } + final ArrayList<Entry<Integer, Integer>> codePointOccurrenceArray = + new ArrayList<>(codePointOccurrenceCounts.entrySet()); + // Descending order sort by occurrence (value side) + Collections.sort(codePointOccurrenceArray, new Comparator<Entry<Integer, Integer>>() { + @Override + public int compare(final Entry<Integer, Integer> a, final Entry<Integer, Integer> b) { + if (a.getValue() != b.getValue()) { + return b.getValue().compareTo(a.getValue()); + } + return b.getKey().compareTo(a.getKey()); + } + }); + int currentCodePointTableIndex = FormatSpec.MINIMAL_ONE_BYTE_CHARACTER_VALUE; + // Temporary map for writing of nodes + final HashMap<Integer, Integer> codePointToOneByteCodeMap = new HashMap<>(); + for (final Entry<Integer, Integer> entry : codePointOccurrenceArray) { + // Put a relation from the original code point to the one byte code. + codePointToOneByteCodeMap.put(entry.getKey(), currentCodePointTableIndex); + if (FormatSpec.MAXIMAL_ONE_BYTE_CHARACTER_VALUE < ++currentCodePointTableIndex) { + break; + } + } + // codePointToOneByteCodeMap for writing the trie + // codePointOccurrenceArray for writing the header + return new CodePointTable(codePointToOneByteCodeMap, codePointOccurrenceArray); + } + @Override public void writeDictionary(final FusionDictionary dict, final FormatOptions formatOptions) throws IOException, UnsupportedFormatException { @@ -80,7 +133,12 @@ public class Ver2DictEncoder implements DictEncoder { if (mOutStream == null) { openStream(); } - BinaryDictEncoderUtils.writeDictionaryHeader(mOutStream, dict, formatOptions); + + // Make code point conversion table ordered by occurrence of code points + final CodePointTable codePointTable = makeCodePointTable(dict); + + BinaryDictEncoderUtils.writeDictionaryHeader(mOutStream, dict, formatOptions, + codePointTable.mCodePointOccurrenceArray); // Addresses are limited to 3 bytes, but since addresses can be relative to each node // array, the structure itself is not limited to 16MB. However, if it is over 16MB deciding @@ -223,12 +281,6 @@ public class Ver2DictEncoder implements DictEncoder { } @Override - public void writeForwardLinkAddress(final int forwardLinkAddress) { - mPosition = BinaryDictEncoderUtils.writeUIntToBuffer(mBuffer, mPosition, forwardLinkAddress, - FormatSpec.FORWARD_LINK_ADDRESS_SIZE); - } - - @Override public void writePtNode(final PtNode ptNode, final FusionDictionary dict) { writePtNodeFlags(ptNode); writeCharacters(ptNode.mChars, ptNode.hasSeveralChars()); diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java new file mode 100644 index 000000000..9104c2fcb --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoderTests.java @@ -0,0 +1,91 @@ +/* + * 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.latin.makedict; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils.CodePointTable; +import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import android.util.Log; + +/** + * Unit tests for Ver2DictEncoder + */ +@LargeTest +public class Ver2DictEncoderTests extends AndroidTestCase { + private static final String TAG = Ver2DictEncoderTests.class.getSimpleName(); + private static final int UNIGRAM_FREQ = 10; + + public void testCodePointTable() { + final String[] wordSource = {"words", "used", "for", "testing", "a", "code point", "table"}; + final List<String> words = Arrays.asList(wordSource); + final String correctCodePointTable = "eotdsanirfg bclwup"; + final String correctCodePointOccurrenceArrayString = + "11641114101411531003114211021052972119111711121108110311021991981321"; + final String correctCodePointExpectedMapString = "343332363540383937464549484744414243"; + final String dictName = "codePointTableTest"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + + final FormatSpec.FormatOptions formatOptions = + new FormatSpec.FormatOptions(FormatSpec.VERSION2); + final FusionDictionary sourcedict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(sourcedict, words, null /* shortcutMap */); + final CodePointTable codePointTable = Ver2DictEncoder.makeCodePointTable(sourcedict); + + // Check if mCodePointOccurrenceArray is correct + final StringBuilder codePointOccurrenceArrayString = new StringBuilder(); + for (Entry<Integer, Integer> entry : codePointTable.mCodePointOccurrenceArray) { + codePointOccurrenceArrayString.append(entry.getKey()); + codePointOccurrenceArrayString.append(entry.getValue()); + } + assertEquals(correctCodePointOccurrenceArrayString, + codePointOccurrenceArrayString.toString()); + + // Check if mCodePointToOneByteCodeMap is correct + final StringBuilder codePointExpectedMapString = new StringBuilder(); + for (int i = 0; i < correctCodePointTable.length(); ++i) { + codePointExpectedMapString.append(codePointTable.mCodePointToOneByteCodeMap.get( + correctCodePointTable.codePointAt(i))); + } + assertEquals(correctCodePointExpectedMapString, codePointExpectedMapString.toString()); + } + + /** + * Adds unigrams to the dictionary. + */ + private void addUnigrams(final FusionDictionary dict, final List<String> words, + final HashMap<String, List<String>> shortcutMap) { + for (final String word : words) { + final ArrayList<WeightedString> shortcuts = new ArrayList<>(); + if (shortcutMap != null && shortcutMap.containsKey(word)) { + for (final String shortcut : shortcutMap.get(word)) { + shortcuts.add(new WeightedString(shortcut, UNIGRAM_FREQ)); + } + } + dict.add(word, new ProbabilityInfo(UNIGRAM_FREQ), + (shortcutMap == null) ? null : shortcuts, false /* isNotAWord */); + } + } +} diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java index 76eaef431..74da93766 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java @@ -19,7 +19,7 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.Dictionary; -import com.android.inputmethod.latin.PrevWordsInfo; +import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; @@ -104,12 +104,12 @@ public class Ver4DictEncoder implements DictEncoder { for (final WordProperty word0Property : dict) { if (null == word0Property.mBigrams) continue; for (final WeightedString word1 : word0Property.mBigrams) { - final PrevWordsInfo prevWordsInfo = - new PrevWordsInfo(new PrevWordsInfo.WordInfo(word0Property.mWord)); - if (!binaryDict.addNgramEntry(prevWordsInfo, word1.mWord, + final NgramContext ngramContext = + new NgramContext(new NgramContext.WordInfo(word0Property.mWord)); + if (!binaryDict.addNgramEntry(ngramContext, word1.mWord, word1.getProbability(), 0 /* timestamp */)) { MakedictLog.e("Cannot add n-gram entry for " - + prevWordsInfo + " -> " + word1.mWord); + + ngramContext + " -> " + word1.mWord); return; } if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) { @@ -141,10 +141,6 @@ public class Ver4DictEncoder implements DictEncoder { } @Override - public void writeForwardLinkAddress(int forwardLinkAddress) { - } - - @Override public void writePtNode(PtNode ptNode, FusionDictionary dict) { } } diff --git a/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java new file mode 100644 index 000000000..d151732aa --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/network/BlockingHttpClientTests.java @@ -0,0 +1,174 @@ +/* + * 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.latin.network; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.util.Arrays; +import java.util.Random; + +/** + * Tests for {@link BlockingHttpClient}. + */ +@SmallTest +public class BlockingHttpClientTests extends AndroidTestCase { + @Mock HttpURLConnection mMockHttpConnection; + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + } + + public void testError_badGateway() throws IOException { + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = + new FakeErrorResponseProcessor(HttpURLConnection.HTTP_BAD_GATEWAY); + + client.execute(null /* empty request */, processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + public void testError_clientTimeout() throws IOException { + when(mMockHttpConnection.getResponseCode()).thenReturn( + HttpURLConnection.HTTP_CLIENT_TIMEOUT); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = + new FakeErrorResponseProcessor(HttpURLConnection.HTTP_CLIENT_TIMEOUT); + + client.execute(null /* empty request */, processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + public void testError_forbiddenWithRequest() throws IOException { + final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN); + when(mMockHttpConnection.getOutputStream()).thenReturn(mockOutputStream); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeErrorResponseProcessor processor = + new FakeErrorResponseProcessor(HttpURLConnection.HTTP_FORBIDDEN); + + client.execute(new byte[100], processor); + verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100)); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + public void testSuccess_emptyRequest() throws IOException { + final Random rand = new Random(); + byte[] response = new byte[100]; + rand.nextBytes(response); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + when(mMockHttpConnection.getInputStream()).thenReturn(new ByteArrayInputStream(response)); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeSuccessResponseProcessor processor = + new FakeSuccessResponseProcessor(response); + + client.execute(null /* empty request */, processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + public void testSuccess() throws IOException { + final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); + final Random rand = new Random(); + byte[] response = new byte[100]; + rand.nextBytes(response); + when(mMockHttpConnection.getOutputStream()).thenReturn(mockOutputStream); + when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + when(mMockHttpConnection.getInputStream()).thenReturn(new ByteArrayInputStream(response)); + final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); + final FakeSuccessResponseProcessor processor = + new FakeSuccessResponseProcessor(response); + + client.execute(new byte[100], processor); + assertTrue("ResponseProcessor was not invoked", processor.mInvoked); + } + + private static class FakeErrorResponseProcessor implements ResponseProcessor { + private final int mExpectedStatusCode; + + boolean mInvoked; + + FakeErrorResponseProcessor(int expectedStatusCode) { + mExpectedStatusCode = expectedStatusCode; + } + + @Override + public void onError(int httpStatusCode, String message) { + mInvoked = true; + assertEquals("onError:", mExpectedStatusCode, httpStatusCode); + } + + @Override + public void onSuccess(InputStream response) { + fail("Expected an error but received success"); + } + } + + private static class FakeSuccessResponseProcessor implements ResponseProcessor { + private final byte[] mExpectedResponse; + + boolean mInvoked; + + FakeSuccessResponseProcessor(byte[] expectedResponse) { + mExpectedResponse = expectedResponse; + } + + @Override + public void onError(int httpStatusCode, String message) { + fail("Expected a response but received an error"); + } + + @Override + public void onSuccess(InputStream response) { + try { + mInvoked = true; + BufferedInputStream in = new BufferedInputStream(response); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int read = 0; + while ((read = in.read()) != -1) { + buffer.write(read); + } + byte[] actualResponse = buffer.toByteArray(); + in.close(); + assertTrue("Response doesn't match", + Arrays.equals(mExpectedResponse, actualResponse)); + } catch (IOException ex) { + fail("IOException in onSuccess"); + } + } + } +} diff --git a/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java new file mode 100644 index 000000000..2b43d5b14 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/network/HttpUrlConnectionBuilderTests.java @@ -0,0 +1,145 @@ +/* + * 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.latin.network; + +import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_BI_DIRECTIONAL; +import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_DOWNLOAD_ONLY; +import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_UPLOAD_ONLY; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; + + +/** + * Tests for {@link HttpUrlConnectionBuilder}. + */ +@SmallTest +public class HttpUrlConnectionBuilderTests extends AndroidTestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testSetUrl_malformed() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setUrl("dadasd!@%@!:11"); + fail("Expected a MalformedURLException."); + } catch (MalformedURLException e) { + // Expected + } + } + + public void testSetConnectTimeout_invalid() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setConnectTimeout(-1); + fail("Expected an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // Expected + } + } + + public void testSetConnectTimeout() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setConnectTimeout(8765); + HttpURLConnection connection = builder.build(); + assertEquals(8765, connection.getConnectTimeout()); + } + + public void testSetReadTimeout_invalid() { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + try { + builder.setReadTimeout(-1); + fail("Expected an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // Expected + } + } + + public void testSetReadTimeout() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setReadTimeout(8765); + HttpURLConnection connection = builder.build(); + assertEquals(8765, connection.getReadTimeout()); + } + + public void testAddHeader() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + builder.addHeader("some-random-key", "some-random-value"); + HttpURLConnection connection = builder.build(); + assertEquals("some-random-value", connection.getRequestProperty("some-random-key")); + } + + public void testSetUseCache_notSet() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + assertFalse(connection.getUseCaches()); + } + + public void testSetUseCache_false() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + connection.setUseCaches(false); + assertFalse(connection.getUseCaches()); + } + + public void testSetUseCache_true() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + HttpURLConnection connection = builder.build(); + connection.setUseCaches(true); + assertTrue(connection.getUseCaches()); + } + + public void testSetMode_uploadOnly() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("http://www.example.com"); + builder.setMode(MODE_UPLOAD_ONLY); + HttpURLConnection connection = builder.build(); + assertTrue(connection.getDoInput()); + assertFalse(connection.getDoOutput()); + } + + public void testSetMode_downloadOnly() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setMode(MODE_DOWNLOAD_ONLY); + HttpURLConnection connection = builder.build(); + assertFalse(connection.getDoInput()); + assertTrue(connection.getDoOutput()); + } + + public void testSetMode_bidirectional() throws IOException { + HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); + builder.setUrl("https://www.example.com"); + builder.setMode(MODE_BI_DIRECTIONAL); + HttpURLConnection connection = builder.build(); + assertTrue(connection.getDoInput()); + assertTrue(connection.getDoOutput()); + } +} diff --git a/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java index 0f2f9814b..4e7e8140a 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java @@ -29,6 +29,7 @@ import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.DictionaryFacilitator; import com.android.inputmethod.latin.ExpandableBinaryDictionary; +import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback; import com.android.inputmethod.latin.makedict.CodePointUtils; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; @@ -36,6 +37,7 @@ import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; +import android.view.inputmethod.InputMethodSubtype; /** * Unit tests for personalization dictionary @@ -52,19 +54,31 @@ public class PersonalizationDictionaryTests extends AndroidTestCase { final ArrayList<String> dictTypes = new ArrayList<>(); dictTypes.add(Dictionary.TYPE_MAIN); dictTypes.add(Dictionary.TYPE_PERSONALIZATION); - final DictionaryFacilitator dictionaryFacilitator = new DictionaryFacilitator(); + final DictionaryFacilitator dictionaryFacilitator = new DictionaryFacilitator(getContext()); dictionaryFacilitator.resetDictionariesForTesting(getContext(), LOCALE_EN_US, dictTypes, new HashMap<String, File>(), new HashMap<String, Map<String, String>>()); + // Set subtypes. + RichInputMethodManager.init(getContext()); + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); + subtypes.add(richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + LOCALE_EN_US.toString(), "qwerty")); + dictionaryFacilitator.updateEnabledSubtypes(subtypes); return dictionaryFacilitator; } public void testAddManyTokens() { final DictionaryFacilitator dictionaryFacilitator = getDictionaryFacilitator(); dictionaryFacilitator.clearPersonalizationDictionary(); - final int dataChunkCount = 20; - final int wordCountInOneChunk = 2000; + final int dataChunkCount = 100; + final int wordCountInOneChunk = 200; + final int uniqueWordCount = 100; final Random random = new Random(System.currentTimeMillis()); final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER; + final ArrayList<String> words = new ArrayList<>(); + for (int i = 0; i < uniqueWordCount; i++) { + words.add(CodePointUtils.generateWord(random, codePointSet)); + } final SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations(getContext().getResources()); @@ -75,10 +89,11 @@ public class PersonalizationDictionaryTests extends AndroidTestCase { for (int i = 0; i < dataChunkCount; i++) { final ArrayList<String> tokens = new ArrayList<>(); for (int j = 0; j < wordCountInOneChunk; j++) { - tokens.add(CodePointUtils.generateWord(random, codePointSet)); + tokens.add(words.get(random.nextInt(words.size()))); } final PersonalizationDataChunk personalizationDataChunk = new PersonalizationDataChunk( - true /* inputByUser */, tokens, timeStampInSeconds, DUMMY_PACKAGE_NAME); + true /* inputByUser */, tokens, timeStampInSeconds, DUMMY_PACKAGE_NAME, + LOCALE_EN_US.getLanguage()); final CountDownLatch countDownLatch = new CountDownLatch(1); final AddMultipleDictionaryEntriesCallback callback = new AddMultipleDictionaryEntriesCallback() { diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index f87f3b494..766627334 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -21,13 +21,14 @@ import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; import com.android.inputmethod.latin.ExpandableBinaryDictionary; -import com.android.inputmethod.latin.PrevWordsInfo; -import com.android.inputmethod.latin.PrevWordsInfo.WordInfo; +import com.android.inputmethod.latin.NgramContext; +import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.DistracterFilter; import com.android.inputmethod.latin.utils.FileUtils; import java.io.File; +import java.io.FilenameFilter; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -41,6 +42,8 @@ import java.util.concurrent.TimeUnit; @LargeTest public class UserHistoryDictionaryTests extends AndroidTestCase { private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName(); + private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000; + private static final String TEST_LOCALE_PREFIX = "test_"; private static final String[] CHARACTERS = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", @@ -49,14 +52,60 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { private int mCurrentTime = 0; + private void removeAllTestDictFiles() { + final Locale dummyLocale = new Locale(TEST_LOCALE_PREFIX); + final String dictName = ExpandableBinaryDictionary.getDictName( + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); + final File dictFile = ExpandableBinaryDictionary.getDictFile( + mContext, dictName, null /* dictFile */); + final FilenameFilter filenameFilter = new FilenameFilter() { + @Override + public boolean accept(File dir, String filename) { + return filename.startsWith(UserHistoryDictionary.NAME + "." + TEST_LOCALE_PREFIX); + } + }; + FileUtils.deleteFilteredFiles(dictFile.getParentFile(), filenameFilter); + } + + private void printAllFiles(final File dir) { + Log.d(TAG, dir.getAbsolutePath()); + for (final File file : dir.listFiles()) { + Log.d(TAG, " " + file.getName()); + } + } + + private void checkExistenceAndRemoveDictFile(final UserHistoryDictionary dict, + final File dictFile) { + Log.d(TAG, "waiting for writing ..."); + dict.waitAllTasksForTests(); + if (!dictFile.exists()) { + try { + Log.d(TAG, dictFile + " is not existing. Wait " + + WAIT_FOR_WRITING_FILE_IN_MILLISECONDS + " ms for writing."); + printAllFiles(dictFile.getParentFile()); + Thread.sleep(WAIT_FOR_WRITING_FILE_IN_MILLISECONDS); + } catch (final InterruptedException e) { + Log.e(TAG, "Interrupted during waiting for writing the dict file."); + } + } + assertTrue("check exisiting of " + dictFile, dictFile.exists()); + FileUtils.deleteRecursively(dictFile); + } + + private static Locale getDummyLocale(final String name) { + return new Locale(TEST_LOCALE_PREFIX + name + System.currentTimeMillis()); + } + @Override protected void setUp() throws Exception { super.setUp(); resetCurrentTimeForTestMode(); + removeAllTestDictFiles(); } @Override protected void tearDown() throws Exception { + removeAllTestDictFiles(); stopTestModeInNativeCode(); super.tearDown(); } @@ -110,13 +159,13 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { return new ArrayList<>(wordSet); } - private static void addToDict(final UserHistoryDictionary dict, final List<String> words) { - PrevWordsInfo prevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO; + private static void addToDict(final UserHistoryDictionary dict, final List<String> words, + final int timestamp) { + NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO; for (String word : words) { - UserHistoryDictionary.addToDictionary(dict, prevWordsInfo, word, true, - (int)TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), + UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp, DistracterFilter.EMPTY_DISTRACTER_FILTER); - prevWordsInfo = prevWordsInfo.getNextPrevWordsInfo(new WordInfo(word)); + ngramContext = ngramContext.getNextNgramContext(new WordInfo(word)); } } @@ -124,13 +173,11 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { * @param checkContents if true, checks whether written words are actually in the dictionary * or not. */ - private void addAndWriteRandomWords(final Locale locale, final int numberOfWords, - final Random random, final boolean checkContents) { + private void addAndWriteRandomWords(final UserHistoryDictionary dict, + final int numberOfWords, final Random random, final boolean checkContents) { final List<String> words = generateWords(numberOfWords, random); - final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - mContext, locale); // Add random words to the user history dictionary. - addToDict(dict, words); + addToDict(dict, words, mCurrentTime); if (checkContents) { dict.waitAllTasksForTests(); for (int i = 0; i < numberOfWords; ++i) { @@ -144,49 +191,31 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { /** * Clear all entries in the user history dictionary. - * @param locale dummy locale for testing. + * @param dict the user history dictionary. */ - private void clearHistory(final Locale locale) { - final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - mContext, locale); + private void clearHistory(final UserHistoryDictionary dict) { dict.waitAllTasksForTests(); dict.clear(); dict.close(); dict.waitAllTasksForTests(); } - /** - * Shut down executer and wait until all operations of user history are done. - * @param locale dummy locale for testing. - */ - private void waitForWriting(final Locale locale) { - final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - mContext, locale); - dict.waitAllTasksForTests(); - } - public void testRandomWords() { Log.d(TAG, "This test can be used for profiling."); Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); - final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); + final Locale dummyLocale = getDummyLocale("random_words"); final String dictName = ExpandableBinaryDictionary.getDictName( UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); final File dictFile = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + getContext(), dummyLocale); final int numberOfWords = 1000; final Random random = new Random(123456); - - try { - clearHistory(dummyLocale); - addAndWriteRandomWords(dummyLocale, numberOfWords, random, - true /* checksContents */); - } finally { - Log.d(TAG, "waiting for writing ..."); - waitForWriting(dummyLocale); - assertTrue("check exisiting of " + dictFile, dictFile.exists()); - FileUtils.deleteRecursively(dictFile); - } + clearHistory(dict); + addAndWriteRandomWords(dict, numberOfWords, random, true /* checksContents */); + checkExistenceAndRemoveDictFile(dict, dictFile); } public void testStressTestForSwitchingLanguagesAndAddingWords() { @@ -195,79 +224,75 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final int numberOfWordsInsertedForEachLanguageSwitch = 100; final File dictFiles[] = new File[numberOfLanguages]; - final Locale dummyLocales[] = new Locale[numberOfLanguages]; + final UserHistoryDictionary dicts[] = new UserHistoryDictionary[numberOfLanguages]; + try { final Random random = new Random(123456); // Create filename suffixes for this test. for (int i = 0; i < numberOfLanguages; i++) { - dummyLocales[i] = new Locale("test_switching_languages" + i); + final Locale dummyLocale = getDummyLocale("switching_languages" + i); final String dictName = ExpandableBinaryDictionary.getDictName( - UserHistoryDictionary.NAME, dummyLocales[i], null /* dictFile */); + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); dictFiles[i] = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); - clearHistory(dummyLocales[i]); + dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(), + dummyLocale); + clearHistory(dicts[i]); } final long start = System.currentTimeMillis(); for (int i = 0; i < numberOfLanguageSwitching; i++) { final int index = i % numberOfLanguages; - // Switch languages to testFilenameSuffixes[index]. - addAndWriteRandomWords(dummyLocales[index], - numberOfWordsInsertedForEachLanguageSwitch, random, - false /* checksContents */); + // Switch to dicts[index]. + addAndWriteRandomWords(dicts[index], numberOfWordsInsertedForEachLanguageSwitch, + random, false /* checksContents */); } final long end = System.currentTimeMillis(); Log.d(TAG, "testStressTestForSwitchingLanguageAndAddingWords took " + (end - start) + " ms"); } finally { - Log.d(TAG, "waiting for writing ..."); for (int i = 0; i < numberOfLanguages; i++) { - waitForWriting(dummyLocales[i]); - } - for (final File dictFile : dictFiles) { - assertTrue("check exisiting of " + dictFile, dictFile.exists()); - FileUtils.deleteRecursively(dictFile); + checkExistenceAndRemoveDictFile(dicts[i], dictFiles[i]); } } } public void testAddManyWords() { - final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); + final Locale dummyLocale = getDummyLocale("many_random_words"); final String dictName = ExpandableBinaryDictionary.getDictName( UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); final File dictFile = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); final int numberOfWords = 10000; final Random random = new Random(123456); - clearHistory(dummyLocale); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + getContext(), dummyLocale); + clearHistory(dict); try { - addAndWriteRandomWords(dummyLocale, numberOfWords, random, true /* checksContents */); + addAndWriteRandomWords(dict, numberOfWords, random, true /* checksContents */); } finally { - Log.d(TAG, "waiting for writing ..."); - waitForWriting(dummyLocale); - assertTrue("check exisiting of " + dictFile, dictFile.exists()); - FileUtils.deleteRecursively(dictFile); + checkExistenceAndRemoveDictFile(dict, dictFile); } } public void testDecaying() { - final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis()); + final Locale dummyLocale = getDummyLocale("decaying"); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + getContext(), dummyLocale); final int numberOfWords = 5000; final Random random = new Random(123456); resetCurrentTimeForTestMode(); - clearHistory(dummyLocale); + clearHistory(dict); final List<String> words = generateWords(numberOfWords, random); - final UserHistoryDictionary dict = - PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale); dict.waitAllTasksForTests(); - PrevWordsInfo prevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO; + NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO; for (final String word : words) { - UserHistoryDictionary.addToDictionary(dict, prevWordsInfo, word, true, mCurrentTime, + UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, mCurrentTime, DistracterFilter.EMPTY_DISTRACTER_FILTER); - prevWordsInfo = prevWordsInfo.getNextPrevWordsInfo(new WordInfo(word)); + ngramContext = ngramContext.getNextNgramContext(new WordInfo(word)); dict.waitAllTasksForTests(); assertTrue(dict.isInDictionary(word)); } diff --git a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java new file mode 100644 index 000000000..2ef8b548f --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java @@ -0,0 +1,132 @@ +/* + * 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.latin.settings; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Intent; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.MediumTest; +import android.view.View; +import android.widget.ListView; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@MediumTest +public class AccountsSettingsFragmentTests + extends ActivityInstrumentationTestCase2<TestFragmentActivity> { + private static final String FRAG_NAME = AccountsSettingsFragment.class.getName(); + private static final long TEST_TIMEOUT_MILLIS = 5000; + + private AlertDialog mDialog; + + public AccountsSettingsFragmentTests() { + super(TestFragmentActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + Intent intent = new Intent(); + intent.putExtra(TestFragmentActivity.EXTRA_SHOW_FRAGMENT, FRAG_NAME); + setActivityIntent(intent); + } + + public void testEmptyAccounts() { + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + try { + fragment.createAccountPicker(new String[0], null); + fail("Expected IllegalArgumentException, never thrown"); + } catch (IllegalArgumentException expected) { + // Expected. + } + } + + public void testMultipleAccounts_noCurrentAccount() { + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final CountDownLatch latch = new CountDownLatch(1); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mDialog = fragment.createAccountPicker( + new String[] { + "1@example.com", + "2@example.com", + "3@example.com", + "4@example.com"}, + null); + mDialog.show(); + latch.countDown(); + } + }); + + try { + latch.await(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + } catch (InterruptedException ex) { + fail(); + } + getInstrumentation().waitForIdleSync(); + final ListView lv = mDialog.getListView(); + // The 1st account should be checked by default. + assertEquals("checked-item", 0, lv.getCheckedItemPosition()); + // There should be 4 accounts in the list. + assertEquals("count", 4, lv.getCount()); + // The sign-out button shouldn't exist + assertEquals(View.GONE, mDialog.getButton(Dialog.BUTTON_NEUTRAL).getVisibility()); + assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_NEGATIVE).getVisibility()); + assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_POSITIVE).getVisibility()); + } + + public void testMultipleAccounts_currentAccount() { + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final CountDownLatch latch = new CountDownLatch(1); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mDialog = fragment.createAccountPicker( + new String[] { + "1@example.com", + "2@example.com", + "3@example.com", + "4@example.com"}, + "3@example.com"); + mDialog.show(); + latch.countDown(); + } + }); + + try { + latch.await(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); + } catch (InterruptedException ex) { + fail(); + } + getInstrumentation().waitForIdleSync(); + final ListView lv = mDialog.getListView(); + // The 3rd account should be checked by default. + assertEquals("checked-item", 2, lv.getCheckedItemPosition()); + // There should be 4 accounts in the list. + assertEquals("count", 4, lv.getCount()); + // The sign-out button should be shown + assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_NEUTRAL).getVisibility()); + assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_NEGATIVE).getVisibility()); + assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_POSITIVE).getVisibility()); + } +} diff --git a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java index 91c9c3775..66a12b99b 100644 --- a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java @@ -151,25 +151,25 @@ public class AdditionalSubtypeUtilsTests extends AndroidTestCase { } public void testRestorable() { - final InputMethodSubtype EN_UK_DVORAK = + final InputMethodSubtype EN_US_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( Locale.US.toString(), "dvorak"); final InputMethodSubtype ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( SubtypeLocaleUtils.NO_LANGUAGE, "azerty"); - assertEnUsDvorak(EN_UK_DVORAK); + assertEnUsDvorak(EN_US_DVORAK); assertAzerty(ZZ_AZERTY); // Make sure the subtype can be stored and restored in a deterministic manner. - final InputMethodSubtype[] subtypes = { EN_UK_DVORAK, ZZ_AZERTY }; + final InputMethodSubtype[] subtypes = { EN_US_DVORAK, ZZ_AZERTY }; final String prefSubtype = AdditionalSubtypeUtils.createPrefSubtypes(subtypes); final InputMethodSubtype[] restoredSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype); assertEquals(2, restoredSubtypes.length); - final InputMethodSubtype restored_EN_UK_DVORAK = restoredSubtypes[0]; + final InputMethodSubtype restored_EN_US_DVORAK = restoredSubtypes[0]; final InputMethodSubtype restored_ZZ_AZERTY = restoredSubtypes[1]; - assertEnUsDvorak(restored_EN_UK_DVORAK); + assertEnUsDvorak(restored_EN_US_DVORAK); assertAzerty(restored_ZZ_AZERTY); } } diff --git a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java index c746c8345..4646a823d 100644 --- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java @@ -124,5 +124,29 @@ public class CapsModeUtilsTests extends AndroidTestCase { allPathsForCaps("Word. ", c | w, sp, false); // Armenian period : capitalize if MODE_SENTENCES allPathsForCaps("Word\u0589 ", c | w | s, sp, false); + + // Test for sentence terminators + sp = job.runInLocale(res, Locale.ENGLISH); + allPathsForCaps("Word? ", c | w | s, sp, false); + allPathsForCaps("Word?", c | w | s, sp, true); + allPathsForCaps("Word?", c, sp, false); + allPathsForCaps("Word! ", c | w | s, sp, false); + allPathsForCaps("Word!", c | w | s, sp, true); + allPathsForCaps("Word!", c, sp, false); + allPathsForCaps("Word; ", c | w, sp, false); + allPathsForCaps("Word;", c | w, sp, true); + allPathsForCaps("Word;", c, sp, false); + // Test for sentence terminators in Greek + sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("el")); + allPathsForCaps("Word? ", c | w | s, sp, false); + allPathsForCaps("Word?", c | w | s, sp, true); + allPathsForCaps("Word?", c, sp, false); + allPathsForCaps("Word! ", c | w | s, sp, false); + allPathsForCaps("Word!", c | w | s, sp, true); + allPathsForCaps("Word!", c, sp, false); + // In Greek ";" is the question mark and it terminates the sentence + allPathsForCaps("Word; ", c | w | s, sp, false); + allPathsForCaps("Word;", c | w | s, sp, true); + allPathsForCaps("Word;", c, sp, false); } } diff --git a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java b/tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java index e6fb28260..8360d53fb 100644 --- a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java +++ b/tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.inputmethod.latin; +package com.android.inputmethod.latin.utils; import java.util.ArrayList; import java.util.Locale; @@ -24,7 +24,9 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.view.inputmethod.InputMethodSubtype; -import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatchesAndSuggestions; +import com.android.inputmethod.latin.NgramContext; +import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.utils.DistracterFilter.HandlingType; /** * Unit test for DistracterFilter @@ -50,8 +52,13 @@ public class DistracterFilterTest extends AndroidTestCase { mDistracterFilter.updateEnabledSubtypes(subtypes); } - public void testIsDistractorToWordsInDictionaries() { - final PrevWordsInfo EMPTY_PREV_WORDS_INFO = PrevWordsInfo.EMPTY_PREV_WORDS_INFO; + @Override + protected void tearDown() { + mDistracterFilter.close(); + } + + public void testIsDistracterToWordsInDictionaries() { + final NgramContext EMPTY_PREV_WORDS_INFO = NgramContext.EMPTY_PREV_WORDS_INFO; final Locale localeEnUs = new Locale("en", "US"); String typedWord; @@ -194,4 +201,25 @@ public class DistracterFilterTest extends AndroidTestCase { assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); } + + public void testGetWordHandlingType() { + final Locale localeEnUs = new Locale("en", "US"); + final NgramContext EMPTY_PREV_WORDS_INFO = NgramContext.EMPTY_PREV_WORDS_INFO; + int handlingType = 0; + + handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO, + "this", localeEnUs); + assertFalse(HandlingType.shouldBeLowerCased(handlingType)); + assertFalse(HandlingType.shouldBeHandledAsOov(handlingType)); + + handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO, + "This", localeEnUs); + assertTrue(HandlingType.shouldBeLowerCased(handlingType)); + assertFalse(HandlingType.shouldBeHandledAsOov(handlingType)); + + handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO, + "thibk", localeEnUs); + assertFalse(HandlingType.shouldBeLowerCased(handlingType)); + assertTrue(HandlingType.shouldBeHandledAsOov(handlingType)); + } } diff --git a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java index 819d76328..cbabf7e8d 100644 --- a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java @@ -16,18 +16,18 @@ package com.android.inputmethod.latin.utils; -import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE; import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION; +import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE; import android.content.Context; import android.content.SharedPreferences; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.MediumTest; import android.text.TextUtils; import java.util.concurrent.TimeUnit; -@SmallTest +@MediumTest public class ImportantNoticeUtilsTests extends AndroidTestCase { // This should be aligned with R.integer.config_important_notice_version. private static final int CURRENT_IMPORTANT_NOTICE_VERSION = 1; @@ -112,6 +112,28 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { ImportantNoticeUtils.getCurrentImportantNoticeVersion(getContext())); } + public void testStateAfterFreshInstall() { + mImportantNoticePreferences.clear(); + + // Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)} + // after fresh install. + assertEquals("Has new imortant notice after fresh install", true, + ImportantNoticeUtils.hasNewImportantNotice(getContext())); + assertEquals("Next important norice title after fresh install", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Is in system setup wizard after fresh install", false, + ImportantNoticeUtils.isInSystemSetupWizard(getContext())); + final long currentTimeMillis = System.currentTimeMillis(); + assertEquals("Has timeout passed after fresh install", false, + ImportantNoticeUtils.hasTimeoutPassed(getContext(), currentTimeMillis)); + assertEquals("Timestamp of first important notice after fresh install", + (Long)currentTimeMillis, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + + assertEquals("Current boolean before update", true, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + } + public void testUpdateVersion() { mImportantNoticePreferences.clear(); @@ -163,7 +185,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); assertEquals("Next version before timeout 1", 1, ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); - assertEquals("Last time before timeout 1", (Long)lastTime, + assertEquals("Timestamp of first important notice before timeout 1", (Long)lastTime, mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); assertEquals("Current title before timeout 1", false, TextUtils.isEmpty( ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); @@ -180,7 +202,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); assertEquals("Next version before timeout 2", 1, ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); - assertEquals("Last time before timeout 2", (Long)lastTime, + assertEquals("Timestamp of first important notice before timeout 2", (Long)lastTime, mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); assertEquals("Current title before timeout 2", false, TextUtils.isEmpty( ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); @@ -196,7 +218,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); assertEquals("Next version after timeout 1", 2, ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); - assertEquals("Last time aflter timeout 1", null, + assertEquals("Timestamp of first important notice after timeout 1", null, mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); assertEquals("Current title after timeout 1", true, TextUtils.isEmpty( ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); @@ -212,7 +234,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase { ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); assertEquals("Next version after timeout 2", 2, ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); - assertEquals("Last time aflter timeout 2", null, + assertEquals("Timestamp of first important notice after timeout 2", null, mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); assertEquals("Current title after timeout 2", true, TextUtils.isEmpty( ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java new file mode 100644 index 000000000..b766ab2e7 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2011 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.utils; + +import android.content.Context; +import android.content.res.Resources; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.RichInputMethodSubtype; + +import java.util.ArrayList; +import java.util.Locale; + +@SmallTest +public class SpacebarLanguageUtilsTests extends AndroidTestCase { + // All input method subtypes of LatinIME. + private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>(); + + private RichInputMethodManager mRichImm; + private Resources mRes; + + RichInputMethodSubtype EN_US; + RichInputMethodSubtype EN_GB; + RichInputMethodSubtype ES_US; + RichInputMethodSubtype FR; + RichInputMethodSubtype FR_CA; + RichInputMethodSubtype FR_CH; + RichInputMethodSubtype DE; + RichInputMethodSubtype DE_CH; + RichInputMethodSubtype HI_ZZ; + RichInputMethodSubtype ZZ; + RichInputMethodSubtype DE_QWERTY; + RichInputMethodSubtype FR_QWERTZ; + RichInputMethodSubtype EN_US_AZERTY; + RichInputMethodSubtype EN_UK_DVORAK; + RichInputMethodSubtype ES_US_COLEMAK; + RichInputMethodSubtype ZZ_AZERTY; + RichInputMethodSubtype ZZ_PC; + + @Override + protected void setUp() throws Exception { + super.setUp(); + final Context context = getContext(); + RichInputMethodManager.init(context); + mRichImm = RichInputMethodManager.getInstance(); + mRes = context.getResources(); + SubtypeLocaleUtils.init(context); + + final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme(); + final int subtypeCount = imi.getSubtypeCount(); + for (int index = 0; index < subtypeCount; index++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(index); + mSubtypesList.add(new RichInputMethodSubtype(subtype)); + } + + EN_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), "qwerty")); + EN_GB = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.UK.toString(), "qwerty")); + ES_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "es_US", "spanish")); + FR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.FRENCH.toString(), "azerty")); + FR_CA = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.CANADA_FRENCH.toString(), "qwerty")); + FR_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "fr_CH", "swiss")); + DE = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.GERMAN.toString(), "qwertz")); + DE_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "de_CH", "swiss")); + HI_ZZ = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "hi_ZZ", "qwerty")); + ZZ = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + SubtypeLocaleUtils.NO_LANGUAGE, "qwerty")); + DE_QWERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.GERMAN.toString(), "qwerty")); + FR_QWERTZ = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.FRENCH.toString(), "qwertz")); + EN_US_AZERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.US.toString(), "azerty")); + EN_UK_DVORAK = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + Locale.UK.toString(), "dvorak")); + ES_US_COLEMAK = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "es_US", "colemak")); + ZZ_AZERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "azerty")); + ZZ_PC = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty")); + } + + public void testAllFullDisplayNameForSpacebar() { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + final String spacebarText = subtype.getFullDisplayName(); + final String languageName = SubtypeLocaleUtils + .getSubtypeLocaleDisplayName(subtype.getLocale()); + if (subtype.isNoLanguage()) { + assertFalse(subtypeName, spacebarText.contains(languageName)); + } else { + assertTrue(subtypeName, spacebarText.contains(languageName)); + } + } + } + + public void testAllMiddleDisplayNameForSpacebar() { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final String subtypeName = SubtypeLocaleUtils + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + if (SubtypeLocaleUtils.sExceptionalLocaleDisplayedInRootLocale.contains( + subtype.getLocale())) { + // Skip test because the language part of this locale string doesn't represent + // the locale to be displayed on the spacebar (for example hi_ZZ and Hinglish). + continue; + } + final String spacebarText = subtype.getMiddleDisplayName(); + if (subtype.isNoLanguage()) { + assertEquals(subtypeName, SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName( + subtype.getRawSubtype()), spacebarText); + } else { + final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype); + assertEquals(subtypeName, + SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()), + spacebarText); + } + } + } + + // InputMethodSubtype's display name for spacebar text in its locale. + // isAdditionalSubtype (T=true, F=false) + // locale layout | Middle Full + // ------ ------- - --------- ---------------------- + // en_US qwerty F English English (US) exception + // en_GB qwerty F English English (UK) exception + // es_US spanish F Español Español (EE.UU.) exception + // fr azerty F Français Français + // fr_CA qwerty F Français Français (Canada) + // fr_CH swiss F Français Français (Suisse) + // de qwertz F Deutsch Deutsch + // de_CH swiss F Deutsch Deutsch (Schweiz) + // hi_ZZ qwerty F Hinglish Hinglish + // zz qwerty F QWERTY QWERTY + // fr qwertz T Français Français + // de qwerty T Deutsch Deutsch + // en_US azerty T English English (US) + // zz azerty T AZERTY AZERTY + + private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("en_US", "English (US)", EN_US.getFullDisplayName()); + assertEquals("en_GB", "English (UK)", EN_GB.getFullDisplayName()); + assertEquals("es_US", "Español (EE.UU.)", ES_US.getFullDisplayName()); + assertEquals("fr", "Français", FR.getFullDisplayName()); + assertEquals("fr_CA", "Français (Canada)", FR_CA.getFullDisplayName()); + assertEquals("fr_CH", "Français (Suisse)", FR_CH.getFullDisplayName()); + assertEquals("de", "Deutsch", DE.getFullDisplayName()); + assertEquals("de_CH", "Deutsch (Schweiz)", DE_CH.getFullDisplayName()); + assertEquals("hi_ZZ", "Hinglish", HI_ZZ.getFullDisplayName()); + assertEquals("zz", "QWERTY", ZZ.getFullDisplayName()); + + assertEquals("en_US", "English", EN_US.getMiddleDisplayName()); + assertEquals("en_GB", "English", EN_GB.getMiddleDisplayName()); + assertEquals("es_US", "Español", ES_US.getMiddleDisplayName()); + assertEquals("fr", "Français", FR.getMiddleDisplayName()); + assertEquals("fr_CA", "Français", FR_CA.getMiddleDisplayName()); + assertEquals("fr_CH", "Français", FR_CH.getMiddleDisplayName()); + assertEquals("de", "Deutsch", DE.getMiddleDisplayName()); + assertEquals("de_CH", "Deutsch", DE_CH.getMiddleDisplayName()); + assertEquals("hi_ZZ", "Hinglish", HI_ZZ.getMiddleDisplayName()); + assertEquals("zz", "QWERTY", ZZ.getMiddleDisplayName()); + return null; + } + }; + + private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() { + @Override + protected Void job(final Resources res) { + assertEquals("fr qwertz", "Français", FR_QWERTZ.getFullDisplayName()); + assertEquals("de qwerty", "Deutsch", DE_QWERTY.getFullDisplayName()); + assertEquals("en_US azerty", "English (US)", EN_US_AZERTY.getFullDisplayName()); + assertEquals("en_UK dvorak", "English (UK)", EN_UK_DVORAK.getFullDisplayName()); + assertEquals("es_US colemak", "Español (EE.UU.)", ES_US_COLEMAK.getFullDisplayName()); + assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getFullDisplayName()); + assertEquals("zz pc", "PC", ZZ_PC.getFullDisplayName()); + + assertEquals("fr qwertz", "Français", FR_QWERTZ.getMiddleDisplayName()); + assertEquals("de qwerty", "Deutsch", DE_QWERTY.getMiddleDisplayName()); + assertEquals("en_US azerty", "English", EN_US_AZERTY.getMiddleDisplayName()); + assertEquals("en_UK dvorak", "English", EN_UK_DVORAK.getMiddleDisplayName()); + assertEquals("es_US colemak", "Español", ES_US_COLEMAK.getMiddleDisplayName()); + assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getMiddleDisplayName()); + assertEquals("zz pc", "PC", ZZ_PC.getMiddleDisplayName()); + return null; + } + }; + + public void testPredefinedSubtypesForSpacebarInEnglish() { + testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); + } + + public void testAdditionalSubtypeForSpacebarInEnglish() { + testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); + } + + public void testPredefinedSubtypesForSpacebarInFrench() { + testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); + } + + public void testAdditionalSubtypeForSpacebarInFrench() { + testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); + } +} diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java deleted file mode 100644 index fdde34251..000000000 --- a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2011 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.utils; - -import android.content.Context; -import android.content.res.Resources; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; -import android.view.inputmethod.InputMethodInfo; -import android.view.inputmethod.InputMethodSubtype; - -import com.android.inputmethod.latin.RichInputMethodManager; - -import java.util.ArrayList; -import java.util.Locale; - -@SmallTest -public class SpacebarLanguagetUtilsTests extends AndroidTestCase { - // All input method subtypes of LatinIME. - private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>(); - - private RichInputMethodManager mRichImm; - private Resources mRes; - - InputMethodSubtype EN_US; - InputMethodSubtype EN_GB; - InputMethodSubtype ES_US; - InputMethodSubtype FR; - InputMethodSubtype FR_CA; - InputMethodSubtype FR_CH; - InputMethodSubtype DE; - InputMethodSubtype DE_CH; - InputMethodSubtype ZZ; - InputMethodSubtype DE_QWERTY; - InputMethodSubtype FR_QWERTZ; - InputMethodSubtype EN_US_AZERTY; - InputMethodSubtype EN_UK_DVORAK; - InputMethodSubtype ES_US_COLEMAK; - InputMethodSubtype ZZ_AZERTY; - InputMethodSubtype ZZ_PC; - - @Override - protected void setUp() throws Exception { - super.setUp(); - final Context context = getContext(); - RichInputMethodManager.init(context); - mRichImm = RichInputMethodManager.getInstance(); - mRes = context.getResources(); - SubtypeLocaleUtils.init(context); - - final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme(); - final int subtypeCount = imi.getSubtypeCount(); - for (int index = 0; index < subtypeCount; index++) { - final InputMethodSubtype subtype = imi.getSubtypeAt(index); - mSubtypesList.add(subtype); - } - - EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.US.toString(), "qwerty"); - EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.UK.toString(), "qwerty"); - ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - "es_US", "spanish"); - FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.FRENCH.toString(), "azerty"); - FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.CANADA_FRENCH.toString(), "qwerty"); - FR_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - "fr_CH", "swiss"); - DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - Locale.GERMAN.toString(), "qwertz"); - DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - "de_CH", "swiss"); - ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( - SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"); - DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - Locale.GERMAN.toString(), "qwerty"); - FR_QWERTZ = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - Locale.FRENCH.toString(), "qwertz"); - EN_US_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - Locale.US.toString(), "azerty"); - EN_UK_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - Locale.UK.toString(), "dvorak"); - ES_US_COLEMAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - "es_US", "colemak"); - ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - SubtypeLocaleUtils.NO_LANGUAGE, "azerty"); - ZZ_PC = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( - SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty"); - } - - public void testAllFullDisplayNameForSpacebar() { - for (final InputMethodSubtype subtype : mSubtypesList) { - final String subtypeName = SubtypeLocaleUtils - .getSubtypeDisplayNameInSystemLocale(subtype); - final String spacebarText = SpacebarLanguageUtils.getFullDisplayName(subtype); - final String languageName = SubtypeLocaleUtils - .getSubtypeLocaleDisplayName(subtype.getLocale()); - if (SubtypeLocaleUtils.isNoLanguage(subtype)) { - assertFalse(subtypeName, spacebarText.contains(languageName)); - } else { - assertTrue(subtypeName, spacebarText.contains(languageName)); - } - } - } - - public void testAllMiddleDisplayNameForSpacebar() { - for (final InputMethodSubtype subtype : mSubtypesList) { - final String subtypeName = SubtypeLocaleUtils - .getSubtypeDisplayNameInSystemLocale(subtype); - final String spacebarText = SpacebarLanguageUtils.getMiddleDisplayName(subtype); - if (SubtypeLocaleUtils.isNoLanguage(subtype)) { - assertEquals(subtypeName, - SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype), spacebarText); - } else { - final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype); - assertEquals(subtypeName, - SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()), - spacebarText); - } - } - } - - // InputMethodSubtype's display name for spacebar text in its locale. - // isAdditionalSubtype (T=true, F=false) - // locale layout | Middle Full - // ------ ------- - --------- ---------------------- - // en_US qwerty F English English (US) exception - // en_GB qwerty F English English (UK) exception - // es_US spanish F Español Español (EE.UU.) exception - // fr azerty F Français Français - // fr_CA qwerty F Français Français (Canada) - // fr_CH swiss F Français Français (Suisse) - // de qwertz F Deutsch Deutsch - // de_CH swiss F Deutsch Deutsch (Schweiz) - // zz qwerty F QWERTY QWERTY - // fr qwertz T Français Français - // de qwerty T Deutsch Deutsch - // en_US azerty T English English (US) - // zz azerty T AZERTY AZERTY - - private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() { - @Override - protected Void job(final Resources res) { - assertEquals("en_US", "English (US)", - SpacebarLanguageUtils.getFullDisplayName(EN_US)); - assertEquals("en_GB", "English (UK)", - SpacebarLanguageUtils.getFullDisplayName(EN_GB)); - assertEquals("es_US", "Español (EE.UU.)", - SpacebarLanguageUtils.getFullDisplayName(ES_US)); - assertEquals("fr", "Français", - SpacebarLanguageUtils.getFullDisplayName(FR)); - assertEquals("fr_CA", "Français (Canada)", - SpacebarLanguageUtils.getFullDisplayName(FR_CA)); - assertEquals("fr_CH", "Français (Suisse)", - SpacebarLanguageUtils.getFullDisplayName(FR_CH)); - assertEquals("de", "Deutsch", - SpacebarLanguageUtils.getFullDisplayName(DE)); - assertEquals("de_CH", "Deutsch (Schweiz)", - SpacebarLanguageUtils.getFullDisplayName(DE_CH)); - assertEquals("zz", "QWERTY", - SpacebarLanguageUtils.getFullDisplayName(ZZ)); - - assertEquals("en_US", "English", - SpacebarLanguageUtils.getMiddleDisplayName(EN_US)); - assertEquals("en_GB", "English", - SpacebarLanguageUtils.getMiddleDisplayName(EN_GB)); - assertEquals("es_US", "Español", - SpacebarLanguageUtils.getMiddleDisplayName(ES_US)); - assertEquals("fr", "Français", - SpacebarLanguageUtils.getMiddleDisplayName(FR)); - assertEquals("fr_CA", "Français", - SpacebarLanguageUtils.getMiddleDisplayName(FR_CA)); - assertEquals("fr_CH", "Français", - SpacebarLanguageUtils.getMiddleDisplayName(FR_CH)); - assertEquals("de", "Deutsch", - SpacebarLanguageUtils.getMiddleDisplayName(DE)); - assertEquals("de_CH", "Deutsch", - SpacebarLanguageUtils.getMiddleDisplayName(DE_CH)); - assertEquals("zz", "QWERTY", - SpacebarLanguageUtils.getMiddleDisplayName(ZZ)); - return null; - } - }; - - private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() { - @Override - protected Void job(final Resources res) { - assertEquals("fr qwertz", "Français", - SpacebarLanguageUtils.getFullDisplayName(FR_QWERTZ)); - assertEquals("de qwerty", "Deutsch", - SpacebarLanguageUtils.getFullDisplayName(DE_QWERTY)); - assertEquals("en_US azerty", "English (US)", - SpacebarLanguageUtils.getFullDisplayName(EN_US_AZERTY)); - assertEquals("en_UK dvorak", "English (UK)", - SpacebarLanguageUtils.getFullDisplayName(EN_UK_DVORAK)); - assertEquals("es_US colemak", "Español (EE.UU.)", - SpacebarLanguageUtils.getFullDisplayName(ES_US_COLEMAK)); - assertEquals("zz azerty", "AZERTY", - SpacebarLanguageUtils.getFullDisplayName(ZZ_AZERTY)); - assertEquals("zz pc", "PC", - SpacebarLanguageUtils.getFullDisplayName(ZZ_PC)); - - assertEquals("fr qwertz", "Français", - SpacebarLanguageUtils.getMiddleDisplayName(FR_QWERTZ)); - assertEquals("de qwerty", "Deutsch", - SpacebarLanguageUtils.getMiddleDisplayName(DE_QWERTY)); - assertEquals("en_US azerty", "English", - SpacebarLanguageUtils.getMiddleDisplayName(EN_US_AZERTY)); - assertEquals("en_UK dvorak", "English", - SpacebarLanguageUtils.getMiddleDisplayName(EN_UK_DVORAK)); - assertEquals("es_US colemak", "Español", - SpacebarLanguageUtils.getMiddleDisplayName(ES_US_COLEMAK)); - assertEquals("zz azerty", "AZERTY", - SpacebarLanguageUtils.getMiddleDisplayName(ZZ_AZERTY)); - assertEquals("zz pc", "PC", - SpacebarLanguageUtils.getMiddleDisplayName(ZZ_PC)); - return null; - } - }; - - public void testPredefinedSubtypesForSpacebarInEnglish() { - testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); - } - - public void testAdditionalSubtypeForSpacebarInEnglish() { - testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); - } - - public void testPredefinedSubtypesForSpacebarInFrench() { - testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); - } - - public void testAdditionalSubtypeForSpacebarInFrench() { - testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); - } -} diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java index ce3df7dd6..c095e6831 100644 --- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java @@ -24,6 +24,7 @@ import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.RichInputMethodSubtype; import java.util.ArrayList; import java.util.Locale; @@ -31,7 +32,7 @@ import java.util.Locale; @SmallTest public class SubtypeLocaleUtilsTests extends AndroidTestCase { // All input method subtypes of LatinIME. - private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>(); + private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>(); private RichInputMethodManager mRichImm; private Resources mRes; @@ -44,6 +45,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { InputMethodSubtype FR_CH; InputMethodSubtype DE; InputMethodSubtype DE_CH; + InputMethodSubtype HI_ZZ; InputMethodSubtype ZZ; InputMethodSubtype DE_QWERTY; InputMethodSubtype FR_QWERTZ; @@ -66,7 +68,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { final int subtypeCount = imi.getSubtypeCount(); for (int index = 0; index < subtypeCount; index++) { final InputMethodSubtype subtype = imi.getSubtypeAt(index); - mSubtypesList.add(subtype); + mSubtypesList.add(new RichInputMethodSubtype(subtype)); } EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( @@ -85,6 +87,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { Locale.GERMAN.toString(), "qwertz"); DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( "de_CH", "swiss"); + HI_ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "hi_ZZ", "qwerty"); ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"); DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( @@ -104,12 +108,12 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { } public void testAllFullDisplayName() { - for (final InputMethodSubtype subtype : mSubtypesList) { + for (final RichInputMethodSubtype subtype : mSubtypesList) { final String subtypeName = SubtypeLocaleUtils - .getSubtypeDisplayNameInSystemLocale(subtype); - if (SubtypeLocaleUtils.isNoLanguage(subtype)) { + .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype()); + if (subtype.isNoLanguage()) { final String layoutName = SubtypeLocaleUtils - .getKeyboardLayoutSetDisplayName(subtype); + .getKeyboardLayoutSetDisplayName(subtype.getRawSubtype()); assertTrue(subtypeName, subtypeName.contains(layoutName)); } else { final String languageName = SubtypeLocaleUtils @@ -128,6 +132,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { assertEquals("fr_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CH)); assertEquals("de", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE)); assertEquals("de_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_CH)); + assertEquals("hi_ZZ", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_ZZ)); assertEquals("zz", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ)); assertEquals("de qwerty", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_QWERTY)); @@ -154,6 +159,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // fr_CH swiss F French (Switzerland) // de qwertz F German // de_CH swiss F German (Switzerland) + // hi_ZZ qwerty F Hinglish // zz qwerty F Alphabet (QWERTY) // fr qwertz T French (QWERTZ) // de qwerty T German (QWERTY) @@ -182,6 +188,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE)); assertEquals("de_CH", "German (Switzerland)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH)); + assertEquals("hi_ZZ", "Hinglish", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_ZZ)); assertEquals("zz", "Alphabet (QWERTY)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ)); return null; @@ -226,6 +234,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // fr_CH swiss F Français (Suisse) // de qwertz F Allemand // de_CH swiss F Allemand (Suisse) + // hi_ZZ qwerty F Hinglish // zz qwerty F Alphabet latin (QWERTY) // fr qwertz T Français (QWERTZ) // de qwerty T Allemand (QWERTY) @@ -254,6 +263,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE)); assertEquals("de_CH", "Allemand (Suisse)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH)); + assertEquals("hi_ZZ", "Hindi/Anglais", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_ZZ)); assertEquals("zz", "Alphabet latin (QWERTY)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ)); return null; @@ -298,10 +309,12 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { .findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew"); assertNotNull("Hebrew", HEBREW); - for (final InputMethodSubtype subtype : mSubtypesList) { + for (final RichInputMethodSubtype subtype : mSubtypesList) { + final InputMethodSubtype rawSubtype = subtype.getRawSubtype(); final String subtypeName = SubtypeLocaleUtils - .getSubtypeDisplayNameInSystemLocale(subtype); - if (subtype.equals(ARABIC) || subtype.equals(FARSI) || subtype.equals(HEBREW)) { + .getSubtypeDisplayNameInSystemLocale(rawSubtype); + if (rawSubtype.equals(ARABIC) || rawSubtype.equals(FARSI) + || rawSubtype.equals(HEBREW)) { assertTrue(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype)); } else { assertFalse(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype)); |