aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java55
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java94
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java47
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java14
5 files changed, 136 insertions, 76 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 039f581a7..1a249ce45 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -368,8 +368,8 @@ public class InputLogicTests extends InputTestsBase {
// Choose the auto-correction, which is always in position 0. For "Barack", the
// auto-correction should be "Barack".
pickSuggestionManually(0, WORD_TO_TYPE);
- runMessages();
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
// Test the first prediction is displayed
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWords();
assertEquals("predictions after manual pick", "Obama",
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
index 6ad125053..f19d1853e 100644
--- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
+++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
@@ -16,16 +16,13 @@
package com.android.inputmethod.latin;
-import com.android.inputmethod.latin.settings.SettingsValues;
-import com.android.inputmethod.latin.utils.TextRange;
-
+import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.os.Parcel;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.SpannableString;
-import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.SuggestionSpan;
import android.view.inputmethod.ExtractedText;
@@ -33,6 +30,10 @@ import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+import com.android.inputmethod.latin.utils.RunInLocale;
+import com.android.inputmethod.latin.utils.TextRange;
+
import java.util.Locale;
@SmallTest
@@ -40,12 +41,19 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
// The following is meant to be a reasonable default for
// the "word_separators" resource.
- private static final SettingsValues sSettings =
- SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH);
+ private SpacingAndPunctuations mSpacingAndPunctuations;
@Override
protected void setUp() throws Exception {
super.setUp();
+ final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
+ @Override
+ protected SpacingAndPunctuations job(final Resources res) {
+ return new SpacingAndPunctuations(res);
+ }
+ };
+ final Resources res = getContext().getResources();
+ mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH);
}
private class MockConnection extends InputConnectionWrapper {
@@ -139,9 +147,12 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
*/
public void testGetPreviousWord() {
// If one of the following cases breaks, the bigram suggestions won't work.
- assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSettings, 2), "abc");
- assertNull(RichInputConnection.getNthPreviousWord("abc", sSettings, 2));
- assertNull(RichInputConnection.getNthPreviousWord("abc. def", sSettings, 2));
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def", mSpacingAndPunctuations, 2), "abc");
+ assertNull(RichInputConnection.getNthPreviousWord(
+ "abc", mSpacingAndPunctuations, 2));
+ assertNull(RichInputConnection.getNthPreviousWord(
+ "abc. def", mSpacingAndPunctuations, 2));
// The following tests reflect the current behavior of the function
// RichInputConnection#getNthPreviousWord.
@@ -150,15 +161,23 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
// this function if needed - especially since it does not seem very
// logical. These tests are just there to catch any unintentional
// changes in the behavior of the RichInputConnection#getPreviousWord method.
- assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSettings, 2), "abc");
- assertEquals(RichInputConnection.getNthPreviousWord("abc def.", sSettings, 2), "abc");
- assertEquals(RichInputConnection.getNthPreviousWord("abc def .", sSettings, 2), "def");
- assertNull(RichInputConnection.getNthPreviousWord("abc ", sSettings, 2));
-
- assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSettings, 1), "def");
- assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSettings, 1), "def");
- assertNull(RichInputConnection.getNthPreviousWord("abc def.", sSettings, 1));
- assertNull(RichInputConnection.getNthPreviousWord("abc def .", sSettings, 1));
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def ", mSpacingAndPunctuations, 2), "abc");
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def.", mSpacingAndPunctuations, 2), "abc");
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def .", mSpacingAndPunctuations, 2), "def");
+ assertNull(RichInputConnection.getNthPreviousWord(
+ "abc ", mSpacingAndPunctuations, 2));
+
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def", mSpacingAndPunctuations, 1), "def");
+ assertEquals(RichInputConnection.getNthPreviousWord(
+ "abc def ", mSpacingAndPunctuations, 1), "def");
+ assertNull(RichInputConnection.getNthPreviousWord(
+ "abc def.", mSpacingAndPunctuations, 1));
+ assertNull(RichInputConnection.getNthPreviousWord(
+ "abc def .", mSpacingAndPunctuations, 1));
}
/**
diff --git a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
index 1fd5c989a..40a103b84 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
@@ -16,75 +16,83 @@
package com.android.inputmethod.latin.utils;
-import com.android.inputmethod.latin.settings.SettingsValues;
-
+import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+
import java.util.Locale;
@SmallTest
public class CapsModeUtilsTests extends AndroidTestCase {
private static void onePathForCaps(final CharSequence cs, final int expectedResult,
- final int mask, final SettingsValues sv, final boolean hasSpaceBefore) {
- int oneTimeResult = expectedResult & mask;
+ final int mask, final SpacingAndPunctuations sp, final boolean hasSpaceBefore) {
+ final int oneTimeResult = expectedResult & mask;
assertEquals("After >" + cs + "<", oneTimeResult,
- CapsModeUtils.getCapsMode(cs, mask, sv, hasSpaceBefore));
+ CapsModeUtils.getCapsMode(cs, mask, sp, hasSpaceBefore));
}
private static void allPathsForCaps(final CharSequence cs, final int expectedResult,
- final SettingsValues sv, final boolean hasSpaceBefore) {
+ final SpacingAndPunctuations sp, 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, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w | s, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | s, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | w, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, s, sv, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | w | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | w, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, s, sp, 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;
- SettingsValues sv = SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH);
- allPathsForCaps("", c | w | s, sv, false);
- allPathsForCaps("Word", c, sv, false);
- allPathsForCaps("Word.", c, sv, false);
- allPathsForCaps("Word ", c | w, sv, false);
- allPathsForCaps("Word. ", c | w | s, sv, false);
- allPathsForCaps("Word..", c, sv, false);
- allPathsForCaps("Word.. ", c | w | s, sv, false);
- allPathsForCaps("Word... ", c | w | s, sv, false);
- allPathsForCaps("Word ... ", c | w | s, sv, false);
- allPathsForCaps("Word . ", c | w, sv, false);
- allPathsForCaps("In the U.S ", c | w, sv, false);
- allPathsForCaps("In the U.S. ", c | w, sv, false);
- allPathsForCaps("Some stuff (e.g. ", c | w, sv, false);
- allPathsForCaps("In the U.S.. ", c | w | s, sv, false);
- allPathsForCaps("\"Word.\" ", c | w | s, sv, false);
- allPathsForCaps("\"Word\". ", c | w | s, sv, false);
- allPathsForCaps("\"Word\" ", c | w, sv, false);
+ final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
+ @Override
+ protected SpacingAndPunctuations job(final Resources res) {
+ return new SpacingAndPunctuations(res);
+ }
+ };
+ final Resources res = getContext().getResources();
+ SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
+ allPathsForCaps("", c | w | s, sp, false);
+ allPathsForCaps("Word", c, sp, false);
+ allPathsForCaps("Word.", c, sp, false);
+ allPathsForCaps("Word ", c | w, sp, false);
+ allPathsForCaps("Word. ", c | w | s, sp, false);
+ allPathsForCaps("Word..", c, sp, false);
+ allPathsForCaps("Word.. ", c | w | s, sp, false);
+ allPathsForCaps("Word... ", c | w | s, sp, false);
+ allPathsForCaps("Word ... ", c | w | s, sp, false);
+ allPathsForCaps("Word . ", c | w, sp, false);
+ allPathsForCaps("In the U.S ", c | w, sp, false);
+ allPathsForCaps("In the U.S. ", c | w, sp, false);
+ allPathsForCaps("Some stuff (e.g. ", c | w, sp, false);
+ allPathsForCaps("In the U.S.. ", c | w | s, sp, false);
+ allPathsForCaps("\"Word.\" ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\". ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\" ", c | w, sp, false);
// Test for phantom space
- allPathsForCaps("Word", c | w, sv, true);
- allPathsForCaps("Word.", c | w | s, sv, true);
+ allPathsForCaps("Word", c | w, sp, true);
+ allPathsForCaps("Word.", c | w | s, sp, true);
// Tests after some whitespace
- allPathsForCaps("Word\n", c | w | s, sv, false);
- allPathsForCaps("Word\n", c | w | s, sv, true);
- allPathsForCaps("Word\n ", c | w | s, sv, true);
- allPathsForCaps("Word.\n", c | w | s, sv, false);
- allPathsForCaps("Word.\n", c | w | s, sv, true);
- allPathsForCaps("Word.\n ", c | w | s, sv, true);
+ allPathsForCaps("Word\n", c | w | s, sp, false);
+ allPathsForCaps("Word\n", c | w | s, sp, true);
+ allPathsForCaps("Word\n ", c | w | s, sp, true);
+ allPathsForCaps("Word.\n", c | w | s, sp, false);
+ allPathsForCaps("Word.\n", c | w | s, sp, true);
+ allPathsForCaps("Word.\n ", c | w | s, sp, true);
- sv = SettingsValues.makeDummySettingsValuesForTest(Locale.FRENCH);
- allPathsForCaps("\"Word.\" ", c | w, sv, false);
- allPathsForCaps("\"Word\". ", c | w | s, sv, false);
- allPathsForCaps("\"Word\" ", c | w, sv, false);
+ sp = job.runInLocale(res, Locale.FRENCH);
+ allPathsForCaps("\"Word.\" ", c | w, sp, false);
+ allPathsForCaps("\"Word\". ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\" ", c | w, sp, false);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java
new file mode 100644
index 000000000..6e716074c
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/DictionaryInfoUtilsTests.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.utils;
+
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+
+import java.util.Locale;
+
+@SmallTest
+public class DictionaryInfoUtilsTests extends AndroidTestCase {
+ public void testLooksValidForDictionaryInsertion() {
+ final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
+ @Override
+ protected SpacingAndPunctuations job(final Resources res) {
+ return new SpacingAndPunctuations(res);
+ }
+ };
+ final Resources res = getContext().getResources();
+ final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
+ assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("aochaueo", sp));
+ assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("", sp));
+ assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp));
+ assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("2908743256", sp));
+ assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("31aochaueo", sp));
+ assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .",
+ sp));
+ assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
index 0c88f34f0..71966124f 100644
--- a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.latin.utils;
-import com.android.inputmethod.latin.settings.SettingsValues;
-
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -208,18 +206,6 @@ public class StringAndJsonUtilsTests extends AndroidTestCase {
assertTrue(StringUtils.isIdenticalAfterDowncase(""));
}
- public void testLooksValidForDictionaryInsertion() {
- final SettingsValues settings =
- SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH);
- assertTrue(StringUtils.looksValidForDictionaryInsertion("aochaueo", settings));
- assertFalse(StringUtils.looksValidForDictionaryInsertion("", settings));
- assertTrue(StringUtils.looksValidForDictionaryInsertion("ao-ch'aueo", settings));
- assertFalse(StringUtils.looksValidForDictionaryInsertion("2908743256", settings));
- assertTrue(StringUtils.looksValidForDictionaryInsertion("31aochaueo", settings));
- assertFalse(StringUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .", settings));
- assertFalse(StringUtils.looksValidForDictionaryInsertion("!!!", settings));
- }
-
private static void checkCapitalize(final String src, final String dst, final String separators,
final Locale locale) {
assertEquals(dst, StringUtils.capitalizeEachWord(src, separators, locale));