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 -->
<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) -->
<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]-->
<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] -->
<string name="subtype_en_GB">English (UK)</string>
<!-- Description for English (United States) keyboard subtype [CHAR LIMIT=22] -->

View File

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

View File

@ -806,7 +806,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
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,
float origTextSize) {
final Rect bounds = new Rect();

View File

@ -16,10 +16,7 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.LocaleUtils;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@ -30,24 +27,22 @@ import java.util.List;
import java.util.Locale;
public class SubtypeLocaleTests extends AndroidTestCase {
private static final String PACKAGE = LatinIME.class.getPackage().getName();
private Resources mRes;
private List<InputMethodSubtype> mKeyboardSubtypes = new ArrayList<InputMethodSubtype>();
private List<InputMethodSubtype> mKeyboardSubtypes;
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
mRes = context.getResources();
final String packageName = context.getApplicationInfo().packageName;
SubtypeLocale.init(context);
final InputMethodManager imm = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE);
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();
for (int i = 0; i < subtypeCount; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i);
@ -58,37 +53,29 @@ public class SubtypeLocaleTests extends AndroidTestCase {
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);
}
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() {
final StringBuilder messages = new StringBuilder();
int failedCount = 0;
for (final InputMethodSubtype subtype : mKeyboardSubtypes) {
final String localeCode = subtype.getLocale();
final Locale locale = LocaleUtils.constructLocaleFromString(localeCode);
// The locale name which will be displayed on spacebar. For example 'English (US)' or
// 'Francais (Canada)'. (c=\u008d)
final String displayName = SubtypeLocale.getFullDisplayName(locale);
// The subtype name in its locale. For example 'English (US) Keyboard' or
// 'Clavier Francais (Canada)'. (c=\u008d)
final String subtypeName = getStringWithLocale(subtype.getNameResId(), locale);
if (subtypeName.contains(displayName)) {
final Locale locale = LocaleUtils.constructLocaleFromString(subtype.getLocale());
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)) {
failedCount++;
messages.append(String.format(
"subtype name is '%s' and should contain locale '%s' name '%s'\n",
subtypeName, localeCode, displayName));
"subtype name is '%s' and should contain locale '%s' language name '%s'\n",
subtypeName, subtypeLocale, languageName));
}
}
assertEquals(messages.toString(), 0, failedCount);