Add additional subtypes test

Change-Id: I2994fd72bc284c84757f5a2bfa8045aa574a8fbc
main
Tadashi G. Takaoka 2014-03-03 17:12:12 +09:00
parent f2b0829aa1
commit 3f91acdc96
2 changed files with 14 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils; import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -42,6 +43,7 @@ public final class AdditionalSubtypeUtils {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }
@UsedForTesting
public static boolean isAdditionalSubtype(final InputMethodSubtype subtype) { public static boolean isAdditionalSubtype(final InputMethodSubtype subtype) {
return subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE); return subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE);
} }

View File

@ -43,6 +43,7 @@ import java.util.Locale;
public class KeyboardLayoutSetTestsBase extends AndroidTestCase { public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
private static final int NUMBER_OF_SUBTYPES = 63; private static final int NUMBER_OF_SUBTYPES = 63;
private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 40; private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 40;
private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2;
private static final KeyboardTheme DEFAULT_KEYBOARD_THEME = private static final KeyboardTheme DEFAULT_KEYBOARD_THEME =
KeyboardSwitcher.KEYBOARD_THEMES[KeyboardSwitcher.THEME_INDEX_DEFAULT]; KeyboardSwitcher.KEYBOARD_THEMES[KeyboardSwitcher.THEME_INDEX_DEFAULT];
@ -51,6 +52,8 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList(); private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList = private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList =
CollectionUtils.newArrayList(); CollectionUtils.newArrayList();
private final ArrayList<InputMethodSubtype> mAdditionalSubtypesList =
CollectionUtils.newArrayList();
private Context mThemeContext; private Context mThemeContext;
private int mScreenMetrics; private int mScreenMetrics;
@ -68,6 +71,10 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
final int subtypeCount = imi.getSubtypeCount(); final int subtypeCount = imi.getSubtypeCount();
for (int index = 0; index < subtypeCount; index++) { for (int index = 0; index < subtypeCount; index++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(index); final InputMethodSubtype subtype = imi.getSubtypeAt(index);
if (AdditionalSubtypeUtils.isAdditionalSubtype(subtype)) {
mAdditionalSubtypesList.add(subtype);
continue;
}
mAllSubtypesList.add(subtype); mAllSubtypesList.add(subtype);
if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) { if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
mAsciiCapableSubtypesList.add(subtype); mAsciiCapableSubtypesList.add(subtype);
@ -101,6 +108,11 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
NUMBER_OF_ASCII_CAPABLE_SUBTYPES, mAsciiCapableSubtypesList.size()); NUMBER_OF_ASCII_CAPABLE_SUBTYPES, mAsciiCapableSubtypesList.size());
} }
public final void testAdditionalSubtypesCount() {
assertEquals(toString(mAdditionalSubtypesList),
NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES, mAdditionalSubtypesList.size());
}
protected final InputMethodSubtype getSubtype(final Locale locale, protected final InputMethodSubtype getSubtype(final Locale locale,
final String keyboardLayout) { final String keyboardLayout) {
for (final InputMethodSubtype subtype : mAllSubtypesList) { for (final InputMethodSubtype subtype : mAllSubtypesList) {