aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java18
-rw-r--r--tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java18
-rw-r--r--tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java226
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java22
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java28
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java19
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java72
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java62
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java95
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueueTests.java21
-rw-r--r--tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java34
-rw-r--r--tests/src/com/android/inputmethod/latin/CapsModeUtilsTests.java88
-rw-r--r--tests/src/com/android/inputmethod/latin/EditDistanceTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/FusionDictionaryTests.java18
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java82
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java73
-rw-r--r--tests/src/com/android/inputmethod/latin/InputPointersTests.java18
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java62
-rw-r--r--tests/src/com/android/inputmethod/latin/PunctuationTests.java19
-rw-r--r--tests/src/com/android/inputmethod/latin/ResizableIntArrayTests.java18
-rw-r--r--tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java20
-rw-r--r--tests/src/com/android/inputmethod/latin/StringUtilsTests.java83
-rw-r--r--tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java333
-rw-r--r--tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java21
-rw-r--r--tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java68
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java47
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java395
-rw-r--r--tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java20
-rw-r--r--tests/src/com/android/inputmethod/research/MotionEventReaderTests.java171
30 files changed, 1482 insertions, 673 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
index 2a244a772..8fef1de2a 100644
--- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderFixedOrderTests.java
@@ -1,25 +1,27 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.keyboard.MoreKeysKeyboard.MoreKeysKeyboardParams;
+@SmallTest
public class MoreKeysKeyboardBuilderFixedOrderTests extends AndroidTestCase {
private static final int WIDTH = 10;
private static final int HEIGHT = 10;
diff --git a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
index e6c76db85..ee4c72a85 100644
--- a/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/MoreKeysKeyboardBuilderTests.java
@@ -1,25 +1,27 @@
/*
* Copyright (C) 2011 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
+ * 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
+ * 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.
+ * 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.keyboard;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.keyboard.MoreKeysKeyboard.MoreKeysKeyboardParams;
+@SmallTest
public class MoreKeysKeyboardBuilderTests extends AndroidTestCase {
private static final int WIDTH = 10;
private static final int HEIGHT = 10;
diff --git a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
index bc5043911..1398db97c 100644
--- a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
@@ -1,17 +1,17 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard;
@@ -19,35 +19,70 @@ package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.AdditionalSubtype;
import com.android.inputmethod.latin.CollectionUtils;
-import com.android.inputmethod.latin.ImfUtils;
+import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.util.ArrayList;
import java.util.Locale;
+@SmallTest
public class SpacebarTextTests extends AndroidTestCase {
// Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
+ private RichInputMethodManager mRichImm;
private Resources mRes;
+ InputMethodSubtype EN_US;
+ InputMethodSubtype EN_GB;
+ InputMethodSubtype ES_US;
+ InputMethodSubtype FR;
+ InputMethodSubtype FR_CA;
+ InputMethodSubtype DE;
+ InputMethodSubtype ZZ;
+ InputMethodSubtype DE_QWERTY;
+ InputMethodSubtype FR_QWERTZ;
+ InputMethodSubtype US_AZERTY;
+ InputMethodSubtype ZZ_AZERTY;
+
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
+ RichInputMethodManager.init(context);
+ mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources();
SubtypeLocale.init(context);
+
+ EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.US.toString(), "qwerty");
+ EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.UK.toString(), "qwerty");
+ ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("es_US", "spanish");
+ FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.FRENCH.toString(), "azerty");
+ FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.CANADA_FRENCH.toString(), "qwerty");
+ DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.GERMAN.toString(), "qwertz");
+ ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(SubtypeLocale.NO_LANGUAGE, "qwerty");
+ DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
+ Locale.GERMAN.toString(), "qwerty", null);
+ FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
+ Locale.FRENCH.toString(), "qwertz", null);
+ US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
+ Locale.US.toString(), "azerty", null);
+ ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
+ SubtypeLocale.NO_LANGUAGE, "azerty", null);
}
public void testAllFullDisplayName() {
for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
- final String spacebarText = MainKeyboardView.getFullDisplayName(subtype, mRes);
+ final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
+ final String spacebarText = MainKeyboardView.getFullDisplayName(subtype);
final String languageName =
SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale());
if (SubtypeLocale.isNoLanguage(subtype)) {
@@ -60,7 +95,7 @@ public class SpacebarTextTests extends AndroidTestCase {
public void testAllMiddleDisplayName() {
for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
+ final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
final String spacebarText = MainKeyboardView.getMiddleDisplayName(subtype);
if (SubtypeLocale.isNoLanguage(subtype)) {
assertEquals(subtypeName,
@@ -75,7 +110,7 @@ public class SpacebarTextTests extends AndroidTestCase {
public void testAllShortDisplayName() {
for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
+ final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
final String languageCode = StringUtils.toTitleCase(locale.getLanguage(), locale);
@@ -89,89 +124,92 @@ public class SpacebarTextTests extends AndroidTestCase {
// InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false)
- // locale layout | Short Middle Full
- // ------ ------ - ---- --------- ----------------------
- // en_US qwerty F En English English (US) exception
- // en_GB qwerty F En English English (UK) exception
- // fr azerty F Fr Français Français
- // fr_CA qwerty F Fr Français Français (Canada)
- // de qwertz F De Deutsch Deutsch
- // zz qwerty F QWERTY QWERTY
- // fr qwertz T Fr Français Français (QWERTZ)
- // de qwerty T De Deutsch Deutsch (QWERTY)
- // en_US azerty T En English English (US) (AZERTY)
- // zz azerty T AZERTY AZERTY
-
- public void testPredefinedSubtypes() {
- final Context context = getContext();
- final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.US.toString(), "qwerty");
- final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.UK.toString(), "qwerty");
- final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.FRENCH.toString(), "azerty");
- final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.CANADA_FRENCH.toString(), "qwerty");
- final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.GERMAN.toString(), "qwertz");
- final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, SubtypeLocale.NO_LANGUAGE, "qwerty");
-
- assertEquals("en_US", "English (US)",
- MainKeyboardView.getFullDisplayName(EN_US, mRes));
- assertEquals("en_GB", "English (UK)",
- MainKeyboardView.getFullDisplayName(EN_GB, mRes));
- assertEquals("fr ", "Français",
- MainKeyboardView.getFullDisplayName(FR, mRes));
- assertEquals("fr_CA", "Français (Canada)",
- MainKeyboardView.getFullDisplayName(FR_CA, mRes));
- assertEquals("de ", "Deutsch",
- MainKeyboardView.getFullDisplayName(DE, mRes));
- assertEquals("zz ", "QWERTY",
- MainKeyboardView.getFullDisplayName(ZZ, mRes));
-
- assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
- assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
- assertEquals("fr ", "Français", MainKeyboardView.getMiddleDisplayName(FR));
- assertEquals("fr_CA", "Français", MainKeyboardView.getMiddleDisplayName(FR_CA));
- assertEquals("de ", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE));
- assertEquals("zz ", "QWERTY", MainKeyboardView.getMiddleDisplayName(ZZ));
-
- assertEquals("en_US", "En", MainKeyboardView.getShortDisplayName(EN_US));
- assertEquals("en_GB", "En", MainKeyboardView.getShortDisplayName(EN_GB));
- assertEquals("fr ", "Fr", MainKeyboardView.getShortDisplayName(FR));
- assertEquals("fr_CA", "Fr", MainKeyboardView.getShortDisplayName(FR_CA));
- assertEquals("de ", "De", MainKeyboardView.getShortDisplayName(DE));
- assertEquals("zz ", "", MainKeyboardView.getShortDisplayName(ZZ));
+ // locale layout | Short Middle Full
+ // ------ ------- - ---- --------- ----------------------
+ // en_US qwerty F En English English (US) exception
+ // en_GB qwerty F En English English (UK) exception
+ // es_US spanish F Es Español Español (EE.UU.) exception
+ // fr azerty F Fr Français Français
+ // fr_CA qwerty F Fr Français Français (Canada)
+ // de qwertz F De Deutsch Deutsch
+ // zz qwerty F QWERTY QWERTY
+ // fr qwertz T Fr Français Français
+ // de qwerty T De Deutsch Deutsch
+ // en_US azerty T En English English (US)
+ // zz azerty T AZERTY AZERTY
+
+ private final RunInLocale<Void> testsPredefinedSubtypes = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("en_US", "English (US)", MainKeyboardView.getFullDisplayName(EN_US));
+ assertEquals("en_GB", "English (UK)", MainKeyboardView.getFullDisplayName(EN_GB));
+ assertEquals("es_US", "Español (EE.UU.)", MainKeyboardView.getFullDisplayName(ES_US));
+ assertEquals("fr ", "Français", MainKeyboardView.getFullDisplayName(FR));
+ assertEquals("fr_CA", "Français (Canada)", MainKeyboardView.getFullDisplayName(FR_CA));
+ assertEquals("de ", "Deutsch", MainKeyboardView.getFullDisplayName(DE));
+ assertEquals("zz ", "QWERTY", MainKeyboardView.getFullDisplayName(ZZ));
+
+ assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
+ assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
+ assertEquals("es_US", "Español", MainKeyboardView.getMiddleDisplayName(ES_US));
+ assertEquals("fr ", "Français", MainKeyboardView.getMiddleDisplayName(FR));
+ assertEquals("fr_CA", "Français", MainKeyboardView.getMiddleDisplayName(FR_CA));
+ assertEquals("de ", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE));
+ assertEquals("zz ", "QWERTY", MainKeyboardView.getMiddleDisplayName(ZZ));
+
+ assertEquals("en_US", "En", MainKeyboardView.getShortDisplayName(EN_US));
+ assertEquals("en_GB", "En", MainKeyboardView.getShortDisplayName(EN_GB));
+ assertEquals("es_US", "Es", MainKeyboardView.getShortDisplayName(ES_US));
+ assertEquals("fr ", "Fr", MainKeyboardView.getShortDisplayName(FR));
+ assertEquals("fr_CA", "Fr", MainKeyboardView.getShortDisplayName(FR_CA));
+ assertEquals("de ", "De", MainKeyboardView.getShortDisplayName(DE));
+ assertEquals("zz ", "", MainKeyboardView.getShortDisplayName(ZZ));
+ return null;
+ }
+ };
+
+ private final RunInLocale<Void> testsAdditionalSubtypes = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("fr qwertz", "Français",
+ MainKeyboardView.getFullDisplayName(FR_QWERTZ));
+ assertEquals("de qwerty", "Deutsch",
+ MainKeyboardView.getFullDisplayName(DE_QWERTY));
+ assertEquals("en_US azerty", "English (US)",
+ MainKeyboardView.getFullDisplayName(US_AZERTY));
+ assertEquals("zz azerty", "AZERTY",
+ MainKeyboardView.getFullDisplayName(ZZ_AZERTY));
+
+ assertEquals("fr qwertz", "Français",
+ MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
+ assertEquals("de qwerty", "Deutsch",
+ MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
+ assertEquals("en_US azerty", "English",
+ MainKeyboardView.getMiddleDisplayName(US_AZERTY));
+ assertEquals("zz azerty", "AZERTY",
+ MainKeyboardView.getMiddleDisplayName(ZZ_AZERTY));
+
+ assertEquals("fr qwertz", "Fr", MainKeyboardView.getShortDisplayName(FR_QWERTZ));
+ assertEquals("de qwerty", "De", MainKeyboardView.getShortDisplayName(DE_QWERTY));
+ assertEquals("en_US azerty", "En", MainKeyboardView.getShortDisplayName(US_AZERTY));
+ assertEquals("zz azerty", "", MainKeyboardView.getShortDisplayName(ZZ_AZERTY));
+ return null;
+ }
+ };
+
+ public void testPredefinedSubtypesInEnglish() {
+ testsPredefinedSubtypes.runInLocale(mRes, Locale.ENGLISH);
}
- public void testAdditionalSubtype() {
- final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.GERMAN.toString(), "qwerty", null);
- final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
- Locale.FRENCH.toString(), "qwertz", null);
- final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.US.toString(), "azerty", null);
- final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- SubtypeLocale.NO_LANGUAGE, "azerty", null);
+ public void testAdditionalSubtypeInEnglish() {
+ testsAdditionalSubtypes.runInLocale(mRes, Locale.ENGLISH);
+ }
+
+ public void testPredefinedSubtypesInFrench() {
+ testsPredefinedSubtypes.runInLocale(mRes, Locale.FRENCH);
+ }
- assertEquals("fr qwertz", "Français (QWERTZ)",
- MainKeyboardView.getFullDisplayName(FR_QWERTZ, mRes));
- assertEquals("de qwerty", "Deutsch (QWERTY)",
- MainKeyboardView.getFullDisplayName(DE_QWERTY, mRes));
- assertEquals("en_US azerty", "English (US) (AZERTY)",
- MainKeyboardView.getFullDisplayName(US_AZERTY, mRes));
- assertEquals("zz azerty", "AZERTY",
- MainKeyboardView.getFullDisplayName(ZZ_AZERTY, mRes));
-
- assertEquals("fr qwertz", "Français", MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
- assertEquals("de qwerty", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
- assertEquals("en_US azerty", "English", MainKeyboardView.getMiddleDisplayName(US_AZERTY));
- assertEquals("zz azerty", "AZERTY", MainKeyboardView.getMiddleDisplayName(ZZ_AZERTY));
-
- assertEquals("fr qwertz", "Fr", MainKeyboardView.getShortDisplayName(FR_QWERTZ));
- assertEquals("de qwerty", "De", MainKeyboardView.getShortDisplayName(DE_QWERTY));
- assertEquals("en_US azerty", "En", MainKeyboardView.getShortDisplayName(US_AZERTY));
- assertEquals("zz azerty", "", MainKeyboardView.getShortDisplayName(ZZ_AZERTY));
+ public void testAdditionalSubtypeInFrench() {
+ testsAdditionalSubtypes.runInLocale(mRes, Locale.FRENCH);
}
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
index 1346c00f4..05f39551b 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java
@@ -1,31 +1,34 @@
/*
* Copyright (C) 2010 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
import android.app.Instrumentation;
import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.CollectionUtils;
+import com.android.inputmethod.latin.StringUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
+@SmallTest
public class KeySpecParserCsvTests extends InstrumentationTestCase {
private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
@@ -72,7 +75,8 @@ public class KeySpecParserCsvTests extends InstrumentationTestCase {
}
private void assertTextArray(String message, String value, String ... expectedArray) {
- final String[] actual = KeySpecParser.parseCsvString(value, mTextsSet);
+ final String resolvedActual = KeySpecParser.resolveTextReference(value, mTextsSet);
+ final String[] actual = StringUtils.parseCsvString(resolvedActual);
final String[] expected = (expectedArray.length == 0) ? null : expectedArray;
assertArrayEquals(message, expected, actual);
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
index 1ab577557..b1ae6f5b7 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java
@@ -1,32 +1,34 @@
/*
* Copyright (C) 2010 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
-import static com.android.inputmethod.keyboard.Keyboard.CODE_OUTPUT_TEXT;
-import static com.android.inputmethod.keyboard.Keyboard.CODE_UNSPECIFIED;
import static com.android.inputmethod.keyboard.internal.KeyboardIconsSet.ICON_UNDEFINED;
+import static com.android.inputmethod.latin.Constants.CODE_OUTPUT_TEXT;
+import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
-import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.Constants;
import java.util.Arrays;
import java.util.Locale;
+@SmallTest
public class KeySpecParserTests extends AndroidTestCase {
private final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
private final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();
@@ -69,8 +71,8 @@ public class KeySpecParserTests extends AndroidTestCase {
KeyboardIconsSet.getIconName(expectedIcon),
KeyboardIconsSet.getIconName(spec.mIconId));
assertEquals(message + " [code]",
- Keyboard.printableCode(expectedCode),
- Keyboard.printableCode(spec.mCode));
+ Constants.printableCode(expectedCode),
+ Constants.printableCode(spec.mCode));
}
private void assertParserError(String message, String moreKeySpec, String expectedLabel,
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
index 053bcb53a..b193e66dc 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
@@ -1,21 +1,24 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
+import android.test.suitebuilder.annotation.SmallTest;
+
+@SmallTest
public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Chording input in alphabet.
public void testChordingAlphabet() {
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java
index a1ceb8e2e..df9ce5e31 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateSingleTouchTests.java
@@ -1,21 +1,24 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
+import android.test.suitebuilder.annotation.SmallTest;
+
+@SmallTest
public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Shift key in alphabet.
public void testShiftAlphabet() {
@@ -150,59 +153,6 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
pressAndReleaseKey(CODE_SPACE, SYMBOLS_SHIFTED, ALPHABET_SHIFT_LOCKED);
}
- // Automatic switch back to alphabet by registered letters.
- public void testSwitchBackChar() {
- // Set switch back chars.
- final String switchBackSymbols = "'";
- final int switchBackCode = switchBackSymbols.codePointAt(0);
- setLayoutSwitchBackSymbols(switchBackSymbols);
- loadKeyboard(ALPHABET_UNSHIFTED);
-
- // Press/release "?123" key, enter into symbols.
- pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Enter symbol letter.
- pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Enter switch back letter, switch back to alphabet.
- pressAndReleaseKey(switchBackCode, SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED);
-
- // Press/release "?123" key, enter into symbols.
- pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Press/release "=\<" key, enter into symbols shifted.
- pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
- // Enter symbol shift letter.
- pressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
- // Enter switch abck letter, switch back to alphabet.
- pressAndReleaseKey(switchBackCode, SYMBOLS_SHIFTED, ALPHABET_UNSHIFTED);
- }
-
- // Automatic switch back to alphabet shift locked by registered letters.
- public void testSwitchBackCharShiftLocked() {
- // Set switch back chars.
- final String switchBackSymbols = "'";
- final int switchBackCode = switchBackSymbols.codePointAt(0);
- setLayoutSwitchBackSymbols(switchBackSymbols);
- loadKeyboard(ALPHABET_UNSHIFTED);
- // Long press shift key, enter alphabet shift locked.
- longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
- ALPHABET_SHIFT_LOCKED);
-
- // Press/release "?123" key, enter into symbols.
- pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Enter symbol letter.
- pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Enter switch back letter, switch back to alphabet shift locked.
- pressAndReleaseKey(switchBackCode, SYMBOLS_UNSHIFTED, ALPHABET_SHIFT_LOCKED);
-
- // Press/release "?123" key, enter into symbols.
- pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
- // Press/release "=\<" key, enter into symbols shifted.
- pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
- // Enter symbol shift letter.
- pressAndReleaseKey(CODE_SPACE, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
- // Enter switch back letter, switch back to alphabet shift locked.
- pressAndReleaseKey(switchBackCode, SYMBOLS_SHIFTED, ALPHABET_SHIFT_LOCKED);
- }
-
// Automatic upper case test
public void testAutomaticUpperCase() {
// Set capitalize the first character of all words mode.
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
index 2770ed54a..5e94aebf6 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
@@ -1,17 +1,17 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
@@ -19,11 +19,9 @@ package com.android.inputmethod.keyboard.internal;
import android.test.AndroidTestCase;
public class KeyboardStateTestsBase extends AndroidTestCase
- implements MockKeyboardSwitcher.Constants {
+ implements MockKeyboardSwitcher.MockConstants {
protected MockKeyboardSwitcher mSwitcher;
- private String mLayoutSwitchBackSymbols = "";
-
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -34,88 +32,86 @@ public class KeyboardStateTestsBase extends AndroidTestCase
loadKeyboard(ALPHABET_UNSHIFTED);
}
- public void setAutoCapsMode(int autoCaps) {
+ public void setAutoCapsMode(final int autoCaps) {
mSwitcher.setAutoCapsMode(autoCaps);
}
- public void setLayoutSwitchBackSymbols(String switchBackSymbols) {
- mLayoutSwitchBackSymbols = switchBackSymbols;
- }
-
- private static void assertLayout(String message, int expected, int actual) {
+ private static void assertLayout(final String message, final int expected, final int actual) {
assertTrue(message + ": expected=" + MockKeyboardSwitcher.getLayoutName(expected)
+ " actual=" + MockKeyboardSwitcher.getLayoutName(actual),
expected == actual);
}
- public void updateShiftState(int afterUpdate) {
+ public void updateShiftState(final int afterUpdate) {
mSwitcher.updateShiftState();
assertLayout("afterUpdate", afterUpdate, mSwitcher.getLayoutId());
}
- public void loadKeyboard(int afterLoad) {
- mSwitcher.loadKeyboard(mLayoutSwitchBackSymbols);
+ public void loadKeyboard(final int afterLoad) {
+ mSwitcher.loadKeyboard();
mSwitcher.updateShiftState();
assertLayout("afterLoad", afterLoad, mSwitcher.getLayoutId());
}
- public void rotateDevice(int afterRotate) {
+ public void rotateDevice(final int afterRotate) {
mSwitcher.saveKeyboardState();
- mSwitcher.loadKeyboard(mLayoutSwitchBackSymbols);
+ mSwitcher.loadKeyboard();
assertLayout("afterRotate", afterRotate, mSwitcher.getLayoutId());
}
- private void pressKeyWithoutTimerExpire(int code, boolean isSinglePointer, int afterPress) {
+ private void pressKeyWithoutTimerExpire(final int code, final boolean isSinglePointer,
+ final int afterPress) {
mSwitcher.onPressKey(code, isSinglePointer);
assertLayout("afterPress", afterPress, mSwitcher.getLayoutId());
}
- public void pressKey(int code, int afterPress) {
+ public void pressKey(final int code, final int afterPress) {
mSwitcher.expireDoubleTapTimeout();
pressKeyWithoutTimerExpire(code, true, afterPress);
}
- public void releaseKey(int code, int afterRelease) {
+ public void releaseKey(final int code, final int afterRelease) {
mSwitcher.onCodeInput(code, SINGLE);
mSwitcher.onReleaseKey(code, NOT_SLIDING);
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
}
- public void pressAndReleaseKey(int code, int afterPress, int afterRelease) {
+ public void pressAndReleaseKey(final int code, final int afterPress, final int afterRelease) {
pressKey(code, afterPress);
releaseKey(code, afterRelease);
}
- public void chordingPressKey(int code, int afterPress) {
+ public void chordingPressKey(final int code, final int afterPress) {
mSwitcher.expireDoubleTapTimeout();
pressKeyWithoutTimerExpire(code, false, afterPress);
}
- public void chordingReleaseKey(int code, int afterRelease) {
+ public void chordingReleaseKey(final int code, final int afterRelease) {
mSwitcher.onCodeInput(code, MULTI);
mSwitcher.onReleaseKey(code, NOT_SLIDING);
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
}
- public void chordingPressAndReleaseKey(int code, int afterPress, int afterRelease) {
+ public void chordingPressAndReleaseKey(final int code, final int afterPress,
+ final int afterRelease) {
chordingPressKey(code, afterPress);
chordingReleaseKey(code, afterRelease);
}
- public void pressAndSlideFromKey(int code, int afterPress, int afterSlide) {
+ public void pressAndSlideFromKey(final int code, final int afterPress, final int afterSlide) {
pressKey(code, afterPress);
mSwitcher.onReleaseKey(code, SLIDING);
assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId());
}
- public void longPressKey(int code, int afterPress, int afterLongPress) {
+ public void longPressKey(final int code, final int afterPress, final int afterLongPress) {
pressKey(code, afterPress);
mSwitcher.onLongPressTimeout(code);
assertLayout("afterLongPress", afterLongPress, mSwitcher.getLayoutId());
}
- public void longPressAndReleaseKey(int code, int afterPress, int afterLongPress,
- int afterRelease) {
+ public void longPressAndReleaseKey(final int code, final int afterPress,
+ final int afterLongPress, final int afterRelease) {
longPressKey(code, afterPress, afterLongPress);
releaseKey(code, afterRelease);
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
index dd4caadf1..eb484084e 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
@@ -1,42 +1,41 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
import android.text.TextUtils;
-import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.Constants;
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
- public interface Constants {
+ public interface MockConstants {
// Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}.
public static final boolean NOT_SLIDING = false;
public static final boolean SLIDING = true;
// Argument for {@link KeyboardState#onCodeInput}.
public static final boolean SINGLE = true;
public static final boolean MULTI = false;
- public static final int CAP_MODE_OFF =
- com.android.inputmethod.latin.Constants.TextUtils.CAP_MODE_OFF;
+ public static final int CAP_MODE_OFF = Constants.TextUtils.CAP_MODE_OFF;
public static final int CAP_MODE_WORDS = TextUtils.CAP_MODE_WORDS;
public static final int CAP_MODE_CHARACTERS = TextUtils.CAP_MODE_CHARACTERS;
- public static final int CODE_SHIFT = Keyboard.CODE_SHIFT;
- public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
- public static final int CODE_SPACE = Keyboard.CODE_SPACE;
- public static final int CODE_AUTO_CAPS_TRIGGER = Keyboard.CODE_SPACE;
+ public static final int CODE_SHIFT = Constants.CODE_SHIFT;
+ public static final int CODE_SYMBOL = Constants.CODE_SWITCH_ALPHA_SYMBOL;
+ public static final int CODE_SPACE = Constants.CODE_SPACE;
+ public static final int CODE_AUTO_CAPS_TRIGGER = Constants.CODE_SPACE;
public static final int ALPHABET_UNSHIFTED = 0;
public static final int ALPHABET_MANUAL_SHIFTED = 1;
@@ -47,11 +46,11 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
public static final int SYMBOLS_SHIFTED = 6;
}
- private int mLayout = Constants.ALPHABET_UNSHIFTED;
+ private int mLayout = MockConstants.ALPHABET_UNSHIFTED;
- private int mAutoCapsMode = Constants.CAP_MODE_OFF;
+ private int mAutoCapsMode = MockConstants.CAP_MODE_OFF;
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
- private int mAutoCapsState = Constants.CAP_MODE_OFF;
+ private int mAutoCapsState = MockConstants.CAP_MODE_OFF;
private boolean mIsInDoubleTapTimeout;
private int mLongPressTimeoutCode;
@@ -62,20 +61,20 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
return mLayout;
}
- public static String getLayoutName(int layoutId) {
+ public static String getLayoutName(final int layoutId) {
switch (layoutId) {
- case Constants.ALPHABET_UNSHIFTED: return "ALPHABET_UNSHIFTED";
- case Constants.ALPHABET_MANUAL_SHIFTED: return "ALPHABET_MANUAL_SHIFTED";
- case Constants.ALPHABET_AUTOMATIC_SHIFTED: return "ALPHABET_AUTOMATIC_SHIFTED";
- case Constants.ALPHABET_SHIFT_LOCKED: return "ALPHABET_SHIFT_LOCKED";
- case Constants.ALPHABET_SHIFT_LOCK_SHIFTED: return "ALPHABET_SHIFT_LOCK_SHIFTED";
- case Constants.SYMBOLS_UNSHIFTED: return "SYMBOLS_UNSHIFTED";
- case Constants.SYMBOLS_SHIFTED: return "SYMBOLS_SHIFTED";
+ case MockConstants.ALPHABET_UNSHIFTED: return "ALPHABET_UNSHIFTED";
+ case MockConstants.ALPHABET_MANUAL_SHIFTED: return "ALPHABET_MANUAL_SHIFTED";
+ case MockConstants.ALPHABET_AUTOMATIC_SHIFTED: return "ALPHABET_AUTOMATIC_SHIFTED";
+ case MockConstants.ALPHABET_SHIFT_LOCKED: return "ALPHABET_SHIFT_LOCKED";
+ case MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED: return "ALPHABET_SHIFT_LOCK_SHIFTED";
+ case MockConstants.SYMBOLS_UNSHIFTED: return "SYMBOLS_UNSHIFTED";
+ case MockConstants.SYMBOLS_SHIFTED: return "SYMBOLS_SHIFTED";
default: return "UNKNOWN<" + layoutId + ">";
}
}
- public void setAutoCapsMode(int autoCaps) {
+ public void setAutoCapsMode(final int autoCaps) {
mAutoCapsMode = autoCaps;
mAutoCapsState = autoCaps;
}
@@ -86,37 +85,37 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
@Override
public void setAlphabetKeyboard() {
- mLayout = Constants.ALPHABET_UNSHIFTED;
+ mLayout = MockConstants.ALPHABET_UNSHIFTED;
}
@Override
public void setAlphabetManualShiftedKeyboard() {
- mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
+ mLayout = MockConstants.ALPHABET_MANUAL_SHIFTED;
}
@Override
public void setAlphabetAutomaticShiftedKeyboard() {
- mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
+ mLayout = MockConstants.ALPHABET_AUTOMATIC_SHIFTED;
}
@Override
public void setAlphabetShiftLockedKeyboard() {
- mLayout = Constants.ALPHABET_SHIFT_LOCKED;
+ mLayout = MockConstants.ALPHABET_SHIFT_LOCKED;
}
@Override
public void setAlphabetShiftLockShiftedKeyboard() {
- mLayout = Constants.ALPHABET_SHIFT_LOCK_SHIFTED;
+ mLayout = MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED;
}
@Override
public void setSymbolsKeyboard() {
- mLayout = Constants.SYMBOLS_UNSHIFTED;
+ mLayout = MockConstants.SYMBOLS_UNSHIFTED;
}
@Override
public void setSymbolsShiftedKeyboard() {
- mLayout = Constants.SYMBOLS_SHIFTED;
+ mLayout = MockConstants.SYMBOLS_SHIFTED;
}
@Override
@@ -140,7 +139,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
}
@Override
- public void startLongPressTimer(int code) {
+ public void startLongPressTimer(final int code) {
mLongPressTimeoutCode = code;
}
@@ -150,11 +149,11 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
}
@Override
- public void hapticAndAudioFeedback(int code) {
+ public void hapticAndAudioFeedback(final int code) {
// Nothing to do.
}
- public void onLongPressTimeout(int code) {
+ public void onLongPressTimeout(final int code) {
// TODO: Handle simultaneous long presses.
if (mLongPressTimeoutCode == code) {
mLongPressTimeoutCode = 0;
@@ -166,30 +165,30 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onUpdateShiftState(mAutoCapsState);
}
- public void loadKeyboard(String layoutSwitchBackSymbols) {
- mState.onLoadKeyboard(layoutSwitchBackSymbols);
+ public void loadKeyboard() {
+ mState.onLoadKeyboard();
}
public void saveKeyboardState() {
mState.onSaveKeyboardState();
}
- public void onPressKey(int code, boolean isSinglePointer) {
+ public void onPressKey(final int code, final boolean isSinglePointer) {
mState.onPressKey(code, isSinglePointer, mAutoCapsState);
}
- public void onReleaseKey(int code, boolean withSliding) {
+ public void onReleaseKey(final int code, final boolean withSliding) {
mState.onReleaseKey(code, withSliding);
if (mLongPressTimeoutCode == code) {
mLongPressTimeoutCode = 0;
}
}
- public void onCodeInput(int code, boolean isSinglePointer) {
- if (mAutoCapsMode == Constants.CAP_MODE_WORDS) {
- if (Keyboard.isLetterCode(code)) {
- mAutoCapsState = (code == Constants.CODE_AUTO_CAPS_TRIGGER)
- ? mAutoCapsMode : Constants.CAP_MODE_OFF;
+ public void onCodeInput(final int code, final boolean isSinglePointer) {
+ if (mAutoCapsMode == MockConstants.CAP_MODE_WORDS) {
+ if (Constants.isLetterCode(code)) {
+ mAutoCapsState = (code == MockConstants.CODE_AUTO_CAPS_TRIGGER)
+ ? mAutoCapsMode : MockConstants.CAP_MODE_OFF;
}
} else {
mAutoCapsState = mAutoCapsMode;
@@ -197,7 +196,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onCodeInput(code, isSinglePointer, mAutoCapsState);
}
- public void onCancelInput(boolean isSinglePointer) {
+ public void onCancelInput(final boolean isSinglePointer) {
mState.onCancelInput(isSinglePointer);
}
} \ No newline at end of file
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueueTests.java b/tests/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueueTests.java
index 8fed28f9e..d6700cfb5 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueueTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueueTests.java
@@ -1,23 +1,25 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.internal;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+@SmallTest
public class PointerTrackerQueueTests extends AndroidTestCase {
public static class Element implements PointerTrackerQueue.Element {
public static int sPhantomUpCount;
@@ -49,6 +51,9 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
}
@Override
+ public void cancelTracking() {}
+
+ @Override
public String toString() {
return Integer.toString(mId);
}
diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
index 03310c88b..7275d3afa 100644
--- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
+++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java
@@ -1,26 +1,26 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.Keyboard;
-
+import android.test.suitebuilder.annotation.LargeTest;
import android.text.style.SuggestionSpan;
import android.text.style.UnderlineSpan;
+@LargeTest
public class BlueUnderlineTests extends InputTestsBase {
public void testBlueUnderline() {
@@ -67,13 +67,13 @@ public class BlueUnderlineTests extends InputTestsBase {
type(STRING_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- type(Keyboard.CODE_SPACE);
+ type(Constants.CODE_SPACE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
final SpanGetter suggestionSpan = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
@@ -88,17 +88,19 @@ public class BlueUnderlineTests extends InputTestsBase {
public void testBlueUnderlineDisappearsWhenCursorMoved() {
final String STRING_TO_TYPE = "tgis";
+ final int typedLength = STRING_TO_TYPE.length();
final int NEW_CURSOR_POSITION = 0;
type(STRING_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
// Simulate the onUpdateSelection() event
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
runMessages();
// Here the blue underline has been set. testBlueUnderline() is testing for this already,
// so let's not test it here again.
// Now simulate the user moving the cursor.
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
- mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
+ mLatinIME.onUpdateSelection(typedLength, typedLength,
+ NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
@@ -117,7 +119,5 @@ public class BlueUnderlineTests extends InputTestsBase {
// Now simulate the user moving the cursor.
SpanGetter span = new SpanGetter(mTextView.getText(), UnderlineSpan.class);
assertNull("should not be composing, so should not have an underline span", span.mSpan);
- span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
- assertNull("should not be composing, so should not have an underline span", span.mSpan);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/CapsModeUtilsTests.java
new file mode 100644
index 000000000..339791d57
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/CapsModeUtilsTests.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2013 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 android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
+
+import java.util.Locale;
+
+@SmallTest
+public class CapsModeUtilsTests extends AndroidTestCase {
+ private static void onePathForCaps(final CharSequence cs, final int expectedResult,
+ final int mask, final Locale l, final boolean hasSpaceBefore) {
+ int oneTimeResult = expectedResult & mask;
+ assertEquals("After >" + cs + "<", oneTimeResult,
+ CapsModeUtils.getCapsMode(cs, mask, l, hasSpaceBefore));
+ }
+
+ private static void allPathsForCaps(final CharSequence cs, final int expectedResult,
+ final Locale l, final boolean hasSpaceBefore) {
+ final int c = TextUtils.CAP_MODE_CHARACTERS;
+ final int w = TextUtils.CAP_MODE_WORDS;
+ final int s = TextUtils.CAP_MODE_SENTENCES;
+ onePathForCaps(cs, expectedResult, c | w | s, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w | s, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | s, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | w, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w, l, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, s, l, hasSpaceBefore);
+ }
+
+ public void testGetCapsMode() {
+ final int c = TextUtils.CAP_MODE_CHARACTERS;
+ final int w = TextUtils.CAP_MODE_WORDS;
+ final int s = TextUtils.CAP_MODE_SENTENCES;
+ Locale l = Locale.ENGLISH;
+ allPathsForCaps("", c | w | s, l, false);
+ allPathsForCaps("Word", c, l, false);
+ allPathsForCaps("Word.", c, l, false);
+ allPathsForCaps("Word ", c | w, l, false);
+ allPathsForCaps("Word. ", c | w | s, l, false);
+ allPathsForCaps("Word..", c, l, false);
+ allPathsForCaps("Word.. ", c | w | s, l, false);
+ allPathsForCaps("Word... ", c | w | s, l, false);
+ allPathsForCaps("Word ... ", c | w | s, l, false);
+ allPathsForCaps("Word . ", c | w, l, false);
+ allPathsForCaps("In the U.S ", c | w, l, false);
+ allPathsForCaps("In the U.S. ", c | w, l, false);
+ allPathsForCaps("Some stuff (e.g. ", c | w, l, false);
+ allPathsForCaps("In the U.S.. ", c | w | s, l, false);
+ allPathsForCaps("\"Word.\" ", c | w | s, l, false);
+ allPathsForCaps("\"Word\". ", c | w | s, l, false);
+ allPathsForCaps("\"Word\" ", c | w, l, false);
+
+ // Test for phantom space
+ allPathsForCaps("Word", c | w, l, true);
+ allPathsForCaps("Word.", c | w | s, l, true);
+
+ // Tests after some whitespace
+ allPathsForCaps("Word\n", c | w | s, l, false);
+ allPathsForCaps("Word\n", c | w | s, l, true);
+ allPathsForCaps("Word\n ", c | w | s, l, true);
+ allPathsForCaps("Word.\n", c | w | s, l, false);
+ allPathsForCaps("Word.\n", c | w | s, l, true);
+ allPathsForCaps("Word.\n ", c | w | s, l, true);
+
+ l = Locale.FRENCH;
+ allPathsForCaps("\"Word.\" ", c | w, l, false);
+ allPathsForCaps("\"Word\". ", c | w | s, l, false);
+ allPathsForCaps("\"Word\" ", c | w, l, false);
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
index c053a49e5..0b7fcbbe8 100644
--- a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
+++ b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java
@@ -17,7 +17,9 @@
package com.android.inputmethod.latin;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+@SmallTest
public class EditDistanceTests extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
diff --git a/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java b/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java
index a2e71c11a..3259312df 100644
--- a/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java
+++ b/tests/src/com/android/inputmethod/latin/ForgettingCurveTests.java
@@ -17,7 +17,9 @@
package com.android.inputmethod.latin;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+@SmallTest
public class ForgettingCurveTests extends AndroidTestCase {
public void testFcToFreq() {
for (int i = 0; i < Byte.MAX_VALUE; ++i) {
diff --git a/tests/src/com/android/inputmethod/latin/FusionDictionaryTests.java b/tests/src/com/android/inputmethod/latin/FusionDictionaryTests.java
index 123959b4d..65dfd2dde 100644
--- a/tests/src/com/android/inputmethod/latin/FusionDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/FusionDictionaryTests.java
@@ -1,22 +1,23 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@@ -26,6 +27,7 @@ import java.util.HashMap;
/**
* Unit test for FusionDictionary
*/
+@SmallTest
public class FusionDictionaryTests extends AndroidTestCase {
public void testFindWordInTree() {
FusionDictionary dict = new FusionDictionary(new Node(),
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 38e57aaed..72c8d9c2f 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -1,23 +1,24 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.keyboard.Keyboard;
+import android.test.suitebuilder.annotation.LargeTest;
+@LargeTest
public class InputLogicTests extends InputTestsBase {
public void testTypeWord() {
@@ -32,7 +33,7 @@ public class InputLogicTests extends InputTestsBase {
type(WORD_TO_TYPE);
pickSuggestionManually(0, WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("press suggestion then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -48,7 +49,7 @@ public class InputLogicTests extends InputTestsBase {
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK,
mTextView.getText().toString());
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -63,7 +64,7 @@ public class InputLogicTests extends InputTestsBase {
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE,
mTextView.getText().toString());
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -79,13 +80,14 @@ public class InputLogicTests extends InputTestsBase {
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick different suggestion then backspace", WORD_TO_PICK,
mTextView.getText().toString());
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("pick different suggestion then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testDeleteSelection() {
final String STRING_TO_TYPE = "some text delete me some text";
+ final int typedLength = STRING_TO_TYPE.length();
final int SELECTION_START = 10;
final int SELECTION_END = 19;
final String EXPECTED_RESULT = "some text some text";
@@ -94,14 +96,36 @@ public class InputLogicTests extends InputTestsBase {
// Send once to simulate the cursor actually responding to the move caused by typing.
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
// move with a move triggered by LatinIME inputting stuff.
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
// And now we simulate the user actually selecting some text.
- mLatinIME.onUpdateSelection(0, 0, SELECTION_START, SELECTION_END, -1, -1);
- type(Keyboard.CODE_DELETE);
+ mLatinIME.onUpdateSelection(typedLength, typedLength,
+ SELECTION_START, SELECTION_END, -1, -1);
+ type(Constants.CODE_DELETE);
assertEquals("delete selection", EXPECTED_RESULT, mTextView.getText().toString());
}
+ public void testDeleteSelectionTwice() {
+ final String STRING_TO_TYPE = "some text delete me some text";
+ final int typedLength = STRING_TO_TYPE.length();
+ final int SELECTION_START = 10;
+ final int SELECTION_END = 19;
+ final String EXPECTED_RESULT = "some text some text";
+ type(STRING_TO_TYPE);
+ // There is no IMF to call onUpdateSelection for us so we must do it by hand.
+ // Send once to simulate the cursor actually responding to the move caused by typing.
+ // This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
+ // move with a move triggered by LatinIME inputting stuff.
+ mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
+ mInputConnection.setSelection(SELECTION_START, SELECTION_END);
+ // And now we simulate the user actually selecting some text.
+ mLatinIME.onUpdateSelection(typedLength, typedLength,
+ SELECTION_START, SELECTION_END, -1, -1);
+ type(Constants.CODE_DELETE);
+ type(Constants.CODE_DELETE);
+ assertEquals("delete selection twice", EXPECTED_RESULT, mTextView.getText().toString());
+ }
+
public void testAutoCorrect() {
final String STRING_TO_TYPE = "tgis ";
final String EXPECTED_RESULT = "this ";
@@ -121,7 +145,7 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "tgis.";
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("auto-correct with period then revert", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -131,7 +155,7 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "tgis ";
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("auto-correct with space then revert", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -141,7 +165,7 @@ public class InputLogicTests extends InputTestsBase {
final String EXPECTED_RESULT = "this";
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("auto-correct with space does not revert", EXPECTED_RESULT,
mTextView.getText().toString());
}
@@ -157,32 +181,36 @@ public class InputLogicTests extends InputTestsBase {
final String STRING_TO_TYPE = "this ";
final String EXPECTED_RESULT = "this ";
type(STRING_TO_TYPE);
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
assertEquals("double space make a period", EXPECTED_RESULT, mTextView.getText().toString());
}
public void testBackspaceAtStartAfterAutocorrect() {
final String STRING_TO_TYPE = "tgis ";
+ final int typedLength = STRING_TO_TYPE.length();
final String EXPECTED_RESULT = "this ";
final int NEW_CURSOR_POSITION = 0;
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
- mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
- type(Keyboard.CODE_DELETE);
+ mLatinIME.onUpdateSelection(typedLength, typedLength,
+ NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
+ type(Constants.CODE_DELETE);
assertEquals("auto correct then move cursor to start of line then backspace",
EXPECTED_RESULT, mTextView.getText().toString());
}
public void testAutoCorrectThenMoveCursorThenBackspace() {
final String STRING_TO_TYPE = "and tgis ";
+ final int typedLength = STRING_TO_TYPE.length();
final String EXPECTED_RESULT = "andthis ";
final int NEW_CURSOR_POSITION = STRING_TO_TYPE.indexOf('t');
type(STRING_TO_TYPE);
- mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
+ mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
- mLatinIME.onUpdateSelection(0, 0, NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
- type(Keyboard.CODE_DELETE);
+ mLatinIME.onUpdateSelection(typedLength, typedLength,
+ NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
+ type(Constants.CODE_DELETE);
assertEquals("auto correct then move cursor then backspace",
EXPECTED_RESULT, mTextView.getText().toString());
}
@@ -258,7 +286,7 @@ public class InputLogicTests extends InputTestsBase {
final String WORD_TO_TYPE = "this";
type(WORD_TO_TYPE);
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
- type(Keyboard.CODE_DELETE);
+ type(Constants.CODE_DELETE);
}
assertEquals("delete whole composing word", "", mTextView.getText().toString());
}
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
index 78143ac5b..333b60277 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
@@ -1,22 +1,28 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.suitebuilder.annotation.LargeTest;
+
+import com.android.inputmethod.latin.suggestions.SuggestionStripView;
+
+@LargeTest
public class InputLogicTestsNonEnglish extends InputTestsBase {
+ final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq ";
@@ -43,16 +49,47 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
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());
- pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
- pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
- assertEquals("type word then type space then punctuation from strip twice for French",
- EXPECTED_RESULT, mTextView.getText().toString());
+ final boolean defaultNextWordPredictionOption =
+ mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
+ final boolean previousNextWordPredictionOption =
+ setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
+ defaultNextWordPredictionOption);
+ try {
+ 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());
+ pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
+ pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
+ assertEquals("type word then type space then punctuation from strip twice for French",
+ EXPECTED_RESULT, mTextView.getText().toString());
+ } finally {
+ setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
+ defaultNextWordPredictionOption);
+ }
+ }
+
+ public void testWordThenSpaceDisplaysPredictions() {
+ final String WORD_TO_TYPE = "beaujolais ";
+ final String EXPECTED_RESULT = "nouveau";
+ final boolean defaultNextWordPredictionOption =
+ mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
+ final boolean previousNextWordPredictionOption =
+ setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true,
+ defaultNextWordPredictionOption);
+ try {
+ changeLanguage("fr");
+ type(WORD_TO_TYPE);
+ sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
+ runMessages();
+ assertEquals("type word then type space yields predictions for French",
+ EXPECTED_RESULT, mLatinIME.getFirstSuggestedWord());
+ } finally {
+ setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
+ defaultNextWordPredictionOption);
+ }
}
public void testAutoCorrectForGerman() {
diff --git a/tests/src/com/android/inputmethod/latin/InputPointersTests.java b/tests/src/com/android/inputmethod/latin/InputPointersTests.java
index cc55076c0..e1149b3fd 100644
--- a/tests/src/com/android/inputmethod/latin/InputPointersTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputPointersTests.java
@@ -1,25 +1,27 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import java.util.Arrays;
+@SmallTest
public class InputPointersTests extends AndroidTestCase {
private static final int DEFAULT_CAPACITY = 48;
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index fe58cb84e..4ccbf4857 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -1,17 +1,17 @@
/*
* 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
+ * 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
+ * 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.
+ * 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;
@@ -31,16 +31,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
-import android.view.inputmethod.InputMethodInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.view.inputmethod.InputMethodSubtype;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
-import java.util.HashMap;
import java.util.Locale;
public class InputTestsBase extends ServiceTestCase<LatinIME> {
@@ -53,9 +49,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
protected LatinIME mLatinIME;
protected Keyboard mKeyboard;
protected MyTextView mTextView;
+ protected View mInputView;
protected InputConnection mInputConnection;
- private final HashMap<String, InputMethodSubtype> mSubtypeMap =
- new HashMap<String, InputMethodSubtype>();
// A helper class to ease span tests
public static class SpanGetter {
@@ -142,7 +137,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
final boolean previousDebugSetting = setDebugMode(true);
mLatinIME.onCreate();
setDebugMode(previousDebugSetting);
- initSubtypeMap();
final EditorInfo ei = new EditorInfo();
ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
final InputConnection ic = mTextView.onCreateInputConnection(ei);
@@ -150,9 +144,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
final LayoutInflater inflater =
(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewGroup vg = new FrameLayout(getContext());
- final View inputView = inflater.inflate(R.layout.input_view, vg);
+ mInputView = inflater.inflate(R.layout.input_view, vg);
mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
- mLatinIME.setInputView(inputView);
+ mLatinIME.setInputView(mInputView);
mLatinIME.onBindInput();
mLatinIME.onCreateInputView();
mLatinIME.onStartInputView(ei, false);
@@ -160,26 +154,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
changeLanguage("en_US");
}
- private void initSubtypeMap() {
- final InputMethodManager imm = (InputMethodManager)mLatinIME.getSystemService(
- Context.INPUT_METHOD_SERVICE);
- final String packageName = mLatinIME.getPackageName();
- // The IMEs and subtypes don't need to be enabled to run this test because IMF isn't
- // involved here.
- for (final InputMethodInfo imi : imm.getInputMethodList()) {
- if (imi.getPackageName().equals(packageName)) {
- final int subtypeCount = imi.getSubtypeCount();
- for (int i = 0; i < subtypeCount; i++) {
- final InputMethodSubtype ims = imi.getSubtypeAt(i);
- final String locale = ims.getLocale();
- mSubtypeMap.put(locale, ims);
- }
- return;
- }
- }
- fail("LatinIME is not found");
- }
-
// We need to run the messages added to the handler from LatinIME. The only way to do
// that is to call Looper#loop() on the right looper, so we're going to get the looper
// object and call #loop() here. The messages in the handler actually run on the UI
@@ -211,7 +185,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
// any subsequent post in this queue. However the queue itself is still fully functional!
// If we have a way of resetting "queue.mQuiting" then we can continue using it as normal,
// coming back to this method to run the messages.
- MessageQueue queue = looper.getQueue();
+ MessageQueue queue = Looper.myQueue();
try {
// However there is no way of doing it externally, and mQuiting is private.
// So... get out the big guns.
@@ -253,8 +227,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
}
protected void waitForDictionaryToBeLoaded() {
- int remainingAttempts = 10;
- while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) {
+ int remainingAttempts = 300;
+ while (remainingAttempts > 0 && mLatinIME.mSuggest.isCurrentlyWaitingForMainDictionary()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
@@ -269,18 +243,14 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
}
protected void changeLanguage(final String locale) {
- final InputMethodSubtype subtype = mSubtypeMap.get(locale);
mTextView.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale);
- if (subtype == null) {
- fail("InputMethodSubtype for locale " + locale + " is not enabled");
- }
- SubtypeSwitcher.getInstance().updateSubtype(subtype);
+ SubtypeSwitcher.getInstance().forceLocale(mTextView.mCurrentLocale);
mLatinIME.loadKeyboard();
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();
waitForDictionaryToBeLoaded();
}
- protected void pickSuggestionManually(final int index, final CharSequence suggestion) {
+ protected void pickSuggestionManually(final int index, final String suggestion) {
mLatinIME.pickSuggestionManually(index, suggestion);
}
diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java
index 0eb3ba41a..1b2f0e679 100644
--- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java
+++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java
@@ -1,23 +1,26 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.suitebuilder.annotation.LargeTest;
+
import com.android.inputmethod.latin.R;
+@LargeTest
public class PunctuationTests extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
diff --git a/tests/src/com/android/inputmethod/latin/ResizableIntArrayTests.java b/tests/src/com/android/inputmethod/latin/ResizableIntArrayTests.java
index 995fc14ea..2d1b836c2 100644
--- a/tests/src/com/android/inputmethod/latin/ResizableIntArrayTests.java
+++ b/tests/src/com/android/inputmethod/latin/ResizableIntArrayTests.java
@@ -1,23 +1,25 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+@SmallTest
public class ResizableIntArrayTests extends AndroidTestCase {
private static final int DEFAULT_CAPACITY = 48;
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java
index ad9937940..9e545a5b2 100644
--- a/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java
+++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java
@@ -1,23 +1,24 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * 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
+ * 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
+ * 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.
+ * 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 android.inputmethodservice.InputMethodService;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
@@ -25,6 +26,7 @@ import android.view.inputmethod.InputConnectionWrapper;
import com.android.inputmethod.latin.RichInputConnection.Range;
+@SmallTest
public class RichInputConnectionTests extends AndroidTestCase {
// The following is meant to be a reasonable default for
diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
index 3142bd602..923ab2ecc 100644
--- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java
@@ -1,26 +1,25 @@
/*
* 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
+ * 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
+ * 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.
+ * 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 android.test.AndroidTestCase;
-import android.text.TextUtils;
-
-import java.util.Locale;
+import android.test.suitebuilder.annotation.SmallTest;
+@SmallTest
public class StringUtilsTests extends AndroidTestCase {
public void testContainsInArray() {
assertFalse("empty array", StringUtils.containsInArray("key", new String[0]));
@@ -91,66 +90,4 @@ public class StringUtilsTests extends AndroidTestCase {
assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5"));
}
-
- private void onePathForCaps(final CharSequence cs, final int expectedResult, final int mask,
- final Locale l, final boolean hasSpaceBefore) {
- int oneTimeResult = expectedResult & mask;
- assertEquals("After >" + cs + "<", oneTimeResult,
- StringUtils.getCapsMode(cs, mask, l, hasSpaceBefore));
- }
-
- private void allPathsForCaps(final CharSequence cs, final int expectedResult, final Locale l,
- final boolean hasSpaceBefore) {
- final int c = TextUtils.CAP_MODE_CHARACTERS;
- final int w = TextUtils.CAP_MODE_WORDS;
- final int s = TextUtils.CAP_MODE_SENTENCES;
- onePathForCaps(cs, expectedResult, c | w | s, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w | s, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | s, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | w, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w, l, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, s, l, hasSpaceBefore);
- }
-
- public void testGetCapsMode() {
- final int c = TextUtils.CAP_MODE_CHARACTERS;
- final int w = TextUtils.CAP_MODE_WORDS;
- final int s = TextUtils.CAP_MODE_SENTENCES;
- Locale l = Locale.ENGLISH;
- allPathsForCaps("", c | w | s, l, false);
- allPathsForCaps("Word", c, l, false);
- allPathsForCaps("Word.", c, l, false);
- allPathsForCaps("Word ", c | w, l, false);
- allPathsForCaps("Word. ", c | w | s, l, false);
- allPathsForCaps("Word..", c, l, false);
- allPathsForCaps("Word.. ", c | w | s, l, false);
- allPathsForCaps("Word... ", c | w | s, l, false);
- allPathsForCaps("Word ... ", c | w | s, l, false);
- allPathsForCaps("Word . ", c | w, l, false);
- allPathsForCaps("In the U.S ", c | w, l, false);
- allPathsForCaps("In the U.S. ", c | w, l, false);
- allPathsForCaps("Some stuff (e.g. ", c | w, l, false);
- allPathsForCaps("In the U.S.. ", c | w | s, l, false);
- allPathsForCaps("\"Word.\" ", c | w | s, l, false);
- allPathsForCaps("\"Word\". ", c | w | s, l, false);
- allPathsForCaps("\"Word\" ", c | w, l, false);
-
- // Test for phantom space
- allPathsForCaps("Word", c | w, l, true);
- allPathsForCaps("Word.", c | w | s, l, true);
-
- // Tests after some whitespace
- allPathsForCaps("Word\n", c | w | s, l, false);
- allPathsForCaps("Word\n", c | w | s, l, true);
- allPathsForCaps("Word\n ", c | w | s, l, true);
- allPathsForCaps("Word.\n", c | w | s, l, false);
- allPathsForCaps("Word.\n", c | w | s, l, true);
- allPathsForCaps("Word.\n ", c | w | s, l, true);
-
- l = Locale.FRENCH;
- allPathsForCaps("\"Word.\" ", c | w, l, false);
- allPathsForCaps("\"Word\". ", c | w | s, l, false);
- allPathsForCaps("\"Word\" ", c | w, l, false);
- }
}
diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
index 52a3745fa..abfaf3062 100644
--- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
+++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
@@ -1,17 +1,17 @@
/*
* Copyright (C) 2011 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
+ * 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
+ * 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.
+ * 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;
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
@@ -26,23 +27,69 @@ import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.util.ArrayList;
import java.util.Locale;
+@SmallTest
public class SubtypeLocaleTests extends AndroidTestCase {
// Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
+ private RichInputMethodManager mRichImm;
private Resources mRes;
+ InputMethodSubtype EN_US;
+ InputMethodSubtype EN_GB;
+ InputMethodSubtype ES_US;
+ InputMethodSubtype FR;
+ InputMethodSubtype FR_CA;
+ InputMethodSubtype DE;
+ InputMethodSubtype ZZ;
+ InputMethodSubtype DE_QWERTY;
+ InputMethodSubtype FR_QWERTZ;
+ InputMethodSubtype EN_US_AZERTY;
+ InputMethodSubtype EN_UK_DVORAK;
+ InputMethodSubtype ES_US_COLEMAK;
+ InputMethodSubtype ZZ_PC;
+
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
+ RichInputMethodManager.init(context);
+ mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources();
SubtypeLocale.init(context);
+
+ EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.US.toString(), "qwerty");
+ EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.UK.toString(), "qwerty");
+ ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "es_US", "spanish");
+ FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.FRENCH.toString(), "azerty");
+ FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.CANADA_FRENCH.toString(), "qwerty");
+ DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.GERMAN.toString(), "qwertz");
+ ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ SubtypeLocale.NO_LANGUAGE, "qwerty");
+ DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
+ Locale.GERMAN.toString(), "qwerty", null);
+ FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
+ Locale.FRENCH.toString(), "qwertz", null);
+ EN_US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
+ Locale.US.toString(), "azerty", null);
+ EN_UK_DVORAK = AdditionalSubtype.createAdditionalSubtype(
+ Locale.UK.toString(), "dvorak", null);
+ ES_US_COLEMAK = AdditionalSubtype.createAdditionalSubtype(
+ "es_US", "colemak", null);
+ ZZ_PC = AdditionalSubtype.createAdditionalSubtype(
+ SubtypeLocale.NO_LANGUAGE, "pcqwerty", null);
+
}
public void testAllFullDisplayName() {
for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
+ final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
if (SubtypeLocale.isNoLanguage(subtype)) {
final String noLanguage = mRes.getString(R.string.subtype_no_language);
assertTrue(subtypeName, subtypeName.contains(noLanguage));
@@ -56,36 +103,26 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// InputMethodSubtype's display name in its locale.
// isAdditionalSubtype (T=true, F=false)
- // locale layout | display name
- // ------ ------ - ----------------------
- // en_US qwerty F English (US) exception
- // en_GB qwerty F English (UK) exception
- // fr azerty F Français
- // fr_CA qwerty F Français (Canada)
- // de qwertz F Deutsch
- // zz qwerty F No language (QWERTY) in system locale
- // fr qwertz T Français (QWERTZ)
- // de qwerty T Deutsch (QWERTY)
- // en_US azerty T English (US) (AZERTY)
- // zz azerty T No language (AZERTY) in system locale
+ // locale layout | display name
+ // ------ ------- - ----------------------
+ // en_US qwerty F English (US) exception
+ // en_GB qwerty F English (UK) exception
+ // es_US spanish F Español (EE.UU.) exception
+ // fr azerty F Français
+ // fr_CA qwerty F Français (Canada)
+ // de qwertz F Deutsch
+ // zz qwerty F No language (QWERTY) in system locale
+ // fr qwertz T Français (QWERTZ)
+ // de qwerty T Deutsch (QWERTY)
+ // en_US azerty T English (US) (AZERTY) exception
+ // en_UK dvorak T English (UK) (Dvorak) exception
+ // es_US colemak T Español (EE.UU.) (Colemak) exception
+ // zz pc T No language (PC) in system locale
public void testPredefinedSubtypesInEnglish() {
- final Context context = getContext();
- final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.US.toString(), "qwerty");
- final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.UK.toString(), "qwerty");
- final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.FRENCH.toString(), "azerty");
- final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.CANADA_FRENCH.toString(), "qwerty");
- final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.GERMAN.toString(), "qwertz");
- final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, SubtypeLocale.NO_LANGUAGE, "qwerty");
-
assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US));
assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB));
+ assertEquals("es_US", "spanish", SubtypeLocale.getKeyboardLayoutSetName(ES_US));
assertEquals("fr ", "azerty", SubtypeLocale.getKeyboardLayoutSetName(FR));
assertEquals("fr_CA", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(FR_CA));
assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE));
@@ -95,17 +132,19 @@ public class SubtypeLocaleTests extends AndroidTestCase {
@Override
protected Void job(Resources res) {
assertEquals("en_US", "English (US)",
- SubtypeLocale.getSubtypeDisplayName(EN_US, res));
+ SubtypeLocale.getSubtypeDisplayName(EN_US));
assertEquals("en_GB", "English (UK)",
- SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
+ SubtypeLocale.getSubtypeDisplayName(EN_GB));
+ assertEquals("es_US", "Español (EE.UU.)",
+ SubtypeLocale.getSubtypeDisplayName(ES_US));
assertEquals("fr ", "Français",
- SubtypeLocale.getSubtypeDisplayName(FR, res));
+ SubtypeLocale.getSubtypeDisplayName(FR));
assertEquals("fr_CA", "Français (Canada)",
- SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
+ SubtypeLocale.getSubtypeDisplayName(FR_CA));
assertEquals("de ", "Deutsch",
- SubtypeLocale.getSubtypeDisplayName(DE, res));
+ SubtypeLocale.getSubtypeDisplayName(DE));
assertEquals("zz ", "No language (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ, res));
+ SubtypeLocale.getSubtypeDisplayName(ZZ));
return null;
}
};
@@ -113,26 +152,21 @@ public class SubtypeLocaleTests extends AndroidTestCase {
}
public void testAdditionalSubtypesInEnglish() {
- final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.GERMAN.toString(), "qwerty", null);
- final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
- Locale.FRENCH.toString(), "qwertz", null);
- final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.US.toString(), "azerty", null);
- final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- SubtypeLocale.NO_LANGUAGE, "azerty", null);
-
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(Resources res) {
assertEquals("fr qwertz", "Français (QWERTZ)",
- SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
+ SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
+ SubtypeLocale.getSubtypeDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English (US) (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
- assertEquals("zz azerty", "No language (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
+ SubtypeLocale.getSubtypeDisplayName(EN_US_AZERTY));
+ assertEquals("en_UK dvorak", "English (UK) (Dvorak)",
+ SubtypeLocale.getSubtypeDisplayName(EN_UK_DVORAK));
+ assertEquals("es_US colemak","Español (EE.UU.) (Colemak)",
+ SubtypeLocale.getSubtypeDisplayName(ES_US_COLEMAK));
+ assertEquals("zz pc", "No language (PC)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ_PC));
return null;
}
};
@@ -140,35 +174,23 @@ public class SubtypeLocaleTests extends AndroidTestCase {
}
public void testPredefinedSubtypesInFrench() {
- final Context context = getContext();
- final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.US.toString(), "qwerty");
- final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.UK.toString(), "qwerty");
- final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.FRENCH.toString(), "azerty");
- final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.CANADA_FRENCH.toString(), "qwerty");
- final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, Locale.GERMAN.toString(), "qwertz");
- final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
- context, SubtypeLocale.NO_LANGUAGE, "qwerty");
-
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(Resources res) {
assertEquals("en_US", "English (US)",
- SubtypeLocale.getSubtypeDisplayName(EN_US, res));
+ SubtypeLocale.getSubtypeDisplayName(EN_US));
assertEquals("en_GB", "English (UK)",
- SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
+ SubtypeLocale.getSubtypeDisplayName(EN_GB));
+ assertEquals("es_US", "Español (EE.UU.)",
+ SubtypeLocale.getSubtypeDisplayName(ES_US));
assertEquals("fr ", "Français",
- SubtypeLocale.getSubtypeDisplayName(FR, res));
+ SubtypeLocale.getSubtypeDisplayName(FR));
assertEquals("fr_CA", "Français (Canada)",
- SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
+ SubtypeLocale.getSubtypeDisplayName(FR_CA));
assertEquals("de ", "Deutsch",
- SubtypeLocale.getSubtypeDisplayName(DE, res));
- assertEquals("zz ", "Pas de langue (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ, res));
+ SubtypeLocale.getSubtypeDisplayName(DE));
+ assertEquals("zz ", "Aucune langue (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ));
return null;
}
};
@@ -176,26 +198,157 @@ public class SubtypeLocaleTests extends AndroidTestCase {
}
public void testAdditionalSubtypesInFrench() {
- final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.GERMAN.toString(), "qwerty", null);
- final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
- Locale.FRENCH.toString(), "qwertz", null);
- final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- Locale.US.toString(), "azerty", null);
- final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
- SubtypeLocale.NO_LANGUAGE, "azerty", null);
-
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(Resources res) {
assertEquals("fr qwertz", "Français (QWERTZ)",
- SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
+ SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
+ SubtypeLocale.getSubtypeDisplayName(DE_QWERTY));
+ assertEquals("en_US azerty", "English (US) (AZERTY)",
+ SubtypeLocale.getSubtypeDisplayName(EN_US_AZERTY));
+ assertEquals("en_UK dvorak", "English (UK) (Dvorak)",
+ SubtypeLocale.getSubtypeDisplayName(EN_UK_DVORAK));
+ assertEquals("es_US colemak","Español (EE.UU.) (Colemak)",
+ SubtypeLocale.getSubtypeDisplayName(ES_US_COLEMAK));
+ assertEquals("zz azerty", "Aucune langue (PC)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ_PC));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.FRENCH);
+ }
+
+ // InputMethodSubtype's display name in system locale (en_US).
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ ------- - ----------------------
+ // en_US qwerty F English (US) exception
+ // en_GB qwerty F English (UK) exception
+ // es_US spanish F Spanish (US) exception
+ // fr azerty F French
+ // fr_CA qwerty F French (Canada)
+ // de qwertz F German
+ // zz qwerty F No language (QWERTY)
+ // fr qwertz T French (QWERTZ)
+ // de qwerty T German (QWERTY)
+ // en_US azerty T English (US) (AZERTY) exception
+ // en_UK dvorak T English (UK) (Dvorak) exception
+ // es_US colemak T Spanish (US) (Colemak) exception
+ // zz pc T No language (PC)
+
+ public void testPredefinedSubtypesInEnglishSystemLocale() {
+ assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US));
+ assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB));
+ assertEquals("es_US", "spanish", SubtypeLocale.getKeyboardLayoutSetName(ES_US));
+ assertEquals("fr ", "azerty", SubtypeLocale.getKeyboardLayoutSetName(FR));
+ assertEquals("fr_CA", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(FR_CA));
+ assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE));
+ assertEquals("zz ", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ));
+
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("en_US", "English (US)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_US));
+ assertEquals("en_GB", "English (UK)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_GB));
+ assertEquals("es_US", "Spanish (US)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ES_US));
+ assertEquals("fr ", "French",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR));
+ assertEquals("fr_CA", "French (Canada)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR_CA));
+ assertEquals("de ", "German",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(DE));
+ assertEquals("zz ", "No language (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ZZ));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.ENGLISH);
+ }
+
+ public void testAdditionalSubtypesInEnglishSystemLocale() {
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("fr qwertz", "French (QWERTZ)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ));
+ assertEquals("de qwerty", "German (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(DE_QWERTY));
assertEquals("en_US azerty", "English (US) (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
- assertEquals("zz azerty", "Aucune langue (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY));
+ assertEquals("en_UK dvorak", "English (UK) (Dvorak)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK));
+ assertEquals("es_US colemak","Spanish (US) (Colemak)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK));
+ assertEquals("zz azerty", "No language (PC)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.ENGLISH);
+ }
+
+ // InputMethodSubtype's display name in system locale (fr).
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ ------- - ----------------------
+ // en_US qwerty F Anglais (États-Unis) exception
+ // en_GB qwerty F Anglais (Royaume-Uni) exception
+ // es_US spanish F Espagnol (États-Unis) exception
+ // fr azerty F Français
+ // fr_CA qwerty F Français (Canada)
+ // de qwertz F Allemand
+ // zz qwerty F Aucune langue (QWERTY)
+ // fr qwertz T Français (QWERTZ)
+ // de qwerty T Allemand (QWERTY)
+ // en_US azerty T Anglais (États-Unis) (AZERTY) exception
+ // en_UK dvorak T Anglais (Royaume-Uni) (Dvorak) exception
+ // es_US colemak T Espagnol (États-Unis) (Colemak) exception
+ // zz pc T Aucune langue (PC)
+
+ public void testPredefinedSubtypesInFrenchSystemLocale() {
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("en_US", "Anglais (États-Unis)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_US));
+ assertEquals("en_GB", "Anglais (Royaume-Uni)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_GB));
+ assertEquals("es_US", "Espagnol (États-Unis)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ES_US));
+ assertEquals("fr ", "Français",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR));
+ assertEquals("fr_CA", "Français (Canada)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR_CA));
+ assertEquals("de ", "Allemand",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(DE));
+ assertEquals("zz ", "Aucune langue (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ZZ));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.FRENCH);
+ }
+
+ public void testAdditionalSubtypesInFrenchSystemLocale() {
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("fr qwertz", "Français (QWERTZ)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ));
+ assertEquals("de qwerty", "Allemand (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(DE_QWERTY));
+ assertEquals("en_US azerty", "Anglais (États-Unis) (AZERTY)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY));
+ assertEquals("en_UK dvorak", "Anglais (Royaume-Uni) (Dvorak)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK));
+ assertEquals("es_US colemak","Espagnol (États-Unis) (Colemak)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK));
+ assertEquals("zz azerty", "Aucune langue (PC)",
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
return null;
}
};
diff --git a/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
index 70f916c1a..211d012d2 100644
--- a/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
@@ -16,17 +16,17 @@
package com.android.inputmethod.latin;
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface;
import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener;
-import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.util.Log;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -39,6 +39,7 @@ import java.util.HashMap;
/**
* Unit tests for UserHistoryDictIOUtils
*/
+@LargeTest
public class UserHistoryDictIOUtilsTests extends AndroidTestCase
implements BigramDictionaryInterface {
@@ -139,7 +140,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
out.flush();
out.close();
} catch (IOException e) {
- Log.e(TAG, "IO exception while writing file: " + e);
+ Log.e(TAG, "IO exception while writing file", e);
}
}
@@ -154,9 +155,9 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
UserHistoryDictIOUtils.readDictionaryBinary(
new UserHistoryDictIOUtils.ByteArrayWrapper(buffer), listener);
} catch (FileNotFoundException e) {
- Log.e(TAG, "file not found: " + e);
+ Log.e(TAG, "file not found", e);
} catch (IOException e) {
- Log.e(TAG, "IOException: " + e);
+ Log.e(TAG, "IOException", e);
} finally {
if (inStream != null) {
try {
@@ -188,9 +189,9 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
File file = null;
try {
- file = File.createTempFile("testReadAndWrite", ".dict");
+ file = File.createTempFile("testReadAndWrite", ".dict", getContext().getCacheDir());
} catch (IOException e) {
- Log.d(TAG, "IOException while creating a temporary file: " + e);
+ Log.d(TAG, "IOException while creating a temporary file", e);
}
assertNotNull(file);
diff --git a/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java
index f2a17d206..594ba0e7b 100644
--- a/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java
@@ -16,13 +16,13 @@
package com.android.inputmethod.latin;
-import com.android.inputmethod.latin.UserHistoryDictionary;
-
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -31,6 +31,7 @@ import java.util.Set;
/**
* Unit tests for UserHistoryDictionary
*/
+@LargeTest
public class UserHistoryDictionaryTests extends AndroidTestCase {
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
private SharedPreferences mPrefs;
@@ -76,34 +77,43 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
}
public void testRandomWords() {
- Log.d(TAG, "This test can be used for profiling.");
- Log.d(TAG, "Usage: please set UserHisotoryDictionary.PROFILE_SAVE_RESTORE to true.");
- final int numberOfWords = 1000;
- final Random random = new Random(123456);
- List<String> words = generateWords(numberOfWords, random);
-
- final String locale = "testRandomWords";
- final UserHistoryDictionary dict = UserHistoryDictionary.getInstance(getContext(),
- locale, mPrefs);
- dict.isTest = true;
-
- addToDict(dict, words);
-
- try {
- Log.d(TAG, "waiting for adding the word ...");
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- Log.d(TAG, "InterruptedException: " + e);
- }
-
- // write to file
- dict.close();
-
+ File dictFile = null;
try {
- Log.d(TAG, "waiting for writing ...");
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- Log.d(TAG, "InterruptedException: " + e);
+ Log.d(TAG, "This test can be used for profiling.");
+ Log.d(TAG, "Usage: please set UserHisotoryDictionary.PROFILE_SAVE_RESTORE to true.");
+ final int numberOfWords = 1000;
+ final Random random = new Random(123456);
+ List<String> words = generateWords(numberOfWords, random);
+
+ final String locale = "testRandomWords";
+ final String fileName = "UserHistoryDictionary." + locale + ".dict";
+ dictFile = new File(getContext().getFilesDir(), fileName);
+ final UserHistoryDictionary dict = UserHistoryDictionary.getInstance(getContext(),
+ locale, mPrefs);
+ dict.isTest = true;
+
+ addToDict(dict, words);
+
+ try {
+ Log.d(TAG, "waiting for adding the word ...");
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ Log.d(TAG, "InterruptedException: " + e);
+ }
+
+ // write to file
+ dict.close();
+
+ try {
+ Log.d(TAG, "waiting for writing ...");
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ Log.d(TAG, "InterruptedException: " + e);
+ }
+ } finally {
+ if (dictFile != null) {
+ dictFile.delete();
+ }
}
}
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
index 2f954318c..ade010981 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
@@ -16,6 +16,12 @@
package com.android.inputmethod.latin.makedict;
+import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+import android.util.SparseArray;
+
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.UserHistoryDictIOUtils;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
@@ -24,11 +30,6 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import android.test.AndroidTestCase;
-import android.test.MoreAsserts;
-import android.util.Log;
-import android.util.SparseArray;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -47,6 +48,7 @@ import java.util.Set;
/**
* Unit tests for BinaryDictInputOutput
*/
+@LargeTest
public class BinaryDictIOTests extends AndroidTestCase {
private static final String TAG = BinaryDictIOTests.class.getSimpleName();
private static final int MAX_UNIGRAMS = 1000;
@@ -114,13 +116,13 @@ public class BinaryDictIOTests extends AndroidTestCase {
return new BinaryDictInputOutput.ByteBufferWrapper(buffer);
}
} catch (IOException e) {
- Log.e(TAG, "IOException while making buffer: " + e);
+ Log.e(TAG, "IOException while making buffer", e);
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (IOException e) {
- Log.e(TAG, "IOException while closing stream: " + e);
+ Log.e(TAG, "IOException while closing stream", e);
}
}
}
@@ -193,9 +195,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
out.flush();
out.close();
} catch (IOException e) {
- Log.e(TAG, "IO exception while writing file: " + e);
+ Log.e(TAG, "IO exception while writing file", e);
} catch (UnsupportedFormatException e) {
- Log.e(TAG, "UnsupportedFormatException: " + e);
+ Log.e(TAG, "UnsupportedFormatException", e);
}
return diff;
@@ -255,9 +257,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
dict = BinaryDictInputOutput.readDictionaryBinary(buffer, null);
diff = System.currentTimeMillis() - now;
} catch (IOException e) {
- Log.e(TAG, "IOException while reading dictionary: " + e);
+ Log.e(TAG, "IOException while reading dictionary", e);
} catch (UnsupportedFormatException e) {
- Log.e(TAG, "Unsupported format: " + e);
+ Log.e(TAG, "Unsupported format", e);
}
checkDictionary(dict, words, bigrams, shortcutMap);
@@ -271,9 +273,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
final String message) {
File file = null;
try {
- file = File.createTempFile("runReadAndWrite", ".dict");
+ file = File.createTempFile("runReadAndWrite", ".dict", getContext().getCacheDir());
} catch (IOException e) {
- Log.e(TAG, "IOException: " + e);
+ Log.e(TAG, "IOException", e);
}
assertNotNull(file);
@@ -390,9 +392,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
resultBigrams);
diff = System.currentTimeMillis() - now;
} catch (IOException e) {
- Log.e(TAG, "IOException " + e);
+ Log.e(TAG, "IOException", e);
} catch (UnsupportedFormatException e) {
- Log.e(TAG, "UnsupportedFormatException: " + e);
+ Log.e(TAG, "UnsupportedFormatException", e);
} finally {
if (inStream != null) {
try {
@@ -412,9 +414,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
final FormatSpec.FormatOptions formatOptions, final String message) {
File file = null;
try {
- file = File.createTempFile("runReadUnigrams", ".dict");
+ file = File.createTempFile("runReadUnigrams", ".dict", getContext().getCacheDir());
} catch (IOException e) {
- Log.e(TAG, "IOException: " + e);
+ Log.e(TAG, "IOException", e);
}
assertNotNull(file);
@@ -484,7 +486,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
}
if (header == null) return null;
return BinaryDictInputOutput.getWordAtAddress(buffer, header.mHeaderSize,
- address - header.mHeaderSize, header.mFormatOptions);
+ address - header.mHeaderSize, header.mFormatOptions).mWord;
}
private long runGetTerminalPosition(final FusionDictionaryBufferInterface buffer,
@@ -497,9 +499,9 @@ public class BinaryDictIOTests extends AndroidTestCase {
position = BinaryDictIOUtils.getTerminalPosition(buffer, word);
diff = System.nanoTime() - now;
} catch (IOException e) {
- Log.e(TAG, "IOException while getTerminalPosition: " + e);
+ Log.e(TAG, "IOException while getTerminalPosition", e);
} catch (UnsupportedFormatException e) {
- Log.e(TAG, "UnsupportedFormatException while getTermianlPosition: " + e);
+ Log.e(TAG, "UnsupportedFormatException while getTerminalPosition", e);
}
assertEquals(FormatSpec.NOT_VALID_WORD != position, contained);
@@ -510,7 +512,8 @@ public class BinaryDictIOTests extends AndroidTestCase {
public void testGetTerminalPosition() {
File file = null;
try {
- file = File.createTempFile("testGetTerminalPosition", ".dict");
+ file = File.createTempFile("testGetTerminalPosition", ".dict",
+ getContext().getCacheDir());
} catch (IOException e) {
// do nothing
}
@@ -561,7 +564,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
public void testDeleteWord() {
File file = null;
try {
- file = File.createTempFile("testDeleteWord", ".dict");
+ file = File.createTempFile("testDeleteWord", ".dict", getContext().getCacheDir());
} catch (IOException e) {
// do nothing
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java
new file mode 100644
index 000000000..47885f023
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java
@@ -0,0 +1,395 @@
+/*
+ * 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.makedict;
+
+import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
+import com.android.inputmethod.latin.CollectionUtils;
+import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.ByteBufferWrapper;
+import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
+import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
+import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
+import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+
+@LargeTest
+public class BinaryDictIOUtilsTests extends AndroidTestCase {
+ private static final String TAG = BinaryDictIOUtilsTests.class.getSimpleName();
+ private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
+ new FormatSpec.FormatOptions(3, true);
+ private static final int MAX_UNIGRAMS = 1500;
+
+ private static final ArrayList<String> sWords = CollectionUtils.newArrayList();
+
+ private static final String[] CHARACTERS = {
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
+ "\u00FC" /* ü */, "\u00E2" /* â */, "\u00F1" /* ñ */, // accented characters
+ "\u4E9C" /* 亜 */, "\u4F0A" /* 伊 */, "\u5B87" /* 宇 */, // kanji
+ "\uD841\uDE28" /* 𠘨 */, "\uD840\uDC0B" /* 𠀋 */, "\uD861\uDeD7" /* 𨛗 */ // surrogate pair
+ };
+
+ public BinaryDictIOUtilsTests() {
+ super();
+ final Random random = new Random(123456);
+ sWords.clear();
+ for (int i = 0; i < MAX_UNIGRAMS; ++i) {
+ sWords.add(generateWord(random.nextInt()));
+ }
+ }
+
+ // Utilities for test
+ private String generateWord(final int value) {
+ final int lengthOfChars = CHARACTERS.length;
+ StringBuilder builder = new StringBuilder("");
+ long lvalue = Math.abs((long)value);
+ while (lvalue > 0) {
+ builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]);
+ lvalue /= lengthOfChars;
+ }
+ if (builder.toString().equals("")) return "a";
+ return builder.toString();
+ }
+
+ private static void printCharGroup(final CharGroupInfo info) {
+ Log.d(TAG, " CharGroup at " + info.mOriginalAddress);
+ Log.d(TAG, " flags = " + info.mFlags);
+ Log.d(TAG, " parentAddress = " + info.mParentAddress);
+ Log.d(TAG, " characters = " + new String(info.mCharacters, 0,
+ info.mCharacters.length));
+ if (info.mFrequency != -1) Log.d(TAG, " frequency = " + info.mFrequency);
+ if (info.mChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS) {
+ Log.d(TAG, " children address = no children address");
+ } else {
+ Log.d(TAG, " children address = " + info.mChildrenAddress);
+ }
+ if (info.mShortcutTargets != null) {
+ for (final WeightedString ws : info.mShortcutTargets) {
+ Log.d(TAG, " shortcuts = " + ws.mWord);
+ }
+ }
+ if (info.mBigrams != null) {
+ for (final PendingAttribute attr : info.mBigrams) {
+ Log.d(TAG, " bigram = " + attr.mAddress);
+ }
+ }
+ Log.d(TAG, " end address = " + info.mEndAddress);
+ }
+
+ private static void printNode(final FusionDictionaryBufferInterface buffer,
+ final FormatSpec.FormatOptions formatOptions) {
+ Log.d(TAG, "Node at " + buffer.position());
+ final int count = BinaryDictInputOutput.readCharGroupCount(buffer);
+ Log.d(TAG, " charGroupCount = " + count);
+ for (int i = 0; i < count; ++i) {
+ final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer,
+ buffer.position(), formatOptions);
+ printCharGroup(currentInfo);
+ }
+ if (formatOptions.mSupportsDynamicUpdate) {
+ final int forwardLinkAddress = buffer.readUnsignedInt24();
+ Log.d(TAG, " forwardLinkAddress = " + forwardLinkAddress);
+ }
+ }
+
+ private static void printBinaryFile(final FusionDictionaryBufferInterface buffer)
+ throws IOException, UnsupportedFormatException {
+ FileHeader header = BinaryDictInputOutput.readHeader(buffer);
+ while (buffer.position() < buffer.limit()) {
+ printNode(buffer, header.mFormatOptions);
+ }
+ }
+
+ private int getWordPosition(final File file, final String word) {
+ int position = FormatSpec.NOT_VALID_WORD;
+ FileInputStream inStream = null;
+ try {
+ inStream = new FileInputStream(file);
+ final FusionDictionaryBufferInterface buffer = new ByteBufferWrapper(
+ inStream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length()));
+ position = BinaryDictIOUtils.getTerminalPosition(buffer, word);
+ } catch (IOException e) {
+ } catch (UnsupportedFormatException e) {
+ } finally {
+ if (inStream != null) {
+ try {
+ inStream.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ return position;
+ }
+
+ private CharGroupInfo findWordFromFile(final File file, final String word) {
+ FileInputStream inStream = null;
+ CharGroupInfo info = null;
+ try {
+ inStream = new FileInputStream(file);
+ final FusionDictionaryBufferInterface buffer = new ByteBufferWrapper(
+ inStream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length()));
+ info = BinaryDictIOUtils.findWordFromBuffer(buffer, word);
+ } catch (IOException e) {
+ } catch (UnsupportedFormatException e) {
+ } finally {
+ if (inStream != null) {
+ try {
+ inStream.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ return info;
+ }
+
+ // return amount of time to insert a word
+ private long insertAndCheckWord(final File file, final String word, final int frequency,
+ final boolean exist, final ArrayList<WeightedString> bigrams,
+ final ArrayList<WeightedString> shortcuts) {
+ RandomAccessFile raFile = null;
+ BufferedOutputStream outStream = null;
+ FusionDictionaryBufferInterface buffer = null;
+ long amountOfTime = -1;
+ try {
+ raFile = new RandomAccessFile(file, "rw");
+ buffer = new ByteBufferWrapper(raFile.getChannel().map(
+ FileChannel.MapMode.READ_WRITE, 0, file.length()));
+ outStream = new BufferedOutputStream(new FileOutputStream(file, true));
+
+ if (!exist) {
+ assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word));
+ }
+ final long now = System.nanoTime();
+ BinaryDictIOUtils.insertWord(buffer, outStream, word, frequency, bigrams, shortcuts,
+ false, false);
+ amountOfTime = System.nanoTime() - now;
+ outStream.flush();
+ MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word));
+ outStream.close();
+ raFile.close();
+ } catch (IOException e) {
+ } catch (UnsupportedFormatException e) {
+ } finally {
+ if (outStream != null) {
+ try {
+ outStream.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ if (raFile != null) {
+ try {
+ raFile.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ return amountOfTime;
+ }
+
+ private void deleteWord(final File file, final String word) {
+ RandomAccessFile raFile = null;
+ FusionDictionaryBufferInterface buffer = null;
+ try {
+ raFile = new RandomAccessFile(file, "rw");
+ buffer = new ByteBufferWrapper(raFile.getChannel().map(
+ FileChannel.MapMode.READ_WRITE, 0, file.length()));
+ BinaryDictIOUtils.deleteWord(buffer, word);
+ } catch (IOException e) {
+ } catch (UnsupportedFormatException e) {
+ } finally {
+ if (raFile != null) {
+ try {
+ raFile.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ }
+
+ private void checkReverseLookup(final File file, final String word, final int position) {
+ FileInputStream inStream = null;
+ try {
+ inStream = new FileInputStream(file);
+ final FusionDictionaryBufferInterface buffer = new ByteBufferWrapper(
+ inStream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length()));
+ final FileHeader header = BinaryDictInputOutput.readHeader(buffer);
+ assertEquals(word, BinaryDictInputOutput.getWordAtAddress(buffer, header.mHeaderSize,
+ position - header.mHeaderSize, header.mFormatOptions).mWord);
+ } catch (IOException e) {
+ } catch (UnsupportedFormatException e) {
+ } finally {
+ if (inStream != null) {
+ try {
+ inStream.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ }
+
+ public void testInsertWord() {
+ File file = null;
+ try {
+ file = File.createTempFile("testInsertWord", ".dict", getContext().getCacheDir());
+ } catch (IOException e) {
+ fail("IOException while creating temporary file: " + e);
+ }
+
+ // set an initial dictionary.
+ final FusionDictionary dict = new FusionDictionary(new Node(),
+ new FusionDictionary.DictionaryOptions(new HashMap<String,String>(), false, false));
+ dict.add("abcd", 10, null, false);
+
+ try {
+ final FileOutputStream out = new FileOutputStream(file);
+ BinaryDictInputOutput.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
+ out.close();
+ } catch (IOException e) {
+ fail("IOException while writing an initial dictionary : " + e);
+ } catch (UnsupportedFormatException e) {
+ fail("UnsupportedFormatException while writing an initial dictionary : " + e);
+ }
+
+ MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "abcd"));
+ insertAndCheckWord(file, "abcde", 10, false, null, null);
+
+ insertAndCheckWord(file, "abcdefghijklmn", 10, false, null, null);
+ checkReverseLookup(file, "abcdefghijklmn", getWordPosition(file, "abcdefghijklmn"));
+
+ insertAndCheckWord(file, "abcdabcd", 10, false, null, null);
+ checkReverseLookup(file, "abcdabcd", getWordPosition(file, "abcdabcd"));
+
+ // update the existing word.
+ insertAndCheckWord(file, "abcdabcd", 15, true, null, null);
+
+ // split 1
+ insertAndCheckWord(file, "ab", 20, false, null, null);
+
+ // split 2
+ insertAndCheckWord(file, "ami", 30, false, null, null);
+
+ deleteWord(file, "ami");
+ assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "ami"));
+
+ insertAndCheckWord(file, "abcdabfg", 30, false, null, null);
+
+ deleteWord(file, "abcd");
+ assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, "abcd"));
+ }
+
+ public void testInsertWordWithBigrams() {
+ File file = null;
+ try {
+ file = File.createTempFile("testInsertWordWithBigrams", ".dict",
+ getContext().getCacheDir());
+ } catch (IOException e) {
+ fail("IOException while creating temporary file: " + e);
+ }
+
+ // set an initial dictionary.
+ final FusionDictionary dict = new FusionDictionary(new Node(),
+ new FusionDictionary.DictionaryOptions(new HashMap<String,String>(), false, false));
+ dict.add("abcd", 10, null, false);
+ dict.add("efgh", 15, null, false);
+
+ try {
+ final FileOutputStream out = new FileOutputStream(file);
+ BinaryDictInputOutput.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
+ out.close();
+ } catch (IOException e) {
+ fail("IOException while writing an initial dictionary : " + e);
+ } catch (UnsupportedFormatException e) {
+ fail("UnsupportedFormatException while writing an initial dictionary : " + e);
+ }
+
+ final ArrayList<WeightedString> banana = new ArrayList<WeightedString>();
+ banana.add(new WeightedString("banana", 10));
+
+ insertAndCheckWord(file, "banana", 0, false, null, null);
+ insertAndCheckWord(file, "recursive", 60, true, banana, null);
+
+ final CharGroupInfo info = findWordFromFile(file, "recursive");
+ int bananaPos = getWordPosition(file, "banana");
+ assertNotNull(info.mBigrams);
+ assertEquals(info.mBigrams.size(), 1);
+ assertEquals(info.mBigrams.get(0).mAddress, bananaPos);
+ }
+
+ public void testRandomWords() {
+ File file = null;
+ try {
+ file = File.createTempFile("testRandomWord", ".dict", getContext().getCacheDir());
+ } catch (IOException e) {
+ }
+ assertNotNull(file);
+
+ // set an initial dictionary.
+ final FusionDictionary dict = new FusionDictionary(new Node(),
+ new FusionDictionary.DictionaryOptions(new HashMap<String, String>(), false,
+ false));
+ dict.add("initial", 10, null, false);
+
+ try {
+ final FileOutputStream out = new FileOutputStream(file);
+ BinaryDictInputOutput.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
+ out.close();
+ } catch (IOException e) {
+ assertTrue(false);
+ } catch (UnsupportedFormatException e) {
+ assertTrue(false);
+ }
+
+ long maxTimeToInsert = 0, sum = 0;
+ long minTimeToInsert = 100000000; // 1000000000 is an upper bound for minTimeToInsert.
+ int cnt = 0;
+ for (final String word : sWords) {
+ final long diff = insertAndCheckWord(file, word,
+ cnt % FormatSpec.MAX_TERMINAL_FREQUENCY, false, null, null);
+ maxTimeToInsert = Math.max(maxTimeToInsert, diff);
+ minTimeToInsert = Math.min(minTimeToInsert, diff);
+ sum += diff;
+ cnt++;
+ }
+ cnt = 0;
+ for (final String word : sWords) {
+ MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word));
+ }
+
+ Log.d(TAG, "max = " + ((double)maxTimeToInsert/1000000) + " ms.");
+ Log.d(TAG, "min = " + ((double)minTimeToInsert/1000000) + " ms.");
+ Log.d(TAG, "avg = " + ((double)sum/MAX_UNIGRAMS/1000000) + " ms.");
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java
index 21406d370..879cc4664 100644
--- a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java
+++ b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java
@@ -1,27 +1,27 @@
/*
* 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
+ * 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
+ * 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.
+ * 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.spellcheck;
-import android.text.SpannableStringBuilder;
-import android.text.style.CharacterStyle;
+import android.test.suitebuilder.annotation.LargeTest;
import android.text.style.SuggestionSpan;
import com.android.inputmethod.latin.InputTestsBase;
+@LargeTest
public class AndroidSpellCheckerServiceTest extends InputTestsBase {
public void testSpellchecker() {
mTextView.onAttachedToWindow();
diff --git a/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java b/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java
new file mode 100644
index 000000000..28a9f3d5c
--- /dev/null
+++ b/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2013 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.research;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.JsonReader;
+
+import com.android.inputmethod.research.MotionEventReader.ReplayData;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+@SmallTest
+public class MotionEventReaderTests extends AndroidTestCase {
+ private MotionEventReader mMotionEventReader = new MotionEventReader();
+ private ReplayData mReplayData;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mReplayData = new ReplayData();
+ }
+
+ private JsonReader jsonReaderForString(final String s) {
+ return new JsonReader(new StringReader(s));
+ }
+
+ public void testTopLevelDataVariant() {
+ final JsonReader jsonReader = jsonReaderForString(
+ "{"
+ + "\"_ct\": 1359590400000,"
+ + "\"_ut\": 4381933,"
+ + "\"_ty\": \"MotionEvent\","
+ + "\"action\": \"UP\","
+ + "\"isLoggingRelated\": false,"
+ + "\"x\": 100.0,"
+ + "\"y\": 200.0"
+ + "}"
+ );
+ try {
+ mMotionEventReader.readLogStatement(jsonReader, mReplayData);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("IOException thrown");
+ }
+ assertEquals("x set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
+ assertEquals("y set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
+ assertEquals("only one pointer", mReplayData.mPointerCoordsArrays.get(0).length, 1);
+ assertEquals("only one MotionEvent", mReplayData.mPointerCoordsArrays.size(), 1);
+ }
+
+ public void testNestedDataVariant() {
+ final JsonReader jsonReader = jsonReaderForString(
+ "{"
+ + " \"_ct\": 135959040000,"
+ + " \"_ut\": 4382702,"
+ + " \"_ty\": \"MotionEvent\","
+ + " \"action\": \"MOVE\","
+ + " \"isLoggingRelated\": false,"
+ + " \"motionEvent\": {"
+ + " \"pointerIds\": ["
+ + " 0"
+ + " ],"
+ + " \"xyt\": ["
+ + " {"
+ + " \"t\": 4382551,"
+ + " \"d\": ["
+ + " {"
+ + " \"x\": 100.0,"
+ + " \"y\": 200.0,"
+ + " \"toma\": 999.0,"
+ + " \"tomi\": 999.0,"
+ + " \"o\": 0.0"
+ + " }"
+ + " ]"
+ + " },"
+ + " {"
+ + " \"t\": 4382559,"
+ + " \"d\": ["
+ + " {"
+ + " \"x\": 300.0,"
+ + " \"y\": 400.0,"
+ + " \"toma\": 999.0,"
+ + " \"tomi\": 999.0,"
+ + " \"o\": 0.0"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + " }"
+ + "}"
+ );
+ try {
+ mMotionEventReader.readLogStatement(jsonReader, mReplayData);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("IOException thrown");
+ }
+ assertEquals("x1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
+ assertEquals("y1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
+ assertEquals("x2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(1)[0].x, 300);
+ assertEquals("y2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(1)[0].y, 400);
+ assertEquals("only one pointer", mReplayData.mPointerCoordsArrays.get(0).length, 1);
+ assertEquals("two MotionEvents", mReplayData.mPointerCoordsArrays.size(), 2);
+ }
+
+ public void testNestedDataVariantMultiPointer() {
+ final JsonReader jsonReader = jsonReaderForString(
+ "{"
+ + " \"_ct\": 135959040000,"
+ + " \"_ut\": 4382702,"
+ + " \"_ty\": \"MotionEvent\","
+ + " \"action\": \"MOVE\","
+ + " \"isLoggingRelated\": false,"
+ + " \"motionEvent\": {"
+ + " \"pointerIds\": ["
+ + " 1"
+ + " ],"
+ + " \"xyt\": ["
+ + " {"
+ + " \"t\": 4382551,"
+ + " \"d\": ["
+ + " {"
+ + " \"x\": 100.0,"
+ + " \"y\": 200.0,"
+ + " \"toma\": 999.0,"
+ + " \"tomi\": 999.0,"
+ + " \"o\": 0.0"
+ + " },"
+ + " {"
+ + " \"x\": 300.0,"
+ + " \"y\": 400.0,"
+ + " \"toma\": 999.0,"
+ + " \"tomi\": 999.0,"
+ + " \"o\": 0.0"
+ + " }"
+ + " ]"
+ + " }"
+ + " ]"
+ + " }"
+ + "}"
+ );
+ try {
+ mMotionEventReader.readLogStatement(jsonReader, mReplayData);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("IOException thrown");
+ }
+ assertEquals("x1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
+ assertEquals("y1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
+ assertEquals("x2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[1].x, 300);
+ assertEquals("y2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[1].y, 400);
+ assertEquals("two pointers", mReplayData.mPointerCoordsArrays.get(0).length, 2);
+ assertEquals("one MotionEvent", mReplayData.mPointerCoordsArrays.size(), 1);
+ }
+}