diff options
Diffstat (limited to 'core/tests')
3 files changed, 215 insertions, 7 deletions
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java index 34393f9..0cd19f2 100644 --- a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java +++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothInstrumentation.java @@ -25,6 +25,7 @@ public class BluetoothInstrumentation extends Instrumentation { private BluetoothTestUtils mUtils = null; private BluetoothAdapter mAdapter = null; private Bundle mArgs = null; + private Bundle mSuccessResult = null; private BluetoothTestUtils getBluetoothTestUtils() { if (mUtils == null) { @@ -46,6 +47,9 @@ public class BluetoothInstrumentation extends Instrumentation { public void onCreate(Bundle arguments) { super.onCreate(arguments); mArgs = arguments; + // create the default result response, but only use it in success code path + mSuccessResult = new Bundle(); + mSuccessResult.putString("result", "SUCCESS"); start(); } @@ -67,24 +71,23 @@ public class BluetoothInstrumentation extends Instrumentation { public void enable() { getBluetoothTestUtils().enable(getBluetoothAdapter()); - finish(null); + finish(mSuccessResult); } public void disable() { getBluetoothTestUtils().disable(getBluetoothAdapter()); - finish(null); + finish(mSuccessResult); } public void unpairAll() { getBluetoothTestUtils().unpairAll(getBluetoothAdapter()); - finish(null); + finish(mSuccessResult); } public void getName() { String name = getBluetoothAdapter().getName(); - Bundle bundle = new Bundle(); - bundle.putString("name", name); - finish(bundle); + mSuccessResult.putString("name", name); + finish(mSuccessResult); } public void finish(Bundle result) { diff --git a/core/tests/inputmethodtests/run_core_inputmethod_test.sh b/core/tests/inputmethodtests/run_core_inputmethod_test.sh index b0b119b..9029ba5 100755 --- a/core/tests/inputmethodtests/run_core_inputmethod_test.sh +++ b/core/tests/inputmethodtests/run_core_inputmethod_test.sh @@ -21,4 +21,4 @@ if [[ $rebuild == true ]]; then $COMMAND fi -adb shell am instrument -w -e class android.os.InputMethodTest,android.os.InputMethodSubtypeArrayTest com.android.frameworks.coretests.inputmethod/android.test.InstrumentationTestRunner +adb shell am instrument -w -e class android.os.InputMethodTest,android.os.InputMethodSubtypeArrayTest,android.os.InputMethodSubtypeSwitchingControllerTest com.android.frameworks.coretests.inputmethod/android.test.InstrumentationTestRunner diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java new file mode 100644 index 0000000..6d33529 --- /dev/null +++ b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os; + +import android.content.pm.ApplicationInfo; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; +import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder; + +import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController; +import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTestCase { + final private static String DUMMY_PACKAGE_NAME = "dymmy package name"; + final private static String DUMMY_SETTING_ACTIVITY_NAME = ""; + final private static boolean DUMMY_IS_AUX_IME = false; + final private static boolean DUMMY_FORCE_DEFAULT = false; + final private static int DUMMY_IS_DEFAULT_RES_ID = 0; + final private static String SYSTEM_LOCALE = "en_US"; + + private static InputMethodSubtype createDummySubtype(final String locale) { + final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder(); + return builder.setSubtypeNameResId(0) + .setSubtypeIconResId(0) + .setSubtypeLocale(locale) + .setIsAsciiCapable(true) + .build(); + } + + private static void addDummyImeSubtypeListItems(List<ImeSubtypeListItem> items, + String imeName, String imeLabel, List<String> subtypeLocales, + boolean supportsSwitchingToNextInputMethod) { + final ResolveInfo ri = new ResolveInfo(); + final ServiceInfo si = new ServiceInfo(); + final ApplicationInfo ai = new ApplicationInfo(); + ai.packageName = DUMMY_PACKAGE_NAME; + ai.enabled = true; + si.applicationInfo = ai; + si.enabled = true; + si.packageName = DUMMY_PACKAGE_NAME; + si.name = imeName; + si.exported = true; + si.nonLocalizedLabel = imeLabel; + ri.serviceInfo = si; + final List<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + for (String subtypeLocale : subtypeLocales) { + subtypes.add(createDummySubtype(subtypeLocale)); + } + final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME, + DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID, + DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod); + for (int i = 0; i < subtypes.size(); ++i) { + final String subtypeLocale = subtypeLocales.get(i); + final InputMethodSubtype subtype = subtypes.get(i); + items.add(new ImeSubtypeListItem(imeName, subtypeLocale, imi, i, subtypeLocale, + SYSTEM_LOCALE)); + } + } + + private static List<ImeSubtypeListItem> createTestData() { + final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>(); + addDummyImeSubtypeListItems(items, "switchAwareLatinIme", "switchAwareLatinIme", + Arrays.asList("en_US", "es_US", "fr"), + true /* supportsSwitchingToNextInputMethod*/); + addDummyImeSubtypeListItems(items, "nonSwitchAwareLatinIme", "nonSwitchAwareLatinIme", + Arrays.asList("en_UK", "hi"), + false /* supportsSwitchingToNextInputMethod*/); + addDummyImeSubtypeListItems(items, "switchAwareJapaneseIme", "switchAwareJapaneseIme", + Arrays.asList("ja_JP"), + true /* supportsSwitchingToNextInputMethod*/); + addDummyImeSubtypeListItems(items, "nonSwitchAwareJapaneseIme", "nonSwitchAwareJapaneseIme", + Arrays.asList("ja_JP"), + false /* supportsSwitchingToNextInputMethod*/); + return items; + } + + @SmallTest + public void testGetNextInputMethodImplWithNotOnlyCurrentIme() throws Exception { + final List<ImeSubtypeListItem> imList = createTestData(); + + final boolean ONLY_CURRENT_IME = false; + ImeSubtypeListItem currentIme; + ImeSubtypeListItem nextIme; + + // "switchAwareLatinIme/en_US" -> "switchAwareLatinIme/es_US" + currentIme = imList.get(0); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(1), nextIme); + // "switchAwareLatinIme/es_US" -> "switchAwareLatinIme/fr" + currentIme = imList.get(1); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(2), nextIme); + // "switchAwareLatinIme/fr" -> "nonSwitchAwareLatinIme/en_UK + currentIme = imList.get(2); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(3), nextIme); + // "nonSwitchAwareLatinIme/en_UK" -> "nonSwitchAwareLatinIme/hi" + currentIme = imList.get(3); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(4), nextIme); + // "nonSwitchAwareLatinIme/hi" -> "switchAwareJapaneseIme/ja_JP" + currentIme = imList.get(4); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(5), nextIme); + // "switchAwareJapaneseIme/ja_JP" -> "nonSwitchAwareJapaneseIme/ja_JP" + currentIme = imList.get(5); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(6), nextIme); + // "nonSwitchAwareJapaneseIme/ja_JP" -> "switchAwareLatinIme/en_US" + currentIme = imList.get(6); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(0), nextIme); + } + + @SmallTest + public void testGetNextInputMethodImplWithOnlyCurrentIme() throws Exception { + final List<ImeSubtypeListItem> imList = createTestData(); + + final boolean ONLY_CURRENT_IME = true; + ImeSubtypeListItem currentIme; + ImeSubtypeListItem nextIme; + + // "switchAwareLatinIme/en_US" -> "switchAwareLatinIme/es_US" + currentIme = imList.get(0); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(1), nextIme); + // "switchAwareLatinIme/es_US" -> "switchAwareLatinIme/fr" + currentIme = imList.get(1); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(2), nextIme); + // "switchAwareLatinIme/fr" -> "switchAwareLatinIme/en_US" + currentIme = imList.get(2); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(0), nextIme); + + // "nonSwitchAwareLatinIme/en_UK" -> "nonSwitchAwareLatinIme/hi" + currentIme = imList.get(3); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(4), nextIme); + // "nonSwitchAwareLatinIme/hi" -> "switchAwareLatinIme/en_UK" + currentIme = imList.get(4); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertEquals(imList.get(3), nextIme); + + // "switchAwareJapaneseIme/ja_JP" -> null + currentIme = imList.get(5); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertNull(nextIme); + + // "nonSwitchAwareJapaneseIme/ja_JP" -> null + currentIme = imList.get(6); + nextIme = InputMethodSubtypeSwitchingController.getNextInputMethodImpl( + imList, ONLY_CURRENT_IME, currentIme.mImi, createDummySubtype( + currentIme.mSubtypeName.toString())); + assertNull(nextIme); + } + } |