aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java9
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java3
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java4
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java9
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java6
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java73
-rw-r--r--tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java202
-rw-r--r--tests/src/com/android/inputmethod/latin/DistracterFilterTest.java55
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java21
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/LatinImeStressTests.java1
-rw-r--r--tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java24
-rw-r--r--tests/src/com/android/inputmethod/latin/ShiftModeTests.java53
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java14
-rw-r--r--tests/src/com/android/inputmethod/latin/WordComposerTests.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java54
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java3
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java11
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java9
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java5
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java43
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java117
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java16
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java8
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java57
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java105
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java10
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java2
-rw-r--r--tests/src/com/android/inputmethod/research/MotionEventReaderTests.java171
37 files changed, 597 insertions, 512 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
index 75bd60999..1ccb58c0f 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
@@ -32,7 +32,6 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@@ -42,11 +41,9 @@ import java.util.Locale;
@SmallTest
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
// All input method subtypes of LatinIME.
- private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
- private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList =
- CollectionUtils.newArrayList();
- private final ArrayList<InputMethodSubtype> mAdditionalSubtypesList =
- CollectionUtils.newArrayList();
+ private final ArrayList<InputMethodSubtype> mAllSubtypesList = new ArrayList<>();
+ private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList = new ArrayList<>();
+ private final ArrayList<InputMethodSubtype> mAdditionalSubtypesList = new ArrayList<>();
private Context mThemeContext;
private int mScreenMetrics;
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java
index eb906cd9f..72211015f 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java
@@ -23,7 +23,6 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.RichInputMethodManager;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.ArrayList;
@@ -42,7 +41,7 @@ public final class KeyboardTextsSetTests extends AndroidTestCase {
RichInputMethodManager.init(getContext());
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
- final ArrayList<InputMethodSubtype> allSubtypesList = CollectionUtils.newArrayList();
+ final ArrayList<InputMethodSubtype> allSubtypesList = new ArrayList<>();
final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme();
final int subtypeCount = imi.getSubtypeCount();
for (int index = 0; index < subtypeCount; index++) {
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
index 514ad1cf0..29b169d80 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
@@ -22,8 +22,6 @@ import android.content.res.Resources;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
-import com.android.inputmethod.latin.utils.CollectionUtils;
-
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
@@ -53,7 +51,7 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase {
}
private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) {
- final ArrayList<String> names = CollectionUtils.newArrayList();
+ final ArrayList<String> names = new ArrayList<>();
for (final Field field : resourceIdClass.getFields()) {
if (field.getType() == Integer.TYPE) {
names.add(field.getName());
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
index d0fea58b0..56149189f 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
@@ -20,7 +20,6 @@ import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.Constants;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
@@ -34,7 +33,7 @@ import java.util.List;
*/
public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
private static ArrayList<Key> filterOutSpacer(final List<Key> keys) {
- final ArrayList<Key> filteredKeys = CollectionUtils.newArrayList();
+ final ArrayList<Key> filteredKeys = new ArrayList<>();
for (final Key key : keys) {
if (key.isSpacer()) {
continue;
@@ -55,15 +54,15 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder<Key> {
final ArrayList<Key> filteredSortedKeys = filterOutSpacer(sortedKeys);
// Grouping keys into rows.
- final ArrayList<ArrayList<Key>> rows = CollectionUtils.newArrayList();
- ArrayList<Key> elements = CollectionUtils.newArrayList();
+ final ArrayList<ArrayList<Key>> rows = new ArrayList<>();
+ ArrayList<Key> elements = new ArrayList<>();
int lastY = filteredSortedKeys.get(0).getY();
for (final Key key : filteredSortedKeys) {
if (lastY != key.getY()) {
// A new row is starting.
lastY = key.getY();
rows.add(elements);
- elements = CollectionUtils.newArrayList();
+ elements = new ArrayList<>();
}
elements.add(key);
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java
index ad08ba5a6..0e1c71cd1 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard.layout.expected;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
@@ -73,9 +72,8 @@ public class ExpectedKey {
// The additional more keys can be defined independently from other more keys.
// The position of the additional more keys in the long press popup keyboard can be
// controlled by specifying special marker "%" in the usual more keys definitions.
- final ArrayList<ExpectedKey> moreKeysList = CollectionUtils.newArrayList();
- final ArrayList<ExpectedAdditionalMoreKey> additionalMoreKeys =
- CollectionUtils.newArrayList();
+ final ArrayList<ExpectedKey> moreKeysList = new ArrayList<>();
+ final ArrayList<ExpectedAdditionalMoreKey> additionalMoreKeys = new ArrayList<>();
int firstAdditionalMoreKeyIndex = -1;
for (int index = 0; index < moreKeys.length; index++) {
final ExpectedKey moreKey = moreKeys[index];
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
index e06d34d67..9b7de88ea 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.keyboard.layout.expected;
-import com.android.inputmethod.latin.utils.CollectionUtils;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
@@ -116,7 +114,7 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<Expec
// Helper method to create {@link ExpectedKey} array by joining {@link ExpectedKey},
// {@link ExpectedKey} array, and {@link String}.
static ExpectedKey[] joinKeys(final Object ... keys) {
- final ArrayList<ExpectedKey> list = CollectionUtils.newArrayList();
+ final ArrayList<ExpectedKey> list = new ArrayList<>();
for (final Object key : keys) {
if (key instanceof ExpectedKey) {
list.add((ExpectedKey)key);
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
index 2c2fed3c1..28cce834c 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
@@ -63,12 +63,16 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
super.tearDown();
}
+ private static boolean supportsBeginningOfSentence(final int formatVersion) {
+ return formatVersion > FormatSpec.VERSION401;
+ }
+
private void addUnigramWord(final BinaryDictionary binaryDictionary, final String word,
final int probability) {
binaryDictionary.addUnigramEntry(word, probability, "" /* shortcutTarget */,
BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */,
- false /* isNotAWord */, false /* isBlacklisted */,
- mCurrentTime /* timestamp */);
+ false /* isBeginningOfSentence */, false /* isNotAWord */,
+ false /* isBlacklisted */, mCurrentTime /* timestamp */);
}
private void addBigramWords(final BinaryDictionary binaryDictionary, final String word0,
@@ -115,7 +119,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
final File file = File.createTempFile(dictId, TEST_DICT_FILE_EXTENSION,
getContext().getCacheDir());
FileUtils.deleteRecursively(file);
- Map<String, String> attributeMap = new HashMap<String, String>();
+ Map<String, String> attributeMap = new HashMap<>();
attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, dictId);
attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
@@ -329,7 +333,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
setCurrentTimeForTestMode(mCurrentTime);
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final ArrayList<String> words = new ArrayList<String>();
+ final ArrayList<String> words = new ArrayList<>();
for (int i = 0; i < unigramCount; i++) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -452,8 +456,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
setCurrentTimeForTestMode(mCurrentTime);
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final ArrayList<String> words = new ArrayList<String>();
- final ArrayList<Pair<String, String>> bigrams = new ArrayList<Pair<String, String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final ArrayList<Pair<String, String>> bigrams = new ArrayList<>();
for (int i = 0; i < unigramCount; ++i) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -467,7 +471,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
}
final String word0 = words.get(word0Index);
final String word1 = words.get(word1Index);
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
bigrams.add(bigram);
}
@@ -531,7 +535,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
setCurrentTimeForTestMode(mCurrentTime);
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final ArrayList<String> words = new ArrayList<String>();
+ final ArrayList<String> words = new ArrayList<>();
for (int i = 0; i < unigramCount; i++) {
final String word = CodePointUtils.generateWord(random, codePointSet);
words.add(word);
@@ -631,4 +635,57 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
binaryDictionary.close();
dictFile.delete();
}
+
+ public void testBeginningOfSentence() {
+ for (final int formatVersion : DICT_FORMAT_VERSIONS) {
+ if (supportsBeginningOfSentence(formatVersion)) {
+ testBeginningOfSentence(formatVersion);
+ }
+ }
+ }
+
+ private void testBeginningOfSentence(final int formatVersion) {
+ setCurrentTimeForTestMode(mCurrentTime);
+ File dictFile = null;
+ try {
+ dictFile = createEmptyDictionaryAndGetFile("TestBinaryDictionary", formatVersion);
+ } catch (IOException e) {
+ fail("IOException while writing an initial dictionary : " + e);
+ }
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(),
+ 0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
+ Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
+
+ binaryDictionary.addUnigramEntry("", DUMMY_PROBABILITY, "" /* shortcutTarget */,
+ BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */,
+ true /* isBeginningOfSentence */, true /* isNotAWord */, false /* isBlacklisted */,
+ mCurrentTime);
+ final PrevWordsInfo prevWordsInfoStartOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE;
+ addUnigramWord(binaryDictionary, "aaa", DUMMY_PROBABILITY);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY,
+ mCurrentTime);
+ assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa"));
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY,
+ mCurrentTime);
+ addUnigramWord(binaryDictionary, "bbb", DUMMY_PROBABILITY);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", DUMMY_PROBABILITY,
+ mCurrentTime);
+ assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa"));
+ assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb"));
+
+ forcePassingLongTime(binaryDictionary);
+ assertFalse(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa"));
+ assertFalse(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb"));
+
+ addUnigramWord(binaryDictionary, "aaa", DUMMY_PROBABILITY);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", DUMMY_PROBABILITY,
+ mCurrentTime);
+ addUnigramWord(binaryDictionary, "bbb", DUMMY_PROBABILITY);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", DUMMY_PROBABILITY,
+ mCurrentTime);
+ assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "aaa"));
+ assertTrue(binaryDictionary.isValidNgram(prevWordsInfoStartOfSentence, "bbb"));
+ binaryDictionary.close();
+ dictFile.delete();
+ }
}
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
index 2b82e544a..ccede0e39 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
@@ -47,7 +47,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
new int[] { FormatSpec.VERSION4, FormatSpec.VERSION4_DEV };
private static boolean canCheckBigramProbability(final int formatVersion) {
- return formatVersion >= FormatSpec.VERSION4_DEV;
+ return formatVersion > FormatSpec.VERSION401;
+ }
+
+ private static boolean supportsBeginningOfSentence(final int formatVersion) {
+ return formatVersion > FormatSpec.VERSION401;
}
private File createEmptyDictionaryAndGetFile(final String dictId,
@@ -68,7 +72,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
getContext().getCacheDir());
file.delete();
file.mkdir();
- Map<String, String> attributeMap = new HashMap<String, String>();
+ Map<String, String> attributeMap = new HashMap<>();
if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion,
Locale.ENGLISH, attributeMap)) {
return file;
@@ -171,7 +175,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
addUnigramWord(binaryDictionary, invalidLongWord, probability);
// Too long short cut.
binaryDictionary.addUnigramEntry("a", probability, invalidLongWord,
- 10 /* shortcutProbability */, false /* isNotAWord */, false /* isBlacklisted */,
+ 10 /* shortcutProbability */, false /* isBeginningOfSentence */,
+ false /* isNotAWord */, false /* isBlacklisted */,
BinaryDictionary.NOT_A_VALID_TIMESTAMP);
addUnigramWord(binaryDictionary, "abc", probability);
final int updatedProbability = 200;
@@ -192,8 +197,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final int probability) {
binaryDictionary.addUnigramEntry(word, probability, "" /* shortcutTarget */,
BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */,
- false /* isNotAWord */, false /* isBlacklisted */,
- BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
+ false /* isBeginningOfSentence */, false /* isNotAWord */,
+ false /* isBlacklisted */, BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
}
private static void addBigramWords(final BinaryDictionary binaryDictionary, final String word0,
@@ -282,7 +287,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
- final HashMap<String, Integer> probabilityMap = new HashMap<String, Integer>();
+ final HashMap<String, Integer> probabilityMap = new HashMap<>();
// Test a word that isn't contained within the dictionary.
final Random random = new Random(seed);
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
@@ -400,12 +405,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
- final ArrayList<String> words = new ArrayList<String>();
- final ArrayList<Pair<String, String>> bigramWords = new ArrayList<Pair<String,String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
for (int i = 0; i < wordCount; ++i) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -421,7 +425,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
if (TextUtils.equals(word0, word1)) {
continue;
}
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
bigramWords.add(bigram);
final int unigramProbability = unigramProbabilities.get(word1);
final int bigramProbability =
@@ -624,12 +628,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
- final ArrayList<String> words = new ArrayList<String>();
- final ArrayList<Pair<String, String>> bigramWords = new ArrayList<Pair<String,String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
for (int i = 0; i < wordCount; ++i) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -645,7 +648,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
if (TextUtils.equals(word0, word1)) {
continue;
}
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
bigramWords.add(bigram);
final int unigramProbability = unigramProbabilities.get(word1);
final int bigramProbability =
@@ -702,12 +705,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(),
0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
- final ArrayList<String> words = new ArrayList<String>();
- final ArrayList<Pair<String, String>> bigramWords = new ArrayList<Pair<String,String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final ArrayList<Pair<String, String>> bigramWords = new ArrayList<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
for (int i = 0; i < initialUnigramCount; ++i) {
final String word = CodePointUtils.generateWord(random, codePointSet);
words.add(word);
@@ -746,7 +748,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final int unigramProbability = unigramProbabilities.get(word1);
final int bigramProbability =
unigramProbability + random.nextInt(0xFF - unigramProbability);
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
bigramWords.add(bigram);
bigramProbabilities.put(bigram, bigramProbability);
addBigramWords(binaryDictionary, word0, word1, bigramProbability);
@@ -812,8 +814,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
fail("IOException while writing an initial dictionary : " + e);
}
- final ArrayList<String> words = new ArrayList<String>();
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
+ final ArrayList<String> words = new ArrayList<>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
BinaryDictionary binaryDictionary;
@@ -863,8 +865,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
fail("IOException while writing an initial dictionary : " + e);
}
- final ArrayList<String> words = new ArrayList<String>();
- final HashSet<Pair<String, String>> bigrams = new HashSet<Pair<String, String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final HashSet<Pair<String, String>> bigrams = new HashSet<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
BinaryDictionary binaryDictionary;
@@ -884,18 +886,18 @@ public class BinaryDictionaryTests extends AndroidTestCase {
if (TextUtils.equals(word0, word1)) {
continue;
}
- bigrams.add(new Pair<String, String>(word0, word1));
+ bigrams.add(new Pair<>(word0, word1));
final int bigramProbability = random.nextInt(0xF);
addBigramWords(binaryDictionary, word0, word1, bigramProbability);
}
- assertEquals(new HashSet<String>(words).size(), Integer.parseInt(
+ assertEquals(new HashSet<>(words).size(), Integer.parseInt(
binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY)));
- assertEquals(new HashSet<Pair<String, String>>(bigrams).size(), Integer.parseInt(
+ assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt(
binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY)));
binaryDictionary.flushWithGC();
- assertEquals(new HashSet<String>(words).size(), Integer.parseInt(
+ assertEquals(new HashSet<>(words).size(), Integer.parseInt(
binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY)));
- assertEquals(new HashSet<Pair<String, String>>(bigrams).size(), Integer.parseInt(
+ assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt(
binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY)));
binaryDictionary.close();
}
@@ -924,9 +926,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
}
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
final LanguageModelParam[] languageModelParams = new LanguageModelParam[lmParamCount];
String prevWord = null;
@@ -941,7 +942,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
} else {
languageModelParams[i] = new LanguageModelParam(prevWord, word, probability,
bigramProbability, BinaryDictionary.NOT_A_VALID_TIMESTAMP);
- bigramProbabilities.put(new Pair<String, String>(prevWord, word),
+ bigramProbabilities.put(new Pair<>(prevWord, word),
bigramProbability);
}
prevWord = (random.nextDouble() < bigramContinueRate) ? word : null;
@@ -996,11 +997,10 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord");
assertFalse(invalidWordProperty.isValid());
- final ArrayList<String> words = new ArrayList<String>();
- final HashMap<String, Integer> wordProbabilities = new HashMap<String, Integer>();
- final HashMap<String, HashSet<String>> bigrams = new HashMap<String, HashSet<String>>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final ArrayList<String> words = new ArrayList<>();
+ final HashMap<String, Integer> wordProbabilities = new HashMap<>();
+ final HashMap<String, HashSet<String>> bigrams = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
for (int i = 0; i < UNIGRAM_COUNT; i++) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -1010,7 +1010,8 @@ public class BinaryDictionaryTests extends AndroidTestCase {
// TODO: Add tests for historical info.
binaryDictionary.addUnigramEntry(word, unigramProbability,
null /* shortcutTarget */, BinaryDictionary.NOT_A_PROBABILITY,
- isNotAWord, isBlacklisted, BinaryDictionary.NOT_A_VALID_TIMESTAMP);
+ false /* isBeginningOfSentence */, isNotAWord, isBlacklisted,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP);
if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) {
binaryDictionary.flushWithGC();
}
@@ -1043,11 +1044,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.flushWithGC();
}
if (!bigrams.containsKey(word0)) {
- final HashSet<String> bigramWord1s = new HashSet<String>();
+ final HashSet<String> bigramWord1s = new HashSet<>();
bigrams.put(word0, bigramWord1s);
}
bigrams.get(word0).add(word1);
- bigramProbabilities.put(new Pair<String, String>(word0, word1), bigramProbability);
+ bigramProbabilities.put(new Pair<>(word0, word1), bigramProbability);
}
for (int i = 0; i < words.size(); i++) {
@@ -1062,8 +1063,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final String word1 = wordProperty.mBigrams.get(j).mWord;
assertTrue(bigramWord1s.contains(word1));
if (canCheckBigramProbability(formatVersion)) {
- final int bigramProbability = bigramProbabilities.get(
- new Pair<String, String>(word0, word1));
+ final int bigramProbability = bigramProbabilities.get(new Pair<>(word0, word1));
assertEquals(bigramProbability, wordProperty.mBigrams.get(j).getProbability());
}
}
@@ -1097,12 +1097,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord");
assertFalse(invalidWordProperty.isValid());
- final ArrayList<String> words = new ArrayList<String>();
- final HashMap<String, Integer> wordProbabilitiesToCheckLater =
- new HashMap<String, Integer>();
- final HashMap<String, HashSet<String>> bigrams = new HashMap<String, HashSet<String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final HashMap<String, Integer> wordProbabilitiesToCheckLater = new HashMap<>();
+ final HashMap<String, HashSet<String>> bigrams = new HashMap<>();
final HashMap<Pair<String, String>, Integer> bigramProbabilitiesToCheckLater =
- new HashMap<Pair<String, String>, Integer>();
+ new HashMap<>();
for (int i = 0; i < UNIGRAM_COUNT; i++) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -1131,17 +1130,16 @@ public class BinaryDictionaryTests extends AndroidTestCase {
binaryDictionary.flushWithGC();
}
if (!bigrams.containsKey(word0)) {
- final HashSet<String> bigramWord1s = new HashSet<String>();
+ final HashSet<String> bigramWord1s = new HashSet<>();
bigrams.put(word0, bigramWord1s);
}
bigrams.get(word0).add(word1);
- bigramProbabilitiesToCheckLater.put(
- new Pair<String, String>(word0, word1), bigramProbability);
+ bigramProbabilitiesToCheckLater.put(new Pair<>(word0, word1), bigramProbability);
}
- final HashSet<String> wordSet = new HashSet<String>(words);
+ final HashSet<String> wordSet = new HashSet<>(words);
final HashSet<Pair<String, String>> bigramSet =
- new HashSet<Pair<String,String>>(bigramProbabilitiesToCheckLater.keySet());
+ new HashSet<>(bigramProbabilitiesToCheckLater.keySet());
int token = 0;
do {
final BinaryDictionary.GetNextWordPropertyResult result =
@@ -1155,7 +1153,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
final String word1 = wordProperty.mBigrams.get(j).mWord;
assertTrue(bigramWord1s.contains(word1));
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
if (canCheckBigramProbability(formatVersion)) {
final int bigramProbability = bigramProbabilitiesToCheckLater.get(bigram);
assertEquals(bigramProbability, wordProperty.mBigrams.get(j).getProbability());
@@ -1188,25 +1186,25 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final int unigramProbability = 100;
final int shortcutProbability = 10;
binaryDictionary.addUnigramEntry("aaa", unigramProbability, "zzz",
- shortcutProbability, false /* isNotAWord */, false /* isBlacklisted */,
- 0 /* timestamp */);
+ shortcutProbability, false /* isBeginningOfSentence */,
+ false /* isNotAWord */, false /* isBlacklisted */, 0 /* timestamp */);
WordProperty wordProperty = binaryDictionary.getWordProperty("aaa");
assertEquals(1, wordProperty.mShortcutTargets.size());
assertEquals("zzz", wordProperty.mShortcutTargets.get(0).mWord);
assertEquals(shortcutProbability, wordProperty.mShortcutTargets.get(0).getProbability());
final int updatedShortcutProbability = 2;
binaryDictionary.addUnigramEntry("aaa", unigramProbability, "zzz",
- updatedShortcutProbability, false /* isNotAWord */, false /* isBlacklisted */,
- 0 /* timestamp */);
+ updatedShortcutProbability, false /* isBeginningOfSentence */,
+ false /* isNotAWord */, false /* isBlacklisted */, 0 /* timestamp */);
wordProperty = binaryDictionary.getWordProperty("aaa");
assertEquals(1, wordProperty.mShortcutTargets.size());
assertEquals("zzz", wordProperty.mShortcutTargets.get(0).mWord);
assertEquals(updatedShortcutProbability,
wordProperty.mShortcutTargets.get(0).getProbability());
binaryDictionary.addUnigramEntry("aaa", unigramProbability, "yyy",
- shortcutProbability, false /* isNotAWord */, false /* isBlacklisted */,
- 0 /* timestamp */);
- final HashMap<String, Integer> shortcutTargets = new HashMap<String, Integer>();
+ shortcutProbability, false /* isBeginningOfSentence */, false /* isNotAWord */,
+ false /* isBlacklisted */, 0 /* timestamp */);
+ final HashMap<String, Integer> shortcutTargets = new HashMap<>();
shortcutTargets.put("zzz", updatedShortcutProbability);
shortcutTargets.put("yyy", shortcutProbability);
wordProperty = binaryDictionary.getWordProperty("aaa");
@@ -1244,10 +1242,9 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final int codePointSetSize = 20;
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final ArrayList<String> words = new ArrayList<String>();
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<String, HashMap<String, Integer>> shortcutTargets =
- new HashMap<String, HashMap<String, Integer>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<String, HashMap<String, Integer>> shortcutTargets = new HashMap<>();
File dictFile = null;
try {
@@ -1275,14 +1272,13 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final String word = words.get(random.nextInt(words.size()));
final int unigramProbability = unigramProbabilities.get(word);
binaryDictionary.addUnigramEntry(word, unigramProbability, shortcutTarget,
- shortcutProbability, false /* isNotAWord */, false /* isBlacklisted */,
- 0 /* timestamp */);
+ shortcutProbability, false /* isBeginningOfSentence */, false /* isNotAWord */,
+ false /* isBlacklisted */, 0 /* timestamp */);
if (shortcutTargets.containsKey(word)) {
final HashMap<String, Integer> shortcutTargetsOfWord = shortcutTargets.get(word);
shortcutTargetsOfWord.put(shortcutTarget, shortcutProbability);
} else {
- final HashMap<String, Integer> shortcutTargetsOfWord =
- new HashMap<String, Integer>();
+ final HashMap<String, Integer> shortcutTargetsOfWord = new HashMap<>();
shortcutTargetsOfWord.put(shortcutTarget, shortcutProbability);
shortcutTargets.put(word, shortcutTargetsOfWord);
}
@@ -1331,10 +1327,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
addBigramWords(binaryDictionary, "aaa", "bbb", bigramProbability);
final int shortcutProbability = 10;
binaryDictionary.addUnigramEntry("ccc", unigramProbability, "xxx", shortcutProbability,
- false /* isNotAWord */, false /* isBlacklisted */, 0 /* timestamp */);
+ false /* isBeginningOfSentence */, false /* isNotAWord */,
+ false /* isBlacklisted */, 0 /* timestamp */);
binaryDictionary.addUnigramEntry("ddd", unigramProbability, null /* shortcutTarget */,
- Dictionary.NOT_A_PROBABILITY, true /* isNotAWord */,
- true /* isBlacklisted */, 0 /* timestamp */);
+ Dictionary.NOT_A_PROBABILITY, false /* isBeginningOfSentence */,
+ true /* isNotAWord */, true /* isBlacklisted */, 0 /* timestamp */);
assertEquals(unigramProbability, binaryDictionary.getFrequency("aaa"));
assertEquals(unigramProbability, binaryDictionary.getFrequency("bbb"));
assertTrue(isValidBigram(binaryDictionary, "aaa", "bbb"));
@@ -1379,12 +1376,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
- final ArrayList<String> words = new ArrayList<String>();
- final ArrayList<Pair<String, String>> bigrams = new ArrayList<Pair<String,String>>();
+ final ArrayList<String> words = new ArrayList<>();
+ final ArrayList<Pair<String, String>> bigrams = new ArrayList<>();
final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random);
- final HashMap<String, Integer> unigramProbabilities = new HashMap<String, Integer>();
- final HashMap<Pair<String, String>, Integer> bigramProbabilities =
- new HashMap<Pair<String, String>, Integer>();
+ final HashMap<String, Integer> unigramProbabilities = new HashMap<>();
+ final HashMap<Pair<String, String>, Integer> bigramProbabilities = new HashMap<>();
for (int i = 0; i < UNIGRAM_COUNT; i++) {
final String word = CodePointUtils.generateWord(random, codePointSet);
@@ -1412,7 +1408,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) {
binaryDictionary.flushWithGC();
}
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
bigrams.add(bigram);
bigramProbabilities.put(bigram, bigramProbability);
}
@@ -1434,4 +1430,46 @@ public class BinaryDictionaryTests extends AndroidTestCase {
assertEquals(bigramProbabilities.size(), Integer.parseInt(
binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY)));
}
+
+ public void testBeginningOfSentence() {
+ for (final int formatVersion : DICT_FORMAT_VERSIONS) {
+ if (supportsBeginningOfSentence(formatVersion)) {
+ testBeginningOfSentence(formatVersion);
+ }
+ }
+ }
+
+ private void testBeginningOfSentence(final int formatVersion) {
+ File dictFile = null;
+ try {
+ dictFile = createEmptyDictionaryAndGetFile("TestBinaryDictionary", formatVersion);
+ } catch (IOException e) {
+ fail("IOException while writing an initial dictionary : " + e);
+ }
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(),
+ 0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
+ Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
+ final int dummyProbability = 0;
+ binaryDictionary.addUnigramEntry("", dummyProbability, "" /* shortcutTarget */,
+ BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */,
+ true /* isBeginningOfSentence */, true /* isNotAWord */, false /* isBlacklisted */,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
+ final PrevWordsInfo prevWordsInfoStartOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE;
+ final int bigramProbability = 200;
+ addUnigramWord(binaryDictionary, "aaa", dummyProbability);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", bigramProbability,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
+ assertEquals(bigramProbability,
+ binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "aaa"));
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", bigramProbability,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
+ addUnigramWord(binaryDictionary, "bbb", dummyProbability);
+ binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", bigramProbability,
+ BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
+ binaryDictionary.flushWithGC();
+ assertEquals(bigramProbability,
+ binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "aaa"));
+ assertEquals(bigramProbability,
+ binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "bbb"));
+ }
}
diff --git a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
index e98f9eacc..406e9a9b8 100644
--- a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
+++ b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
@@ -20,55 +20,78 @@ import java.util.Locale;
import android.test.suitebuilder.annotation.LargeTest;
-import com.android.inputmethod.latin.utils.DistracterFilter;
+import com.android.inputmethod.latin.utils.DistracterFilterUsingSuggestion;
/**
* Unit test for DistracterFilter
*/
@LargeTest
public class DistracterFilterTest extends InputTestsBase {
- private DistracterFilter mDistracterFilter;
+ private DistracterFilterUsingSuggestion mDistracterFilter;
@Override
protected void setUp() throws Exception {
super.setUp();
- mDistracterFilter = mLatinIME.createDistracterFilter();
+ mDistracterFilter = new DistracterFilterUsingSuggestion(getContext());
+ mDistracterFilter.updateEnabledSubtypes(mLatinIME.getEnabledSubtypesForTest());
}
public void testIsDistractorToWordsInDictionaries() {
- final PrevWordsInfo EMPTY_PREV_WORDS_INFO = new PrevWordsInfo(null);
+ final PrevWordsInfo EMPTY_PREV_WORDS_INFO = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
final Locale localeEnUs = new Locale("en", "US");
- String typedWord = "alot";
- // For this test case, we consider "alot" is a distracter to "a lot".
+ String typedWord;
+
+ typedWord = "google";
+ // For this test case, we consider "google" is a distracter to "Google".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "mot";
- // For this test case, we consider "mot" is a distracter to "not".
+ typedWord = "Bill";
+ // For this test case, we consider "Bill" is a distracter to "bill".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "wierd";
- // For this test case, we consider "wierd" is a distracter to "weird".
+ typedWord = "nOt";
+ // For this test case, we consider "nOt" is a distracter to "not".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "hoe";
- // For this test case, we consider "hoe" is a distracter to "how".
+ typedWord = "youre";
+ // For this test case, we consider "youre" is a distracter to "you're".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "nit";
- // For this test case, we consider "nit" is a distracter to "not".
+ typedWord = "Banana";
+ // For this test case, we consider "Banana" is a distracter to "banana".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "ill";
- // For this test case, we consider "ill" is a distracter to "I'll".
+ typedWord = "orange";
+ // For this test case, we consider "orange" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "Orange";
+ // For this test case, we consider "Orange" is a distracter to "orange".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "café";
+ // For this test case, we consider "café" is a distracter to "cafe".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+ typedWord = "cafe";
+ // For this test case, we consider "café" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "ill";
+ // For this test case, we consider "ill" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
typedWord = "asdfd";
// For this test case, we consider "asdfd" is not a distracter to any word in dictionaries.
assertFalse(
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index a9444160f..460f600ac 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -481,6 +481,27 @@ public class InputLogicTests extends InputTestsBase {
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
}
+ public void testPredictionsWithDoubleSpaceToPeriod() {
+ final String WORD_TO_TYPE = "Barack ";
+ type(WORD_TO_TYPE);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
+ // No need to test here, testPredictionsAfterSpace is testing it already
+ type(" ");
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
+ // Test the predictions have been cleared
+ SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
+ assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0);
+ type(Constants.CODE_DELETE);
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
+ // Test the first prediction is displayed
+ suggestedWords = mLatinIME.getSuggestedWordsForTest();
+ assertEquals("predictions after cancel double-space-to-period", "Obama",
+ suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
+ }
+
public void testPredictionsAfterManualPick() {
final String WORD_TO_TYPE = "Barack";
type(WORD_TO_TYPE);
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
index e38ba721e..2560407dc 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java
@@ -19,8 +19,6 @@ package com.android.inputmethod.latin;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.inputmethod.BaseInputConnection;
-import com.android.inputmethod.latin.suggestions.SuggestionStripView;
-
@LargeTest
public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
public void testAutoCorrectForLanguageWithoutSpaces() {
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
index 68b6ee674..914b0bb23 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java
@@ -18,8 +18,6 @@ package com.android.inputmethod.latin;
import android.test.suitebuilder.annotation.LargeTest;
-import com.android.inputmethod.latin.suggestions.SuggestionStripView;
-
@LargeTest
public class InputLogicTestsNonEnglish extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java
index bb36a2a16..61eae4e8b 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java
@@ -77,6 +77,7 @@ import android.util.Pair;
*/
@LargeTest
+@SuppressWarnings("rawtypes")
public class InputLogicTestsReorderingMyanmar extends InputTestsBase {
// The tests are formatted as follows.
// Each test is an entry in the array of Pair arrays.
@@ -202,6 +203,7 @@ public class InputLogicTestsReorderingMyanmar extends InputTestsBase {
*/
};
+ @SuppressWarnings("unchecked")
private void doMyanmarTest(final int testNumber, final Pair[] test) {
int stepNumber = 0;
for (final Pair<int[], String> step : test) {
diff --git a/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java
index 0a29d8326..f5e993de8 100644
--- a/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java
+++ b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java
@@ -30,7 +30,6 @@ public class LatinImeStressTests extends InputTestsBase {
final int maxWordCountToTypeInEachIteration = 20;
final long seed = System.currentTimeMillis();
final Random random = new Random(seed);
- final int codePointSetSize = 30;
final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER;
for (int i = 0; i < switchCount; ++i) {
changeLanguageWithoutWait(locales[random.nextInt(locales.length)],
diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
index f3351ff84..c471eca57 100644
--- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
+++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java
@@ -157,10 +157,10 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
// If one of the following cases breaks, the bigram suggestions won't work.
assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 2).mPrevWord, "abc");
- assertNull(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
- "abc", mSpacingAndPunctuations, 2).mPrevWord);
- assertNull(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
- "abc. def", mSpacingAndPunctuations, 2).mPrevWord);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc. def", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
assertFalse(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 2).mIsBeginningOfSentence);
@@ -180,16 +180,22 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
"abc def .", mSpacingAndPunctuations, 2).mPrevWord, "def");
assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
- "abc ", mSpacingAndPunctuations, 2).mPrevWord, null);
+ "abc ", mSpacingAndPunctuations, 2), PrevWordsInfo.BEGINNING_OF_SENTENCE);
assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
"abc def", mSpacingAndPunctuations, 1).mPrevWord, "def");
assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
"abc def ", mSpacingAndPunctuations, 1).mPrevWord, "def");
- assertNull(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
- "abc def.", mSpacingAndPunctuations, 1).mPrevWord);
- assertNull(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
- "abc def .", mSpacingAndPunctuations, 1).mPrevWord);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc def.", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc def .", mSpacingAndPunctuations, 1), PrevWordsInfo.BEGINNING_OF_SENTENCE);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc, def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc? def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
+ assertEquals(RichInputConnection.getPrevWordsInfoFromNthPreviousWord(
+ "abc! def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
}
/**
diff --git a/tests/src/com/android/inputmethod/latin/ShiftModeTests.java b/tests/src/com/android/inputmethod/latin/ShiftModeTests.java
index 6fc9df793..a319ffda6 100644
--- a/tests/src/com/android/inputmethod/latin/ShiftModeTests.java
+++ b/tests/src/com/android/inputmethod/latin/ShiftModeTests.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.latin;
+import android.os.Build;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
@@ -78,4 +79,56 @@ public class ShiftModeTests extends InputTestsBase {
runMessages();
assertTrue("Caps after a while after repeating Backspace a lot", isCapsModeAutoShifted());
}
+
+ public void testAutoCapsAfterDigitsPeriod() {
+ changeLanguage("en");
+ type("On 22.11.");
+ assertFalse("(English) Auto caps after digits-period", isCapsModeAutoShifted());
+ type(" ");
+ assertTrue("(English) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
+ mEditText.setText("");
+ changeLanguage("fr");
+ type("Le 22.");
+ assertFalse("(French) Auto caps after digits-period", isCapsModeAutoShifted());
+ type(" ");
+ assertTrue("(French) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
+ mEditText.setText("");
+ changeLanguage("de");
+ type("Am 22.");
+ assertFalse("(German) Auto caps after digits-period", isCapsModeAutoShifted());
+ type(" ");
+ // For German, no auto-caps in this case
+ assertFalse("(German) Auto caps after digits-period-whitespace", isCapsModeAutoShifted());
+ }
+
+ public void testAutoCapsAfterInvertedMarks() {
+ changeLanguage("es");
+ assertTrue("(Spanish) Auto caps at start", isCapsModeAutoShifted());
+ type("Hey. ¿");
+ assertTrue("(Spanish) Auto caps after inverted what", isCapsModeAutoShifted());
+ mEditText.setText("");
+ type("¡");
+ assertTrue("(Spanish) Auto caps after inverted bang", isCapsModeAutoShifted());
+ }
+
+ public void DISABLED_testOtherSentenceSeparators() {
+ // We only run this test on Kitkat+ because previous versions of Android don't
+ // have an Armenian locale. For some reason I don't know, when the requested
+ // locale is not present as a device locale, then the application under test can't
+ // access the resources in that locale -- though it works when the app is actually
+ // running on the device and not under test. If we ever figure out what's going
+ // on, remove this test.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ changeLanguage("hy-AM");
+ assertTrue("(Armenian) Auto caps at start", isCapsModeAutoShifted());
+ type("Hey. ");
+ assertFalse("(Armenian) No auto-caps after latin period", isCapsModeAutoShifted());
+ type("Hey\u0589");
+ assertFalse("(Armenian) No auto-caps directly after armenian period",
+ isCapsModeAutoShifted());
+ type(" ");
+ assertTrue("(Armenian) Auto-caps after armenian period-whitespace",
+ isCapsModeAutoShifted());
+ }
+ }
}
diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
index 8fe473523..66b4a9c71 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
@@ -16,12 +16,10 @@
package com.android.inputmethod.latin;
-import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
-
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import com.android.inputmethod.latin.utils.CollectionUtils;
+import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.util.ArrayList;
import java.util.Locale;
@@ -33,7 +31,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
final String TYPED_WORD = "typed";
final int TYPED_WORD_FREQ = 5;
final int NUMBER_OF_ADDED_SUGGESTIONS = 5;
- final ArrayList<SuggestedWordInfo> list = CollectionUtils.newArrayList();
+ final ArrayList<SuggestedWordInfo> list = new ArrayList<>();
list.add(new SuggestedWordInfo(TYPED_WORD, TYPED_WORD_FREQ,
SuggestedWordInfo.KIND_TYPED, null /* sourceDict */,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
@@ -53,16 +51,16 @@ public class SuggestedWordsTests extends AndroidTestCase {
false /* isPrediction*/);
assertEquals(NUMBER_OF_ADDED_SUGGESTIONS + 1, words.size());
assertEquals("typed", words.getWord(0));
- assertEquals(SuggestedWordInfo.KIND_TYPED, words.getInfo(0).mKind);
+ assertTrue(words.getInfo(0).isKindOf(SuggestedWordInfo.KIND_TYPED));
assertEquals("0", words.getWord(1));
- assertEquals(SuggestedWordInfo.KIND_CORRECTION, words.getInfo(1).mKind);
+ assertTrue(words.getInfo(1).isKindOf(SuggestedWordInfo.KIND_CORRECTION));
assertEquals("4", words.getWord(5));
- assertEquals(SuggestedWordInfo.KIND_CORRECTION, words.getInfo(5).mKind);
+ assertTrue(words.getInfo(5).isKindOf(SuggestedWordInfo.KIND_CORRECTION));
final SuggestedWords wordsWithoutTyped = words.getSuggestedWordsExcludingTypedWord();
assertEquals(words.size() - 1, wordsWithoutTyped.size());
assertEquals("0", wordsWithoutTyped.getWord(0));
- assertEquals(SuggestedWordInfo.KIND_CORRECTION, wordsWithoutTyped.getInfo(0).mKind);
+ assertTrue(wordsWithoutTyped.getInfo(0).isKindOf(SuggestedWordInfo.KIND_CORRECTION));
}
// Helper for testGetTransformedWordInfo
diff --git a/tests/src/com/android/inputmethod/latin/WordComposerTests.java b/tests/src/com/android/inputmethod/latin/WordComposerTests.java
index 17e718541..274555a03 100644
--- a/tests/src/com/android/inputmethod/latin/WordComposerTests.java
+++ b/tests/src/com/android/inputmethod/latin/WordComposerTests.java
@@ -74,7 +74,7 @@ public class WordComposerTests extends AndroidTestCase {
CoordinateUtils.newCoordinateArray(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR.length,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, COORDINATES_WITH_SUPPLEMENTARY_CHAR,
- new PrevWordsInfo(null));
+ PrevWordsInfo.EMPTY_PREV_WORDS_INFO);
assertEquals(wc.size(), CODEPOINTS_WITH_SUPPLEMENTARY_CHAR.length);
assertFalse(wc.isCursorFrontOrMiddleOfComposingWord());
wc.setCursorPositionWithinWord(3);
@@ -109,7 +109,7 @@ public class WordComposerTests extends AndroidTestCase {
assertEquals(PREV_WORDS_INFO_STR_WITHIN_BMP, wc.getPrevWordsInfoForSuggestion());
- final PrevWordsInfo PREV_WORDS_INFO_NULL = new PrevWordsInfo(null);
+ final PrevWordsInfo PREV_WORDS_INFO_NULL = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
wc.setComposingWord(CODEPOINTS_WITH_SUPPLEMENTARY_CHAR, COORDINATES_WITH_SUPPLEMENTARY_CHAR,
PREV_WORDS_INFO_NULL);
wc.setCursorPositionWithinWord(3);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
index f29fc21c1..4b332ca84 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
@@ -28,10 +28,8 @@ import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
-import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import com.android.inputmethod.latin.utils.ByteArrayDictBuffer;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import java.io.File;
import java.io.IOException;
@@ -61,15 +59,12 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
private static final int NUM_OF_NODES_HAVING_SHORTCUTS = 50;
private static final int NUM_OF_SHORTCUTS = 5;
- private static final ArrayList<String> sWords = CollectionUtils.newArrayList();
- private static final ArrayList<String> sWordsWithVariousCodePoints =
- CollectionUtils.newArrayList();
- private static final SparseArray<List<Integer>> sEmptyBigrams =
- CollectionUtils.newSparseArray();
- private static final SparseArray<List<Integer>> sStarBigrams = CollectionUtils.newSparseArray();
- private static final SparseArray<List<Integer>> sChainBigrams =
- CollectionUtils.newSparseArray();
- private static final HashMap<String, List<String>> sShortcuts = CollectionUtils.newHashMap();
+ private static final ArrayList<String> sWords = new ArrayList<>();
+ private static final ArrayList<String> sWordsWithVariousCodePoints = new ArrayList<>();
+ private static final SparseArray<List<Integer>> sEmptyBigrams = new SparseArray<>();
+ private static final SparseArray<List<Integer>> sStarBigrams = new SparseArray<>();
+ private static final SparseArray<List<Integer>> sChainBigrams = new SparseArray<>();
+ private static final HashMap<String, List<String>> sShortcuts = new HashMap<>();
public BinaryDictDecoderEncoderTests() {
this(System.currentTimeMillis(), DEFAULT_MAX_UNIGRAMS);
@@ -125,7 +120,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
private void generateWords(final int number, final Random random) {
final int[] codePointSet = CodePointUtils.generateCodePointSet(DEFAULT_CODE_POINT_SET_SIZE,
random);
- final Set<String> wordSet = CollectionUtils.newHashSet();
+ final Set<String> wordSet = new HashSet<>();
while (wordSet.size() < number) {
wordSet.add(CodePointUtils.generateWord(random, codePointSet));
}
@@ -147,7 +142,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
final List<String> words, final HashMap<String, List<String>> shortcutMap) {
for (int i = 0; i < number; ++i) {
final String word = words.get(i);
- final ArrayList<WeightedString> shortcuts = CollectionUtils.newArrayList();
+ final ArrayList<WeightedString> shortcuts = new ArrayList<>();
if (shortcutMap != null && shortcutMap.containsKey(word)) {
for (final String shortcut : shortcutMap.get(word)) {
shortcuts.add(new WeightedString(shortcut, UNIGRAM_FREQ));
@@ -325,7 +320,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
public void testReadAndWriteWithByteBuffer() {
- final List<String> results = CollectionUtils.newArrayList();
+ final List<String> results = new ArrayList<>();
runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
BinaryDictUtils.VERSION2_OPTIONS);
@@ -339,7 +334,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
public void testReadAndWriteWithByteArray() {
- final List<String> results = CollectionUtils.newArrayList();
+ final List<String> results = new ArrayList<>();
runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
BinaryDictUtils.VERSION2_OPTIONS);
@@ -362,8 +357,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
final TreeMap<Integer, ArrayList<PendingAttribute>> resultBigrams,
final boolean checkProbability) {
// check unigrams
- final Set<String> actualWordsSet = new HashSet<String>(resultWords.values());
- final Set<String> expectedWordsSet = new HashSet<String>(expectedWords);
+ final Set<String> actualWordsSet = new HashSet<>(resultWords.values());
+ final Set<String> expectedWordsSet = new HashSet<>(expectedWords);
assertEquals(actualWordsSet, expectedWordsSet);
if (checkProbability) {
for (int freq : resultFrequencies.values()) {
@@ -372,7 +367,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
// check bigrams
- final HashMap<String, Set<String>> expBigrams = new HashMap<String, Set<String>>();
+ final HashMap<String, Set<String>> expBigrams = new HashMap<>();
for (int i = 0; i < expectedBigrams.size(); ++i) {
final String word1 = expectedWords.get(expectedBigrams.keyAt(i));
for (int w2 : expectedBigrams.valueAt(i)) {
@@ -383,7 +378,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
}
- final HashMap<String, Set<String>> actBigrams = new HashMap<String, Set<String>>();
+ final HashMap<String, Set<String>> actBigrams = new HashMap<>();
for (Entry<Integer, ArrayList<PendingAttribute>> entry : resultBigrams.entrySet()) {
final String word1 = resultWords.get(entry.getKey());
final int unigramFreq = resultFrequencies.get(entry.getKey());
@@ -407,10 +402,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
private long timeAndCheckReadUnigramsAndBigramsBinary(final File file, final List<String> words,
final SparseArray<List<Integer>> bigrams, final int bufferType,
final boolean checkProbability) {
- final TreeMap<Integer, String> resultWords = CollectionUtils.newTreeMap();
- final TreeMap<Integer, ArrayList<PendingAttribute>> resultBigrams =
- CollectionUtils.newTreeMap();
- final TreeMap<Integer, Integer> resultFreqs = CollectionUtils.newTreeMap();
+ final TreeMap<Integer, String> resultWords = new TreeMap<>();
+ final TreeMap<Integer, ArrayList<PendingAttribute>> resultBigrams = new TreeMap<>();
+ final TreeMap<Integer, Integer> resultFreqs = new TreeMap<>();
long now = -1, diff = -1;
try {
@@ -468,7 +462,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
public void testReadUnigramsAndBigramsBinaryWithByteBuffer() {
- final ArrayList<String> results = CollectionUtils.newArrayList();
+ final ArrayList<String> results = new ArrayList<>();
runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
BinaryDictUtils.VERSION2_OPTIONS);
@@ -479,7 +473,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
public void testReadUnigramsAndBigramsBinaryWithByteArray() {
- final ArrayList<String> results = CollectionUtils.newArrayList();
+ final ArrayList<String> results = new ArrayList<>();
runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
BinaryDictUtils.VERSION2_OPTIONS);
@@ -590,7 +584,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
public void testGetTerminalPosition() {
- final ArrayList<String> results = CollectionUtils.newArrayList();
+ final ArrayList<String> results = new ArrayList<>();
runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
BinaryDictUtils.VERSION2_OPTIONS);
@@ -656,15 +650,15 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
0 /* offset */, file.length(), true /* useFullEditDistance */,
Locale.ENGLISH, dictName, false /* isUpdatable */);
- final HashSet<String> wordSet = new HashSet<String>(words);
- final HashSet<Pair<String, String>> bigramSet = new HashSet<Pair<String,String>>();
+ final HashSet<String> wordSet = new HashSet<>(words);
+ final HashSet<Pair<String, String>> bigramSet = new HashSet<>();
for (int i = 0; i < words.size(); i++) {
final List<Integer> bigramList = bigrams.get(i);
if (bigramList != null) {
for (final Integer word1Index : bigramList) {
final String word1 = words.get(word1Index);
- bigramSet.add(new Pair<String, String>(words.get(i), word1));
+ bigramSet.add(new Pair<>(words.get(i), word1));
}
}
}
@@ -689,7 +683,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
}
for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
final String word1 = wordProperty.mBigrams.get(j).mWord;
- final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
+ final Pair<String, String> bigram = new Pair<>(word0, word1);
assertTrue(bigramSet.contains(bigram));
bigramSet.remove(bigram);
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 6f8b07a34..96604a197 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -32,9 +32,6 @@ import java.nio.ByteBuffer;
* TODO: Rename this class to DictDecoderUtils.
*/
public final class BinaryDictDecoderUtils {
-
- private static final boolean DBG = MakedictLog.DBG;
-
private BinaryDictDecoderUtils() {
// This utility class is not publicly instantiable.
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
index 39bd98bad..084371944 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
@@ -258,7 +258,7 @@ public class BinaryDictEncoderUtils {
final PtNodeArray rootNodeArray) {
final int treeSize = FusionDictionary.countPtNodes(rootNodeArray);
MakedictLog.i("Counted nodes : " + treeSize);
- final ArrayList<PtNodeArray> flatTree = new ArrayList<PtNodeArray>(treeSize);
+ final ArrayList<PtNodeArray> flatTree = new ArrayList<>(treeSize);
return flattenTreeInner(flatTree, rootNodeArray);
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index 42a50be66..9c3b37387 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -90,7 +90,7 @@ public final class BinaryDictIOUtils {
final Map<Integer, ArrayList<PendingAttribute>> bigrams) {
int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1];
- Stack<Position> stack = new Stack<Position>();
+ Stack<Position> stack = new Stack<>();
int index = 0;
Position initPos = new Position(bodyOffset, 0);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index f60b3af4f..4a8c178b5 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -57,7 +57,7 @@ public final class FusionDictionary implements Iterable<WordProperty> {
int mCachedParentAddress = 0;
public PtNodeArray() {
- mData = new ArrayList<PtNode>();
+ mData = new ArrayList<>();
}
public PtNodeArray(ArrayList<PtNode> data) {
Collections.sort(data, PTNODE_COMPARATOR);
@@ -161,14 +161,14 @@ public final class FusionDictionary implements Iterable<WordProperty> {
// We don't want write permission to escape outside the package, so we return a copy
if (null == mShortcutTargets) return null;
final ArrayList<WeightedString> copyOfShortcutTargets =
- new ArrayList<WeightedString>(mShortcutTargets);
+ new ArrayList<>(mShortcutTargets);
return copyOfShortcutTargets;
}
public ArrayList<WeightedString> getBigrams() {
// We don't want write permission to escape outside the package, so we return a copy
if (null == mBigrams) return null;
- final ArrayList<WeightedString> copyOfBigrams = new ArrayList<WeightedString>(mBigrams);
+ final ArrayList<WeightedString> copyOfBigrams = new ArrayList<>(mBigrams);
return copyOfBigrams;
}
@@ -183,7 +183,7 @@ public final class FusionDictionary implements Iterable<WordProperty> {
*/
public void addBigram(final String word, final ProbabilityInfo probabilityInfo) {
if (mBigrams == null) {
- mBigrams = new ArrayList<WeightedString>();
+ mBigrams = new ArrayList<>();
}
WeightedString bigram = getBigram(word);
if (bigram != null) {
@@ -571,7 +571,6 @@ public final class FusionDictionary implements Iterable<WordProperty> {
/**
* Helper method to find a word in a given branch.
*/
- @SuppressWarnings("unused")
public static PtNode findWordInTree(PtNodeArray nodeArray, final String string) {
int index = 0;
final StringBuilder checker = DBG ? new StringBuilder() : null;
@@ -651,7 +650,7 @@ public final class FusionDictionary implements Iterable<WordProperty> {
public DictionaryIterator(ArrayList<PtNode> ptRoot) {
mCurrentString = new StringBuilder();
- mPositions = new LinkedList<Position>();
+ mPositions = new LinkedList<>();
final Position rootPos = new Position(ptRoot);
mPositions.add(rootPos);
}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
index 7091c119e..65b84d5f7 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
@@ -20,7 +20,6 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import java.io.File;
import java.io.FileNotFoundException;
@@ -34,8 +33,6 @@ import java.util.Arrays;
// TODO: Separate logics that are used only for testing.
@UsedForTesting
public class Ver2DictDecoder extends AbstractDictDecoder {
- private static final String TAG = Ver2DictDecoder.class.getSimpleName();
-
/**
* A utility class for reading a PtNode.
*/
@@ -233,7 +230,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
final ArrayList<WeightedString> shortcutTargets;
if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) {
// readShortcut will add shortcuts to shortcutTargets.
- shortcutTargets = new ArrayList<WeightedString>();
+ shortcutTargets = new ArrayList<>();
addressPointer += PtNodeReader.readShortcut(mDictBuffer, shortcutTargets);
} else {
shortcutTargets = null;
@@ -241,7 +238,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
final ArrayList<PendingAttribute> bigrams;
if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) {
- bigrams = new ArrayList<PendingAttribute>();
+ bigrams = new ArrayList<>();
addressPointer += PtNodeReader.readBigramAddresses(mDictBuffer, bigrams,
addressPointer);
if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
@@ -267,7 +264,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
final FusionDictionary fusionDict =
new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions);
int token = 0;
- final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList();
+ final ArrayList<WordProperty> wordProperties = new ArrayList<>();
do {
final BinaryDictionary.GetNextWordPropertyResult result =
binaryDictionary.getNextWordProperty(token);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java
index 9dc2b1058..3882c2c55 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java
@@ -58,7 +58,6 @@ public class Ver2DictDecoderTests extends AndroidTestCase {
}
}
- @SuppressWarnings("null")
public void runTestOpenBuffer(final String testName, final DictionaryBufferFactory factory) {
File testFile = null;
try {
@@ -102,7 +101,6 @@ public class Ver2DictDecoderTests extends AndroidTestCase {
new DictionaryBufferFromWritableByteBufferFactory());
}
- @SuppressWarnings("null")
public void runTestGetBuffer(final String testName, final DictionaryBufferFactory factory) {
File testFile = null;
try {
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
index f3fad7e99..5e8417ed6 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.BinaryDictionary;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.FileUtils;
import java.io.File;
@@ -31,8 +30,6 @@ import java.util.ArrayList;
*/
@UsedForTesting
public class Ver4DictDecoder extends AbstractDictDecoder {
- private static final String TAG = Ver4DictDecoder.class.getSimpleName();
-
final File mDictDirectory;
@UsedForTesting
@@ -73,7 +70,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
final FusionDictionary fusionDict =
new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions);
int token = 0;
- final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList();
+ final ArrayList<WordProperty> wordProperties = new ArrayList<>();
do {
final BinaryDictionary.GetNextWordPropertyResult result =
binaryDictionary.getNextWordProperty(token);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
index a04b81024..8f32e5336 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
@@ -75,33 +75,54 @@ public class Ver4DictEncoder implements DictEncoder {
for (final WordProperty wordProperty : dict) {
// TODO: switch to addMultipleDictionaryEntries when they support shortcuts
if (null == wordProperty.mShortcutTargets || wordProperty.mShortcutTargets.isEmpty()) {
- binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
+ if (!binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
null /* shortcutTarget */, 0 /* shortcutProbability */,
- wordProperty.mIsNotAWord, wordProperty.mIsBlacklistEntry,
- 0 /* timestamp */);
+ wordProperty.mIsBeginningOfSentence, wordProperty.mIsNotAWord,
+ wordProperty.mIsBlacklistEntry, 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add unigram entry for " + wordProperty.mWord);
+ }
} else {
for (final WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
- binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
+ if (!binaryDict.addUnigramEntry(wordProperty.mWord,
+ wordProperty.getProbability(),
shortcutTarget.mWord, shortcutTarget.getProbability(),
- wordProperty.mIsNotAWord, wordProperty.mIsBlacklistEntry,
- 0 /* timestamp */);
+ wordProperty.mIsBeginningOfSentence, wordProperty.mIsNotAWord,
+ wordProperty.mIsBlacklistEntry, 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add unigram entry for " + wordProperty.mWord
+ + ", shortcutTarget: " + shortcutTarget.mWord);
+ return;
+ }
}
}
if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
}
}
for (final WordProperty word0Property : dict) {
if (null == word0Property.mBigrams) continue;
for (final WeightedString word1 : word0Property.mBigrams) {
- binaryDict.addNgramEntry(new PrevWordsInfo(word0Property.mWord), word1.mWord,
- word1.getProbability(), 0 /* timestamp */);
+ final PrevWordsInfo prevWordsInfo = new PrevWordsInfo(word0Property.mWord);
+ if (!binaryDict.addNgramEntry(prevWordsInfo, word1.mWord,
+ word1.getProbability(), 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add n-gram entry for "
+ + prevWordsInfo + " -> " + word1.mWord);
+ return;
+ }
if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
}
}
}
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
binaryDict.close();
}
diff --git a/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java
new file mode 100644
index 000000000..0f2f9814b
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.personalization;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import com.android.inputmethod.latin.BinaryDictionary;
+import com.android.inputmethod.latin.Dictionary;
+import com.android.inputmethod.latin.DictionaryFacilitator;
+import com.android.inputmethod.latin.ExpandableBinaryDictionary;
+import com.android.inputmethod.latin.ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback;
+import com.android.inputmethod.latin.makedict.CodePointUtils;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
+/**
+ * Unit tests for personalization dictionary
+ */
+@LargeTest
+public class PersonalizationDictionaryTests extends AndroidTestCase {
+ private static final String TAG = PersonalizationDictionaryTests.class.getSimpleName();
+
+ private static final Locale LOCALE_EN_US = new Locale("en", "US");
+ private static final String DUMMY_PACKAGE_NAME = "test.package.name";
+ private static final long TIMEOUT_TO_WAIT_DICTIONARY_OPERATIONS_IN_SECONDS = 120;
+
+ private DictionaryFacilitator getDictionaryFacilitator() {
+ final ArrayList<String> dictTypes = new ArrayList<>();
+ dictTypes.add(Dictionary.TYPE_MAIN);
+ dictTypes.add(Dictionary.TYPE_PERSONALIZATION);
+ final DictionaryFacilitator dictionaryFacilitator = new DictionaryFacilitator();
+ dictionaryFacilitator.resetDictionariesForTesting(getContext(), LOCALE_EN_US, dictTypes,
+ new HashMap<String, File>(), new HashMap<String, Map<String, String>>());
+ return dictionaryFacilitator;
+ }
+
+ public void testAddManyTokens() {
+ final DictionaryFacilitator dictionaryFacilitator = getDictionaryFacilitator();
+ dictionaryFacilitator.clearPersonalizationDictionary();
+ final int dataChunkCount = 20;
+ final int wordCountInOneChunk = 2000;
+ final Random random = new Random(System.currentTimeMillis());
+ final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER;
+
+ final SpacingAndPunctuations spacingAndPunctuations =
+ new SpacingAndPunctuations(getContext().getResources());
+
+ final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds(
+ System.currentTimeMillis());
+
+ for (int i = 0; i < dataChunkCount; i++) {
+ final ArrayList<String> tokens = new ArrayList<>();
+ for (int j = 0; j < wordCountInOneChunk; j++) {
+ tokens.add(CodePointUtils.generateWord(random, codePointSet));
+ }
+ final PersonalizationDataChunk personalizationDataChunk = new PersonalizationDataChunk(
+ true /* inputByUser */, tokens, timeStampInSeconds, DUMMY_PACKAGE_NAME);
+ final CountDownLatch countDownLatch = new CountDownLatch(1);
+ final AddMultipleDictionaryEntriesCallback callback =
+ new AddMultipleDictionaryEntriesCallback() {
+ @Override
+ public void onFinished() {
+ countDownLatch.countDown();
+ }
+ };
+ dictionaryFacilitator.addEntriesToPersonalizationDictionary(personalizationDataChunk,
+ spacingAndPunctuations, callback);
+ try {
+ countDownLatch.await(TIMEOUT_TO_WAIT_DICTIONARY_OPERATIONS_IN_SECONDS,
+ TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Log.e(TAG, "Interrupted while waiting for finishing dictionary operations.", e);
+ }
+ }
+ dictionaryFacilitator.flushPersonalizationDictionary();
+ try {
+ dictionaryFacilitator.waitForLoadingDictionariesForTesting(
+ TIMEOUT_TO_WAIT_DICTIONARY_OPERATIONS_IN_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Log.e(TAG, "Interrupted while waiting for finishing dictionary operations.", e);
+ }
+ final String dictName = ExpandableBinaryDictionary.getDictName(
+ PersonalizationDictionary.NAME, LOCALE_EN_US, null /* dictFile */);
+ final File dictFile = ExpandableBinaryDictionary.getDictFile(
+ getContext(), dictName, null /* dictFile */);
+
+ final BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(),
+ 0 /* offset */, 0 /* size */,
+ true /* useFullEditDistance */, LOCALE_EN_US, Dictionary.TYPE_PERSONALIZATION,
+ true /* isUpdatable */);
+ assertTrue(binaryDictionary.isValidDictionary());
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
index bc8686410..c67d1fa5e 100644
--- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
@@ -23,15 +23,15 @@ import android.util.Log;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.PrevWordsInfo;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
-import com.android.inputmethod.latin.utils.CollectionUtils;
+import com.android.inputmethod.latin.utils.DistracterFilter;
import com.android.inputmethod.latin.utils.FileUtils;
import java.io.File;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
@@ -102,18 +102,19 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
}
private static List<String> generateWords(final int number, final Random random) {
- final Set<String> wordSet = CollectionUtils.newHashSet();
+ final HashSet<String> wordSet = new HashSet<>();
while (wordSet.size() < number) {
wordSet.add(generateWord(random.nextInt()));
}
- return new ArrayList<String>(wordSet);
+ return new ArrayList<>(wordSet);
}
private static void addToDict(final UserHistoryDictionary dict, final List<String> words) {
- PrevWordsInfo prevWordsInfo = new PrevWordsInfo(null);
+ PrevWordsInfo prevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
for (String word : words) {
UserHistoryDictionary.addToDictionary(dict, prevWordsInfo, word, true,
- (int)TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
+ (int)TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()),
+ DistracterFilter.EMPTY_DISTRACTER_FILTER);
prevWordsInfo = new PrevWordsInfo(word);
}
}
@@ -263,7 +264,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
dict.waitAllTasksForTests();
PrevWordsInfo prevWordsInfo = new PrevWordsInfo(null);
for (final String word : words) {
- UserHistoryDictionary.addToDictionary(dict, prevWordsInfo, word, true, mCurrentTime);
+ UserHistoryDictionary.addToDictionary(dict, prevWordsInfo, word, true, mCurrentTime,
+ DistracterFilter.EMPTY_DISTRACTER_FILTER);
prevWordsInfo = new PrevWordsInfo(word);
dict.waitAllTasksForTests();
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
diff --git a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
index 7fd167977..1501e942a 100644
--- a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
@@ -45,27 +45,27 @@ public class AsyncResultHolderTests extends AndroidTestCase {
}
public void testGetWithoutSet() {
- final AsyncResultHolder<Integer> holder = new AsyncResultHolder<Integer>();
+ final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(DEFAULT_VALUE, resultValue);
}
public void testGetBeforeSet() {
- final AsyncResultHolder<Integer> holder = new AsyncResultHolder<Integer>();
+ final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(DEFAULT_VALUE, resultValue);
}
public void testGetAfterSet() {
- final AsyncResultHolder<Integer> holder = new AsyncResultHolder<Integer>();
+ final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
holder.set(SET_VALUE);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(SET_VALUE, resultValue);
}
public void testGetBeforeTimeout() {
- final AsyncResultHolder<Integer> holder = new AsyncResultHolder<Integer>();
+ final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(SET_VALUE, resultValue);
diff --git a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
index d86639101..a333ee9bc 100644
--- a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
@@ -48,7 +48,7 @@ public class BinaryDictionaryUtilsTests extends AndroidTestCase {
private File createEmptyVer4DictionaryAndGetFile(final String dictId) throws IOException {
final File file = getDictFile(dictId);
FileUtils.deleteRecursively(file);
- Map<String, String> attributeMap = new HashMap<String, String>();
+ Map<String, String> attributeMap = new HashMap<>();
attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, dictId);
attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
diff --git a/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java
new file mode 100644
index 000000000..ae2623d12
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/ExecutorUtilsTests.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.utils;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.util.Log;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Unit tests for ExecutorUtils.
+ */
+@MediumTest
+public class ExecutorUtilsTests extends AndroidTestCase {
+ private static final String TAG = ExecutorUtilsTests.class.getSimpleName();
+
+ private static final String TEST_EXECUTOR_ID = "test";
+ private static final int NUM_OF_TASKS = 10;
+ private static final int DELAY_FOR_WAITING_TASKS_MILLISECONDS = 500;
+
+ public void testExecute() {
+ final ExecutorService executor = ExecutorUtils.getExecutor(TEST_EXECUTOR_ID);
+ final AtomicInteger v = new AtomicInteger(0);
+ for (int i = 0; i < NUM_OF_TASKS; ++i) {
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ v.incrementAndGet();
+ }
+ });
+ }
+ try {
+ executor.awaitTermination(DELAY_FOR_WAITING_TASKS_MILLISECONDS, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Log.d(TAG, "Exception while sleeping.", e);
+ }
+
+ assertEquals(NUM_OF_TASKS, v.get());
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java b/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java
deleted file mode 100644
index e0755483c..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.utils;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.util.Log;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Unit tests for PrioritizedSerialExecutor.
- * TODO: Add more detailed tests to make use of priorities, etc.
- */
-@MediumTest
-public class PrioritizedSerialExecutorTests extends AndroidTestCase {
- private static final String TAG = PrioritizedSerialExecutorTests.class.getSimpleName();
-
- private static final int NUM_OF_TASKS = 10;
- private static final int DELAY_FOR_WAITING_TASKS_MILLISECONDS = 500;
-
- public void testExecute() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
- final AtomicInteger v = new AtomicInteger(0);
- for (int i = 0; i < NUM_OF_TASKS; ++i) {
- executor.execute(new Runnable() {
- @Override
- public void run() {
- v.incrementAndGet();
- }
- });
- }
- try {
- Thread.sleep(DELAY_FOR_WAITING_TASKS_MILLISECONDS);
- } catch (InterruptedException e) {
- Log.d(TAG, "Exception while sleeping.", e);
- }
-
- assertEquals(NUM_OF_TASKS, v.get());
- }
-
- public void testExecutePrioritized() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
- final AtomicInteger v = new AtomicInteger(0);
- for (int i = 0; i < NUM_OF_TASKS; ++i) {
- executor.executePrioritized(new Runnable() {
- @Override
- public void run() {
- v.incrementAndGet();
- }
- });
- }
- try {
- Thread.sleep(DELAY_FOR_WAITING_TASKS_MILLISECONDS);
- } catch (InterruptedException e) {
- Log.d(TAG, "Exception while sleeping.", e);
- }
-
- assertEquals(NUM_OF_TASKS, v.get());
- }
-
- public void testExecuteCombined() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
- final AtomicInteger v = new AtomicInteger(0);
- for (int i = 0; i < NUM_OF_TASKS; ++i) {
- executor.execute(new Runnable() {
- @Override
- public void run() {
- v.incrementAndGet();
- }
- });
- }
-
- for (int i = 0; i < NUM_OF_TASKS; ++i) {
- executor.executePrioritized(new Runnable() {
- @Override
- public void run() {
- v.incrementAndGet();
- }
- });
- }
-
- try {
- Thread.sleep(DELAY_FOR_WAITING_TASKS_MILLISECONDS);
- } catch (InterruptedException e) {
- Log.d(TAG, "Exception while sleeping.", e);
- }
-
- assertEquals(2 * NUM_OF_TASKS, v.get());
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
index 3eb704093..8e764e40f 100644
--- a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java
@@ -24,10 +24,10 @@ import java.util.HashMap;
@SmallTest
public class ResourceUtilsTests extends AndroidTestCase {
public void testFindConstantForKeyValuePairsSimple() {
- final HashMap<String,String> anyKeyValue = CollectionUtils.newHashMap();
+ final HashMap<String,String> anyKeyValue = new HashMap<>();
anyKeyValue.put("anyKey", "anyValue");
final HashMap<String,String> nullKeyValue = null;
- final HashMap<String,String> emptyKeyValue = CollectionUtils.newHashMap();
+ final HashMap<String,String> emptyKeyValue = new HashMap<>();
final String[] nullArray = null;
assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, nullArray));
@@ -48,7 +48,7 @@ public class ResourceUtilsTests extends AndroidTestCase {
"HARDWARE=mako,0.5",
};
- final HashMap<String,String> keyValues = CollectionUtils.newHashMap();
+ final HashMap<String,String> keyValues = new HashMap<>();
keyValues.put(HARDWARE_KEY, "grouper");
assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array));
keyValues.put(HARDWARE_KEY, "mako");
@@ -88,7 +88,7 @@ public class ResourceUtilsTests extends AndroidTestCase {
"HARDWARE=mantaray:MODEL=Nexus 10:MANUFACTURER=samsung,0.2"
};
- final HashMap<String,String> keyValues = CollectionUtils.newHashMap();
+ final HashMap<String,String> keyValues = new HashMap<>();
keyValues.put(HARDWARE_KEY, "grouper");
keyValues.put(MODEL_KEY, "Nexus 7");
keyValues.put(MANUFACTURER_KEY, "asus");
@@ -126,7 +126,7 @@ public class ResourceUtilsTests extends AndroidTestCase {
"HARDWARE=manta.*:MODEL=Nexus 10:MANUFACTURER=samsung,0.2"
};
- final HashMap<String,String> keyValues = CollectionUtils.newHashMap();
+ final HashMap<String,String> keyValues = new HashMap<>();
keyValues.put(HARDWARE_KEY, "grouper");
keyValues.put(MODEL_KEY, "Nexus 7");
keyValues.put(MANUFACTURER_KEY, "asus");
diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java
index ff1103e4f..4156de78b 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java
@@ -31,7 +31,7 @@ import java.util.Locale;
@SmallTest
public class SpacebarLanguagetUtilsTests extends AndroidTestCase {
// All input method subtypes of LatinIME.
- private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
+ private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>();
private RichInputMethodManager mRichImm;
private Resources mRes;
diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
index ee345905c..8e409ab99 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
@@ -31,7 +31,7 @@ import java.util.Locale;
@SmallTest
public class SubtypeLocaleUtilsTests extends AndroidTestCase {
// All input method subtypes of LatinIME.
- private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
+ private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>();
private RichInputMethodManager mRichImm;
private Resources mRes;
diff --git a/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java b/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java
deleted file mode 100644
index 28a9f3d5c..000000000
--- a/tests/src/com/android/inputmethod/research/MotionEventReaderTests.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.research;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.JsonReader;
-
-import com.android.inputmethod.research.MotionEventReader.ReplayData;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-@SmallTest
-public class MotionEventReaderTests extends AndroidTestCase {
- private MotionEventReader mMotionEventReader = new MotionEventReader();
- private ReplayData mReplayData;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mReplayData = new ReplayData();
- }
-
- private JsonReader jsonReaderForString(final String s) {
- return new JsonReader(new StringReader(s));
- }
-
- public void testTopLevelDataVariant() {
- final JsonReader jsonReader = jsonReaderForString(
- "{"
- + "\"_ct\": 1359590400000,"
- + "\"_ut\": 4381933,"
- + "\"_ty\": \"MotionEvent\","
- + "\"action\": \"UP\","
- + "\"isLoggingRelated\": false,"
- + "\"x\": 100.0,"
- + "\"y\": 200.0"
- + "}"
- );
- try {
- mMotionEventReader.readLogStatement(jsonReader, mReplayData);
- } catch (IOException e) {
- e.printStackTrace();
- fail("IOException thrown");
- }
- assertEquals("x set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
- assertEquals("y set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
- assertEquals("only one pointer", mReplayData.mPointerCoordsArrays.get(0).length, 1);
- assertEquals("only one MotionEvent", mReplayData.mPointerCoordsArrays.size(), 1);
- }
-
- public void testNestedDataVariant() {
- final JsonReader jsonReader = jsonReaderForString(
- "{"
- + " \"_ct\": 135959040000,"
- + " \"_ut\": 4382702,"
- + " \"_ty\": \"MotionEvent\","
- + " \"action\": \"MOVE\","
- + " \"isLoggingRelated\": false,"
- + " \"motionEvent\": {"
- + " \"pointerIds\": ["
- + " 0"
- + " ],"
- + " \"xyt\": ["
- + " {"
- + " \"t\": 4382551,"
- + " \"d\": ["
- + " {"
- + " \"x\": 100.0,"
- + " \"y\": 200.0,"
- + " \"toma\": 999.0,"
- + " \"tomi\": 999.0,"
- + " \"o\": 0.0"
- + " }"
- + " ]"
- + " },"
- + " {"
- + " \"t\": 4382559,"
- + " \"d\": ["
- + " {"
- + " \"x\": 300.0,"
- + " \"y\": 400.0,"
- + " \"toma\": 999.0,"
- + " \"tomi\": 999.0,"
- + " \"o\": 0.0"
- + " }"
- + " ]"
- + " }"
- + " ]"
- + " }"
- + "}"
- );
- try {
- mMotionEventReader.readLogStatement(jsonReader, mReplayData);
- } catch (IOException e) {
- e.printStackTrace();
- fail("IOException thrown");
- }
- assertEquals("x1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
- assertEquals("y1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
- assertEquals("x2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(1)[0].x, 300);
- assertEquals("y2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(1)[0].y, 400);
- assertEquals("only one pointer", mReplayData.mPointerCoordsArrays.get(0).length, 1);
- assertEquals("two MotionEvents", mReplayData.mPointerCoordsArrays.size(), 2);
- }
-
- public void testNestedDataVariantMultiPointer() {
- final JsonReader jsonReader = jsonReaderForString(
- "{"
- + " \"_ct\": 135959040000,"
- + " \"_ut\": 4382702,"
- + " \"_ty\": \"MotionEvent\","
- + " \"action\": \"MOVE\","
- + " \"isLoggingRelated\": false,"
- + " \"motionEvent\": {"
- + " \"pointerIds\": ["
- + " 1"
- + " ],"
- + " \"xyt\": ["
- + " {"
- + " \"t\": 4382551,"
- + " \"d\": ["
- + " {"
- + " \"x\": 100.0,"
- + " \"y\": 200.0,"
- + " \"toma\": 999.0,"
- + " \"tomi\": 999.0,"
- + " \"o\": 0.0"
- + " },"
- + " {"
- + " \"x\": 300.0,"
- + " \"y\": 400.0,"
- + " \"toma\": 999.0,"
- + " \"tomi\": 999.0,"
- + " \"o\": 0.0"
- + " }"
- + " ]"
- + " }"
- + " ]"
- + " }"
- + "}"
- );
- try {
- mMotionEventReader.readLogStatement(jsonReader, mReplayData);
- } catch (IOException e) {
- e.printStackTrace();
- fail("IOException thrown");
- }
- assertEquals("x1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].x, 100);
- assertEquals("y1 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[0].y, 200);
- assertEquals("x2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[1].x, 300);
- assertEquals("y2 set correctly", (int) mReplayData.mPointerCoordsArrays.get(0)[1].y, 400);
- assertEquals("two pointers", mReplayData.mPointerCoordsArrays.get(0).length, 2);
- assertEquals("one MotionEvent", mReplayData.mPointerCoordsArrays.size(), 1);
- }
-}