diff options
Diffstat (limited to 'tests/src')
3 files changed, 103 insertions, 34 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicFrenchTests.java b/tests/src/com/android/inputmethod/latin/InputLogicFrenchTests.java index 5db120d82..60a7b05a9 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicFrenchTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicFrenchTests.java @@ -16,8 +16,6 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.keyboard.Keyboard; - public class InputLogicFrenchTests extends InputTestsBase { public void testAutoCorrectForFrench() { diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 5f6b229dd..4dfe22800 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -95,7 +95,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME); final boolean previousDebugSetting = prefs.getBoolean(PREF_DEBUG_MODE, false); final SharedPreferences.Editor editor = prefs.edit(); - editor.putBoolean(PREF_DEBUG_MODE, true); + editor.putBoolean(PREF_DEBUG_MODE, mode); editor.commit(); return previousDebugSetting; } @@ -138,17 +138,20 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { final InputMethodManager imm = (InputMethodManager)mLatinIME.getSystemService( Context.INPUT_METHOD_SERVICE); final String packageName = mLatinIME.getPackageName(); - for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) { + // The IMEs and subtypes don't need to be enabled to run this test because IMF isn't + // involved here. + for (final InputMethodInfo imi : imm.getInputMethodList()) { if (imi.getPackageName().equals(packageName)) { - for (final InputMethodSubtype ims : - imm.getEnabledInputMethodSubtypeList(imi, true)) { + final int subtypeCount = imi.getSubtypeCount(); + for (int i = 0; i < subtypeCount; i++) { + final InputMethodSubtype ims = imi.getSubtypeAt(i); final String locale = ims.getLocale(); mSubtypeMap.put(locale, ims); } return; } } - fail("LatinIME is disabled"); + fail("LatinIME is not found"); } // We need to run the messages added to the handler from LatinIME. The only way to do @@ -176,7 +179,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { // The only way to get out of Looper#loop() is to call #quit() on it (or on its queue). // Once #quit() is called remaining messages are not processed, which is why we post // a message that calls it instead of calling it directly. - looper.loop(); + Looper.loop(); // Once #quit() has been called, the message queue has an "mQuiting" field that prevents // any subsequent post in this queue. However the queue itself is still fully functional! diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java index 089fdc52c..6180ff5f9 100644 --- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java @@ -23,11 +23,14 @@ import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import java.util.ArrayList; -import java.util.List; import java.util.Locale; public class SubtypeLocaleTests extends AndroidTestCase { - private List<InputMethodSubtype> mKeyboardSubtypes; + private static final Locale LOCALE_zz_QY = SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY; + private static final Locale LOCALE_de_QY = + new Locale(Locale.GERMAN.getLanguage(), SubtypeLocale.QWERTY); + + private ArrayList<InputMethodSubtype> mSubtypesList; @Override protected void setUp() throws Exception { @@ -42,46 +45,111 @@ public class SubtypeLocaleTests extends AndroidTestCase { Context.INPUT_METHOD_SERVICE); for (final InputMethodInfo imi : imm.getInputMethodList()) { if (imi.getPackageName().equals(packageName)) { - mKeyboardSubtypes = new ArrayList<InputMethodSubtype>(); + mSubtypesList = new ArrayList<InputMethodSubtype>(); final int subtypeCount = imi.getSubtypeCount(); - for (int i = 0; i < subtypeCount; ++i) { - InputMethodSubtype subtype = imi.getSubtypeAt(i); - if (subtype.getMode().equals("keyboard")) { - mKeyboardSubtypes.add(subtype); - } + for (int i = 0; i < subtypeCount; i++) { + final InputMethodSubtype ims = imi.getSubtypeAt(i); + mSubtypesList.add(ims); } break; } } - assertNotNull("Can not find input method " + packageName, mKeyboardSubtypes); - assertTrue("Can not find keyboard subtype", mKeyboardSubtypes.size() > 0); + assertNotNull("Can not find input method " + packageName, mSubtypesList); + assertTrue("Can not find keyboard subtype", mSubtypesList.size() > 0); + } + + private static Locale getSubtypeLocale(InputMethodSubtype subtype) { + return LocaleUtils.constructLocaleFromString(subtype.getLocale()); + } + + private static Locale getKeyboardLocale(InputMethodSubtype subtype) { + final String subtypeLocaleString = subtype.containsExtraValueKey( + LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) + ? subtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) + : subtype.getLocale(); + return LocaleUtils.constructLocaleFromString(subtypeLocaleString); } - public void testSubtypeLocale() { + public void testFullDisplayName() { final StringBuilder messages = new StringBuilder(); int failedCount = 0; - for (final InputMethodSubtype subtype : mKeyboardSubtypes) { - final Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale()); - if (locale.getLanguage().equals("zz")) { + for (final InputMethodSubtype subtype : mSubtypesList) { + final Locale locale = getKeyboardLocale(subtype); + if (locale.getLanguage().equals(SubtypeLocale.NO_LANGUAGE)) { // This is special language name for language agnostic usage. continue; } - final String subtypeLocaleString = - subtype.containsExtraValueKey(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) - ? subtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE) - : subtype.getLocale(); - final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtypeLocaleString); - // The subtype name in its locale. For example 'English (US)' or 'Deutsch (QWERTY)'. - final String subtypeName = SubtypeLocale.getFullDisplayName(subtypeLocale); - // The locale language name in its locale. - final String languageName = locale.getDisplayLanguage(locale); - if (!subtypeName.contains(languageName)) { + final String keyboardName = SubtypeLocale.getFullDisplayName(locale); + final String languageName = SubtypeLocale.toTitleCase( + locale.getDisplayLanguage(locale), locale); + if (!keyboardName.contains(languageName)) { failedCount++; messages.append(String.format( - "subtype name is '%s' and should contain locale '%s' language name '%s'\n", - subtypeName, subtypeLocale, languageName)); + "locale %s: keyboard name '%s' should contain language name '%s'\n", + locale, keyboardName, languageName)); } } assertEquals(messages.toString(), 0, failedCount); } + + public void testFullDisplayNameNoLanguage() { + assertEquals("zz_QY", "QWERTY", SubtypeLocale.getFullDisplayName(LOCALE_zz_QY)); + + final String de_QY = SubtypeLocale.getFullDisplayName(LOCALE_de_QY); + assertTrue("de_QY", de_QY.contains("(QWERTY")); + assertTrue("de_QY", de_QY.contains(Locale.GERMAN.getDisplayLanguage(Locale.GERMAN))); + } + + public void testMiddleDisplayName() { + final StringBuilder messages = new StringBuilder(); + int failedCount = 0; + for (final InputMethodSubtype subtype : mSubtypesList) { + final Locale locale = getKeyboardLocale(subtype); + if (locale.getLanguage().equals(SubtypeLocale.NO_LANGUAGE)) { + // This is special language name for language agnostic usage. + continue; + } + final String keyboardName = SubtypeLocale.getMiddleDisplayName(locale); + final String languageName = SubtypeLocale.toTitleCase( + locale.getDisplayLanguage(locale), locale); + if (!keyboardName.equals(languageName)) { + failedCount++; + messages.append(String.format( + "locale %s: keyboard name '%s' should be equals to language name '%s'\n", + locale, keyboardName, languageName)); + } + } + assertEquals(messages.toString(), 0, failedCount); + } + + public void testMiddleDisplayNameNoLanguage() { + assertEquals("zz_QY", "QWERTY", SubtypeLocale.getMiddleDisplayName(LOCALE_zz_QY)); + assertEquals("de_QY", "Deutsch", SubtypeLocale.getMiddleDisplayName(LOCALE_de_QY)); + } + + public void testShortDisplayName() { + final StringBuilder messages = new StringBuilder(); + int failedCount = 0; + for (final InputMethodSubtype subtype : mSubtypesList) { + final Locale locale = getKeyboardLocale(subtype); + if (locale.getCountry().equals(SubtypeLocale.QWERTY)) { + // This is special country code for QWERTY keyboard. + continue; + } + final String keyboardName = SubtypeLocale.getShortDisplayName(locale); + final String languageCode = SubtypeLocale.toTitleCase(locale.getLanguage(), locale); + if (!keyboardName.equals(languageCode)) { + failedCount++; + messages.append(String.format( + "locale %s: keyboard name '%s' should be equals to language code '%s'\n", + locale, keyboardName, languageCode)); + } + } + assertEquals(messages.toString(), 0, failedCount); + } + + public void testShortDisplayNameNoLanguage() { + assertEquals("zz_QY", "QY", SubtypeLocale.getShortDisplayName(LOCALE_zz_QY)); + assertEquals("de_QY", "De", SubtypeLocale.getShortDisplayName(LOCALE_de_QY)); + } } |