am 46c37e63: Merge "Fix SubtypeLocaleUtilsTests"

* commit '46c37e63cc81a3a7e1bc72f82ad00925f334c8f9':
  Fix SubtypeLocaleUtilsTests
main
Tadashi G. Takaoka 2014-01-27 01:35:44 -08:00 committed by Android Git Automerger
commit 3312f281ff
1 changed files with 27 additions and 18 deletions

View File

@ -20,9 +20,9 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,7 +30,7 @@ import java.util.Locale;
@SmallTest @SmallTest
public class SubtypeLocaleUtilsTests extends AndroidTestCase { public class SubtypeLocaleUtilsTests extends AndroidTestCase {
// Locale to subtypes list. // All input method subtypes of LatinIME.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList(); private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private RichInputMethodManager mRichImm; private RichInputMethodManager mRichImm;
@ -62,6 +62,13 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocaleUtils.init(context); 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( EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.US.toString(), "qwerty"); Locale.US.toString(), "qwerty");
EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
@ -99,14 +106,15 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
public void testAllFullDisplayName() { public void testAllFullDisplayName() {
for (final InputMethodSubtype subtype : mSubtypesList) { for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = final String subtypeName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype); .getSubtypeDisplayNameInSystemLocale(subtype);
if (SubtypeLocaleUtils.isNoLanguage(subtype)) { if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
final String noLanguage = mRes.getString(R.string.subtype_no_language); final String layoutName = SubtypeLocaleUtils
assertTrue(subtypeName, subtypeName.contains(noLanguage)); .getKeyboardLayoutSetDisplayName(subtype);
assertTrue(subtypeName, subtypeName.contains(layoutName));
} else { } else {
final String languageName = final String languageName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeLocaleDisplayName(subtype.getLocale()); .getSubtypeLocaleDisplayNameInSystemLocale(subtype.getLocale());
assertTrue(subtypeName, subtypeName.contains(languageName)); assertTrue(subtypeName, subtypeName.contains(languageName));
} }
} }
@ -266,11 +274,11 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
public void testAllFullDisplayNameForSpacebar() { public void testAllFullDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) { for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = final String subtypeName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype); .getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SubtypeLocaleUtils.getFullDisplayName(subtype); final String spacebarText = SubtypeLocaleUtils.getFullDisplayName(subtype);
final String languageName = final String languageName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeLocaleDisplayName(subtype.getLocale()); .getSubtypeLocaleDisplayName(subtype.getLocale());
if (SubtypeLocaleUtils.isNoLanguage(subtype)) { if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertFalse(subtypeName, spacebarText.contains(languageName)); assertFalse(subtypeName, spacebarText.contains(languageName));
} else { } else {
@ -281,15 +289,16 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
public void testAllMiddleDisplayNameForSpacebar() { public void testAllMiddleDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) { for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = final String subtypeName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype); .getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SubtypeLocaleUtils.getMiddleDisplayName(subtype); final String spacebarText = SubtypeLocaleUtils.getMiddleDisplayName(subtype);
if (SubtypeLocaleUtils.isNoLanguage(subtype)) { if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertEquals(subtypeName, assertEquals(subtypeName,
SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype), spacebarText); SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype), spacebarText);
} else { } else {
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
assertEquals(subtypeName, assertEquals(subtypeName,
SubtypeLocaleUtils.getSubtypeLocaleDisplayName(subtype.getLocale()), SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()),
spacebarText); spacebarText);
} }
} }
@ -297,8 +306,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
public void testAllShortDisplayNameForSpacebar() { public void testAllShortDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) { for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = final String subtypeName = SubtypeLocaleUtils
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype); .getSubtypeDisplayNameInSystemLocale(subtype);
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype); final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
final String spacebarText = SubtypeLocaleUtils.getShortDisplayName(subtype); final String spacebarText = SubtypeLocaleUtils.getShortDisplayName(subtype);
final String languageCode = StringUtils.capitalizeFirstCodePoint( final String languageCode = StringUtils.capitalizeFirstCodePoint(