Give InputLogicTests the ability to change language

Also fix a typo, and increase the time allowed to load the main
dictionary to 2 secs instead of 1.

Bug: 6114326
Change-Id: I5f70b34fc4277c55977b18466253152aa98a2507
main
Jean Chalard 2012-03-08 15:40:31 +09:00
parent 77541fc92e
commit 274a0643b1
4 changed files with 119 additions and 18 deletions

View File

@ -24,7 +24,7 @@ public abstract class AbstractCompatWrapper {
public AbstractCompatWrapper(Object obj) {
if (obj == null) {
Log.e(TAG, "Invalid input to AbstructCompatWrapper");
Log.e(TAG, "Invalid input to AbstractCompatWrapper");
}
mObj = obj;
}

View File

@ -29,7 +29,7 @@ import java.util.Locale;
// TODO: Override this class with the concrete implementation if we need to take care of the
// performance.
public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper {
public class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper {
private static final boolean DBG = LatinImeLogger.sDBG;
private static final String TAG = InputMethodSubtypeCompatWrapper.class.getSimpleName();
private static final String DEFAULT_LOCALE = "en_US";
@ -65,7 +65,7 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper
public InputMethodSubtypeCompatWrapper(Object subtype) {
super((CLASS_InputMethodSubtype != null && CLASS_InputMethodSubtype.isInstance(subtype))
? subtype : null);
? subtype : new Object());
mDummyNameResId = 0;
mDummyIconResId = 0;
mDummyLocale = DEFAULT_LOCALE;
@ -76,7 +76,7 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper
// Constructor for creating a dummy subtype.
public InputMethodSubtypeCompatWrapper(int nameResId, int iconResId, String locale,
String mode, String extraValues) {
super(null);
super(new Object());
if (DBG) {
Log.d(TAG, "CreateInputMethodSubtypeCompatWrapper");
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2012 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 com.android.inputmethod.latin;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
public class ArbitrarySubtype extends InputMethodSubtypeCompatWrapper {
final String mLocale;
final String mExtraValue;
public ArbitrarySubtype(final String locale, final String extraValue) {
super(locale);
mLocale = locale;
mExtraValue = extraValue;
}
public String getLocale() {
return mLocale;
}
public String getExtraValue() {
return mExtraValue;
}
public String getMode() {
return "keyboard";
}
public String getExtraValueOf(final String key) {
if (LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key)) {
return "";
} else {
return null;
}
}
public boolean containsExtraValueKey(final String key) {
return LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key);
}
}

View File

@ -95,20 +95,7 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
mLatinIME.onStartInputView(ei, false);
mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
mInputConnection = ic;
// Wait for the main dictionary to be loaded (we need it for auto-correction tests)
int remainingAttempts = 10;
while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Don't do much
} finally {
--remainingAttempts;
}
}
if (!mLatinIME.mSuggest.hasMainDictionary()) {
throw new RuntimeException("Can't initialize the main dictionary");
}
changeLanguage("en_US");
}
// We need to run the messages added to the handler from LatinIME. The only way to do
@ -177,6 +164,29 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
}
}
private void waitForDictionaryToBeLoaded() {
int remainingAttempts = 10;
while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// Don't do much
} finally {
--remainingAttempts;
}
}
if (!mLatinIME.mSuggest.hasMainDictionary()) {
throw new RuntimeException("Can't initialize the main dictionary");
}
}
private void changeLanguage(final String locale) {
SubtypeSwitcher.getInstance().updateSubtype(
new ArbitrarySubtype(locale, LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
waitForDictionaryToBeLoaded();
}
// Helper to avoid writing the try{}catch block each time
private static void sleep(final int milliseconds) {
try {
@ -273,6 +283,15 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
assertEquals("simple auto-correct", EXPECTED_RESULT, mTextView.getText().toString());
}
public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq ";
final String EXPECTED_RESULT = "ira ";
changeLanguage("fr");
type(STRING_TO_TYPE);
assertEquals("simple auto-correct for French", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testAutoCorrectWithPeriod() {
final String STRING_TO_TYPE = "tgis.";
final String EXPECTED_RESULT = "this.";
@ -375,6 +394,34 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
mTextView.getText().toString());
}
public void testManualPickThenSeparatorForFrench() {
final String WORD1_TO_TYPE = "test";
final String WORD2_TO_TYPE = "!";
final String EXPECTED_RESULT = "test !";
changeLanguage("fr");
type(WORD1_TO_TYPE);
mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE);
type(WORD2_TO_TYPE);
assertEquals("manual pick then separator for French", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!";
changeLanguage("fr");
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
assertTrue("type word then type space should display punctuation strip",
mLatinIME.isShowingPunctuationList());
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
assertEquals("type word then type space then punctuation from strip twice for French",
EXPECTED_RESULT, mTextView.getText().toString());
}
public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {
final String WORD_TO_TYPE = "this !!";
final String EXPECTED_RESULT = "this !!";