Fix SubtypeLocaleTests

Change-Id: Id85814aa3bcd9cacbe446b2dfda3ca2ab9146c13
main
Tadashi G. Takaoka 2012-01-10 18:13:34 +09:00
parent 16d5e196dc
commit 4015a64a26
5 changed files with 22 additions and 35 deletions

View File

@ -161,6 +161,8 @@
<!-- Generic subtype label --> <!-- Generic subtype label -->
<string name="subtype_generic">%s</string> <string name="subtype_generic">%s</string>
<!-- Description for generic QWERTY keyboard subtype -->
<string name="subtype_generic_qwerty">%s (QWERTY)</string>
<!-- dictionary pack package name /settings activity (for shared prefs and settings) --> <!-- dictionary pack package name /settings activity (for shared prefs and settings) -->
<string name="dictionary_pack_package_name">com.google.android.inputmethod.latin.dictionarypack</string> <string name="dictionary_pack_package_name">com.google.android.inputmethod.latin.dictionarypack</string>

View File

@ -335,8 +335,6 @@
<!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]--> <!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]-->
<string name="keyboard_layout">Keyboard theme</string> <string name="keyboard_layout">Keyboard theme</string>
<!-- Description for German QWERTY keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_de_qwerty">German QWERTY</string>
<!-- Description for English (United Kingdom) keyboard subtype [CHAR LIMIT=22] --> <!-- Description for English (United Kingdom) keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_en_GB">English (UK)</string> <string name="subtype_en_GB">English (UK)</string>
<!-- Description for English (United States) keyboard subtype [CHAR LIMIT=22] --> <!-- Description for English (United States) keyboard subtype [CHAR LIMIT=22] -->

View File

@ -71,7 +71,7 @@
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection" android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
/> />
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_de_qwerty" android:label="@string/subtype_generic_qwerty"
android:imeSubtypeLocale="de" android:imeSubtypeLocale="de"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,KeyboardLocale=de_ZZ,SupportTouchPositionCorrection" android:imeSubtypeExtraValue="AsciiCapable,KeyboardLocale=de_ZZ,SupportTouchPositionCorrection"

View File

@ -806,7 +806,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
return bounds.width(); return bounds.width();
} }
// Layout local language name and left and right arrow on spacebar. // Layout locale language name on spacebar.
private static String layoutSpacebar(Paint paint, Locale locale, int width, private static String layoutSpacebar(Paint paint, Locale locale, int width,
float origTextSize) { float origTextSize) {
final Rect bounds = new Rect(); final Rect bounds = new Rect();

View File

@ -16,10 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.LocaleUtils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -30,24 +27,22 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
public class SubtypeLocaleTests extends AndroidTestCase { public class SubtypeLocaleTests extends AndroidTestCase {
private static final String PACKAGE = LatinIME.class.getPackage().getName(); private List<InputMethodSubtype> mKeyboardSubtypes;
private Resources mRes;
private List<InputMethodSubtype> mKeyboardSubtypes = new ArrayList<InputMethodSubtype>();
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final Context context = getContext(); final Context context = getContext();
mRes = context.getResources(); final String packageName = context.getApplicationInfo().packageName;
SubtypeLocale.init(context); SubtypeLocale.init(context);
final InputMethodManager imm = (InputMethodManager) context.getSystemService( final InputMethodManager imm = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE); Context.INPUT_METHOD_SERVICE);
for (final InputMethodInfo imi : imm.getInputMethodList()) { for (final InputMethodInfo imi : imm.getInputMethodList()) {
if (imi.getPackageName().equals(PACKAGE)) { if (imi.getPackageName().equals(packageName)) {
mKeyboardSubtypes = new ArrayList<InputMethodSubtype>();
final int subtypeCount = imi.getSubtypeCount(); final int subtypeCount = imi.getSubtypeCount();
for (int i = 0; i < subtypeCount; ++i) { for (int i = 0; i < subtypeCount; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i); InputMethodSubtype subtype = imi.getSubtypeAt(i);
@ -58,37 +53,29 @@ public class SubtypeLocaleTests extends AndroidTestCase {
break; break;
} }
} }
assertNotNull("Can not find input method " + PACKAGE, mKeyboardSubtypes); assertNotNull("Can not find input method " + packageName, mKeyboardSubtypes);
assertTrue("Can not find keyboard subtype", mKeyboardSubtypes.size() > 0); assertTrue("Can not find keyboard subtype", mKeyboardSubtypes.size() > 0);
} }
private String getStringWithLocale(int resId, Locale locale) {
final Locale savedLocale = Locale.getDefault();
try {
Locale.setDefault(locale);
return mRes.getString(resId);
} finally {
Locale.setDefault(savedLocale);
}
}
public void testSubtypeLocale() { public void testSubtypeLocale() {
final StringBuilder messages = new StringBuilder(); final StringBuilder messages = new StringBuilder();
int failedCount = 0; int failedCount = 0;
for (final InputMethodSubtype subtype : mKeyboardSubtypes) { for (final InputMethodSubtype subtype : mKeyboardSubtypes) {
final String localeCode = subtype.getLocale(); final Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale());
final Locale locale = LocaleUtils.constructLocaleFromString(localeCode); final String subtypeLocaleString =
// The locale name which will be displayed on spacebar. For example 'English (US)' or subtype.containsExtraValueKey(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE)
// 'Francais (Canada)'. (c=\u008d) ? subtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE)
final String displayName = SubtypeLocale.getFullDisplayName(locale); : subtype.getLocale();
// The subtype name in its locale. For example 'English (US) Keyboard' or final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtypeLocaleString);
// 'Clavier Francais (Canada)'. (c=\u008d) // The subtype name in its locale. For example 'English (US)' or 'Deutsch (QWERTY)'.
final String subtypeName = getStringWithLocale(subtype.getNameResId(), locale); final String subtypeName = SubtypeLocale.getFullDisplayName(subtypeLocale);
if (subtypeName.contains(displayName)) { // The locale language name in its locale.
final String languageName = locale.getDisplayLanguage(locale);
if (!subtypeName.contains(languageName)) {
failedCount++; failedCount++;
messages.append(String.format( messages.append(String.format(
"subtype name is '%s' and should contain locale '%s' name '%s'\n", "subtype name is '%s' and should contain locale '%s' language name '%s'\n",
subtypeName, localeCode, displayName)); subtypeName, subtypeLocale, languageName));
} }
} }
assertEquals(messages.toString(), 0, failedCount); assertEquals(messages.toString(), 0, failedCount);