Migrate to Android Testing Support Lib (part 5/N)

This CL converts 19 test classes under com.android.inputmethod.latin
to Android Testing Support Library.

Bug: 110805255
Test: verified as follows. No new test failures.
        tapas adb LatinIME LatinIMETests arm64 userdebug && \
        DISABLE_PROGUARD=true make -j LatinIME && \
        adb install -r $OUT/system/app/LatinIME/LatinIME.apk && \
        atest LatinIMETests:com.android.inputmethod.latin
Change-Id: I878fcae0126f57c43a644af341e5a0a8ac8f5cc9
main
Yohei Yukawa 2018-07-06 10:10:54 -07:00
parent a497886dda
commit d3b93cc950
19 changed files with 429 additions and 126 deletions

View File

@ -16,8 +16,14 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.LargeTest; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
@ -38,27 +44,31 @@ import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@LargeTest @LargeTest
public class BinaryDictionaryTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class BinaryDictionaryTests {
private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
private static final String TEST_LOCALE = "test"; private static final String TEST_LOCALE = "test";
private static final String DICTIONARY_ID = "TestBinaryDictionary"; private static final String DICTIONARY_ID = "TestBinaryDictionary";
private HashSet<File> mDictFilesToBeDeleted = new HashSet<>(); private HashSet<File> mDictFilesToBeDeleted = new HashSet<>();
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
mDictFilesToBeDeleted.clear(); mDictFilesToBeDeleted.clear();
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
for (final File dictFile : mDictFilesToBeDeleted) { for (final File dictFile : mDictFilesToBeDeleted) {
dictFile.delete(); dictFile.delete();
} }
mDictFilesToBeDeleted.clear(); mDictFilesToBeDeleted.clear();
super.tearDown();
} }
private File createEmptyDictionaryAndGetFile(final int formatVersion) { private File createEmptyDictionaryAndGetFile(final int formatVersion) {
@ -82,7 +92,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
private File createEmptyVer4DictionaryAndGetFile(final int formatVersion, private File createEmptyVer4DictionaryAndGetFile(final int formatVersion,
final HashMap<String, String> attributeMap) throws IOException { final HashMap<String, String> attributeMap) throws IOException {
final File file = File.createTempFile(DICTIONARY_ID, TEST_DICT_FILE_EXTENSION, final File file = File.createTempFile(DICTIONARY_ID, TEST_DICT_FILE_EXTENSION,
getContext().getCacheDir()); InstrumentationRegistry.getTargetContext().getCacheDir());
file.delete(); file.delete();
file.mkdir(); file.mkdir();
if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion, if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion,
@ -106,6 +116,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
} }
@Test
public void testIsValidDictionary() { public void testIsValidDictionary() {
final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403);
BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile);
@ -121,6 +132,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.close(); binaryDictionary.close();
} }
@Test
public void testConstructingDictionaryOnMemory() { public void testConstructingDictionaryOnMemory() {
final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403);
FileUtils.deleteRecursively(dictFile); FileUtils.deleteRecursively(dictFile);
@ -142,6 +154,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.close(); binaryDictionary.close();
} }
@Test
public void testAddTooLongWord() { public void testAddTooLongWord() {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403);
final StringBuffer stringBuilder = new StringBuffer(); final StringBuffer stringBuilder = new StringBuffer();
@ -209,6 +222,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2); new NgramContext(new WordInfo(word1), new WordInfo(word0)), word2);
} }
@Test
public void testAddUnigramWord() { public void testAddUnigramWord() {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403);
final int probability = 100; final int probability = 100;
@ -236,6 +250,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
assertEquals(updatedProbability, binaryDictionary.getFrequency("aaa")); assertEquals(updatedProbability, binaryDictionary.getFrequency("aaa"));
} }
@Test
public void testRandomlyAddUnigramWord() { public void testRandomlyAddUnigramWord() {
final int wordCount = 1000; final int wordCount = 1000;
final int codePointSetSize = 50; final int codePointSetSize = 50;
@ -258,6 +273,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testAddBigramWords() { public void testAddBigramWords() {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403);
@ -311,6 +327,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
getBigramProbability(binaryDictionary, "abcde", "fghij")); getBigramProbability(binaryDictionary, "abcde", "fghij"));
} }
@Test
public void testRandomlyAddBigramWords() { public void testRandomlyAddBigramWords() {
final int wordCount = 100; final int wordCount = 100;
final int bigramCount = 1000; final int bigramCount = 1000;
@ -357,6 +374,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testAddTrigramWords() { public void testAddTrigramWords() {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403);
final int unigramProbability = 100; final int unigramProbability = 100;
@ -383,6 +401,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa")); getTrigramProbability(binaryDictionary, "bcc", "abb", "aaa"));
} }
@Test
public void testFlushDictionary() { public void testFlushDictionary() {
final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403);
BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile);
@ -417,6 +436,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.close(); binaryDictionary.close();
} }
@Test
public void testFlushWithGCDictionary() { public void testFlushWithGCDictionary() {
final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403); final File dictFile = createEmptyDictionaryAndGetFile(FormatSpec.VERSION403);
BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile); BinaryDictionary binaryDictionary = getBinaryDictionary(dictFile);
@ -447,6 +467,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.close(); binaryDictionary.close();
} }
@Test
public void testAddBigramWordsAndFlashWithGC() { public void testAddBigramWordsAndFlashWithGC() {
final int wordCount = 100; final int wordCount = 100;
final int bigramCount = 1000; final int bigramCount = 1000;
@ -499,6 +520,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testRandomOperationsAndFlashWithGC() { public void testRandomOperationsAndFlashWithGC() {
final int maxUnigramCount = 5000; final int maxUnigramCount = 5000;
final int maxBigramCount = 10000; final int maxBigramCount = 10000;
@ -593,6 +615,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testAddManyUnigramsAndFlushWithGC() { public void testAddManyUnigramsAndFlushWithGC() {
final int flashWithGCIterationCount = 3; final int flashWithGCIterationCount = 3;
final int codePointSetSize = 50; final int codePointSetSize = 50;
@ -628,6 +651,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testUnigramAndBigramCount() { public void testUnigramAndBigramCount() {
final int maxUnigramCount = 5000; final int maxUnigramCount = 5000;
final int maxBigramCount = 10000; final int maxBigramCount = 10000;
@ -684,6 +708,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testGetWordProperties() { public void testGetWordProperties() {
final long seed = System.currentTimeMillis(); final long seed = System.currentTimeMillis();
final Random random = new Random(seed); final Random random = new Random(seed);
@ -769,6 +794,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testIterateAllWords() { public void testIterateAllWords() {
final long seed = System.currentTimeMillis(); final long seed = System.currentTimeMillis();
final Random random = new Random(seed); final Random random = new Random(seed);
@ -852,6 +878,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
assertTrue(bigramSet.isEmpty()); assertTrue(bigramSet.isEmpty());
} }
@Test
public void testPossiblyOffensiveAttributeMaintained() { public void testPossiblyOffensiveAttributeMaintained() {
final BinaryDictionary binaryDictionary = final BinaryDictionary binaryDictionary =
getEmptyBinaryDictionary(FormatSpec.VERSION403); getEmptyBinaryDictionary(FormatSpec.VERSION403);
@ -860,6 +887,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
assertEquals(true, wordProperty.mIsPossiblyOffensive); assertEquals(true, wordProperty.mIsPossiblyOffensive);
} }
@Test
public void testBeginningOfSentence() { public void testBeginningOfSentence() {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(FormatSpec.VERSION403);
final int dummyProbability = 0; final int dummyProbability = 0;

View File

@ -16,6 +16,10 @@
package com.android.inputmethod.latin; 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.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
@ -23,34 +27,38 @@ import android.database.MatrixCursor;
import android.net.Uri; import android.net.Uri;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Contacts;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.test.RenamingDelegatingContext; import android.test.RenamingDelegatingContext;
import android.test.mock.MockContentProvider; import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver; import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.ContactsDictionaryConstants; import com.android.inputmethod.latin.ContactsDictionaryConstants;
import com.android.inputmethod.latin.ContactsManager; import com.android.inputmethod.latin.ContactsManager;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Tests for {@link ContactsManager} * Tests for {@link ContactsManager}
*/ */
@SmallTest @SmallTest
public class ContactsManagerTest extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class ContactsManagerTest {
private ContactsManager mManager; private ContactsManager mManager;
private FakeContactsContentProvider mFakeContactsContentProvider; private FakeContactsContentProvider mFakeContactsContentProvider;
private MatrixCursor mMatrixCursor; private MatrixCursor mMatrixCursor;
private final static float EPSILON = 0.00001f;
@Before @Before
@Override
public void setUp() throws Exception { public void setUp() throws Exception {
// Fake content provider // Fake content provider
mFakeContactsContentProvider = new FakeContactsContentProvider(); mFakeContactsContentProvider = new FakeContactsContentProvider();
@ -59,7 +67,8 @@ public class ContactsManagerTest extends AndroidTestCase {
final MockContentResolver contentResolver = new MockContentResolver(); final MockContentResolver contentResolver = new MockContentResolver();
contentResolver.addProvider(ContactsContract.AUTHORITY, mFakeContactsContentProvider); contentResolver.addProvider(ContactsContract.AUTHORITY, mFakeContactsContentProvider);
// Add the fake content resolver to a fake context. // Add the fake content resolver to a fake context.
final ContextWithMockContentResolver context = new ContextWithMockContentResolver(mContext); final ContextWithMockContentResolver context =
new ContextWithMockContentResolver(InstrumentationRegistry.getTargetContext());
context.setContentResolver(contentResolver); context.setContentResolver(contentResolver);
mManager = new ContactsManager(context); mManager = new ContactsManager(context);
@ -113,9 +122,10 @@ public class ContactsManagerTest extends AndroidTestCase {
cursor.moveToFirst(); cursor.moveToFirst();
ContactsManager.RankedContact contact = new ContactsManager.RankedContact(cursor); ContactsManager.RankedContact contact = new ContactsManager.RankedContact(cursor);
contact.computeAffinity(1, month_ago); contact.computeAffinity(1, month_ago);
assertEquals(contact.getAffinity(), 1.0f); assertEquals(contact.getAffinity(), 1.0f, EPSILON);
contact.computeAffinity(2, now); contact.computeAffinity(2, now);
assertEquals(contact.getAffinity(), (2.0f/3.0f + (float)Math.pow(0.5, 3) + 1.0f) / 3); assertEquals(contact.getAffinity(), (2.0f/3.0f + (float)Math.pow(0.5, 3) + 1.0f) / 3,
EPSILON);
} }
@Test @Test

View File

@ -16,16 +16,26 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Locale; import java.util.Locale;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.LargeTest; import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@LargeTest @LargeTest
public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class DictionaryFacilitatorLruCacheTests {
@Test
public void testGetFacilitator() { public void testGetFacilitator() {
final DictionaryFacilitatorLruCache cache = final DictionaryFacilitatorLruCache cache =
new DictionaryFacilitatorLruCache(getContext(), ""); new DictionaryFacilitatorLruCache(InstrumentationRegistry.getTargetContext(), "");
final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US); final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US);
assertNotNull(dictionaryFacilitatorEnUs); assertNotNull(dictionaryFacilitatorEnUs);

View File

@ -16,15 +16,26 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.NgramContextUtils; import com.android.inputmethod.latin.utils.NgramContextUtils;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class NgramContextTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class NgramContextTests {
@Test
public void testConstruct() { public void testConstruct() {
assertEquals(new NgramContext(new WordInfo("a")), new NgramContext(new WordInfo("a"))); assertEquals(new NgramContext(new WordInfo("a")), new NgramContext(new WordInfo("a")));
assertEquals(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO), assertEquals(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO),
@ -35,6 +46,7 @@ public class NgramContextTests extends AndroidTestCase {
new NgramContext(WordInfo.EMPTY_WORD_INFO)); new NgramContext(WordInfo.EMPTY_WORD_INFO));
} }
@Test
public void testIsBeginningOfSentenceContext() { public void testIsBeginningOfSentenceContext() {
assertFalse(new NgramContext().isBeginningOfSentenceContext()); assertFalse(new NgramContext().isBeginningOfSentenceContext());
assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO) assertTrue(new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO)
@ -52,6 +64,7 @@ public class NgramContextTests extends AndroidTestCase {
.isBeginningOfSentenceContext()); .isBeginningOfSentenceContext());
} }
@Test
public void testGetNextNgramContext() { public void testGetNextNgramContext() {
final NgramContext ngramContext_a = new NgramContext(new WordInfo("a")); final NgramContext ngramContext_a = new NgramContext(new WordInfo("a"));
final NgramContext ngramContext_b_a = final NgramContext ngramContext_b_a =
@ -67,6 +80,7 @@ public class NgramContextTests extends AndroidTestCase {
assertEquals("c", ngramContext_c_bos.getNthPrevWord(1)); assertEquals("c", ngramContext_c_bos.getNthPrevWord(1));
} }
@Test
public void testExtractPrevWordsContextTest() { public void testExtractPrevWordsContextTest() {
final NgramContext ngramContext_bos = final NgramContext ngramContext_bos =
new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO);
@ -92,6 +106,7 @@ public class NgramContextTests extends AndroidTestCase {
assertEquals("a", ngramContext_a_empty.extractPrevWordsContext()); assertEquals("a", ngramContext_a_empty.extractPrevWordsContext());
} }
@Test
public void testExtractPrevWordsContextArray() { public void testExtractPrevWordsContextArray() {
final NgramContext ngramContext_bos = final NgramContext ngramContext_bos =
new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO); new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO);
@ -123,9 +138,10 @@ public class NgramContextTests extends AndroidTestCase {
assertEquals("a", ngramContext_a_empty.extractPrevWordsContextArray()[0]); assertEquals("a", ngramContext_a_empty.extractPrevWordsContextArray()[0]);
} }
@Test
public void testGetNgramContextFromNthPreviousWord() { public void testGetNgramContextFromNthPreviousWord() {
SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations( SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations(
mContext.getResources()); InstrumentationRegistry.getTargetContext().getResources());
assertEquals("<S>", NgramContextUtils.getNgramContextFromNthPreviousWord("", assertEquals("<S>", NgramContextUtils.getNgramContextFromNthPreviousWord("",
spacingAndPunctuations, 1).extractPrevWordsContext()); spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ", assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ",

View File

@ -16,12 +16,16 @@
package com.android.inputmethod.latin; 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.content.res.Resources;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.os.Parcel; import android.os.Parcel;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.test.MoreAsserts; import android.support.test.filters.SmallTest;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.runner.AndroidJUnit4;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.SuggestionSpan; import android.text.style.SuggestionSpan;
@ -40,23 +44,27 @@ import com.android.inputmethod.latin.utils.TextRange;
import java.util.Locale; import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class RichInputConnectionAndTextRangeTests {
// The following is meant to be a reasonable default for // The following is meant to be a reasonable default for
// the "word_separators" resource. // the "word_separators" resource.
private SpacingAndPunctuations mSpacingAndPunctuations; private SpacingAndPunctuations mSpacingAndPunctuations;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
@Override @Override
protected SpacingAndPunctuations job(final Resources res) { protected SpacingAndPunctuations job(final Resources res) {
return new SpacingAndPunctuations(res); return new SpacingAndPunctuations(res);
} }
}; };
final Resources res = getContext().getResources(); final Resources res = InstrumentationRegistry.getTargetContext().getResources();
mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH); mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH);
} }
@ -156,6 +164,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
/** /**
* Test for getting previous word (for bigram suggestions) * Test for getting previous word (for bigram suggestions)
*/ */
@Test
public void testGetPreviousWord() { public void testGetPreviousWord() {
// If one of the following cases breaks, the bigram suggestions won't work. // If one of the following cases breaks, the bigram suggestions won't work.
assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord( assertEquals(NgramContextUtils.getNgramContextFromNthPreviousWord(
@ -218,6 +227,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
"abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO); "abc 'def", mSpacingAndPunctuations, 2), NgramContext.EMPTY_PREV_WORDS_INFO);
} }
@Test
public void testGetWordRangeAtCursor() { public void testGetWordRangeAtCursor() {
/** /**
* Test logic in getting the word range at the cursor. * Test logic in getting the word range at the cursor.
@ -282,6 +292,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
/** /**
* Test logic in getting the word range at the cursor. * Test logic in getting the word range at the cursor.
*/ */
@Test
public void testGetSuggestionSpansAtWord() { public void testGetSuggestionSpansAtWord() {
helpTestGetSuggestionSpansAtWord(10); helpTestGetSuggestionSpansAtWord(10);
helpTestGetSuggestionSpansAtWord(12); helpTestGetSuggestionSpansAtWord(12);
@ -309,7 +320,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
suggestions = r.getSuggestionSpansAtWord(); suggestions = r.getSuggestionSpansAtWord();
assertEquals(suggestions.length, 1); 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. // Test the case with 2 suggestion spans in the same place.
text = new SpannableString("This is a string for test"); text = new SpannableString("This is a string for test");
@ -321,8 +332,8 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
suggestions = r.getSuggestionSpansAtWord(); suggestions = r.getSuggestionSpansAtWord();
assertEquals(suggestions.length, 2); assertEquals(suggestions.length, 2);
MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1); assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
MoreAsserts.assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2); assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2);
// Test a case with overlapping spans, 2nd extending past the start of the word // Test a case with overlapping spans, 2nd extending past the start of the word
text = new SpannableString("This is a string for test"); text = new SpannableString("This is a string for test");
@ -334,7 +345,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
suggestions = r.getSuggestionSpansAtWord(); suggestions = r.getSuggestionSpansAtWord();
assertEquals(suggestions.length, 1); 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 // Test a case with overlapping spans, 2nd extending past the end of the word
text = new SpannableString("This is a string for test"); text = new SpannableString("This is a string for test");
@ -346,7 +357,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
suggestions = r.getSuggestionSpansAtWord(); suggestions = r.getSuggestionSpansAtWord();
assertEquals(suggestions.length, 1); 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 // Test a case with overlapping spans, 2nd extending past both ends of the word
text = new SpannableString("This is a string for test"); text = new SpannableString("This is a string for test");
@ -358,7 +369,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN); r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
suggestions = r.getSuggestionSpansAtWord(); suggestions = r.getSuggestionSpansAtWord();
assertEquals(suggestions.length, 1); 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 // Test a case with overlapping spans, none right on the word
text = new SpannableString("This is a string for test"); text = new SpannableString("This is a string for test");
@ -372,6 +383,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
assertEquals(suggestions.length, 0); assertEquals(suggestions.length, 0);
} }
@Test
public void testCursorTouchingWord() { public void testCursorTouchingWord() {
final MockInputMethodService ims = new MockInputMethodService(); final MockInputMethodService ims = new MockInputMethodService();
final RichInputConnection ic = new RichInputConnection(ims); final RichInputConnection ic = new RichInputConnection(ims);

View File

@ -16,12 +16,18 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
@ -33,8 +39,14 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class RichInputMethodSubtypeTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class RichInputMethodSubtypeTests {
// All input method subtypes of LatinIME. // All input method subtypes of LatinIME.
private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>(); private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>();
@ -67,10 +79,9 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase {
RichInputMethodSubtype HI_LATN_DVORAK; RichInputMethodSubtype HI_LATN_DVORAK;
RichInputMethodSubtype SR_LATN_QWERTY; RichInputMethodSubtype SR_LATN_QWERTY;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); final Context context = InstrumentationRegistry.getTargetContext();
final Context context = getContext();
mRes = context.getResources(); mRes = context.getResources();
RichInputMethodManager.init(context); RichInputMethodManager.init(context);
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
@ -152,13 +163,13 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase {
} }
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
// Restore additional subtypes. // Restore additional subtypes.
mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes); mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
super.tearDown();
} }
@Test
public void testAllFullDisplayNameForSpacebar() { public void testAllFullDisplayNameForSpacebar() {
for (final RichInputMethodSubtype subtype : mSubtypesList) { for (final RichInputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils final String subtypeName = SubtypeLocaleUtils
@ -174,6 +185,7 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase {
} }
} }
@Test
public void testAllMiddleDisplayNameForSpacebar() { public void testAllMiddleDisplayNameForSpacebar() {
for (final RichInputMethodSubtype subtype : mSubtypesList) { for (final RichInputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils final String subtypeName = SubtypeLocaleUtils
@ -293,22 +305,27 @@ public class RichInputMethodSubtypeTests extends AndroidTestCase {
} }
}; };
@Test
public void testPredefinedSubtypesForSpacebarInEnglish() { public void testPredefinedSubtypesForSpacebarInEnglish() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
} }
@Test
public void testAdditionalSubtypeForSpacebarInEnglish() { public void testAdditionalSubtypeForSpacebarInEnglish() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH); testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
} }
@Test
public void testPredefinedSubtypesForSpacebarInFrench() { public void testPredefinedSubtypesForSpacebarInFrench() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
} }
@Test
public void testAdditionalSubtypeForSpacebarInFrench() { public void testAdditionalSubtypeForSpacebarInFrench() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH); testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
} }
@Test
public void testRichInputMethodSubtypeForNullInputMethodSubtype() { public void testRichInputMethodSubtypeForNullInputMethodSubtype() {
RichInputMethodSubtype subtype = RichInputMethodSubtype.getRichInputMethodSubtype(null); RichInputMethodSubtype subtype = RichInputMethodSubtype.getRichInputMethodSubtype(null);
assertNotNull(subtype); assertNotNull(subtype);

View File

@ -16,16 +16,24 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
@SmallTest @SmallTest
public class SuggestedWordsTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class SuggestedWordsTests {
/** /**
* Helper method to create a dummy {@link SuggestedWordInfo} with specifying * Helper method to create a dummy {@link SuggestedWordInfo} with specifying
@ -80,30 +88,35 @@ public class SuggestedWordsTests extends AndroidTestCase {
return returnedWordInfo; return returnedWordInfo;
} }
@Test
public void testRemoveDupesNoDupes() { public void testRemoveDupesNoDupes() {
final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "c"); final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "c");
assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(-1, SuggestedWordInfo.removeDups("b", infos));
assertEquals(2, infos.size()); assertEquals(2, infos.size());
} }
@Test
public void testRemoveDupesTypedWordNotDupe() { public void testRemoveDupesTypedWordNotDupe() {
final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "a", "c"); final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "a", "c");
assertEquals(-1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(-1, SuggestedWordInfo.removeDups("b", infos));
assertEquals(2, infos.size()); assertEquals(2, infos.size());
} }
@Test
public void testRemoveDupesTypedWordOnlyDupe() { public void testRemoveDupesTypedWordOnlyDupe() {
final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "c"); final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "c");
assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(1, SuggestedWordInfo.removeDups("b", infos));
assertEquals(2, infos.size()); assertEquals(2, infos.size());
} }
@Test
public void testRemoveDupesTypedWordNotOnlyDupe() { public void testRemoveDupesTypedWordNotOnlyDupe() {
final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "b", "c"); final ArrayList<SuggestedWordInfo> infos = createCorrectionWordInfos("a", "b", "b", "c");
assertEquals(1, SuggestedWordInfo.removeDups("b", infos)); assertEquals(1, SuggestedWordInfo.removeDups("b", infos));
assertEquals(2, infos.size()); assertEquals(2, infos.size());
} }
@Test
public void testGetTransformedSuggestedWordInfo() { public void testGetTransformedSuggestedWordInfo() {
SuggestedWordInfo result = transformWordInfo("word", 0); SuggestedWordInfo result = transformWordInfo("word", 0);
assertEquals(result.mWord, "word"); assertEquals(result.mWord, "word");
@ -119,6 +132,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
assertEquals(result.mWord, "didn't''"); assertEquals(result.mWord, "didn't''");
} }
@Test
public void testGetTypedWordInfoOrNull() { public void testGetTypedWordInfoOrNull() {
final String TYPED_WORD = "typed"; final String TYPED_WORD = "typed";
final SuggestedWordInfo TYPED_WORD_INFO = createTypedWordInfo(TYPED_WORD); final SuggestedWordInfo TYPED_WORD_INFO = createTypedWordInfo(TYPED_WORD);

View File

@ -16,18 +16,29 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.CoordinateUtils; import com.android.inputmethod.latin.common.CoordinateUtils;
import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.common.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Unit tests for WordComposer. * Unit tests for WordComposer.
*/ */
@SmallTest @SmallTest
public class WordComposerTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class WordComposerTests {
@Test
public void testMoveCursor() { public void testMoveCursor() {
final WordComposer wc = new WordComposer(); final WordComposer wc = new WordComposer();
// BMP is the Basic Multilingual Plane, as defined by Unicode. This includes // BMP is the Basic Multilingual Plane, as defined by Unicode. This includes

View File

@ -16,40 +16,54 @@
package com.android.inputmethod.latin.accounts; package com.android.inputmethod.latin.accounts;
import static org.junit.Assert.assertEquals;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.settings.LocalSettingsConstants; import com.android.inputmethod.latin.settings.LocalSettingsConstants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Tests for {@link AccountsChangedReceiver}. * Tests for {@link AccountsChangedReceiver}.
*/ */
public class AccountsChangedReceiverTests extends AndroidTestCase { @SmallTest
@RunWith(AndroidJUnit4.class)
public class AccountsChangedReceiverTests {
private static final String ACCOUNT_1 = "account1@example.com"; private static final String ACCOUNT_1 = "account1@example.com";
private static final String ACCOUNT_2 = "account2@example.com"; private static final String ACCOUNT_2 = "account2@example.com";
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
private String mLastKnownAccount = null; private String mLastKnownAccount = null;
@Override private Context getContext() {
protected void setUp() throws Exception { return InstrumentationRegistry.getTargetContext();
super.setUp(); }
@Before
public void setUp() throws Exception {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
// Keep track of the current account so that we restore it when the test finishes. // Keep track of the current account so that we restore it when the test finishes.
mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null);
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown();
// Restore the account that was present before running the test. // Restore the account that was present before running the test.
updateAccountName(mLastKnownAccount); updateAccountName(mLastKnownAccount);
} }
@Test
public void testUnknownIntent() { public void testUnknownIntent() {
updateAccountName(ACCOUNT_1); updateAccountName(ACCOUNT_1);
AccountsChangedReceiver reciever = new AccountsChangedReceiver(); AccountsChangedReceiver reciever = new AccountsChangedReceiver();
@ -58,6 +72,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase {
assertAccountName(ACCOUNT_1); assertAccountName(ACCOUNT_1);
} }
@Test
public void testAccountRemoved() { public void testAccountRemoved() {
updateAccountName(ACCOUNT_1); updateAccountName(ACCOUNT_1);
AccountsChangedReceiver reciever = new AccountsChangedReceiver() { AccountsChangedReceiver reciever = new AccountsChangedReceiver() {
@ -71,6 +86,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase {
assertAccountName(null); assertAccountName(null);
} }
@Test
public void testAccountRemoved_noAccounts() { public void testAccountRemoved_noAccounts() {
updateAccountName(ACCOUNT_2); updateAccountName(ACCOUNT_2);
AccountsChangedReceiver reciever = new AccountsChangedReceiver() { AccountsChangedReceiver reciever = new AccountsChangedReceiver() {
@ -84,6 +100,7 @@ public class AccountsChangedReceiverTests extends AndroidTestCase {
assertAccountName(null); assertAccountName(null);
} }
@Test
public void testAccountNotRemoved() { public void testAccountNotRemoved() {
updateAccountName(ACCOUNT_2); updateAccountName(ACCOUNT_2);
AccountsChangedReceiver reciever = new AccountsChangedReceiver() { AccountsChangedReceiver reciever = new AccountsChangedReceiver() {

View File

@ -16,15 +16,27 @@
package com.android.inputmethod.latin.common; package com.android.inputmethod.latin.common;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays; import java.util.Arrays;
@SmallTest @SmallTest
public class InputPointersTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class InputPointersTests {
private static final int DEFAULT_CAPACITY = 48; private static final int DEFAULT_CAPACITY = 48;
@Test
public void testNewInstance() { public void testNewInstance() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
assertEquals("new instance size", 0, src.getPointerSize()); assertEquals("new instance size", 0, src.getPointerSize());
@ -34,6 +46,7 @@ public class InputPointersTests extends AndroidTestCase {
assertNotNull("new instance times", src.getTimes()); assertNotNull("new instance times", src.getTimes());
} }
@Test
public void testReset() { public void testReset() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int[] xCoordinates = src.getXCoordinates(); final int[] xCoordinates = src.getXCoordinates();
@ -49,6 +62,7 @@ public class InputPointersTests extends AndroidTestCase {
assertNotSame("times after reset", times, src.getTimes()); assertNotSame("times after reset", times, src.getTimes());
} }
@Test
public void testAdd() { public void testAdd() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int limit = src.getXCoordinates().length * 2 + 10; final int limit = src.getXCoordinates().length * 2 + 10;
@ -72,6 +86,7 @@ public class InputPointersTests extends AndroidTestCase {
} }
} }
@Test
public void testAddAt() { public void testAddAt() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int limit = 1000, step = 100; final int limit = 1000, step = 100;
@ -95,6 +110,7 @@ public class InputPointersTests extends AndroidTestCase {
} }
} }
@Test
public void testSet() { public void testSet() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int limit = src.getXCoordinates().length * 2 + 10; final int limit = src.getXCoordinates().length * 2 + 10;
@ -114,6 +130,7 @@ public class InputPointersTests extends AndroidTestCase {
assertSame("times after set", dst.getTimes(), src.getTimes()); assertSame("times after set", dst.getTimes(), src.getTimes());
} }
@Test
public void testCopy() { public void testCopy() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int limit = 100; final int limit = 100;
@ -142,6 +159,7 @@ public class InputPointersTests extends AndroidTestCase {
dst.getTimes(), 0, src.getTimes(), 0, size); dst.getTimes(), 0, src.getTimes(), 0, size);
} }
@Test
public void testAppend() { public void testAppend() {
final int dstLength = 50; final int dstLength = 50;
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
@ -211,6 +229,7 @@ public class InputPointersTests extends AndroidTestCase {
srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength); srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength);
} }
@Test
public void testAppendResizableIntArray() { public void testAppendResizableIntArray() {
final int dstLength = 50; final int dstLength = 50;
final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); final InputPointers dst = new InputPointers(DEFAULT_CAPACITY);
@ -296,6 +315,7 @@ public class InputPointersTests extends AndroidTestCase {
} }
} }
@Test
public void testShift() { public void testShift() {
final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final InputPointers src = new InputPointers(DEFAULT_CAPACITY);
final int limit = 100; final int limit = 100;

View File

@ -16,15 +16,27 @@
package com.android.inputmethod.latin.common; package com.android.inputmethod.latin.common;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class ResizableIntArrayTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class ResizableIntArrayTests {
private static final int DEFAULT_CAPACITY = 48; private static final int DEFAULT_CAPACITY = 48;
@Test
public void testNewInstance() { public void testNewInstance() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int[] array = src.getPrimitiveArray(); final int[] array = src.getPrimitiveArray();
@ -33,6 +45,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
assertEquals("new instance array length", DEFAULT_CAPACITY, array.length); assertEquals("new instance array length", DEFAULT_CAPACITY, array.length);
} }
@Test
public void testAdd() { public void testAdd() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int[] array = src.getPrimitiveArray(); final int[] array = src.getPrimitiveArray();
@ -62,6 +75,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testAddAt() { public void testAddAt() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2; final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2;
@ -76,6 +90,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testGet() { public void testGet() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
try { try {
@ -105,6 +120,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testReset() { public void testReset() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int[] array = src.getPrimitiveArray(); final int[] array = src.getPrimitiveArray();
@ -136,6 +152,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testSetLength() { public void testSetLength() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int[] array = src.getPrimitiveArray(); final int[] array = src.getPrimitiveArray();
@ -172,6 +189,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testSet() { public void testSet() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int limit = DEFAULT_CAPACITY * 2 + 10; final int limit = DEFAULT_CAPACITY * 2 + 10;
@ -186,6 +204,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray()); assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray());
} }
@Test
public void testCopy() { public void testCopy() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
for (int i = 0; i < DEFAULT_CAPACITY; i++) { for (int i = 0; i < DEFAULT_CAPACITY; i++) {
@ -214,6 +233,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength()); dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength());
} }
@Test
public void testAppend() { public void testAppend() {
final int srcLength = DEFAULT_CAPACITY; final int srcLength = DEFAULT_CAPACITY;
final ResizableIntArray src = new ResizableIntArray(srcLength); final ResizableIntArray src = new ResizableIntArray(srcLength);
@ -264,6 +284,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
srcLength); srcLength);
} }
@Test
public void testFill() { public void testFill() {
final int srcLength = DEFAULT_CAPACITY; final int srcLength = DEFAULT_CAPACITY;
final ResizableIntArray src = new ResizableIntArray(srcLength); final ResizableIntArray src = new ResizableIntArray(srcLength);
@ -359,6 +380,7 @@ public class ResizableIntArrayTests extends AndroidTestCase {
} }
} }
@Test
public void testShift() { public void testShift() {
final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
final int limit = DEFAULT_CAPACITY * 10; final int limit = DEFAULT_CAPACITY * 10;

View File

@ -16,13 +16,21 @@
package com.android.inputmethod.latin.common; package com.android.inputmethod.latin.common;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import java.util.Locale; import java.util.Locale;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class StringUtilsTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class StringUtilsTests {
private static final Locale US = Locale.US; private static final Locale US = Locale.US;
private static final Locale GERMAN = Locale.GERMAN; private static final Locale GERMAN = Locale.GERMAN;
private static final Locale TURKEY = new Locale("tr", "TR"); private static final Locale TURKEY = new Locale("tr", "TR");
@ -34,6 +42,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale)); StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale));
} }
@Test
public void test_toTitleCaseOfKeyLabel() { public void test_toTitleCaseOfKeyLabel() {
assert_toTitleCaseOfKeyLabel(US, null, null); assert_toTitleCaseOfKeyLabel(US, null, null);
assert_toTitleCaseOfKeyLabel(US, "", ""); assert_toTitleCaseOfKeyLabel(US, "", "");
@ -116,6 +125,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.toTitleCaseOfKeyCode(lowerCase, locale)); StringUtils.toTitleCaseOfKeyCode(lowerCase, locale));
} }
@Test
public void test_toTitleCaseOfKeyCode() { public void test_toTitleCaseOfKeyCode() {
assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER); assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER);
assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE); assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE);
@ -148,6 +158,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.capitalizeFirstCodePoint(text, locale)); StringUtils.capitalizeFirstCodePoint(text, locale));
} }
@Test
public void test_capitalizeFirstCodePoint() { public void test_capitalizeFirstCodePoint() {
assert_capitalizeFirstCodePoint(US, "", ""); assert_capitalizeFirstCodePoint(US, "", "");
assert_capitalizeFirstCodePoint(US, "a", "A"); assert_capitalizeFirstCodePoint(US, "a", "A");
@ -167,6 +178,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.capitalizeFirstAndDowncaseRest(text, locale)); StringUtils.capitalizeFirstAndDowncaseRest(text, locale));
} }
@Test
public void test_capitalizeFirstAndDowncaseRest() { public void test_capitalizeFirstAndDowncaseRest() {
assert_capitalizeFirstAndDowncaseRest(US, "", ""); assert_capitalizeFirstAndDowncaseRest(US, "", "");
assert_capitalizeFirstAndDowncaseRest(US, "a", "A"); assert_capitalizeFirstAndDowncaseRest(US, "a", "A");
@ -185,6 +197,7 @@ public class StringUtilsTests extends AndroidTestCase {
assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση"); assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση");
} }
@Test
public void testContainsInArray() { public void testContainsInArray() {
assertFalse("empty array", StringUtils.containsInArray("key", new String[0])); assertFalse("empty array", StringUtils.containsInArray("key", new String[0]));
assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] { assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] {
@ -202,6 +215,7 @@ public class StringUtilsTests extends AndroidTestCase {
})); }));
} }
@Test
public void testContainsInCommaSplittableText() { public void testContainsInCommaSplittableText() {
assertFalse("null", StringUtils.containsInCommaSplittableText("key", null)); assertFalse("null", StringUtils.containsInCommaSplittableText("key", null));
assertFalse("empty", StringUtils.containsInCommaSplittableText("key", "")); assertFalse("empty", StringUtils.containsInCommaSplittableText("key", ""));
@ -214,6 +228,7 @@ public class StringUtilsTests extends AndroidTestCase {
assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key")); assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key"));
} }
@Test
public void testRemoveFromCommaSplittableTextIfExists() { public void testRemoveFromCommaSplittableTextIfExists() {
assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null)); assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null));
assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", "")); assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", ""));
@ -239,7 +254,7 @@ public class StringUtilsTests extends AndroidTestCase {
"key", "key1,key,key3,key,key5")); "key", "key1,key,key3,key,key5"));
} }
@Test
public void testCapitalizeFirstCodePoint() { public void testCapitalizeFirstCodePoint() {
assertEquals("SSaa", assertEquals("SSaa",
StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN)); StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN));
@ -259,6 +274,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH)); StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH));
} }
@Test
public void testCapitalizeFirstAndDowncaseRest() { public void testCapitalizeFirstAndDowncaseRest() {
assertEquals("SSaa", assertEquals("SSaa",
StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN)); StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN));
@ -278,6 +294,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH)); StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH));
} }
@Test
public void testGetCapitalizationType() { public void testGetCapitalizationType() {
assertEquals(StringUtils.CAPITALIZE_NONE, assertEquals(StringUtils.CAPITALIZE_NONE,
StringUtils.getCapitalizationType("capitalize")); StringUtils.getCapitalizationType("capitalize"));
@ -301,6 +318,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.getCapitalizationType("")); StringUtils.getCapitalizationType(""));
} }
@Test
public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() { public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() {
assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize")); assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize"));
assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize")); assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize"));
@ -337,6 +355,7 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.toSortedCodePointArray(" \n.!?*()&"); StringUtils.toSortedCodePointArray(" \n.!?*()&");
private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&"); private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&");
@Test
public void testCapitalizeEachWord() { public void testCapitalizeEachWord() {
checkCapitalize("", "", SPACE, Locale.ENGLISH); checkCapitalize("", "", SPACE, Locale.ENGLISH);
checkCapitalize("test", "Test", SPACE, Locale.ENGLISH); checkCapitalize("test", "Test", SPACE, Locale.ENGLISH);
@ -367,6 +386,7 @@ public class StringUtilsTests extends AndroidTestCase {
WORD_SEPARATORS, Locale.ENGLISH); WORD_SEPARATORS, Locale.ENGLISH);
} }
@Test
public void testLooksLikeURL() { public void testLooksLikeURL() {
assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google.")); assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google."));
assertFalse(StringUtils.lastPartLooksLikeURL("word wo")); assertFalse(StringUtils.lastPartLooksLikeURL("word wo"));
@ -389,6 +409,7 @@ public class StringUtilsTests extends AndroidTestCase {
assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def")); assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def"));
} }
@Test
public void testHexStringUtils() { public void testHexStringUtils() {
final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33, final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33,
(byte)0x55, (byte)0x88, (byte)0xEE }; (byte)0x55, (byte)0x88, (byte)0xEE };
@ -401,6 +422,7 @@ public class StringUtilsTests extends AndroidTestCase {
assertTrue(bytesStr.equals(bytesStr2)); assertTrue(bytesStr.equals(bytesStr2));
} }
@Test
public void testToCodePointArray() { public void testToCodePointArray() {
final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx"; final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx";
final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h', final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h',
@ -414,6 +436,7 @@ public class StringUtilsTests extends AndroidTestCase {
} }
} }
@Test
public void testCopyCodePointsAndReturnCodePointCount() { public void testCopyCodePointsAndReturnCodePointCount() {
final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx"; final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx";
final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7, final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7,
@ -465,6 +488,7 @@ public class StringUtilsTests extends AndroidTestCase {
exceptionHappened); exceptionHappened);
} }
@Test
public void testGetTrailingSingleQuotesCount() { public void testGetTrailingSingleQuotesCount() {
assertEquals(0, StringUtils.getTrailingSingleQuotesCount("")); assertEquals(0, StringUtils.getTrailingSingleQuotesCount(""));
assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'")); assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'"));

View File

@ -16,18 +16,28 @@
package com.android.inputmethod.latin.common; package com.android.inputmethod.latin.common;
import android.test.AndroidTestCase; import static org.junit.Assert.assertFalse;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class UnicodeSurrogateTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class UnicodeSurrogateTests {
@Test
public void testIsLowSurrogate() { public void testIsLowSurrogate() {
assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF')); assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF'));
assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D')); assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D'));
assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00')); assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00'));
} }
@Test
public void testIsHighSurrogate() { public void testIsHighSurrogate() {
assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF')); assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF'));
assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25')); assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25'));

