aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/KeyboardLayoutTest.java24
-rw-r--r--tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java20
-rw-r--r--tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java36
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/ContextualDictionaryTests.java77
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java136
8 files changed, 69 insertions, 236 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutTest.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutTest.java
index 9aced5cea..733bf96e2 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutTest.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutTest.java
@@ -45,8 +45,10 @@ public class KeyboardLayoutTest {
assertEquals(0, keyboardLayout.getKeyXCoordinates().length);
assertEquals(0, keyboardLayout.getKeyYCoordinates().length);
- Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101, 2, 2);
- Key key2 = new Key("label2", 201, 202, "201", "201hint", 203, 204, 205, 206, 2100, 2201, 2, 2);
+ Key key1 = new Key("label1", 101, 102, "101", "101hint", 103, 104, 105, 106, 1100, 1101,
+ 10, 10);
+ Key key2 = new Key("label2", 201, 103, "201", "201hint", 203, 204, 205, 206, 2100, 2101,
+ 10, 10);
ArrayList<Key> sortedKeys = new ArrayList<>(2);
sortedKeys.add(key1);
@@ -57,5 +59,23 @@ public class KeyboardLayoutTest {
assertEquals(2, keyboardLayout.getKeyHeights().length);
assertEquals(2, keyboardLayout.getKeyXCoordinates().length);
assertEquals(2, keyboardLayout.getKeyYCoordinates().length);
+
+ assertEquals(102, keyboardLayout.getKeyCodes()[0]);
+ // xCo + horizontalGap/2
+ assertEquals(105 + 5, keyboardLayout.getKeyXCoordinates()[0]);
+ assertEquals(106, keyboardLayout.getKeyYCoordinates()[0]);
+ // width - horizontalGap
+ assertEquals(1100 - 10, keyboardLayout.getKeyWidths()[0]);
+ // height - verticalGap
+ assertEquals(1101 - 10, keyboardLayout.getKeyHeights()[0]);
+
+ assertEquals(103, keyboardLayout.getKeyCodes()[1]);
+ // xCo + horizontalGap/2
+ assertEquals(205 + 5, keyboardLayout.getKeyXCoordinates()[1]);
+ assertEquals(206, keyboardLayout.getKeyYCoordinates()[1]);
+ // width - horizontalGap
+ assertEquals(2100 - 10, keyboardLayout.getKeyWidths()[1]);
+ // height - verticalGap
+ assertEquals(2101 - 10, keyboardLayout.getKeyHeights()[1]);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
index 60d2de18c..a8f0d81af 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
@@ -23,8 +23,8 @@ import android.util.Pair;
import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.common.CodePointUtils;
-import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.FileUtils;
+import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.WeightedString;
@@ -171,7 +171,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
private void testAddTooLongWord(final int formatVersion) {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(formatVersion);
final StringBuffer stringBuilder = new StringBuffer();
- for (int i = 0; i < Constants.DICTIONARY_MAX_WORD_LENGTH; i++) {
+ for (int i = 0; i < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; i++) {
stringBuilder.append('a');
}
final String validLongWord = stringBuilder.toString();
diff --git a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
index 3ad659a99..5340b6fa7 100644
--- a/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
+++ b/tests/src/com/android/inputmethod/latin/DictionaryFacilitatorLruCacheTests.java
@@ -23,12 +23,9 @@ import android.test.suitebuilder.annotation.LargeTest;
@LargeTest
public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
- static final int MAX_CACHE_SIZE = 2;
- static final int MAX_CACHE_SIZE_LARGE = 5;
-
public void testCacheSize() {
final DictionaryFacilitatorLruCache cache =
- new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, "");
+ new DictionaryFacilitatorLruCache(getContext(), "");
assertEquals(0, cache.getCachedLocalesForTesting().size());
assertNotNull(cache.get(Locale.US));
@@ -42,12 +39,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
}
public void testGetFacilitator() {
- testGetFacilitator(new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, ""));
- testGetFacilitator(new DictionaryFacilitatorLruCache(
- getContext(), MAX_CACHE_SIZE_LARGE, ""));
- }
+ final DictionaryFacilitatorLruCache cache =
+ new DictionaryFacilitatorLruCache(getContext(), "");
- private static void testGetFacilitator(final DictionaryFacilitatorLruCache cache) {
final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US);
assertNotNull(dictionaryFacilitatorEnUs);
assertTrue(dictionaryFacilitatorEnUs.isForLocales(new Locale[] { Locale.US }));
@@ -62,13 +56,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
}
public void testSetUseContactsDictionary() {
- testSetUseContactsDictionary(new DictionaryFacilitatorLruCache(
- getContext(), MAX_CACHE_SIZE, ""));
- testSetUseContactsDictionary(new DictionaryFacilitatorLruCache(
- getContext(), MAX_CACHE_SIZE_LARGE, ""));
- }
+ final DictionaryFacilitatorLruCache cache =
+ new DictionaryFacilitatorLruCache(getContext(), "");
- private static void testSetUseContactsDictionary(final DictionaryFacilitatorLruCache cache) {
assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));
cache.setUseContactsDictionary(true /* useContactsDictionary */);
assertNotNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));
diff --git a/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java
new file mode 100644
index 000000000..59bb08292
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 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.common;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+@SmallTest
+public class UnicodeSurrogateTests extends AndroidTestCase {
+
+ public void testIsLowSurrogate() {
+ assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF'));
+ assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D'));
+ assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00'));
+ }
+
+ public void testIsHighSurrogate() {
+ assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF'));
+ assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25'));
+ assertFalse(UnicodeSurrogate.isHighSurrogate('\uE000'));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index b104a21f9..a432ca740 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -17,7 +17,7 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory;
import java.io.File;
@@ -183,7 +183,7 @@ public final class BinaryDictIOUtils {
dictDecoder.readHeader();
int wordPos = 0;
final int wordLen = word.codePointCount(0, word.length());
- for (int depth = 0; depth < Constants.DICTIONARY_MAX_WORD_LENGTH; ++depth) {
+ for (int depth = 0; depth < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; ++depth) {
if (wordPos >= wordLen) return FormatSpec.NOT_VALID_WORD;
do {
diff --git a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index 3cffd001c..a42f0a93d 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -17,7 +17,7 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.define.DecoderSpecificConstants;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import java.util.ArrayList;
@@ -387,7 +387,7 @@ public final class FusionDictionary implements Iterable<WordProperty> {
final ArrayList<WeightedString> shortcutTargets,
final boolean isNotAWord, final boolean isPossiblyOffensive) {
assert(probabilityInfo.mProbability <= FormatSpec.MAX_TERMINAL_FREQUENCY);
- if (word.length >= Constants.DICTIONARY_MAX_WORD_LENGTH) {
+ if (word.length >= DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH) {
MakedictLog.w("Ignoring a word that is too long: word.length = " + word.length);
return;
}
diff --git a/tests/src/com/android/inputmethod/latin/personalization/ContextualDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/ContextualDictionaryTests.java
deleted file mode 100644
index b9ce78d00..000000000
--- a/tests/src/com/android/inputmethod/latin/personalization/ContextualDictionaryTests.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-import com.android.inputmethod.latin.Dictionary;
-import com.android.inputmethod.latin.DictionaryFacilitator;
-import com.android.inputmethod.latin.DictionaryFacilitatorProvider;
-import com.android.inputmethod.latin.ExpandableBinaryDictionary;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Unit tests for contextual dictionary
- */
-@LargeTest
-public class ContextualDictionaryTests extends AndroidTestCase {
- private static final Locale LOCALE_EN_US = new Locale("en", "US");
-
- private DictionaryFacilitator getDictionaryFacilitator() {
- final ArrayList<String> dictTypes = new ArrayList<>();
- dictTypes.add(Dictionary.TYPE_CONTEXTUAL);
- final DictionaryFacilitator dictionaryFacilitator =
- DictionaryFacilitatorProvider.newDictionaryFacilitator();
- dictionaryFacilitator.resetDictionariesForTesting(getContext(),
- new Locale[] { LOCALE_EN_US }, dictTypes, new HashMap<String, File>(),
- Collections.<String, Map<String, String>>emptyMap(), null /* account */);
- return dictionaryFacilitator;
- }
-
- public void testAddPhrase() {
- final DictionaryFacilitator dictionaryFacilitator = getDictionaryFacilitator();
- final String[] phrase = new String[] {"a", "b", "c", "d"};
- final int probability = 100;
- final int bigramProbabilityForWords = 150;
- final int bigramProbabilityForPhrases = 200;
- dictionaryFacilitator.addPhraseToContextualDictionary(
- phrase, probability, bigramProbabilityForWords, bigramProbabilityForPhrases);
- final ExpandableBinaryDictionary contextualDictionary =
- dictionaryFacilitator.getSubDictForTesting(Dictionary.TYPE_CONTEXTUAL);
- contextualDictionary.waitAllTasksForTests();
- // Word
- assertTrue(contextualDictionary.isInDictionary("a"));
- assertTrue(contextualDictionary.isInDictionary("b"));
- assertTrue(contextualDictionary.isInDictionary("c"));
- assertTrue(contextualDictionary.isInDictionary("d"));
- // Phrase
- assertTrue(contextualDictionary.isInDictionary("a b c d"));
- assertTrue(contextualDictionary.isInDictionary("b c d"));
- assertTrue(contextualDictionary.isInDictionary("c d"));
- assertFalse(contextualDictionary.isInDictionary("a b c"));
- assertFalse(contextualDictionary.isInDictionary("abcd"));
- // TODO: Add tests for probability.
- // TODO: Add tests for n-grams.
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java
deleted file mode 100644
index 548167f95..000000000
--- a/tests/src/com/android/inputmethod/latin/personalization/PersonalizationDictionaryTests.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.Collections;
-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.DictionaryFacilitatorProvider;
-import com.android.inputmethod.latin.ExpandableBinaryDictionary;
-import com.android.inputmethod.latin.RichInputMethodManager;
-import com.android.inputmethod.latin.ExpandableBinaryDictionary.UpdateEntriesForInputEventsCallback;
-import com.android.inputmethod.latin.common.CodePointUtils;
-import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-import android.view.inputmethod.InputMethodSubtype;
-
-/**
- * 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 =
- DictionaryFacilitatorProvider.newDictionaryFacilitator(getContext());
- dictionaryFacilitator.resetDictionariesForTesting(getContext(),
- new Locale[] { LOCALE_EN_US }, dictTypes, new HashMap<String, File>(),
- Collections.<String, Map<String, String>>emptyMap(), null /* account */);
- // Set subtypes.
- RichInputMethodManager.init(getContext());
- final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
- final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
- subtypes.add(richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- LOCALE_EN_US.toString(), "qwerty"));
- dictionaryFacilitator.updateEnabledSubtypes(subtypes);
- return dictionaryFacilitator;
- }
-
- public void testAddManyTokens() {
- final DictionaryFacilitator dictionaryFacilitator = getDictionaryFacilitator();
- dictionaryFacilitator.clearPersonalizationDictionary();
- final int dataChunkCount = 100;
- final int wordCountInOneChunk = 200;
- final int uniqueWordCount = 100;
- final Random random = new Random(System.currentTimeMillis());
- final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER;
- final ArrayList<String> words = new ArrayList<>();
- for (int i = 0; i < uniqueWordCount; i++) {
- words.add(CodePointUtils.generateWord(random, codePointSet));
- }
-
- 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(words.get(random.nextInt(words.size())));
- }
- final PersonalizationDataChunk personalizationDataChunk = new PersonalizationDataChunk(
- true /* inputByUser */, tokens, timeStampInSeconds, DUMMY_PACKAGE_NAME,
- LOCALE_EN_US.getLanguage());
- final CountDownLatch countDownLatch = new CountDownLatch(1);
- final UpdateEntriesForInputEventsCallback callback =
- new UpdateEntriesForInputEventsCallback() {
- @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());
- }
-}