diff options
author | 2013-09-12 19:11:59 +0900 | |
---|---|---|
committer | 2013-09-24 19:04:51 +0900 | |
commit | 3d68b066626d7e58cbe2853cd186b1ad75b90259 (patch) | |
tree | 532d7a016d69e3b54773f5cb4a89fc7ec0796ad7 /tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java | |
parent | 3ca9c5cbec9ee8eb61b37bb5d11b7e0bc3dc41cc (diff) | |
download | latinime-3d68b066626d7e58cbe2853cd186b1ad75b90259.tar.gz latinime-3d68b066626d7e58cbe2853cd186b1ad75b90259.tar.xz latinime-3d68b066626d7e58cbe2853cd186b1ad75b90259.zip |
Copy only the spans we are interested in.
The PARAGRAPH type of span is dangerous, as concatenating
CharSequences that contain it may crash. We also don't use
other spans than SuggestionSpans, so we don't copy them.
Bug: 10622489
Change-Id: If4e44eca3cdc5bb02cf2e0c8c44ecd4bf27fae57
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java index 4e396a1cf..eb9fb984e 100644 --- a/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java @@ -20,6 +20,11 @@ import com.android.inputmethod.latin.settings.SettingsValues; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; +import android.text.style.SuggestionSpan; +import android.text.style.URLSpan; +import android.text.SpannableStringBuilder; +import android.text.Spannable; +import android.text.Spanned; import java.util.Arrays; import java.util.List; @@ -280,4 +285,34 @@ public class StringUtilsTests extends AndroidTestCase { assertEquals(objs[i], newObjArray.get(i)); } } + + public void testConcatWithSuggestionSpansOnly() { + SpannableStringBuilder s = new SpannableStringBuilder("test string\ntest string\n" + + "test string\ntest string\ntest string\ntest string\ntest string\ntest string\n" + + "test string\ntest string\n"); + final int N = 10; + for (int i = 0; i < N; ++i) { + // Put a PARAGRAPH-flagged span that should not be found in the result. + s.setSpan(new SuggestionSpan(getContext(), + new String[] {"" + i}, Spannable.SPAN_PARAGRAPH), + i * 12, i * 12 + 12, Spannable.SPAN_PARAGRAPH); + // Put a normal suggestion span that should be found in the result. + s.setSpan(new SuggestionSpan(getContext(), new String[] {"" + i}, 0), i, i * 2, 0); + // Put a URL span than should not be found in the result. + s.setSpan(new URLSpan("http://a"), i, i * 2, 0); + } + + final CharSequence a = s.subSequence(0, 15); + final CharSequence b = s.subSequence(15, s.length()); + final Spanned result = + (Spanned)StringUtils.concatWithNonParagraphSuggestionSpansOnly(a, b); + + Object[] spans = result.getSpans(0, result.length(), SuggestionSpan.class); + for (int i = 0; i < spans.length; i++) { + final int flags = result.getSpanFlags(spans[i]); + assertEquals("Should not find a span with PARAGRAPH flag", + flags & Spannable.SPAN_PARAGRAPH, 0); + assertTrue("Should be a SuggestionSpan", spans[i] instanceof SuggestionSpan); + } + } } |