View File

@ -16,13 +16,16 @@
package com.android.inputmethod.latin.network; package com.android.inputmethod.latin.network;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.test.AndroidTestCase; import android.support.test.filters.SmallTest;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor; import com.android.inputmethod.latin.network.BlockingHttpClient.ResponseProcessor;
@ -40,19 +43,24 @@ import java.net.HttpURLConnection;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Tests for {@link BlockingHttpClient}. * Tests for {@link BlockingHttpClient}.
*/ */
@SmallTest @SmallTest
public class BlockingHttpClientTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class BlockingHttpClientTests {
@Mock HttpURLConnection mMockHttpConnection; @Mock HttpURLConnection mMockHttpConnection;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
} }
@Test
public void testError_badGateway() throws IOException, AuthException { public void testError_badGateway() throws IOException, AuthException {
when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY); when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_BAD_GATEWAY);
final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection); final BlockingHttpClient client = new BlockingHttpClient(mMockHttpConnection);
@ -67,6 +75,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
} }
} }
@Test
public void testError_clientTimeout() throws Exception { public void testError_clientTimeout() throws Exception {
when(mMockHttpConnection.getResponseCode()).thenReturn( when(mMockHttpConnection.getResponseCode()).thenReturn(
HttpURLConnection.HTTP_CLIENT_TIMEOUT); HttpURLConnection.HTTP_CLIENT_TIMEOUT);
@ -82,6 +91,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
} }
} }
@Test
public void testError_forbiddenWithRequest() throws Exception { public void testError_forbiddenWithRequest() throws Exception {
final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN); when(mMockHttpConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
@ -98,6 +108,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100)); verify(mockOutputStream).write(any(byte[].class), eq(0), eq(100));
} }
@Test
public void testSuccess_emptyRequest() throws Exception { public void testSuccess_emptyRequest() throws Exception {
final Random rand = new Random(); final Random rand = new Random();
byte[] response = new byte[100]; byte[] response = new byte[100];
@ -112,6 +123,7 @@ public class BlockingHttpClientTests extends AndroidTestCase {
assertTrue("ResponseProcessor was not invoked", processor.mInvoked); assertTrue("ResponseProcessor was not invoked", processor.mInvoked);
} }
@Test
public void testSuccess() throws Exception { public void testSuccess() throws Exception {
final OutputStream mockOutputStream = Mockito.mock(OutputStream.class); final OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
final Random rand = new Random(); final Random rand = new Random();

View File

@ -20,25 +20,28 @@ import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MOD
import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_DOWNLOAD_ONLY; import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_DOWNLOAD_ONLY;
import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_UPLOAD_ONLY; import static com.android.inputmethod.latin.network.HttpUrlConnectionBuilder.MODE_UPLOAD_ONLY;
import android.test.AndroidTestCase; import static org.junit.Assert.assertEquals;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Tests for {@link HttpUrlConnectionBuilder}. * Tests for {@link HttpUrlConnectionBuilder}.
*/ */
@SmallTest @SmallTest
public class HttpUrlConnectionBuilderTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class HttpUrlConnectionBuilderTests {
@Override @Test
protected void setUp() throws Exception {
super.setUp();
}
public void testSetUrl_malformed() { public void testSetUrl_malformed() {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
try { try {
@ -49,6 +52,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
} }
} }
@Test
public void testSetConnectTimeout_invalid() { public void testSetConnectTimeout_invalid() {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
try { try {
@ -59,6 +63,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
} }
} }
@Test
public void testSetConnectTimeout() throws IOException { public void testSetConnectTimeout() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("https://www.example.com"); builder.setUrl("https://www.example.com");
@ -67,6 +72,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertEquals(8765, connection.getConnectTimeout()); assertEquals(8765, connection.getConnectTimeout());
} }
@Test
public void testSetReadTimeout_invalid() { public void testSetReadTimeout_invalid() {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
try { try {
@ -77,6 +83,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
} }
} }
@Test
public void testSetReadTimeout() throws IOException { public void testSetReadTimeout() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("https://www.example.com"); builder.setUrl("https://www.example.com");
@ -85,6 +92,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertEquals(8765, connection.getReadTimeout()); assertEquals(8765, connection.getReadTimeout());
} }
@Test
public void testAddHeader() throws IOException { public void testAddHeader() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("http://www.example.com"); builder.setUrl("http://www.example.com");
@ -93,6 +101,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertEquals("some-random-value", connection.getRequestProperty("some-random-key")); assertEquals("some-random-value", connection.getRequestProperty("some-random-key"));
} }
@Test
public void testSetUseCache_notSet() throws IOException { public void testSetUseCache_notSet() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("http://www.example.com"); builder.setUrl("http://www.example.com");
@ -100,6 +109,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertFalse(connection.getUseCaches()); assertFalse(connection.getUseCaches());
} }
@Test
public void testSetUseCache_false() throws IOException { public void testSetUseCache_false() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("http://www.example.com"); builder.setUrl("http://www.example.com");
@ -108,6 +118,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertFalse(connection.getUseCaches()); assertFalse(connection.getUseCaches());
} }
@Test
public void testSetUseCache_true() throws IOException { public void testSetUseCache_true() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("http://www.example.com"); builder.setUrl("http://www.example.com");
@ -116,6 +127,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertTrue(connection.getUseCaches()); assertTrue(connection.getUseCaches());
} }
@Test
public void testSetMode_uploadOnly() throws IOException { public void testSetMode_uploadOnly() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("http://www.example.com"); builder.setUrl("http://www.example.com");
@ -125,6 +137,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertFalse(connection.getDoOutput()); assertFalse(connection.getDoOutput());
} }
@Test
public void testSetMode_downloadOnly() throws IOException { public void testSetMode_downloadOnly() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("https://www.example.com"); builder.setUrl("https://www.example.com");
@ -134,6 +147,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertTrue(connection.getDoOutput()); assertTrue(connection.getDoOutput());
} }
@Test
public void testSetMode_bidirectional() throws IOException { public void testSetMode_bidirectional() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("https://www.example.com"); builder.setUrl("https://www.example.com");
@ -143,6 +157,7 @@ public class HttpUrlConnectionBuilderTests extends AndroidTestCase {
assertTrue(connection.getDoOutput()); assertTrue(connection.getDoOutput());
} }
@Test
public void testSetAuthToken() throws IOException { public void testSetAuthToken() throws IOException {
HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder(); HttpUrlConnectionBuilder builder = new HttpUrlConnectionBuilder();
builder.setUrl("https://www.example.com"); builder.setUrl("https://www.example.com");

View File

@ -16,8 +16,12 @@
package com.android.inputmethod.latin.personalization; package com.android.inputmethod.latin.personalization;
import android.test.AndroidTestCase; import static org.junit.Assert.assertTrue;
import android.test.suitebuilder.annotation.LargeTest;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary;
@ -27,17 +31,27 @@ import java.io.File;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Unit tests for UserHistoryDictionary * Unit tests for UserHistoryDictionary
*/ */
@LargeTest @LargeTest
public class UserHistoryDictionaryTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class UserHistoryDictionaryTests {
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName(); private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000; private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000;
private static final String TEST_ACCOUNT = "account@example.com"; private static final String TEST_ACCOUNT = "account@example.com";
private int mCurrentTime = 0; private int mCurrentTime = 0;
private Context getContext() {
return InstrumentationRegistry.getTargetContext();
}
private static void printAllFiles(final File dir) { private static void printAllFiles(final File dir) {
Log.d(TAG, dir.getAbsolutePath()); Log.d(TAG, dir.getAbsolutePath());
for (final File file : dir.listFiles()) { for (final File file : dir.listFiles()) {
@ -62,20 +76,18 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
assertTrue("Following dictionary file doesn't exist: " + dictFile, dictFile.exists()); assertTrue("Following dictionary file doesn't exist: " + dictFile, dictFile.exists());
} }
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
resetCurrentTimeForTestMode(); resetCurrentTimeForTestMode();
UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( UserHistoryDictionaryTestsHelper.removeAllTestDictFiles(
UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext());
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( UserHistoryDictionaryTestsHelper.removeAllTestDictFiles(
UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, getContext());
stopTestModeInNativeCode(); stopTestModeInNativeCode();
super.tearDown();
} }
private void resetCurrentTimeForTestMode() { private void resetCurrentTimeForTestMode() {
@ -111,7 +123,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
null /* dictFile */, null /* dictFile */,
testAccount /* account */); testAccount /* account */);
final File dictFile = ExpandableBinaryDictionary.getDictFile( final File dictFile = ExpandableBinaryDictionary.getDictFile(
mContext, dictName, null /* dictFile */); getContext(), dictName, null /* dictFile */);
final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(
getContext(), dummyLocale, testAccount); getContext(), dummyLocale, testAccount);
clearHistory(dict); clearHistory(dict);
@ -123,18 +135,22 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
assertDictionaryExists(dict, dictFile); assertDictionaryExists(dict, dictFile);
} }
@Test
public void testRandomWords_NullAccount() { public void testRandomWords_NullAccount() {
doTestRandomWords(null /* testAccount */); doTestRandomWords(null /* testAccount */);
} }
@Test
public void testRandomWords() { public void testRandomWords() {
doTestRandomWords(TEST_ACCOUNT); doTestRandomWords(TEST_ACCOUNT);
} }
@Test
public void testStressTestForSwitchingLanguagesAndAddingWords() { public void testStressTestForSwitchingLanguagesAndAddingWords() {
doTestStressTestForSwitchingLanguagesAndAddingWords(TEST_ACCOUNT); doTestStressTestForSwitchingLanguagesAndAddingWords(TEST_ACCOUNT);
} }
@Test
public void testStressTestForSwitchingLanguagesAndAddingWords_NullAccount() { public void testStressTestForSwitchingLanguagesAndAddingWords_NullAccount() {
doTestStressTestForSwitchingLanguagesAndAddingWords(null /* testAccount */); doTestStressTestForSwitchingLanguagesAndAddingWords(null /* testAccount */);
} }
@ -158,7 +174,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */,
testAccount /* account */); testAccount /* account */);
dictFiles[i] = ExpandableBinaryDictionary.getDictFile( dictFiles[i] = ExpandableBinaryDictionary.getDictFile(
mContext, dictName, null /* dictFile */); getContext(), dictName, null /* dictFile */);
dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(), dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(),
dummyLocale, testAccount); dummyLocale, testAccount);
clearHistory(dicts[i]); clearHistory(dicts[i]);
@ -186,10 +202,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
} }
} }
@Test
public void testAddManyWords() { public void testAddManyWords() {
doTestAddManyWords(TEST_ACCOUNT); doTestAddManyWords(TEST_ACCOUNT);
} }
@Test
public void testAddManyWords_NullAccount() { public void testAddManyWords_NullAccount() {
doTestAddManyWords(null /* testAccount */); doTestAddManyWords(null /* testAccount */);
} }
@ -200,7 +218,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
final String dictName = UserHistoryDictionary.getUserHistoryDictName( final String dictName = UserHistoryDictionary.getUserHistoryDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, testAccount); UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, testAccount);
final File dictFile = ExpandableBinaryDictionary.getDictFile( final File dictFile = ExpandableBinaryDictionary.getDictFile(
mContext, dictName, null /* dictFile */); getContext(), dictName, null /* dictFile */);
final int numberOfWords = 10000; final int numberOfWords = 10000;
final Random random = new Random(123456); final Random random = new Random(123456);
final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(

View File

@ -16,9 +16,16 @@
package com.android.inputmethod.latin.settings; package com.android.inputmethod.latin.settings;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.test.AndroidTestCase; import android.support.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
@ -28,13 +35,22 @@ import junit.framework.AssertionFailedError;
import java.util.Locale; import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class SpacingAndPunctuationsTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class SpacingAndPunctuationsTests {
private static final int ARMENIAN_FULL_STOP = '\u0589'; private static final int ARMENIAN_FULL_STOP = '\u0589';
private static final int ARMENIAN_COMMA = '\u055D'; private static final int ARMENIAN_COMMA = '\u055D';
private int mScreenMetrics; private int mScreenMetrics;
private Context getContext() {
return InstrumentationRegistry.getTargetContext();
}
private boolean isPhone() { private boolean isPhone() {
return Constants.isPhone(mScreenMetrics); return Constants.isPhone(mScreenMetrics);
} }
@ -63,10 +79,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
private SpacingAndPunctuations CAMBODIA_KHMER; private SpacingAndPunctuations CAMBODIA_KHMER;
private SpacingAndPunctuations LAOS_LAO; private SpacingAndPunctuations LAOS_LAO;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
mScreenMetrics = Settings.readScreenMetrics(getContext().getResources()); mScreenMetrics = Settings.readScreenMetrics(getContext().getResources());
// Language only // Language only
@ -140,6 +154,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse("Tilde", sp.isWordSeparator('~')); assertFalse("Tilde", sp.isWordSeparator('~'));
} }
@Test
public void testWordSeparator() { public void testWordSeparator() {
testingStandardWordSeparator(ENGLISH); testingStandardWordSeparator(ENGLISH);
testingStandardWordSeparator(FRENCH); testingStandardWordSeparator(FRENCH);
@ -192,6 +207,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
} }
@Test
public void testWordConnector() { public void testWordConnector() {
testingStandardWordConnector(ENGLISH); testingStandardWordConnector(ENGLISH);
testingStandardWordConnector(FRENCH); testingStandardWordConnector(FRENCH);
@ -245,6 +261,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); assertFalse("Question", sp.isUsuallyPrecededBySpace('?'));
} }
@Test
public void testIsUsuallyPrecededBySpace() { public void testIsUsuallyPrecededBySpace() {
testingStandardPrecededBySpace(ENGLISH); testingStandardPrecededBySpace(ENGLISH);
testingCommonPrecededBySpace(FRENCH); testingCommonPrecededBySpace(FRENCH);
@ -298,6 +315,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~'));
} }
@Test
public void testIsUsuallyFollowedBySpace() { public void testIsUsuallyFollowedBySpace() {
testingStandardFollowedBySpace(ENGLISH); testingStandardFollowedBySpace(ENGLISH);
testingStandardFollowedBySpace(FRENCH); testingStandardFollowedBySpace(FRENCH);
@ -345,7 +363,8 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~'));
} }
public void isSentenceSeparator() { @Test
public void testIsSentenceSeparator() {
testingStandardSentenceSeparator(ENGLISH); testingStandardSentenceSeparator(ENGLISH);
try { try {
testingStandardSentenceSeparator(ARMENIA_ARMENIAN); testingStandardSentenceSeparator(ARMENIA_ARMENIAN);
@ -357,6 +376,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_COMMA)); assertFalse(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_COMMA));
} }
@Test
public void testLanguageHasSpace() { public void testLanguageHasSpace() {
assertTrue(ENGLISH.mCurrentLanguageHasSpaces); assertTrue(ENGLISH.mCurrentLanguageHasSpaces);
assertTrue(FRENCH.mCurrentLanguageHasSpaces); assertTrue(FRENCH.mCurrentLanguageHasSpaces);
@ -369,6 +389,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertTrue(LAO.mCurrentLanguageHasSpaces); assertTrue(LAO.mCurrentLanguageHasSpaces);
} }
@Test
public void testUsesAmericanTypography() { public void testUsesAmericanTypography() {
assertTrue(ENGLISH.mUsesAmericanTypography); assertTrue(ENGLISH.mUsesAmericanTypography);
assertTrue(UNITED_STATES.mUsesAmericanTypography); assertTrue(UNITED_STATES.mUsesAmericanTypography);
@ -379,6 +400,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
assertFalse(SWISS_GERMAN.mUsesAmericanTypography); assertFalse(SWISS_GERMAN.mUsesAmericanTypography);
} }
@Test
public void testUsesGermanRules() { public void testUsesGermanRules() {
assertFalse(ENGLISH.mUsesGermanRules); assertFalse(ENGLISH.mUsesGermanRules);
assertFalse(FRENCH.mUsesGermanRules); assertFalse(FRENCH.mUsesGermanRules);
@ -436,6 +458,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
} }
} }
@Test
public void testPhonePunctuationSuggestions() { public void testPhonePunctuationSuggestions() {
if (!isPhone()) { if (!isPhone()) {
return; return;
@ -454,6 +477,7 @@ public class SpacingAndPunctuationsTests extends AndroidTestCase {
PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW); PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW);
} }
@Test
public void testTabletPunctuationSuggestions() { public void testTabletPunctuationSuggestions() {
if (!isTablet()) { if (!isTablet()) {
return; return;

View File

@ -16,13 +16,22 @@
package com.android.inputmethod.latin.suggestions; package com.android.inputmethod.latin.suggestions;
import android.test.AndroidTestCase; import static junit.framework.TestCase.assertEquals;
import android.test.suitebuilder.annotation.SmallTest;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest @SmallTest
public class SuggestionStripLayoutHelperTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class SuggestionStripLayoutHelperTests {
private static void confirmShowTypedWord(final String message, final int inputType) { private static void confirmShowTypedWord(final String message, final int inputType) {
assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord( assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
inputType, inputType,
@ -42,6 +51,7 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
true /* shouldShowUiToAcceptTypedWord */)); true /* shouldShowUiToAcceptTypedWord */));
} }
@Test
public void testShouldShowTypedWord() { public void testShouldShowTypedWord() {
confirmShowTypedWord("no input style", confirmShowTypedWord("no input style",
SuggestedWords.INPUT_STYLE_NONE); SuggestedWords.INPUT_STYLE_NONE);
@ -51,7 +61,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
SuggestedWords.INPUT_STYLE_RECORRECTION); SuggestedWords.INPUT_STYLE_RECORRECTION);
} }
public void testshouldOmitTypedWordWhileTyping() { @Test
public void testShouldOmitTypedWordWhileTyping() {
assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord( assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
SuggestedWords.INPUT_STYLE_TYPING, SuggestedWords.INPUT_STYLE_TYPING,
false /* gestureFloatingPreviewTextEnabled */, false /* gestureFloatingPreviewTextEnabled */,
@ -70,7 +81,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
true /* shouldShowUiToAcceptTypedWord */)); true /* shouldShowUiToAcceptTypedWord */));
} }
public void testshouldOmitTypedWordWhileGesturing() { @Test
public void testShouldOmitTypedWordWhileGesturing() {
assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord( assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
SuggestedWords.INPUT_STYLE_UPDATE_BATCH, SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
false /* gestureFloatingPreviewTextEnabled */, false /* gestureFloatingPreviewTextEnabled */,
@ -89,7 +101,8 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
true /* shouldShowUiToAcceptTypedWord */)); true /* shouldShowUiToAcceptTypedWord */));
} }
public void testshouldOmitTypedWordWhenGestured() { @Test
public void testShouldOmitTypedWordWhenGestured() {
assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord( assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
SuggestedWords.INPUT_STYLE_TAIL_BATCH, SuggestedWords.INPUT_STYLE_TAIL_BATCH,
false /* gestureFloatingPreviewTextEnabled */, false /* gestureFloatingPreviewTextEnabled */,
@ -115,6 +128,7 @@ public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
private static final int POSITION_CENTER = 1; private static final int POSITION_CENTER = 1;
private static final int POSITION_RIGHT = 2; private static final int POSITION_RIGHT = 2;
@Test
public void testGetPositionInSuggestionStrip() { public void testGetPositionInSuggestionStrip() {
assertEquals("1st word without auto correction", POSITION_CENTER, assertEquals("1st word without auto correction", POSITION_CENTER,
SuggestionStripLayoutHelper.getPositionInSuggestionStrip( SuggestionStripLayoutHelper.getPositionInSuggestionStrip(

View File

@ -16,18 +16,26 @@
package com.android.inputmethod.latin.touchinputconsumer; package com.android.inputmethod.latin.touchinputconsumer;
import android.test.AndroidTestCase; import static org.junit.Assert.assertFalse;
import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertSame;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Tests for GestureConsumer.NULL_GESTURE_CONSUMER. * Tests for GestureConsumer.NULL_GESTURE_CONSUMER.
*/ */
@SmallTest @SmallTest
public class NullGestureConsumerTests extends AndroidTestCase { @RunWith(AndroidJUnit4.class)
public class NullGestureConsumerTests {
/** /**
* Tests that GestureConsumer.NULL_GESTURE_CONSUMER indicates that it won't consume gesture data * Tests that GestureConsumer.NULL_GESTURE_CONSUMER indicates that it won't consume gesture data
* and that its methods don't raise exceptions even for invalid data. * and that its methods don't raise exceptions even for invalid data.
*/ */
@Test
public void testNullGestureConsumer() { public void testNullGestureConsumer() {
assertFalse(GestureConsumer.NULL_GESTURE_CONSUMER.willConsume()); assertFalse(GestureConsumer.NULL_GESTURE_CONSUMER.willConsume());
GestureConsumer.NULL_GESTURE_CONSUMER.onInit(null, null); GestureConsumer.NULL_GESTURE_CONSUMER.onInit(null, null);
@ -40,6 +48,7 @@ public class NullGestureConsumerTests extends AndroidTestCase {
/** /**
* Tests that newInstance returns NULL_GESTURE_CONSUMER for invalid input. * Tests that newInstance returns NULL_GESTURE_CONSUMER for invalid input.
*/ */
@Test
public void testNewInstanceGivesNullGestureConsumerForInvalidInputs() { public void testNewInstanceGivesNullGestureConsumerForInvalidInputs() {
assertSame(GestureConsumer.NULL_GESTURE_CONSUMER, assertSame(GestureConsumer.NULL_GESTURE_CONSUMER,
GestureConsumer.newInstance(null, null, null, null)); GestureConsumer.newInstance(null, null, null, null));