diff options
author | 2019-07-01 21:00:09 +0000 | |
---|---|---|
committer | 2019-07-01 21:00:09 +0000 | |
commit | 7c33185b41d774123ab565fa8b6d7afac44c1b18 (patch) | |
tree | c1d7ddd47896f4047d307169973e794f2941b029 /tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java | |
parent | e4c638b34727c03a1adfba594d95e3f469c56a34 (diff) | |
parent | 751578eb61b47ba3e85054dd57c1df3e4b94f1fb (diff) | |
download | latinime-7c33185b41d774123ab565fa8b6d7afac44c1b18.tar.gz latinime-7c33185b41d774123ab565fa8b6d7afac44c1b18.tar.xz latinime-7c33185b41d774123ab565fa8b6d7afac44c1b18.zip |
DO NOT MERGE - Merge qt-dev-plus-aosp-without-vendor (5699924) into stage-aosp-master
Bug: 134405016
Change-Id: If86628b9fc81ba5a599ae42e2901066c6bccf173
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java index 128f9f7db..ac38468f9 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java @@ -16,12 +16,13 @@ package com.android.inputmethod.latin; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + 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.TextUtils; import android.text.style.SuggestionSpan; @@ -30,6 +31,10 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnectionWrapper; +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; @@ -38,25 +43,29 @@ import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.TextRange; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.util.Locale; @SmallTest -public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class RichInputConnectionAndTextRangeTests { // The following is meant to be a reasonable default for // the "word_separators" resource. private SpacingAndPunctuations mSpacingAndPunctuations; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { @Override protected SpacingAndPunctuations job(final Resources res) { return new SpacingAndPunctuations(res); } }; - final Resources res = getContext().getResources(); + final Resources res = InstrumentationRegistry.getTargetContext().getResources(); mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH); } @@ -156,6 +165,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { /** * Test for getting previous word (for bigram suggestions) */ + @Test public void testGetPreviousWord() { // If one of the following cases breaks, the bigram suggestions won't work. assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( @@ -218,6 +228,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { "abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); } + @Test public void testGetWordRangeAtCursor() { /** * Test logic in getting the word range at the cursor. @@ -282,6 +293,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { /** * Test logic in getting the word range at the cursor. */ + @Test public void testGetSuggestionSpansAtWord() { helpTestGetSuggestionSpansAtWord(10); helpTestGetSuggestionSpansAtWord(12); @@ -309,7 +321,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test the case with 2 suggestion spans in the same place. text = new SpannableString("This is a string for test"); @@ -321,8 +333,8 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 2); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); - MoreAsserts.assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); // Test a case with overlapping spans, 2nd extending past the start of the word text = new SpannableString("This is a string for test"); @@ -334,7 +346,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, 2nd extending past the end of the word text = new SpannableString("This is a string for test"); @@ -346,7 +358,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, 2nd extending past both ends of the word text = new SpannableString("This is a string for test"); @@ -358,7 +370,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); suggestions = r.getSuggestionSpansAtWord(); assertEquals(suggestions.length, 1); - MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); + assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); // Test a case with overlapping spans, none right on the word text = new SpannableString("This is a string for test"); @@ -372,6 +384,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { assertEquals(suggestions.length, 0); } + @Test public void testCursorTouchingWord() { final MockInputMethodService ims = new MockInputMethodService(); final RichInputConnection ic = new RichInputConnection(ims); |