summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-02-27 17:10:00 +0900
committerYohei Yukawa <yukawa@google.com>2014-02-27 17:32:48 +0900
commit589800485d770cab7b159ffcf4b18c10ae2aee6d (patch)
treee34c52538e5719caa45213303008b9ceb2c9e4d3
parentac5eaa3dc2869a1eab655e97082dcf5a8a19640e (diff)
downloadframeworks_base-589800485d770cab7b159ffcf4b18c10ae2aee6d.zip
frameworks_base-589800485d770cab7b159ffcf4b18c10ae2aee6d.tar.gz
frameworks_base-589800485d770cab7b159ffcf4b18c10ae2aee6d.tar.bz2
Add unit test for InputMethodInfo
This CL adds a unit test to make sure that InputMethodInfo implements Parcelable correctly. BUG: 12954290 Change-Id: I0abe8c266b4b035bf8ef4688d11069b355fabe9f
-rw-r--r--core/tests/inputmethodtests/src/android/os/InputMethodTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
index 0a2b50c..3083f35 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
+++ b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java
@@ -34,6 +34,7 @@ public class InputMethodTest extends InstrumentationTestCase {
private static final boolean IS_AUX = true;
private static final boolean IS_DEFAULT = true;
private static final boolean IS_AUTO = true;
+ private static final ArrayList<InputMethodSubtype> NO_SUBTYPE = null;
@SmallTest
public void testDefaultEnabledImesWithDefaultVoiceIme() throws Exception {
@@ -45,6 +46,7 @@ public class InputMethodTest extends InstrumentationTestCase {
imis.add(createNonDefaultDummyVoiceIme2());
imis.add(createDefaultDummyEnUSKeyboardIme());
imis.add(createNonDefaultDummyJaJPKeyboardIme());
+ imis.add(createNonDefaultDummyJaJPKeyboardImeWithoutSubtypes());
final ArrayList<InputMethodInfo> enabledImis = InputMethodUtils.getDefaultEnabledImes(
context, true, imis);
assertEquals(2, enabledImis.size());
@@ -69,6 +71,7 @@ public class InputMethodTest extends InstrumentationTestCase {
imis.add(createNonDefaultDummyVoiceIme2());
imis.add(createDefaultDummyEnUSKeyboardIme());
imis.add(createNonDefaultDummyJaJPKeyboardIme());
+ imis.add(createNonDefaultDummyJaJPKeyboardImeWithoutSubtypes());
final ArrayList<InputMethodInfo> enabledImis = InputMethodUtils.getDefaultEnabledImes(
context, true, imis);
assertEquals(3, enabledImis.size());
@@ -86,6 +89,49 @@ public class InputMethodTest extends InstrumentationTestCase {
}
}
+ @SmallTest
+ public void testParcelable() throws Exception {
+ final ArrayList<InputMethodInfo> originalList = new ArrayList<InputMethodInfo>();
+ originalList.add(createNonDefaultAutoDummyVoiceIme0());
+ originalList.add(createNonDefaultAutoDummyVoiceIme1());
+ originalList.add(createNonDefaultDummyVoiceIme2());
+ originalList.add(createDefaultDummyEnUSKeyboardIme());
+ originalList.add(createNonDefaultDummyJaJPKeyboardIme());
+ originalList.add(createNonDefaultDummyJaJPKeyboardImeWithoutSubtypes());
+
+ final List<InputMethodInfo> clonedList = cloneViaParcel(originalList);
+ assertNotNull(clonedList);
+ assertEquals(originalList.size(), clonedList.size());
+ assertEquals(originalList, clonedList);
+
+ for (int imeIndex = 0; imeIndex < originalList.size(); ++imeIndex) {
+ final InputMethodInfo original = originalList.get(imeIndex);
+ final InputMethodInfo cloned = clonedList.get(imeIndex);
+ assertEquals(original, cloned);
+ assertEquals(original.getSubtypeCount(), cloned.getSubtypeCount());
+ for (int subtypeIndex = 0; subtypeIndex < original.getSubtypeCount(); ++subtypeIndex) {
+ final InputMethodSubtype originalSubtype = original.getSubtypeAt(subtypeIndex);
+ final InputMethodSubtype clonedSubtype = cloned.getSubtypeAt(subtypeIndex);
+ assertEquals(originalSubtype, clonedSubtype);
+ assertEquals(originalSubtype.hashCode(), clonedSubtype.hashCode());
+ }
+ }
+ }
+
+ private static List<InputMethodInfo> cloneViaParcel(final List<InputMethodInfo> list) {
+ Parcel p = null;
+ try {
+ p = Parcel.obtain();
+ p.writeTypedList(list);
+ p.setDataPosition(0);
+ return p.createTypedArrayList(InputMethodInfo.CREATOR);
+ } finally {
+ if (p != null) {
+ p.recycle();
+ }
+ }
+ }
+
private static InputMethodInfo createDummyInputMethodInfo(String packageName, String name,
CharSequence label, boolean isAuxIme, boolean isDefault,
List<InputMethodSubtype> subtypes) {
@@ -155,4 +201,12 @@ public class InputMethodTest extends InstrumentationTestCase {
return createDummyInputMethodInfo("DummyNonDefaultJaJPKeyboardIme", "dummy.keyboard1",
"DummyKeyboard1", !IS_AUX, !IS_DEFAULT, subtypes);
}
+
+ // Although IMEs that have no subtype are considered to be deprecated, the Android framework
+ // must still be able to handle such IMEs as well as IMEs that have at least one subtype.
+ private static InputMethodInfo createNonDefaultDummyJaJPKeyboardImeWithoutSubtypes() {
+ final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
+ return createDummyInputMethodInfo("DummyNonDefaultJaJPKeyboardImeWithoutSubtypes",
+ "dummy.keyboard2", "DummyKeyboard2", !IS_AUX, !IS_DEFAULT, NO_SUBTYPE);
+ }
}