aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/compat/LocaleSpanCompatUtilsTests.java174
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/Sinhala.java12
-rw-r--r--tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java43
3 files changed, 198 insertions, 31 deletions
diff --git a/tests/src/com/android/inputmethod/compat/LocaleSpanCompatUtilsTests.java b/tests/src/com/android/inputmethod/compat/LocaleSpanCompatUtilsTests.java
index a920373d4..319302c71 100644
--- a/tests/src/com/android/inputmethod/compat/LocaleSpanCompatUtilsTests.java
+++ b/tests/src/com/android/inputmethod/compat/LocaleSpanCompatUtilsTests.java
@@ -16,9 +16,14 @@
package com.android.inputmethod.compat;
+import android.graphics.Typeface;
import android.os.Build;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.StyleSpan;
import java.util.Locale;
@@ -35,4 +40,173 @@ public class LocaleSpanCompatUtilsTests extends AndroidTestCase {
assertEquals(Locale.JAPANESE,
LocaleSpanCompatUtils.getLocaleFromLocaleSpan(japaneseLocaleSpan));
}
+
+ private static void assertLocaleSpan(final Spanned spanned, final int index,
+ final int expectedStart, final int expectedEnd,
+ final Locale expectedLocale, final int expectedSpanFlags) {
+ final Object span = spanned.getSpans(0, spanned.length(), Object.class)[index];
+ assertEquals(expectedLocale, LocaleSpanCompatUtils.getLocaleFromLocaleSpan(span));
+ assertEquals(expectedStart, spanned.getSpanStart(span));
+ assertEquals(expectedEnd, spanned.getSpanEnd(span));
+ assertEquals(expectedSpanFlags, spanned.getSpanFlags(span));
+ }
+
+ private static void assertSpanEquals(final Object expectedSpan, final Spanned spanned,
+ final int index) {
+ final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class);
+ assertEquals(expectedSpan, spans[index]);
+ }
+
+ private static void assertSpanCount(final int expectedCount, final Spanned spanned) {
+ final Object[] spans = spanned.getSpans(0, spanned.length(), Object.class);
+ assertEquals(expectedCount, spans.length);
+ }
+
+ public void testUpdateLocaleSpan() {
+ if (!LocaleSpanCompatUtils.isLocaleSpanAvailable()) {
+ return;
+ }
+
+ // Test if the simplest case works.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if only LocaleSpans are updated.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ final StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
+ text.setSpan(styleSpan, 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE);
+ assertSpanCount(2, text);
+ assertSpanEquals(styleSpan, text, 0);
+ assertLocaleSpan(text, 1, 1, 5, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if two jointed spans are merged into one span.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 3,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 5, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if two overlapped spans are merged into one span.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 4,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 5, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if three overlapped spans are merged into one span.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 4,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 5, 6,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 2, 8, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 8, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if disjoint spans remain disjoint.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 3,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 5, 6,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 8, 9, Locale.JAPANESE);
+ assertSpanCount(3, text);
+ assertLocaleSpan(text, 0, 1, 3, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 1, 5, 6, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 2, 8, 9, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if existing span flags are preserved during merge.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 5,
+ Spannable.SPAN_INCLUSIVE_INCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 4, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 5, Locale.JAPANESE,
+ Spannable.SPAN_INCLUSIVE_INCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ }
+
+ // Test if existing span flags are preserved even when partially overlapped (leading edge).
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 1, 5,
+ Spannable.SPAN_INCLUSIVE_INCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 3, 7, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE,
+ Spannable.SPAN_INCLUSIVE_EXCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ }
+
+ // Test if existing span flags are preserved even when partially overlapped (trailing edge).
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.JAPANESE), 3, 7,
+ Spannable.SPAN_INCLUSIVE_INCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 5, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE,
+ Spannable.SPAN_EXCLUSIVE_INCLUSIVE | Spannable.SPAN_INTERMEDIATE);
+ }
+
+ // Test if existing locale span will be removed when the locale doesn't match.
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 5,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 1, 7, Locale.JAPANESE);
+ assertSpanCount(1, text);
+ assertLocaleSpan(text, 0, 1, 7, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if existing locale span will be removed when the locale doesn't match. (case 2)
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 5, 6, Locale.JAPANESE);
+ assertSpanCount(3, text);
+ assertLocaleSpan(text, 0, 3, 5, Locale.ENGLISH, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 1, 6, 7, Locale.ENGLISH, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 2, 5, 6, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if existing locale span will be removed when the locale doesn't match. (case 3)
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 2, 5, Locale.JAPANESE);
+ assertSpanCount(2, text);
+ assertLocaleSpan(text, 0, 5, 7, Locale.ENGLISH, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 1, 2, 5, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Test if existing locale span will be removed when the locale doesn't match. (case 3)
+ {
+ final SpannableString text = new SpannableString("0123456789");
+ text.setSpan(LocaleSpanCompatUtils.newLocaleSpan(Locale.ENGLISH), 3, 7,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ LocaleSpanCompatUtils.updateLocaleSpan(text, 5, 8, Locale.JAPANESE);
+ assertSpanCount(2, text);
+ assertLocaleSpan(text, 0, 3, 5, Locale.ENGLISH, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ assertLocaleSpan(text, 1, 5, 8, Locale.JAPANESE, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ }
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Sinhala.java b/tests/src/com/android/inputmethod/keyboard/layout/Sinhala.java
index bfd94d5fc..5c0ffb4f9 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Sinhala.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Sinhala.java
@@ -129,25 +129,17 @@ public final class Sinhala extends LayoutBase {
private static final ExpectedKey[][] ALPHABET_SHIFTED_COMMON = new ExpectedKeyboardBuilder()
.setKeysOfRow(1,
// U+0DD6: "ූ" SINHALA VOWEL SIGN DIGA PAA-PILLA
- key("\u0DD6", moreKey("1")),
// U+0D8B: "උ" SINHALA LETTER UYANNA
- key("\u0D8B", moreKey("2")),
// U+0DD1: "ෑ" SINHALA VOWEL SIGN DIGA AEDA-PILLA
- key("\u0DD1", moreKey("3")),
// U+0D8D: "ඍ" SINHALA LETTER IRUYANNA
- key("\u0D8D", moreKey("4")),
// U+0D94: "ඔ" SINHALA LETTER OYANNA
- key("\u0D94", moreKey("5")),
// U+0DC1: "ශ" SINHALA LETTER TAALUJA SAYANNA
- key("\u0DC1", moreKey("6")),
// U+0DB9: "ඹ" SINHALA LETTER AMBA BAYANNA
- key("\u0DB9", moreKey("7")),
// U+0DC2: "ෂ" SINHALA LETTER MUURDHAJA SAYANNA
- key("\u0DC2", moreKey("8")),
// U+0DB0: "ධ" SINHALA LETTER MAHAAPRAANA DAYANNA
- key("\u0DB0", moreKey("9")),
// U+0DA1: "ඡ" SINHALA LETTER MAHAAPRAANA CAYANNA
- key("\u0DA1", moreKey("0")),
+ "\u0DD6", "\u0D8B", "\u0DD1", "\u0D8D", "\u0D94", "\u0DC1", "\u0DB9", "\u0DC2",
+ "\u0DB0", "\u0DA1",
// U+0DA5: "ඥ" SINHALA LETTER TAALUJA SANYOOGA NAAKSIKYAYA
// U+0DF4: "෴" SINHALA PUNCTUATION KUNDDALIYA
key("\u0DA5", moreKey("\u0DF4")))
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
index 2d92e691b..199922491 100644
--- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
+++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
@@ -32,6 +32,7 @@ import android.view.inputmethod.InputConnectionWrapper;
import com.android.inputmethod.latin.PrevWordsInfo.WordInfo;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+import com.android.inputmethod.latin.utils.PrevWordsInfoUtils;
import com.android.inputmethod.latin.utils.RunInLocale;
import com.android.inputmethod.latin.utils.ScriptUtils;
import com.android.inputmethod.latin.utils.StringUtils;
@@ -157,24 +158,24 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
*/
public void testGetPreviousWord() {
// If one of the following cases breaks, the bigram suggestions won't work.
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc. def", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
- assertFalse(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertFalse(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mIsBeginningOfSentence);
- assertTrue(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertTrue(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mIsBeginningOfSentence);
// For n-gram
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[1].mWord, "abc");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 2).mPrevWordsInfo[1],
WordInfo.BEGINNING_OF_SENTENCE);
@@ -185,32 +186,32 @@ 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.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def ", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def.", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "abc");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def .", mSpacingAndPunctuations, 2).mPrevWordsInfo[0].mWord, "def");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc ", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def ", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "def");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc 'def", mSpacingAndPunctuations, 1).mPrevWordsInfo[0].mWord, "'def");
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def.", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc def .", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc, def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc? def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc! def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
- assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ assertEquals(PrevWordsInfoUtils.getPrevWordsInfoFromNthPreviousWord(
"abc 'def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
}