aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/utils')
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java25
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java4
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java10
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java26
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java87
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java225
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/EditDistanceTests.java99
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java36
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java36
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java377
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java251
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java176
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java499
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java192
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java282
16 files changed, 824 insertions, 1503 deletions
diff --git a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
index 91c9c3775..1db839506 100644
--- a/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtilsTests.java
@@ -16,6 +16,13 @@
package com.android.inputmethod.latin.utils;
+import static com.android.inputmethod.latin.common.Constants.Subtype.KEYBOARD_MODE;
+import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
+import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
+import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE;
+import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
+import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME;
+
import android.content.Context;
import android.os.Build;
import android.test.AndroidTestCase;
@@ -26,14 +33,6 @@ import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import java.util.Locale;
-import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
-import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue
- .UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME;
-
@SmallTest
public class AdditionalSubtypeUtilsTests extends AndroidTestCase {
@@ -151,25 +150,25 @@ public class AdditionalSubtypeUtilsTests extends AndroidTestCase {
}
public void testRestorable() {
- final InputMethodSubtype EN_UK_DVORAK =
+ final InputMethodSubtype EN_US_DVORAK =
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
Locale.US.toString(), "dvorak");
final InputMethodSubtype ZZ_AZERTY =
AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
- assertEnUsDvorak(EN_UK_DVORAK);
+ assertEnUsDvorak(EN_US_DVORAK);
assertAzerty(ZZ_AZERTY);
// Make sure the subtype can be stored and restored in a deterministic manner.
- final InputMethodSubtype[] subtypes = { EN_UK_DVORAK, ZZ_AZERTY };
+ final InputMethodSubtype[] subtypes = { EN_US_DVORAK, ZZ_AZERTY };
final String prefSubtype = AdditionalSubtypeUtils.createPrefSubtypes(subtypes);
final InputMethodSubtype[] restoredSubtypes =
AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
assertEquals(2, restoredSubtypes.length);
- final InputMethodSubtype restored_EN_UK_DVORAK = restoredSubtypes[0];
+ final InputMethodSubtype restored_EN_US_DVORAK = restoredSubtypes[0];
final InputMethodSubtype restored_ZZ_AZERTY = restoredSubtypes[1];
- assertEnUsDvorak(restored_EN_UK_DVORAK);
+ assertEnUsDvorak(restored_EN_US_DVORAK);
assertAzerty(restored_ZZ_AZERTY);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
index 1501e942a..170d64383 100644
--- a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java
@@ -22,14 +22,14 @@ import android.util.Log;
@MediumTest
public class AsyncResultHolderTests extends AndroidTestCase {
- private static final String TAG = AsyncResultHolderTests.class.getSimpleName();
+ static final String TAG = AsyncResultHolderTests.class.getSimpleName();
private static final int TIMEOUT_IN_MILLISECONDS = 500;
private static final int MARGIN_IN_MILLISECONDS = 250;
private static final int DEFAULT_VALUE = 2;
private static final int SET_VALUE = 1;
- private <T> void setAfterGivenTime(final AsyncResultHolder<T> holder, final T value,
+ private static <T> void setAfterGivenTime(final AsyncResultHolder<T> holder, final T value,
final long time) {
new Thread(new Runnable() {
@Override
diff --git a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
index a333ee9bc..f50b8e0b8 100644
--- a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
@@ -20,6 +20,8 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import com.android.inputmethod.latin.BinaryDictionary;
+import com.android.inputmethod.latin.common.FileUtils;
+import com.android.inputmethod.latin.common.LocaleUtils;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
@@ -39,10 +41,8 @@ public class BinaryDictionaryUtilsTests extends AndroidTestCase {
final int formatVersion) throws IOException {
if (formatVersion == FormatSpec.VERSION4) {
return createEmptyVer4DictionaryAndGetFile(dictId);
- } else {
- throw new IOException("Dictionary format version " + formatVersion
- + " is not supported.");
}
+ throw new IOException("Dictionary format version " + formatVersion + " is not supported.");
}
private File createEmptyVer4DictionaryAndGetFile(final String dictId) throws IOException {
@@ -59,10 +59,8 @@ public class BinaryDictionaryUtilsTests extends AndroidTestCase {
if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), FormatSpec.VERSION4,
LocaleUtils.constructLocaleFromString(TEST_LOCALE), attributeMap)) {
return file;
- } else {
- throw new IOException("Empty dictionary " + file.getAbsolutePath()
- + " cannot be created.");
}
+ throw new IOException("Empty dictionary " + file.getAbsolutePath() + " cannot be created.");
}
private File getDictFile(final String dictId) {
diff --git a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
index c746c8345..9680d85b3 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
@@ -21,8 +21,8 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
+import com.android.inputmethod.latin.common.LocaleUtils;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
-import com.android.inputmethod.latin.utils.LocaleUtils;
import java.util.Locale;
@@ -124,5 +124,29 @@ public class CapsModeUtilsTests extends AndroidTestCase {
allPathsForCaps("Word. ", c | w, sp, false);
// Armenian period : capitalize if MODE_SENTENCES
allPathsForCaps("Word\u0589 ", c | w | s, sp, false);
+
+ // Test for sentence terminators
+ sp = job.runInLocale(res, Locale.ENGLISH);
+ allPathsForCaps("Word? ", c | w | s, sp, false);
+ allPathsForCaps("Word?", c | w | s, sp, true);
+ allPathsForCaps("Word?", c, sp, false);
+ allPathsForCaps("Word! ", c | w | s, sp, false);
+ allPathsForCaps("Word!", c | w | s, sp, true);
+ allPathsForCaps("Word!", c, sp, false);
+ allPathsForCaps("Word; ", c | w, sp, false);
+ allPathsForCaps("Word;", c | w, sp, true);
+ allPathsForCaps("Word;", c, sp, false);
+ // Test for sentence terminators in Greek
+ sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("el"));
+ allPathsForCaps("Word? ", c | w | s, sp, false);
+ allPathsForCaps("Word?", c | w | s, sp, true);
+ allPathsForCaps("Word?", c, sp, false);
+ allPathsForCaps("Word! ", c | w | s, sp, false);
+ allPathsForCaps("Word!", c | w | s, sp, true);
+ allPathsForCaps("Word!", c, sp, false);
+ // In Greek ";" is the question mark and it terminates the sentence
+ allPathsForCaps("Word; ", c | w | s, sp, false);
+ allPathsForCaps("Word;", c | w | s, sp, true);
+ allPathsForCaps("Word;", c, sp, false);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
new file mode 100644
index 000000000..47fd5feaa
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
@@ -0,0 +1,87 @@
+/*
+ * 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.utils;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.inputmethod.latin.common.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * Tests for {@link CollectionUtils}.
+ */
+@SmallTest
+public class CollectionUtilsTests extends AndroidTestCase {
+ /**
+ * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} fails as expected
+ * with some invalid inputs.
+ */
+ public void testArrayAsListFailure() {
+ final String[] array = { "0", "1" };
+ // Negative start
+ try {
+ CollectionUtils.arrayAsList(array, -1, 1);
+ fail("Failed to catch start < 0");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: -1 end: 1 with array.length: 2", e.getMessage());
+ }
+ // start > end
+ try {
+ CollectionUtils.arrayAsList(array, 1, -1);
+ fail("Failed to catch start > end");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: 1 end: -1 with array.length: 2", e.getMessage());
+ }
+ // end > array.length
+ try {
+ CollectionUtils.arrayAsList(array, 1, 3);
+ fail("Failed to catch end > array.length");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: 1 end: 3 with array.length: 2", e.getMessage());
+ }
+ }
+
+ /**
+ * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} gives the expected
+ * results for a few valid inputs.
+ */
+ public void testArrayAsList() {
+ final ArrayList<String> empty = new ArrayList<>();
+ assertEquals(empty, CollectionUtils.arrayAsList(new String[] { }, 0, 0));
+ final String[] array = { "0", "1", "2", "3", "4" };
+ assertEquals(empty, CollectionUtils.arrayAsList(array, 0, 0));
+ assertEquals(empty, CollectionUtils.arrayAsList(array, 1, 1));
+ assertEquals(empty, CollectionUtils.arrayAsList(array, array.length, array.length));
+ final ArrayList<String> expected123 = new ArrayList<>(Arrays.asList("1", "2", "3"));
+ assertEquals(expected123, CollectionUtils.arrayAsList(array, 1, 4));
+ }
+
+ /**
+ * Tests that {@link CollectionUtils#isNullOrEmpty(java.util.Collection)} gives the expected
+ * results for a few cases.
+ */
+ public void testIsNullOrEmpty() {
+ assertTrue(CollectionUtils.isNullOrEmpty(null));
+ assertTrue(CollectionUtils.isNullOrEmpty(new ArrayList<>()));
+ assertTrue(CollectionUtils.isNullOrEmpty(Collections.EMPTY_SET));
+ assertFalse(CollectionUtils.isNullOrEmpty(Collections.singleton("Not empty")));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java b/tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java
new file mode 100644
index 000000000..8360d53fb
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/DistracterFilterTest.java
@@ -0,0 +1,225 @@
+/*
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.view.inputmethod.InputMethodSubtype;
+
+import com.android.inputmethod.latin.NgramContext;
+import com.android.inputmethod.latin.RichInputMethodManager;
+import com.android.inputmethod.latin.utils.DistracterFilter.HandlingType;
+
+/**
+ * Unit test for DistracterFilter
+ */
+@LargeTest
+public class DistracterFilterTest extends AndroidTestCase {
+ private DistracterFilterCheckingExactMatchesAndSuggestions mDistracterFilter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final Context context = getContext();
+ mDistracterFilter = new DistracterFilterCheckingExactMatchesAndSuggestions(context);
+ RichInputMethodManager.init(context);
+ final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
+ final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
+ subtypes.add(richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.US.toString(), "qwerty"));
+ subtypes.add(richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.FRENCH.toString(), "azerty"));
+ subtypes.add(richImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.GERMAN.toString(), "qwertz"));
+ mDistracterFilter.updateEnabledSubtypes(subtypes);
+ }
+
+ @Override
+ protected void tearDown() {
+ mDistracterFilter.close();
+ }
+
+ public void testIsDistracterToWordsInDictionaries() {
+ final NgramContext EMPTY_PREV_WORDS_INFO = NgramContext.EMPTY_PREV_WORDS_INFO;
+
+ final Locale localeEnUs = new Locale("en", "US");
+ String typedWord;
+
+ typedWord = "Bill";
+ // For this test case, we consider "Bill" is a distracter to "bill".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "nOt";
+ // For this test case, we consider "nOt" is a distracter to "not".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ 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 = "Banana";
+ // For this test case, we consider "Banana" is a distracter to "banana".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ 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 "cafe" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "I'll";
+ // For this test case, we consider "I'll" 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 a distracter to "I'll"
+ assertTrue(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(
+ mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "thank";
+ // For this test case, we consider "thank" is not a distracter to any other word
+ // in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "thabk";
+ // For this test case, we consider "thabk" is a distracter to "thank"
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "thanks";
+ // For this test case, we consider "thanks" is not a distracter to any other word
+ // in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "thabks";
+ // For this test case, we consider "thabks" is a distracter to "thanks"
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "think";
+ // For this test case, we consider "think" is not a distracter to any other word
+ // in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "thibk";
+ // For this test case, we consider "thibk" is a distracter to "think"
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "tgis";
+ // For this test case, we consider "tgis" is a distracter to "this"
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ final Locale localeDeDe = new Locale("de");
+
+ typedWord = "fUEr";
+ // For this test case, we consider "fUEr" is a distracter to "für".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe));
+
+ typedWord = "fuer";
+ // For this test case, we consider "fuer" is a distracter to "für".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe));
+
+ typedWord = "fur";
+ // For this test case, we consider "fur" is a distracter to "für".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe));
+
+ final Locale localeFrFr = new Locale("fr");
+
+ typedWord = "a";
+ // For this test case, we consider "a" is a distracter to "à".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr));
+
+ typedWord = "à";
+ // For this test case, we consider "à" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr));
+
+ typedWord = "etre";
+ // For this test case, we consider "etre" is a distracter to "être".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr));
+
+ typedWord = "États-unis";
+ // For this test case, we consider "États-unis" is a distracter to "États-Unis".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr));
+
+ typedWord = "ÉtatsUnis";
+ // For this test case, we consider "ÉtatsUnis" is a distracter to "États-Unis".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr));
+ }
+
+ public void testGetWordHandlingType() {
+ final Locale localeEnUs = new Locale("en", "US");
+ final NgramContext EMPTY_PREV_WORDS_INFO = NgramContext.EMPTY_PREV_WORDS_INFO;
+ int handlingType = 0;
+
+ handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO,
+ "this", localeEnUs);
+ assertFalse(HandlingType.shouldBeLowerCased(handlingType));
+ assertFalse(HandlingType.shouldBeHandledAsOov(handlingType));
+
+ handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO,
+ "This", localeEnUs);
+ assertTrue(HandlingType.shouldBeLowerCased(handlingType));
+ assertFalse(HandlingType.shouldBeHandledAsOov(handlingType));
+
+ handlingType = mDistracterFilter.getWordHandlingType(EMPTY_PREV_WORDS_INFO,
+ "thibk", localeEnUs);
+ assertFalse(HandlingType.shouldBeLowerCased(handlingType));
+ assertTrue(HandlingType.shouldBeHandledAsOov(handlingType));
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/EditDistanceTests.java b/tests/src/com/android/inputmethod/latin/utils/EditDistanceTests.java
deleted file mode 100644
index 58312264b..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/EditDistanceTests.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2010 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.SmallTest;
-
-@SmallTest
-public class EditDistanceTests extends AndroidTestCase {
- /*
- * dist(kitten, sitting) == 3
- *
- * kitten-
- * .|||.|
- * sitting
- */
- public void testExample1() {
- final int dist = BinaryDictionaryUtils.editDistance("kitten", "sitting");
- assertEquals("edit distance between 'kitten' and 'sitting' is 3",
- 3, dist);
- }
-
- /*
- * dist(Sunday, Saturday) == 3
- *
- * Saturday
- * | |.|||
- * S--unday
- */
- public void testExample2() {
- final int dist = BinaryDictionaryUtils.editDistance("Saturday", "Sunday");
- assertEquals("edit distance between 'Saturday' and 'Sunday' is 3",
- 3, dist);
- }
-
- public void testBothEmpty() {
- final int dist = BinaryDictionaryUtils.editDistance("", "");
- assertEquals("when both string are empty, no edits are needed",
- 0, dist);
- }
-
- public void testFirstArgIsEmpty() {
- final int dist = BinaryDictionaryUtils.editDistance("", "aaaa");
- assertEquals("when only one string of the arguments is empty,"
- + " the edit distance is the length of the other.",
- 4, dist);
- }
-
- public void testSecoondArgIsEmpty() {
- final int dist = BinaryDictionaryUtils.editDistance("aaaa", "");
- assertEquals("when only one string of the arguments is empty,"
- + " the edit distance is the length of the other.",
- 4, dist);
- }
-
- public void testSameStrings() {
- final String arg1 = "The quick brown fox jumps over the lazy dog.";
- final String arg2 = "The quick brown fox jumps over the lazy dog.";
- final int dist = BinaryDictionaryUtils.editDistance(arg1, arg2);
- assertEquals("when same strings are passed, distance equals 0.",
- 0, dist);
- }
-
- public void testSameReference() {
- final String arg = "The quick brown fox jumps over the lazy dog.";
- final int dist = BinaryDictionaryUtils.editDistance(arg, arg);
- assertEquals("when same string references are passed, the distance equals 0.",
- 0, dist);
- }
-
- public void testNullArg() {
- try {
- BinaryDictionaryUtils.editDistance(null, "aaa");
- fail("IllegalArgumentException should be thrown.");
- } catch (Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
- try {
- BinaryDictionaryUtils.editDistance("aaa", null);
- fail("IllegalArgumentException should be thrown.");
- } catch (Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
index 819d76328..cbabf7e8d 100644
--- a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java
@@ -16,18 +16,18 @@
package com.android.inputmethod.latin.utils;
-import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION;
+import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;
import android.content.Context;
import android.content.SharedPreferences;
import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.MediumTest;
import android.text.TextUtils;
import java.util.concurrent.TimeUnit;
-@SmallTest
+@MediumTest
public class ImportantNoticeUtilsTests extends AndroidTestCase {
// This should be aligned with R.integer.config_important_notice_version.
private static final int CURRENT_IMPORTANT_NOTICE_VERSION = 1;
@@ -112,6 +112,28 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.getCurrentImportantNoticeVersion(getContext()));
}
+ public void testStateAfterFreshInstall() {
+ mImportantNoticePreferences.clear();
+
+ // Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)}
+ // after fresh install.
+ assertEquals("Has new imortant notice after fresh install", true,
+ ImportantNoticeUtils.hasNewImportantNotice(getContext()));
+ assertEquals("Next important norice title after fresh install", false, TextUtils.isEmpty(
+ ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
+ assertEquals("Is in system setup wizard after fresh install", false,
+ ImportantNoticeUtils.isInSystemSetupWizard(getContext()));
+ final long currentTimeMillis = System.currentTimeMillis();
+ assertEquals("Has timeout passed after fresh install", false,
+ ImportantNoticeUtils.hasTimeoutPassed(getContext(), currentTimeMillis));
+ assertEquals("Timestamp of first important notice after fresh install",
+ (Long)currentTimeMillis,
+ mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
+
+ assertEquals("Current boolean before update", true,
+ ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
+ }
+
public void testUpdateVersion() {
mImportantNoticePreferences.clear();
@@ -163,7 +185,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version before timeout 1", 1,
ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
- assertEquals("Last time before timeout 1", (Long)lastTime,
+ assertEquals("Timestamp of first important notice before timeout 1", (Long)lastTime,
mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
assertEquals("Current title before timeout 1", false, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -180,7 +202,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version before timeout 2", 1,
ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
- assertEquals("Last time before timeout 2", (Long)lastTime,
+ assertEquals("Timestamp of first important notice before timeout 2", (Long)lastTime,
mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
assertEquals("Current title before timeout 2", false, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -196,7 +218,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version after timeout 1", 2,
ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
- assertEquals("Last time aflter timeout 1", null,
+ assertEquals("Timestamp of first important notice after timeout 1", null,
mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
assertEquals("Current title after timeout 1", true, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
@@ -212,7 +234,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
assertEquals("Next version after timeout 2", 2,
ImportantNoticeUtils.getNextImportantNoticeVersion(getContext()));
- assertEquals("Last time aflter timeout 2", null,
+ assertEquals("Timestamp of first important notice after timeout 2", null,
mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));
assertEquals("Current title after timeout 2", true, TextUtils.isEmpty(
ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
diff --git a/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java
new file mode 100644
index 000000000..194112070
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/JsonUtilsTests.java
@@ -0,0 +1,36 @@
+/*
+ * 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.utils;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.util.Arrays;
+import java.util.List;
+
+@SmallTest
+public class JsonUtilsTests extends AndroidTestCase {
+ public void testJsonUtils() {
+ final Object[] objs = new Object[] { 1, "aaa", "bbb", 3 };
+ final List<Object> objArray = Arrays.asList(objs);
+ final String str = JsonUtils.listToJsonStr(objArray);
+ final List<Object> newObjArray = JsonUtils.jsonStrToList(str);
+ for (int i = 0; i < objs.length; ++i) {
+ assertEquals(objs[i], newObjArray.get(i));
+ }
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java b/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
index a3f2ce586..9b826839f 100644
--- a/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/RecapitalizeStatusTests.java
@@ -19,7 +19,7 @@ package com.android.inputmethod.latin.utils;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.common.Constants;
import java.util.Locale;
diff --git a/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java b/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java
deleted file mode 100644
index 8f58e6873..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Copyright (C) 2012 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.SmallTest;
-
-import java.util.Arrays;
-
-@SmallTest
-public class ResizableIntArrayTests extends AndroidTestCase {
- private static final int DEFAULT_CAPACITY = 48;
-
- public void testNewInstance() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int[] array = src.getPrimitiveArray();
- assertEquals("new instance length", 0, src.getLength());
- assertNotNull("new instance array", array);
- assertEquals("new instance array length", DEFAULT_CAPACITY, array.length);
- }
-
- public void testAdd() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int[] array = src.getPrimitiveArray();
- int[] array2 = null, array3 = null;
- final int limit = DEFAULT_CAPACITY * 2 + 10;
- for (int i = 0; i < limit; i++) {
- final int value = i;
- src.add(value);
- assertEquals("length after add " + i, i + 1, src.getLength());
- if (i == DEFAULT_CAPACITY) {
- array2 = src.getPrimitiveArray();
- }
- if (i == DEFAULT_CAPACITY * 2) {
- array3 = src.getPrimitiveArray();
- }
- if (i < DEFAULT_CAPACITY) {
- assertSame("array after add " + i, array, src.getPrimitiveArray());
- } else if (i < DEFAULT_CAPACITY * 2) {
- assertSame("array after add " + i, array2, src.getPrimitiveArray());
- } else if (i < DEFAULT_CAPACITY * 3) {
- assertSame("array after add " + i, array3, src.getPrimitiveArray());
- }
- }
- for (int i = 0; i < limit; i++) {
- final int value = i;
- assertEquals("value at " + i, value, src.get(i));
- }
- }
-
- public void testAddAt() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2;
- for (int i = 0; i < limit; i += step) {
- final int value = i;
- src.addAt(i, value);
- assertEquals("length after add at " + i, i + 1, src.getLength());
- }
- for (int i = 0; i < limit; i += step) {
- final int value = i;
- assertEquals("value at " + i, value, src.get(i));
- }
- }
-
- public void testGet() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- try {
- final int value = src.get(0);
- fail("get(0) shouldn't succeed");
- } catch (ArrayIndexOutOfBoundsException e) {
- // success
- }
- try {
- final int value = src.get(DEFAULT_CAPACITY);
- fail("get(DEFAULT_CAPACITY) shouldn't succeed");
- } catch (ArrayIndexOutOfBoundsException e) {
- // success
- }
-
- final int index = DEFAULT_CAPACITY / 2;
- final int valueAddAt = 100;
- src.addAt(index, valueAddAt);
- assertEquals("legth after add at " + index, index + 1, src.getLength());
- assertEquals("value after add at " + index, valueAddAt, src.get(index));
- assertEquals("value after add at 0", 0, src.get(0));
- try {
- final int value = src.get(src.getLength());
- fail("get(length) shouldn't succeed");
- } catch (ArrayIndexOutOfBoundsException e) {
- // success
- }
- }
-
- public void testReset() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int[] array = src.getPrimitiveArray();
- for (int i = 0; i < DEFAULT_CAPACITY; i++) {
- final int value = i;
- src.add(value);
- assertEquals("length after add " + i, i + 1, src.getLength());
- }
-
- final int smallerLength = DEFAULT_CAPACITY / 2;
- src.reset(smallerLength);
- final int[] array2 = src.getPrimitiveArray();
- assertEquals("length after reset", 0, src.getLength());
- assertNotSame("array after reset", array, array2);
-
- int[] array3 = null;
- for (int i = 0; i < DEFAULT_CAPACITY; i++) {
- final int value = i;
- src.add(value);
- assertEquals("length after add " + i, i + 1, src.getLength());
- if (i == smallerLength) {
- array3 = src.getPrimitiveArray();
- }
- if (i < smallerLength) {
- assertSame("array after add " + i, array2, src.getPrimitiveArray());
- } else if (i < smallerLength * 2) {
- assertSame("array after add " + i, array3, src.getPrimitiveArray());
- }
- }
- }
-
- public void testSetLength() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int[] array = src.getPrimitiveArray();
- for (int i = 0; i < DEFAULT_CAPACITY; i++) {
- final int value = i;
- src.add(value);
- assertEquals("length after add " + i, i + 1, src.getLength());
- }
-
- final int largerLength = DEFAULT_CAPACITY * 2;
- src.setLength(largerLength);
- final int[] array2 = src.getPrimitiveArray();
- assertEquals("length after larger setLength", largerLength, src.getLength());
- assertNotSame("array after larger setLength", array, array2);
- assertEquals("array length after larger setLength", largerLength, array2.length);
- for (int i = 0; i < largerLength; i++) {
- final int value = i;
- if (i < DEFAULT_CAPACITY) {
- assertEquals("value at " + i, value, src.get(i));
- } else {
- assertEquals("value at " + i, 0, src.get(i));
- }
- }
-
- final int smallerLength = DEFAULT_CAPACITY / 2;
- src.setLength(smallerLength);
- final int[] array3 = src.getPrimitiveArray();
- assertEquals("length after smaller setLength", smallerLength, src.getLength());
- assertSame("array after smaller setLength", array2, array3);
- assertEquals("array length after smaller setLength", largerLength, array3.length);
- for (int i = 0; i < smallerLength; i++) {
- final int value = i;
- assertEquals("value at " + i, value, src.get(i));
- }
- }
-
- public void testSet() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int limit = DEFAULT_CAPACITY * 2 + 10;
- for (int i = 0; i < limit; i++) {
- final int value = i;
- src.add(value);
- }
-
- final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY);
- dst.set(src);
- assertEquals("length after set", dst.getLength(), src.getLength());
- assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray());
- }
-
- public void testCopy() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- for (int i = 0; i < DEFAULT_CAPACITY; i++) {
- final int value = i;
- src.add(value);
- }
-
- final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY);
- final int[] array = dst.getPrimitiveArray();
- dst.copy(src);
- assertEquals("length after copy", dst.getLength(), src.getLength());
- assertSame("array after copy", array, dst.getPrimitiveArray());
- assertNotSame("array after copy", dst.getPrimitiveArray(), src.getPrimitiveArray());
- assertIntArrayEquals("values after copy",
- dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength());
-
- final int smallerLength = DEFAULT_CAPACITY / 2;
- dst.reset(smallerLength);
- final int[] array2 = dst.getPrimitiveArray();
- dst.copy(src);
- final int[] array3 = dst.getPrimitiveArray();
- assertEquals("length after copy to smaller", dst.getLength(), src.getLength());
- assertNotSame("array after copy to smaller", array2, array3);
- assertNotSame("array after copy to smaller", array3, src.getPrimitiveArray());
- assertIntArrayEquals("values after copy to smaller",
- dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength());
- }
-
- public void testAppend() {
- final int srcLength = DEFAULT_CAPACITY;
- final ResizableIntArray src = new ResizableIntArray(srcLength);
- for (int i = 0; i < srcLength; i++) {
- final int value = i;
- src.add(value);
- }
- final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY * 2);
- final int[] array = dst.getPrimitiveArray();
- final int dstLength = DEFAULT_CAPACITY / 2;
- for (int i = 0; i < dstLength; i++) {
- final int value = -i - 1;
- dst.add(value);
- }
- final ResizableIntArray dstCopy = new ResizableIntArray(dst.getLength());
- dstCopy.copy(dst);
-
- final int startPos = 0;
- dst.append(src, startPos, 0 /* length */);
- assertEquals("length after append zero", dstLength, dst.getLength());
- assertSame("array after append zero", array, dst.getPrimitiveArray());
- assertIntArrayEquals("values after append zero", dstCopy.getPrimitiveArray(), startPos,
- dst.getPrimitiveArray(), startPos, dstLength);
-
- dst.append(src, startPos, srcLength);
- assertEquals("length after append", dstLength + srcLength, dst.getLength());
- assertSame("array after append", array, dst.getPrimitiveArray());
- assertTrue("primitive length after append",
- dst.getPrimitiveArray().length >= dstLength + srcLength);
- assertIntArrayEquals("original values after append", dstCopy.getPrimitiveArray(), startPos,
- dst.getPrimitiveArray(), startPos, dstLength);
- assertIntArrayEquals("appended values after append", src.getPrimitiveArray(), startPos,
- dst.getPrimitiveArray(), dstLength, srcLength);
-
- dst.append(src, startPos, srcLength);
- assertEquals("length after 2nd append", dstLength + srcLength * 2, dst.getLength());
- assertNotSame("array after 2nd append", array, dst.getPrimitiveArray());
- assertTrue("primitive length after 2nd append",
- dst.getPrimitiveArray().length >= dstLength + srcLength * 2);
- assertIntArrayEquals("original values after 2nd append",
- dstCopy.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), startPos,
- dstLength);
- assertIntArrayEquals("appended values after 2nd append",
- src.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), dstLength,
- srcLength);
- assertIntArrayEquals("appended values after 2nd append",
- src.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), dstLength + srcLength,
- srcLength);
- }
-
- public void testFill() {
- final int srcLength = DEFAULT_CAPACITY;
- final ResizableIntArray src = new ResizableIntArray(srcLength);
- for (int i = 0; i < srcLength; i++) {
- final int value = i;
- src.add(value);
- }
- final int[] array = src.getPrimitiveArray();
-
- final int startPos = srcLength / 3;
- final int length = srcLength / 3;
- final int endPos = startPos + length;
- assertTrue(startPos >= 1);
- final int fillValue = 123;
- try {
- src.fill(fillValue, -1 /* startPos */, length);
- fail("fill from -1 shouldn't succeed");
- } catch (IllegalArgumentException e) {
- // success
- }
- try {
- src.fill(fillValue, startPos, -1 /* length */);
- fail("fill negative length shouldn't succeed");
- } catch (IllegalArgumentException e) {
- // success
- }
-
- src.fill(fillValue, startPos, length);
- assertEquals("length after fill", srcLength, src.getLength());
- assertSame("array after fill", array, src.getPrimitiveArray());
- for (int i = 0; i < srcLength; i++) {
- final int value = i;
- if (i >= startPos && i < endPos) {
- assertEquals("new values after fill at " + i, fillValue, src.get(i));
- } else {
- assertEquals("unmodified values after fill at " + i, value, src.get(i));
- }
- }
-
- final int length2 = srcLength * 2 - startPos;
- final int largeEnd = startPos + length2;
- assertTrue(largeEnd > srcLength);
- final int fillValue2 = 456;
- src.fill(fillValue2, startPos, length2);
- assertEquals("length after large fill", largeEnd, src.getLength());
- assertNotSame("array after large fill", array, src.getPrimitiveArray());
- for (int i = 0; i < largeEnd; i++) {
- final int value = i;
- if (i >= startPos && i < largeEnd) {
- assertEquals("new values after large fill at " + i, fillValue2, src.get(i));
- } else {
- assertEquals("unmodified values after large fill at " + i, value, src.get(i));
- }
- }
-
- final int startPos2 = largeEnd + length2;
- final int endPos2 = startPos2 + length2;
- final int fillValue3 = 789;
- src.fill(fillValue3, startPos2, length2);
- assertEquals("length after disjoint fill", endPos2, src.getLength());
- for (int i = 0; i < endPos2; i++) {
- final int value = i;
- if (i >= startPos2 && i < endPos2) {
- assertEquals("new values after disjoint fill at " + i, fillValue3, src.get(i));
- } else if (i >= startPos && i < largeEnd) {
- assertEquals("unmodified values after disjoint fill at " + i,
- fillValue2, src.get(i));
- } else if (i < startPos) {
- assertEquals("unmodified values after disjoint fill at " + i, value, src.get(i));
- } else {
- assertEquals("gap values after disjoint fill at " + i, 0, src.get(i));
- }
- }
- }
-
- private static void assertIntArrayEquals(final String message, final int[] expecteds,
- final int expectedPos, final int[] actuals, final int actualPos, final int length) {
- if (expecteds == actuals) {
- return;
- }
- if (expecteds == null || actuals == null) {
- assertEquals(message, Arrays.toString(expecteds), Arrays.toString(actuals));
- return;
- }
- if (expecteds.length < expectedPos + length || actuals.length < actualPos + length) {
- fail(message + ": insufficient length: expecteds=" + Arrays.toString(expecteds)
- + " actuals=" + Arrays.toString(actuals));
- return;
- }
- for (int i = 0; i < length; i++) {
- assertEquals(message + " [" + i + "]",
- expecteds[i + expectedPos], actuals[i + actualPos]);
- }
- }
-
- public void testShift() {
- final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY);
- final int limit = DEFAULT_CAPACITY * 10;
- final int shiftAmount = 20;
- for (int i = 0; i < limit; ++i) {
- final int value = i;
- src.addAt(i, value);
- assertEquals("length after add at " + i, i + 1, src.getLength());
- }
- src.shift(shiftAmount);
- for (int i = 0; i < limit - shiftAmount; ++i) {
- final int oldValue = i + shiftAmount;
- assertEquals("value at " + i, oldValue, src.get(i));
- }
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java
deleted file mode 100644
index fdde34251..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (C) 2011 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.content.Context;
-import android.content.res.Resources;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.view.inputmethod.InputMethodInfo;
-import android.view.inputmethod.InputMethodSubtype;
-
-import com.android.inputmethod.latin.RichInputMethodManager;
-
-import java.util.ArrayList;
-import java.util.Locale;
-
-@SmallTest
-public class SpacebarLanguagetUtilsTests extends AndroidTestCase {
- // All input method subtypes of LatinIME.
- private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>();
-
- private RichInputMethodManager mRichImm;
- private Resources mRes;
-
- InputMethodSubtype EN_US;
- InputMethodSubtype EN_GB;
- InputMethodSubtype ES_US;
- InputMethodSubtype FR;
- InputMethodSubtype FR_CA;
- InputMethodSubtype FR_CH;
- InputMethodSubtype DE;
- InputMethodSubtype DE_CH;
- InputMethodSubtype ZZ;
- InputMethodSubtype DE_QWERTY;
- InputMethodSubtype FR_QWERTZ;
- InputMethodSubtype EN_US_AZERTY;
- InputMethodSubtype EN_UK_DVORAK;
- InputMethodSubtype ES_US_COLEMAK;
- InputMethodSubtype ZZ_AZERTY;
- InputMethodSubtype ZZ_PC;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- final Context context = getContext();
- RichInputMethodManager.init(context);
- mRichImm = RichInputMethodManager.getInstance();
- mRes = context.getResources();
- SubtypeLocaleUtils.init(context);
-
- final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
- final int subtypeCount = imi.getSubtypeCount();
- for (int index = 0; index < subtypeCount; index++) {
- final InputMethodSubtype subtype = imi.getSubtypeAt(index);
- mSubtypesList.add(subtype);
- }
-
- EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- Locale.US.toString(), "qwerty");
- EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- Locale.UK.toString(), "qwerty");
- ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- "es_US", "spanish");
- FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- Locale.FRENCH.toString(), "azerty");
- FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- Locale.CANADA_FRENCH.toString(), "qwerty");
- FR_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- "fr_CH", "swiss");
- DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- Locale.GERMAN.toString(), "qwertz");
- DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- "de_CH", "swiss");
- ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
- SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
- DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- Locale.GERMAN.toString(), "qwerty");
- FR_QWERTZ = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- Locale.FRENCH.toString(), "qwertz");
- EN_US_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- Locale.US.toString(), "azerty");
- EN_UK_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- Locale.UK.toString(), "dvorak");
- ES_US_COLEMAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- "es_US", "colemak");
- ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
- ZZ_PC = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
- SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty");
- }
-
- public void testAllFullDisplayNameForSpacebar() {
- for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocaleUtils
- .getSubtypeDisplayNameInSystemLocale(subtype);
- final String spacebarText = SpacebarLanguageUtils.getFullDisplayName(subtype);
- final String languageName = SubtypeLocaleUtils
- .getSubtypeLocaleDisplayName(subtype.getLocale());
- if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
- assertFalse(subtypeName, spacebarText.contains(languageName));
- } else {
- assertTrue(subtypeName, spacebarText.contains(languageName));
- }
- }
- }
-
- public void testAllMiddleDisplayNameForSpacebar() {
- for (final InputMethodSubtype subtype : mSubtypesList) {
- final String subtypeName = SubtypeLocaleUtils
- .getSubtypeDisplayNameInSystemLocale(subtype);
- final String spacebarText = SpacebarLanguageUtils.getMiddleDisplayName(subtype);
- if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
- assertEquals(subtypeName,
- SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype), spacebarText);
- } else {
- final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
- assertEquals(subtypeName,
- SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()),
- spacebarText);
- }
- }
- }
-
- // InputMethodSubtype's display name for spacebar text in its locale.
- // isAdditionalSubtype (T=true, F=false)
- // locale layout | Middle Full
- // ------ ------- - --------- ----------------------
- // en_US qwerty F English English (US) exception
- // en_GB qwerty F English English (UK) exception
- // es_US spanish F Español Español (EE.UU.) exception
- // fr azerty F Français Français
- // fr_CA qwerty F Français Français (Canada)
- // fr_CH swiss F Français Français (Suisse)
- // de qwertz F Deutsch Deutsch
- // de_CH swiss F Deutsch Deutsch (Schweiz)
- // zz qwerty F QWERTY QWERTY
- // fr qwertz T Français Français
- // de qwerty T Deutsch Deutsch
- // en_US azerty T English English (US)
- // zz azerty T AZERTY AZERTY
-
- private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() {
- @Override
- protected Void job(final Resources res) {
- assertEquals("en_US", "English (US)",
- SpacebarLanguageUtils.getFullDisplayName(EN_US));
- assertEquals("en_GB", "English (UK)",
- SpacebarLanguageUtils.getFullDisplayName(EN_GB));
- assertEquals("es_US", "Español (EE.UU.)",
- SpacebarLanguageUtils.getFullDisplayName(ES_US));
- assertEquals("fr", "Français",
- SpacebarLanguageUtils.getFullDisplayName(FR));
- assertEquals("fr_CA", "Français (Canada)",
- SpacebarLanguageUtils.getFullDisplayName(FR_CA));
- assertEquals("fr_CH", "Français (Suisse)",
- SpacebarLanguageUtils.getFullDisplayName(FR_CH));
- assertEquals("de", "Deutsch",
- SpacebarLanguageUtils.getFullDisplayName(DE));
- assertEquals("de_CH", "Deutsch (Schweiz)",
- SpacebarLanguageUtils.getFullDisplayName(DE_CH));
- assertEquals("zz", "QWERTY",
- SpacebarLanguageUtils.getFullDisplayName(ZZ));
-
- assertEquals("en_US", "English",
- SpacebarLanguageUtils.getMiddleDisplayName(EN_US));
- assertEquals("en_GB", "English",
- SpacebarLanguageUtils.getMiddleDisplayName(EN_GB));
- assertEquals("es_US", "Español",
- SpacebarLanguageUtils.getMiddleDisplayName(ES_US));
- assertEquals("fr", "Français",
- SpacebarLanguageUtils.getMiddleDisplayName(FR));
- assertEquals("fr_CA", "Français",
- SpacebarLanguageUtils.getMiddleDisplayName(FR_CA));
- assertEquals("fr_CH", "Français",
- SpacebarLanguageUtils.getMiddleDisplayName(FR_CH));
- assertEquals("de", "Deutsch",
- SpacebarLanguageUtils.getMiddleDisplayName(DE));
- assertEquals("de_CH", "Deutsch",
- SpacebarLanguageUtils.getMiddleDisplayName(DE_CH));
- assertEquals("zz", "QWERTY",
- SpacebarLanguageUtils.getMiddleDisplayName(ZZ));
- return null;
- }
- };
-
- private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() {
- @Override
- protected Void job(final Resources res) {
- assertEquals("fr qwertz", "Français",
- SpacebarLanguageUtils.getFullDisplayName(FR_QWERTZ));
- assertEquals("de qwerty", "Deutsch",
- SpacebarLanguageUtils.getFullDisplayName(DE_QWERTY));
- assertEquals("en_US azerty", "English (US)",
- SpacebarLanguageUtils.getFullDisplayName(EN_US_AZERTY));
- assertEquals("en_UK dvorak", "English (UK)",
- SpacebarLanguageUtils.getFullDisplayName(EN_UK_DVORAK));
- assertEquals("es_US colemak", "Español (EE.UU.)",
- SpacebarLanguageUtils.getFullDisplayName(ES_US_COLEMAK));
- assertEquals("zz azerty", "AZERTY",
- SpacebarLanguageUtils.getFullDisplayName(ZZ_AZERTY));
- assertEquals("zz pc", "PC",
- SpacebarLanguageUtils.getFullDisplayName(ZZ_PC));
-
- assertEquals("fr qwertz", "Français",
- SpacebarLanguageUtils.getMiddleDisplayName(FR_QWERTZ));
- assertEquals("de qwerty", "Deutsch",
- SpacebarLanguageUtils.getMiddleDisplayName(DE_QWERTY));
- assertEquals("en_US azerty", "English",
- SpacebarLanguageUtils.getMiddleDisplayName(EN_US_AZERTY));
- assertEquals("en_UK dvorak", "English",
- SpacebarLanguageUtils.getMiddleDisplayName(EN_UK_DVORAK));
- assertEquals("es_US colemak", "Español",
- SpacebarLanguageUtils.getMiddleDisplayName(ES_US_COLEMAK));
- assertEquals("zz azerty", "AZERTY",
- SpacebarLanguageUtils.getMiddleDisplayName(ZZ_AZERTY));
- assertEquals("zz pc", "PC",
- SpacebarLanguageUtils.getMiddleDisplayName(ZZ_PC));
- return null;
- }
- };
-
- public void testPredefinedSubtypesForSpacebarInEnglish() {
- testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
- }
-
- public void testAdditionalSubtypeForSpacebarInEnglish() {
- testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
- }
-
- public void testPredefinedSubtypesForSpacebarInFrench() {
- testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
- }
-
- public void testAdditionalSubtypeForSpacebarInFrench() {
- testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
index fa6ad16c1..665d81ccd 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
@@ -20,9 +20,10 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.style.SuggestionSpan;
import android.text.style.URLSpan;
+import android.text.SpannableString;
import android.text.SpannableStringBuilder;
-import android.text.Spannable;
import android.text.Spanned;
+import android.text.SpannedString;
@SmallTest
public class SpannableStringUtilsTests extends AndroidTestCase {
@@ -34,8 +35,8 @@ public class SpannableStringUtilsTests extends AndroidTestCase {
for (int i = 0; i < N; ++i) {
// Put a PARAGRAPH-flagged span that should not be found in the result.
s.setSpan(new SuggestionSpan(getContext(),
- new String[] {"" + i}, Spannable.SPAN_PARAGRAPH),
- i * 12, i * 12 + 12, Spannable.SPAN_PARAGRAPH);
+ new String[] {"" + i}, Spanned.SPAN_PARAGRAPH),
+ i * 12, i * 12 + 12, Spanned.SPAN_PARAGRAPH);
// Put a normal suggestion span that should be found in the result.
s.setSpan(new SuggestionSpan(getContext(), new String[] {"" + i}, 0), i, i * 2, 0);
// Put a URL span than should not be found in the result.
@@ -51,8 +52,175 @@ public class SpannableStringUtilsTests extends AndroidTestCase {
for (int i = 0; i < spans.length; i++) {
final int flags = result.getSpanFlags(spans[i]);
assertEquals("Should not find a span with PARAGRAPH flag",
- flags & Spannable.SPAN_PARAGRAPH, 0);
+ flags & Spanned.SPAN_PARAGRAPH, 0);
assertTrue("Should be a SuggestionSpan", spans[i] instanceof SuggestionSpan);
}
}
+
+ private static void assertSpanCount(final int expectedCount, final CharSequence cs) {
+ final int actualCount;
+ if (cs instanceof Spanned) {
+ final Spanned spanned = (Spanned) cs;
+ actualCount = spanned.getSpans(0, spanned.length(), Object.class).length;
+ } else {
+ actualCount = 0;
+ }
+ assertEquals(expectedCount, actualCount);
+ }
+
+ private static void assertSpan(final CharSequence cs, final Object expectedSpan,
+ final int expectedStart, final int expectedEnd, final int expectedFlags) {
+ assertTrue(cs instanceof Spanned);
+ final Spanned spanned = (Spanned) cs;
+ final Object[] actualSpans = spanned.getSpans(0, spanned.length(), Object.class);
+ for (Object actualSpan : actualSpans) {
+ if (actualSpan == expectedSpan) {
+ final int actualStart = spanned.getSpanStart(actualSpan);
+ final int actualEnd = spanned.getSpanEnd(actualSpan);
+ final int actualFlags = spanned.getSpanFlags(actualSpan);
+ assertEquals(expectedStart, actualStart);
+ assertEquals(expectedEnd, actualEnd);
+ assertEquals(expectedFlags, actualFlags);
+ return;
+ }
+ }
+ assertTrue(false);
+ }
+
+ public void testSplitCharSequenceWithSpan() {
+ // text: " a bcd efg hij "
+ // span1: ^^^^^^^
+ // span2: ^^^^^
+ // span3: ^
+ final SpannableString spannableString = new SpannableString(" a bcd efg hij ");
+ final Object span1 = new Object();
+ final Object span2 = new Object();
+ final Object span3 = new Object();
+ final int SPAN1_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
+ final int SPAN2_FLAGS = Spanned.SPAN_EXCLUSIVE_INCLUSIVE;
+ final int SPAN3_FLAGS = Spanned.SPAN_INCLUSIVE_INCLUSIVE;
+ spannableString.setSpan(span1, 0, 7, SPAN1_FLAGS);
+ spannableString.setSpan(span2, 0, 5, SPAN2_FLAGS);
+ spannableString.setSpan(span3, 12, 13, SPAN3_FLAGS);
+ final CharSequence[] charSequencesFromSpanned = SpannableStringUtils.split(
+ spannableString, " ", true /* preserveTrailingEmptySegmengs */);
+ final CharSequence[] charSequencesFromString = SpannableStringUtils.split(
+ spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */);
+
+
+ assertEquals(7, charSequencesFromString.length);
+ assertEquals(7, charSequencesFromSpanned.length);
+
+ // text: ""
+ // span1: ^
+ // span2: ^
+ // span3:
+ assertEquals("", charSequencesFromString[0].toString());
+ assertSpanCount(0, charSequencesFromString[0]);
+ assertEquals("", charSequencesFromSpanned[0].toString());
+ assertSpanCount(2, charSequencesFromSpanned[0]);
+ assertSpan(charSequencesFromSpanned[0], span1, 0, 0, SPAN1_FLAGS);
+ assertSpan(charSequencesFromSpanned[0], span2, 0, 0, SPAN2_FLAGS);
+
+ // text: "a"
+ // span1: ^
+ // span2: ^
+ // span3:
+ assertEquals("a", charSequencesFromString[1].toString());
+ assertSpanCount(0, charSequencesFromString[1]);
+ assertEquals("a", charSequencesFromSpanned[1].toString());
+ assertSpanCount(2, charSequencesFromSpanned[1]);
+ assertSpan(charSequencesFromSpanned[1], span1, 0, 1, SPAN1_FLAGS);
+ assertSpan(charSequencesFromSpanned[1], span2, 0, 1, SPAN2_FLAGS);
+
+ // text: "bcd"
+ // span1: ^^^
+ // span2: ^^
+ // span3:
+ assertEquals("bcd", charSequencesFromString[2].toString());
+ assertSpanCount(0, charSequencesFromString[2]);
+ assertEquals("bcd", charSequencesFromSpanned[2].toString());
+ assertSpanCount(2, charSequencesFromSpanned[2]);
+ assertSpan(charSequencesFromSpanned[2], span1, 0, 3, SPAN1_FLAGS);
+ assertSpan(charSequencesFromSpanned[2], span2, 0, 2, SPAN2_FLAGS);
+
+ // text: "efg"
+ // span1:
+ // span2:
+ // span3:
+ assertEquals("efg", charSequencesFromString[3].toString());
+ assertSpanCount(0, charSequencesFromString[3]);
+ assertEquals("efg", charSequencesFromSpanned[3].toString());
+ assertSpanCount(0, charSequencesFromSpanned[3]);
+
+ // text: "hij"
+ // span1:
+ // span2:
+ // span3: ^
+ assertEquals("hij", charSequencesFromString[4].toString());
+ assertSpanCount(0, charSequencesFromString[4]);
+ assertEquals("hij", charSequencesFromSpanned[4].toString());
+ assertSpanCount(1, charSequencesFromSpanned[4]);
+ assertSpan(charSequencesFromSpanned[4], span3, 1, 2, SPAN3_FLAGS);
+
+ // text: ""
+ // span1:
+ // span2:
+ // span3:
+ assertEquals("", charSequencesFromString[5].toString());
+ assertSpanCount(0, charSequencesFromString[5]);
+ assertEquals("", charSequencesFromSpanned[5].toString());
+ assertSpanCount(0, charSequencesFromSpanned[5]);
+
+ // text: ""
+ // span1:
+ // span2:
+ // span3:
+ assertEquals("", charSequencesFromString[6].toString());
+ assertSpanCount(0, charSequencesFromString[6]);
+ assertEquals("", charSequencesFromSpanned[6].toString());
+ assertSpanCount(0, charSequencesFromSpanned[6]);
+ }
+
+ public void testSplitCharSequencePreserveTrailingEmptySegmengs() {
+ assertEquals(1, SpannableStringUtils.split("", " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(1, SpannableStringUtils.split("", " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(0, SpannableStringUtils.split(" ", " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(0, SpannableStringUtils.split(new SpannedString(" "), " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(2, SpannableStringUtils.split(" ", " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(2, SpannableStringUtils.split(new SpannedString(" "), " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(3, SpannableStringUtils.split("a b c ", " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(3, SpannableStringUtils.split(new SpannedString("a b c "), " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(5, SpannableStringUtils.split("a b c ", " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(5, SpannableStringUtils.split(new SpannedString("a b c "), " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(6, SpannableStringUtils.split("a b ", " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(6, SpannableStringUtils.split(new SpannedString("a b "), " ",
+ false /* preserveTrailingEmptySegmengs */).length);
+
+ assertEquals(7, SpannableStringUtils.split("a b ", " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+ assertEquals(7, SpannableStringUtils.split(new SpannedString("a b "), " ",
+ true /* preserveTrailingEmptySegmengs */).length);
+ }
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
deleted file mode 100644
index 637ae10ee..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- * Copyright (C) 2012 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.SmallTest;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.SpannedString;
-
-import com.android.inputmethod.latin.Constants;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-
-@SmallTest
-public class StringAndJsonUtilsTests extends AndroidTestCase {
- public void testContainsInArray() {
- assertFalse("empty array", StringUtils.containsInArray("key", new String[0]));
- assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] {
- "key1"
- }));
- assertFalse("not in 2 elements", StringUtils.containsInArray("key", new String[] {
- "key1", "key2"
- }));
-
- assertTrue("in 1 element", StringUtils.containsInArray("key", new String[] {
- "key"
- }));
- assertTrue("in 2 elements", StringUtils.containsInArray("key", new String[] {
- "key1", "key"
- }));
- }
-
- public void testContainsInCommaSplittableText() {
- assertFalse("null", StringUtils.containsInCommaSplittableText("key", null));
- assertFalse("empty", StringUtils.containsInCommaSplittableText("key", ""));
- assertFalse("not in 1 element",
- StringUtils.containsInCommaSplittableText("key", "key1"));
- assertFalse("not in 2 elements",
- StringUtils.containsInCommaSplittableText("key", "key1,key2"));
-
- assertTrue("in 1 element", StringUtils.containsInCommaSplittableText("key", "key"));
- assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key"));
- }
-
- public void testRemoveFromCommaSplittableTextIfExists() {
- assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null));
- assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", ""));
-
- assertEquals("not in 1 element", "key1",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key1"));
- assertEquals("not in 2 elements", "key1,key2",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key2"));
-
- assertEquals("in 1 element", "",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key"));
- assertEquals("in 2 elements at position 1", "key2",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key2"));
- assertEquals("in 2 elements at position 2", "key1",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key"));
- assertEquals("in 3 elements at position 2", "key1,key3",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key,key3"));
-
- assertEquals("in 3 elements at position 1,2,3", "",
- StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key,key"));
- assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
- StringUtils.removeFromCommaSplittableTextIfExists(
- "key", "key1,key,key3,key,key5"));
- }
-
-
- public void testCapitalizeFirstCodePoint() {
- assertEquals("SSaa",
- StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN));
- assertEquals("Aßa",
- StringUtils.capitalizeFirstCodePoint("aßa", Locale.GERMAN));
- assertEquals("Iab",
- StringUtils.capitalizeFirstCodePoint("iab", Locale.ENGLISH));
- assertEquals("CAmElCaSe",
- StringUtils.capitalizeFirstCodePoint("cAmElCaSe", Locale.ENGLISH));
- assertEquals("İab",
- StringUtils.capitalizeFirstCodePoint("iab", new Locale("tr")));
- assertEquals("AİB",
- StringUtils.capitalizeFirstCodePoint("AİB", new Locale("tr")));
- assertEquals("A",
- StringUtils.capitalizeFirstCodePoint("a", Locale.ENGLISH));
- assertEquals("A",
- StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH));
- }
-
- public void testCapitalizeFirstAndDowncaseRest() {
- assertEquals("SSaa",
- StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN));
- assertEquals("Aßa",
- StringUtils.capitalizeFirstAndDowncaseRest("aßa", Locale.GERMAN));
- assertEquals("Iab",
- StringUtils.capitalizeFirstAndDowncaseRest("iab", Locale.ENGLISH));
- assertEquals("Camelcase",
- StringUtils.capitalizeFirstAndDowncaseRest("cAmElCaSe", Locale.ENGLISH));
- assertEquals("İab",
- StringUtils.capitalizeFirstAndDowncaseRest("iab", new Locale("tr")));
- assertEquals("Aib",
- StringUtils.capitalizeFirstAndDowncaseRest("AİB", new Locale("tr")));
- assertEquals("A",
- StringUtils.capitalizeFirstAndDowncaseRest("a", Locale.ENGLISH));
- assertEquals("A",
- StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH));
- }
-
- public void testGetCapitalizationType() {
- assertEquals(StringUtils.CAPITALIZE_NONE,
- StringUtils.getCapitalizationType("capitalize"));
- assertEquals(StringUtils.CAPITALIZE_NONE,
- StringUtils.getCapitalizationType("cApITalize"));
- assertEquals(StringUtils.CAPITALIZE_NONE,
- StringUtils.getCapitalizationType("capitalizE"));
- assertEquals(StringUtils.CAPITALIZE_NONE,
- StringUtils.getCapitalizationType("__c a piu$@tali56ze"));
- assertEquals(StringUtils.CAPITALIZE_FIRST,
- StringUtils.getCapitalizationType("A__c a piu$@tali56ze"));
- assertEquals(StringUtils.CAPITALIZE_FIRST,
- StringUtils.getCapitalizationType("Capitalize"));
- assertEquals(StringUtils.CAPITALIZE_FIRST,
- StringUtils.getCapitalizationType(" Capitalize"));
- assertEquals(StringUtils.CAPITALIZE_ALL,
- StringUtils.getCapitalizationType("CAPITALIZE"));
- assertEquals(StringUtils.CAPITALIZE_ALL,
- StringUtils.getCapitalizationType(" PI26LIE"));
- assertEquals(StringUtils.CAPITALIZE_NONE,
- StringUtils.getCapitalizationType(""));
- }
-
- public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() {
- assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize"));
- assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize"));
- assertFalse(StringUtils.isIdenticalAfterUpcase("cApITalize"));
- assertFalse(StringUtils.isIdenticalAfterDowncase("cApITalize"));
- assertFalse(StringUtils.isIdenticalAfterUpcase("capitalizE"));
- assertFalse(StringUtils.isIdenticalAfterDowncase("capitalizE"));
- assertFalse(StringUtils.isIdenticalAfterUpcase("__c a piu$@tali56ze"));
- assertTrue(StringUtils.isIdenticalAfterDowncase("__c a piu$@tali56ze"));
- assertFalse(StringUtils.isIdenticalAfterUpcase("A__c a piu$@tali56ze"));
- assertFalse(StringUtils.isIdenticalAfterDowncase("A__c a piu$@tali56ze"));
- assertFalse(StringUtils.isIdenticalAfterUpcase("Capitalize"));
- assertFalse(StringUtils.isIdenticalAfterDowncase("Capitalize"));
- assertFalse(StringUtils.isIdenticalAfterUpcase(" Capitalize"));
- assertFalse(StringUtils.isIdenticalAfterDowncase(" Capitalize"));
- assertTrue(StringUtils.isIdenticalAfterUpcase("CAPITALIZE"));
- assertFalse(StringUtils.isIdenticalAfterDowncase("CAPITALIZE"));
- assertTrue(StringUtils.isIdenticalAfterUpcase(" PI26LIE"));
- assertFalse(StringUtils.isIdenticalAfterDowncase(" PI26LIE"));
- assertTrue(StringUtils.isIdenticalAfterUpcase(""));
- assertTrue(StringUtils.isIdenticalAfterDowncase(""));
- }
-
- private static void checkCapitalize(final String src, final String dst,
- final int[] sortedSeparators, final Locale locale) {
- assertEquals(dst, StringUtils.capitalizeEachWord(src, sortedSeparators, locale));
- assert(src.equals(dst)
- == StringUtils.isIdenticalAfterCapitalizeEachWord(src, sortedSeparators));
- }
-
- private static final int[] SPACE = { Constants.CODE_SPACE };
- private static final int[] SPACE_PERIOD = StringUtils.toSortedCodePointArray(" .");
- private static final int[] SENTENCE_SEPARATORS =
- StringUtils.toSortedCodePointArray(" \n.!?*()&");
- private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&");
-
- public void testCapitalizeEachWord() {
- checkCapitalize("", "", SPACE, Locale.ENGLISH);
- checkCapitalize("test", "Test", SPACE, Locale.ENGLISH);
- checkCapitalize(" test", " Test", SPACE, Locale.ENGLISH);
- checkCapitalize("Test", "Test", SPACE, Locale.ENGLISH);
- checkCapitalize(" Test", " Test", SPACE, Locale.ENGLISH);
- checkCapitalize(".Test", ".test", SPACE, Locale.ENGLISH);
- checkCapitalize(".Test", ".Test", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("test and retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test and retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test And Retest", "Test And Retest", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test And.Retest ", "Test And.Retest ", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test And.retest ", "Test And.Retest ", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test And.retest ", "Test And.retest ", SPACE, Locale.ENGLISH);
- checkCapitalize("Test And.Retest ", "Test And.retest ", SPACE, Locale.ENGLISH);
- checkCapitalize("test and ietest", "Test And İetest", SPACE_PERIOD, new Locale("tr"));
- checkCapitalize("test and ietest", "Test And Ietest", SPACE_PERIOD, Locale.ENGLISH);
- checkCapitalize("Test&Retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("Test&retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("test&Retest", "Test&Retest", SENTENCE_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("rest\nrecreation! And in the end...",
- "Rest\nRecreation! And In The End...", WORD_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("lorem ipsum dolor sit amet", "Lorem Ipsum Dolor Sit Amet",
- WORD_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("Lorem!Ipsum (Dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet",
- WORD_SEPARATORS, Locale.ENGLISH);
- checkCapitalize("Lorem!Ipsum (dolor) Sit * Amet", "Lorem!Ipsum (Dolor) Sit * Amet",
- WORD_SEPARATORS, Locale.ENGLISH);
- }
-
- public void testLooksLikeURL() {
- assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google."));
- assertFalse(StringUtils.lastPartLooksLikeURL("word wo"));
- assertTrue(StringUtils.lastPartLooksLikeURL("/etc/foo"));
- assertFalse(StringUtils.lastPartLooksLikeURL("left/right"));
- assertTrue(StringUtils.lastPartLooksLikeURL("www.goo"));
- assertTrue(StringUtils.lastPartLooksLikeURL("www."));
- assertFalse(StringUtils.lastPartLooksLikeURL("U.S.A"));
- assertFalse(StringUtils.lastPartLooksLikeURL("U.S.A."));
- assertTrue(StringUtils.lastPartLooksLikeURL("rtsp://foo."));
- assertTrue(StringUtils.lastPartLooksLikeURL("://"));
- assertFalse(StringUtils.lastPartLooksLikeURL("abc/"));
- assertTrue(StringUtils.lastPartLooksLikeURL("abc.def/ghi"));
- assertFalse(StringUtils.lastPartLooksLikeURL("abc.def"));
- // TODO: ideally this would not look like a URL, but to keep down the complexity of the
- // code for now True is acceptable.
- assertTrue(StringUtils.lastPartLooksLikeURL("abc./def"));
- // TODO: ideally this would not look like a URL, but to keep down the complexity of the
- // code for now True is acceptable.
- assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def"));
- }
-
- public void testHexStringUtils() {
- final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33,
- (byte)0x55, (byte)0x88, (byte)0xEE };
- final String bytesStr = StringUtils.byteArrayToHexString(bytes);
- final byte[] bytes2 = StringUtils.hexStringToByteArray(bytesStr);
- for (int i = 0; i < bytes.length; ++i) {
- assertTrue(bytes[i] == bytes2[i]);
- }
- final String bytesStr2 = StringUtils.byteArrayToHexString(bytes2);
- assertTrue(bytesStr.equals(bytesStr2));
- }
-
- public void testJsonUtils() {
- final Object[] objs = new Object[] { 1, "aaa", "bbb", 3 };
- final List<Object> objArray = Arrays.asList(objs);
- final String str = JsonUtils.listToJsonStr(objArray);
- final List<Object> newObjArray = JsonUtils.jsonStrToList(str);
- for (int i = 0; i < objs.length; ++i) {
- assertEquals(objs[i], newObjArray.get(i));
- }
- }
-
- public void testToCodePointArray() {
- final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx";
- final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h',
- 0, 0x2002, 0x2003, 0x3000, 'x', 'x'};
- final int[] codePointArray = StringUtils.toCodePointArray(STR_WITH_SUPPLEMENTARY_CHAR, 0,
- STR_WITH_SUPPLEMENTARY_CHAR.length());
- assertEquals("toCodePointArray, size matches", codePointArray.length,
- EXPECTED_RESULT.length);
- for (int i = 0; i < EXPECTED_RESULT.length; ++i) {
- assertEquals("toCodePointArray position " + i, codePointArray[i], EXPECTED_RESULT[i]);
- }
- }
-
- public void testCopyCodePointsAndReturnCodePointCount() {
- final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx";
- final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7,
- 'f', 'G', 'h', 0, 0x2002, 0x3000, 'あ', 'x'};
- final int[] EXPECTED_RESULT_DOWNCASE = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7,
- 'f', 'g', 'h', 0, 0x2002, 0x3000, 'あ', 'x'};
-
- int[] codePointArray = new int[50];
- int codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray,
- STR_WITH_SUPPLEMENTARY_CHAR, 0,
- STR_WITH_SUPPLEMENTARY_CHAR.length(), false /* downCase */);
- assertEquals("copyCodePointsAndReturnCodePointCount, size matches", codePointCount,
- EXPECTED_RESULT.length);
- for (int i = 0; i < codePointCount; ++i) {
- assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i],
- EXPECTED_RESULT[i]);
- }
-
- codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray,
- STR_WITH_SUPPLEMENTARY_CHAR, 0,
- STR_WITH_SUPPLEMENTARY_CHAR.length(), true /* downCase */);
- assertEquals("copyCodePointsAndReturnCodePointCount downcase, size matches", codePointCount,
- EXPECTED_RESULT_DOWNCASE.length);
- for (int i = 0; i < codePointCount; ++i) {
- assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i],
- EXPECTED_RESULT_DOWNCASE[i]);
- }
-
- final int JAVA_CHAR_COUNT = 8;
- final int CODEPOINT_COUNT = 7;
- codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray,
- STR_WITH_SUPPLEMENTARY_CHAR, 0, JAVA_CHAR_COUNT, false /* downCase */);
- assertEquals("copyCodePointsAndReturnCodePointCount, size matches", codePointCount,
- CODEPOINT_COUNT);
- for (int i = 0; i < codePointCount; ++i) {
- assertEquals("copyCodePointsAndReturnCodePointCount position " + i, codePointArray[i],
- EXPECTED_RESULT[i]);
- }
-
- boolean exceptionHappened = false;
- codePointArray = new int[5];
- try {
- codePointCount = StringUtils.copyCodePointsAndReturnCodePointCount(codePointArray,
- STR_WITH_SUPPLEMENTARY_CHAR, 0, JAVA_CHAR_COUNT, false /* downCase */);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionHappened = true;
- }
- assertTrue("copyCodePointsAndReturnCodePointCount throws when array is too small",
- exceptionHappened);
- }
-
- public void testGetTrailingSingleQuotesCount() {
- assertEquals(0, StringUtils.getTrailingSingleQuotesCount(""));
- assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'"));
- assertEquals(5, StringUtils.getTrailingSingleQuotesCount("'''''"));
- assertEquals(0, StringUtils.getTrailingSingleQuotesCount("a"));
- assertEquals(0, StringUtils.getTrailingSingleQuotesCount("'this"));
- assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'word'"));
- assertEquals(0, StringUtils.getTrailingSingleQuotesCount("I'm"));
- }
-
- private static void assertSpanCount(final int expectedCount, final CharSequence cs) {
- final int actualCount;
- if (cs instanceof Spanned) {
- final Spanned spanned = (Spanned) cs;
- actualCount = spanned.getSpans(0, spanned.length(), Object.class).length;
- } else {
- actualCount = 0;
- }
- assertEquals(expectedCount, actualCount);
- }
-
- private static void assertSpan(final CharSequence cs, final Object expectedSpan,
- final int expectedStart, final int expectedEnd, final int expectedFlags) {
- assertTrue(cs instanceof Spanned);
- final Spanned spanned = (Spanned) cs;
- final Object[] actualSpans = spanned.getSpans(0, spanned.length(), Object.class);
- for (Object actualSpan : actualSpans) {
- if (actualSpan == expectedSpan) {
- final int actualStart = spanned.getSpanStart(actualSpan);
- final int actualEnd = spanned.getSpanEnd(actualSpan);
- final int actualFlags = spanned.getSpanFlags(actualSpan);
- assertEquals(expectedStart, actualStart);
- assertEquals(expectedEnd, actualEnd);
- assertEquals(expectedFlags, actualFlags);
- return;
- }
- }
- assertTrue(false);
- }
-
- public void testSplitCharSequenceWithSpan() {
- // text: " a bcd efg hij "
- // span1: ^^^^^^^
- // span2: ^^^^^
- // span3: ^
- final SpannableString spannableString = new SpannableString(" a bcd efg hij ");
- final Object span1 = new Object();
- final Object span2 = new Object();
- final Object span3 = new Object();
- final int SPAN1_FLAGS = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
- final int SPAN2_FLAGS = Spanned.SPAN_EXCLUSIVE_INCLUSIVE;
- final int SPAN3_FLAGS = Spanned.SPAN_INCLUSIVE_INCLUSIVE;
- spannableString.setSpan(span1, 0, 7, SPAN1_FLAGS);
- spannableString.setSpan(span2, 0, 5, SPAN2_FLAGS);
- spannableString.setSpan(span3, 12, 13, SPAN3_FLAGS);
- final CharSequence[] charSequencesFromSpanned = StringUtils.split(
- spannableString, " ", true /* preserveTrailingEmptySegmengs */);
- final CharSequence[] charSequencesFromString = StringUtils.split(
- spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */);
-
-
- assertEquals(7, charSequencesFromString.length);
- assertEquals(7, charSequencesFromSpanned.length);
-
- // text: ""
- // span1: ^
- // span2: ^
- // span3:
- assertEquals("", charSequencesFromString[0].toString());
- assertSpanCount(0, charSequencesFromString[0]);
- assertEquals("", charSequencesFromSpanned[0].toString());
- assertSpanCount(2, charSequencesFromSpanned[0]);
- assertSpan(charSequencesFromSpanned[0], span1, 0, 0, SPAN1_FLAGS);
- assertSpan(charSequencesFromSpanned[0], span2, 0, 0, SPAN2_FLAGS);
-
- // text: "a"
- // span1: ^
- // span2: ^
- // span3:
- assertEquals("a", charSequencesFromString[1].toString());
- assertSpanCount(0, charSequencesFromString[1]);
- assertEquals("a", charSequencesFromSpanned[1].toString());
- assertSpanCount(2, charSequencesFromSpanned[1]);
- assertSpan(charSequencesFromSpanned[1], span1, 0, 1, SPAN1_FLAGS);
- assertSpan(charSequencesFromSpanned[1], span2, 0, 1, SPAN2_FLAGS);
-
- // text: "bcd"
- // span1: ^^^
- // span2: ^^
- // span3:
- assertEquals("bcd", charSequencesFromString[2].toString());
- assertSpanCount(0, charSequencesFromString[2]);
- assertEquals("bcd", charSequencesFromSpanned[2].toString());
- assertSpanCount(2, charSequencesFromSpanned[2]);
- assertSpan(charSequencesFromSpanned[2], span1, 0, 3, SPAN1_FLAGS);
- assertSpan(charSequencesFromSpanned[2], span2, 0, 2, SPAN2_FLAGS);
-
- // text: "efg"
- // span1:
- // span2:
- // span3:
- assertEquals("efg", charSequencesFromString[3].toString());
- assertSpanCount(0, charSequencesFromString[3]);
- assertEquals("efg", charSequencesFromSpanned[3].toString());
- assertSpanCount(0, charSequencesFromSpanned[3]);
-
- // text: "hij"
- // span1:
- // span2:
- // span3: ^
- assertEquals("hij", charSequencesFromString[4].toString());
- assertSpanCount(0, charSequencesFromString[4]);
- assertEquals("hij", charSequencesFromSpanned[4].toString());
- assertSpanCount(1, charSequencesFromSpanned[4]);
- assertSpan(charSequencesFromSpanned[4], span3, 1, 2, SPAN3_FLAGS);
-
- // text: ""
- // span1:
- // span2:
- // span3:
- assertEquals("", charSequencesFromString[5].toString());
- assertSpanCount(0, charSequencesFromString[5]);
- assertEquals("", charSequencesFromSpanned[5].toString());
- assertSpanCount(0, charSequencesFromSpanned[5]);
-
- // text: ""
- // span1:
- // span2:
- // span3:
- assertEquals("", charSequencesFromString[6].toString());
- assertSpanCount(0, charSequencesFromString[6]);
- assertEquals("", charSequencesFromSpanned[6].toString());
- assertSpanCount(0, charSequencesFromSpanned[6]);
- }
-
- public void testSplitCharSequencePreserveTrailingEmptySegmengs() {
- assertEquals(1, StringUtils.split("", " ",
- false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(1, StringUtils.split(new SpannedString(""), " ",
- false /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(1, StringUtils.split("", " ",
- true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(1, StringUtils.split(new SpannedString(""), " ",
- true /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(0, StringUtils.split(" ", " ",
- false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(0, StringUtils.split(new SpannedString(" "), " ",
- false /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(2, StringUtils.split(" ", " ",
- true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(2, StringUtils.split(new SpannedString(" "), " ",
- true /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(3, StringUtils.split("a b c ", " ",
- false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(3, StringUtils.split(new SpannedString("a b c "), " ",
- false /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(5, StringUtils.split("a b c ", " ",
- true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(5, StringUtils.split(new SpannedString("a b c "), " ",
- true /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(6, StringUtils.split("a b ", " ",
- false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(6, StringUtils.split(new SpannedString("a b "), " ",
- false /* preserveTrailingEmptySegmengs */).length);
-
- assertEquals(7, StringUtils.split("a b ", " ",
- true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(7, StringUtils.split(new SpannedString("a b "), " ",
- true /* preserveTrailingEmptySegmengs */).length);
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java
deleted file mode 100644
index ba2e99802..000000000
--- a/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java
+++ /dev/null
@@ -1,192 +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.utils;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.inputmethod.latin.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
-
-import java.util.Locale;
-
-@SmallTest
-public class StringUtilsTests extends AndroidTestCase {
- private static final Locale US = Locale.US;
- private static final Locale GERMAN = Locale.GERMAN;
- private static final Locale TURKEY = new Locale("tr", "TR");
- private static final Locale GREECE = new Locale("el", "GR");
-
- private static void assert_toUpperCaseOfStringForLocale(final Locale locale,
- final String lowerCase, final String expected) {
- assertEquals(lowerCase + " in " + locale, expected,
- StringUtils.toUpperCaseOfStringForLocale(
- lowerCase, true /* needsToUpperCase */, locale));
- }
-
- public void test_toUpperCaseOfStringForLocale() {
- assert_toUpperCaseOfStringForLocale(US, null, null);
- assert_toUpperCaseOfStringForLocale(US, "", "");
- assert_toUpperCaseOfStringForLocale(US, "aeiou", "AEIOU");
- // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
- // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE
- // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX
- // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS
- // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON
- // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE
- // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA
- // U+00C0: "À" LATIN CAPITAL LETTER A WITH GRAVE
- // U+00C8: "È" LATIN CAPITAL LETTER E WITH GRAVE
- // U+00CE: "Î" LATIN CAPITAL LETTER I WITH CIRCUMFLEX
- // U+00D6: "Ö" LATIN CAPITAL LETTER O WITH DIAERESIS
- // U+016A: "Ū" LATIN CAPITAL LETTER U WITH MACRON
- // U+00D1: "Ñ" LATIN CAPITAL LETTER N WITH TILDE
- // U+00C7: "Ç" LATIN CAPITAL LETTER C WITH CEDILLA
- assert_toUpperCaseOfStringForLocale(US,
- "\u00E0\u00E8\u00EE\u00F6\u016B\u00F1\u00E7",
- "\u00C0\u00C8\u00CE\u00D6\u016A\u00D1\u00C7");
- // U+00DF: "ß" LATIN SMALL LETTER SHARP S
- // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE
- // U+0161: "š" LATIN SMALL LETTER S WITH CARON
- // U+015A: "Ś" LATIN CAPITAL LETTER S WITH ACUTE
- // U+0160: "Š" LATIN CAPITAL LETTER S WITH CARONZ
- assert_toUpperCaseOfStringForLocale(GERMAN,
- "\u00DF\u015B\u0161",
- "SS\u015A\u0160");
- // U+0259: "ə" LATIN SMALL LETTER SCHWA
- // U+0069: "i" LATIN SMALL LETTER I
- // U+0131: "ı" LATIN SMALL LETTER DOTLESS I
- // U+018F: "Ə" LATIN SMALL LETTER SCHWA
- // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
- // U+0049: "I" LATIN SMALL LETTER I
- assert_toUpperCaseOfStringForLocale(TURKEY,
- "\u0259\u0069\u0131",
- "\u018F\u0130\u0049");
- // U+03C3: "σ" GREEK SMALL LETTER SIGMA
- // U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA
- // U+03A3: "Σ" GREEK CAPITAL LETTER SIGMA
- assert_toUpperCaseOfStringForLocale(GREECE,
- "\u03C3\u03C2",
- "\u03A3\u03A3");
- // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
- // U+03AD: "έ" GREEK SMALL LETTER EPSILON WITH TONOS
- // U+03AE: "ή" GREEK SMALL LETTER ETA WITH TONOS
- // U+03AF: "ί" GREEK SMALL LETTER IOTA WITH TONOS
- // U+03CC: "ό" GREEK SMALL LETTER OMICRON WITH TONOS
- // U+03CD: "ύ" GREEK SMALL LETTER UPSILON WITH TONOS
- // U+03CE: "ώ" GREEK SMALL LETTER OMEGA WITH TONOS
- // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS
- // U+0388: "Έ" GREEK CAPITAL LETTER EPSILON WITH TONOS
- // U+0389: "Ή" GREEK CAPITAL LETTER ETA WITH TONOS
- // U+038A: "Ί" GREEK CAPITAL LETTER IOTA WITH TONOS
- // U+038C: "Ό" GREEK CAPITAL LETTER OMICRON WITH TONOS
- // U+038E: "Ύ" GREEK CAPITAL LETTER UPSILON WITH TONOS
- // U+038F: "Ώ" GREEK CAPITAL LETTER OMEGA WITH TONOS
- assert_toUpperCaseOfStringForLocale(GREECE,
- "\u03AC\u03AD\u03AE\u03AF\u03CC\u03CD\u03CE",
- "\u0386\u0388\u0389\u038A\u038C\u038E\u038F");
- // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
- // U+03CB: "ϋ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA
- // U+0390: "ΐ" GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
- // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
- // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
- // U+03AB: "Ϋ" GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
- // U+0399: "Ι" GREEK CAPITAL LETTER IOTA
- // U+03A5: "Υ" GREEK CAPITAL LETTER UPSILON
- // U+0308: COMBINING DIAERESIS
- // U+0301: COMBINING GRAVE ACCENT
- assert_toUpperCaseOfStringForLocale(GREECE,
- "\u03CA\u03CB\u0390\u03B0",
- "\u03AA\u03AB\u0399\u0308\u0301\u03A5\u0308\u0301");
- }
-
- private static void assert_toUpperCaseOfCodeForLocale(final Locale locale, final int lowerCase,
- final int expected) {
- assertEquals(lowerCase + " in " + locale, expected,
- StringUtils.toUpperCaseOfCodeForLocale(
- lowerCase, true /* needsToUpperCase */, locale));
- }
-
- public void test_toUpperCaseOfCodeForLocale() {
- assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_ENTER, Constants.CODE_ENTER);
- assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_SPACE, Constants.CODE_SPACE);
- assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_COMMA, Constants.CODE_COMMA);
- // U+0069: "i" LATIN SMALL LETTER I
- // U+0131: "ı" LATIN SMALL LETTER DOTLESS I
- // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
- // U+0049: "I" LATIN SMALL LETTER I
- assert_toUpperCaseOfCodeForLocale(US, 0x0069, 0x0049); // i -> I
- assert_toUpperCaseOfCodeForLocale(US, 0x0131, 0x0049); // ı -> I
- assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0069, 0x0130); // i -> İ
- assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0131, 0x0049); // ı -> I
- // U+00DF: "ß" LATIN SMALL LETTER SHARP S
- // The title case of "ß" is "SS".
- assert_toUpperCaseOfCodeForLocale(US, 0x00DF, Constants.CODE_UNSPECIFIED);
- // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
- // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS
- assert_toUpperCaseOfCodeForLocale(GREECE, 0x03AC, 0x0386);
- // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
- // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
- assert_toUpperCaseOfCodeForLocale(GREECE, 0x03CA, 0x03AA);
- // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
- // The title case of "ΰ" is "\u03A5\u0308\u0301".
- assert_toUpperCaseOfCodeForLocale(GREECE, 0x03B0, Constants.CODE_UNSPECIFIED);
- }
-
- private static void assert_capitalizeFirstCodePoint(final Locale locale, final String text,
- final String expected) {
- assertEquals(text + " in " + locale, expected,
- StringUtils.capitalizeFirstCodePoint(text, locale));
- }
-
- public void test_capitalizeFirstCodePoint() {
- assert_capitalizeFirstCodePoint(US, "", "");
- assert_capitalizeFirstCodePoint(US, "a", "A");
- assert_capitalizeFirstCodePoint(US, "à", "À");
- assert_capitalizeFirstCodePoint(US, "ß", "SS");
- assert_capitalizeFirstCodePoint(US, "text", "Text");
- assert_capitalizeFirstCodePoint(US, "iGoogle", "IGoogle");
- assert_capitalizeFirstCodePoint(TURKEY, "iyi", "İyi");
- assert_capitalizeFirstCodePoint(TURKEY, "ısırdı", "Isırdı");
- assert_capitalizeFirstCodePoint(GREECE, "ά", "Ά");
- assert_capitalizeFirstCodePoint(GREECE, "άνεση", "Άνεση");
- }
-
- private static void assert_capitalizeFirstAndDowncaseRest(final Locale locale,
- final String text, final String expected) {
- assertEquals(text + " in " + locale, expected,
- StringUtils.capitalizeFirstAndDowncaseRest(text, locale));
- }
-
- public void test_capitalizeFirstAndDowncaseRest() {
- assert_capitalizeFirstAndDowncaseRest(US, "", "");
- assert_capitalizeFirstAndDowncaseRest(US, "a", "A");
- assert_capitalizeFirstAndDowncaseRest(US, "à", "À");
- assert_capitalizeFirstAndDowncaseRest(US, "ß", "SS");
- assert_capitalizeFirstAndDowncaseRest(US, "text", "Text");
- assert_capitalizeFirstAndDowncaseRest(US, "iGoogle", "Igoogle");
- assert_capitalizeFirstAndDowncaseRest(US, "invite", "Invite");
- assert_capitalizeFirstAndDowncaseRest(US, "INVITE", "Invite");
- assert_capitalizeFirstAndDowncaseRest(TURKEY, "iyi", "İyi");
- assert_capitalizeFirstAndDowncaseRest(TURKEY, "İYİ", "İyi");
- assert_capitalizeFirstAndDowncaseRest(TURKEY, "ısırdı", "Isırdı");
- assert_capitalizeFirstAndDowncaseRest(TURKEY, "ISIRDI", "Isırdı");
- assert_capitalizeFirstAndDowncaseRest(GREECE, "ά", "Ά");
- assert_capitalizeFirstAndDowncaseRest(GREECE, "άνεση", "Άνεση");
- assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση");
- }
-}
diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
index ce3df7dd6..111d5c56a 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
@@ -23,7 +23,9 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
+import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
+import com.android.inputmethod.latin.RichInputMethodSubtype;
import java.util.ArrayList;
import java.util.Locale;
@@ -31,10 +33,11 @@ import java.util.Locale;
@SmallTest
public class SubtypeLocaleUtilsTests extends AndroidTestCase {
// All input method subtypes of LatinIME.
- private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<>();
+ private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>();
private RichInputMethodManager mRichImm;
private Resources mRes;
+ private InputMethodSubtype mSavedAddtionalSubtypes[];
InputMethodSubtype EN_US;
InputMethodSubtype EN_GB;
@@ -44,6 +47,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
InputMethodSubtype FR_CH;
InputMethodSubtype DE;
InputMethodSubtype DE_CH;
+ InputMethodSubtype HI;
+ InputMethodSubtype SR;
InputMethodSubtype ZZ;
InputMethodSubtype DE_QWERTY;
InputMethodSubtype FR_QWERTZ;
@@ -53,20 +58,33 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
InputMethodSubtype ZZ_AZERTY;
InputMethodSubtype ZZ_PC;
+ // These are preliminary subtypes and may not exist.
+ InputMethodSubtype HI_LATN; // Hinglish
+ InputMethodSubtype SR_LATN; // Serbian Latin
+ InputMethodSubtype HI_LATN_DVORAK; // Hinglis Dvorak
+ InputMethodSubtype SR_LATN_QWERTY; // Serbian Latin Qwerty
+
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
+ mRes = context.getResources();
RichInputMethodManager.init(context);
mRichImm = RichInputMethodManager.getInstance();
- mRes = context.getResources();
- SubtypeLocaleUtils.init(context);
+
+ // Save and reset additional subtypes
+ mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes();
+ final InputMethodSubtype[] predefinedAddtionalSubtypes =
+ AdditionalSubtypeUtils.createAdditionalSubtypesArray(
+ AdditionalSubtypeUtils.createPrefSubtypes(
+ mRes.getStringArray(R.array.predefined_subtypes)));
+ mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes);
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
final int subtypeCount = imi.getSubtypeCount();
for (int index = 0; index < subtypeCount; index++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
- mSubtypesList.add(subtype);
+ mSubtypesList.add(new RichInputMethodSubtype(subtype));
}
EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
@@ -85,6 +103,10 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
Locale.GERMAN.toString(), "qwertz");
DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
"de_CH", "swiss");
+ HI = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "hi", "hindi");
+ SR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "sr", "south_slavic");
ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
@@ -101,20 +123,43 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
ZZ_PC = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty");
+
+ HI_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("hi_ZZ", "qwerty");
+ if (HI_LATN != null) {
+ HI_LATN_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ "hi_ZZ", "dvorak");
+ }
+ SR_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("sr_ZZ", "serbian_qwertz");
+ if (SR_LATN != null) {
+ SR_LATN_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ "sr_ZZ", "qwerty");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Restore additional subtypes.
+ mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
+ super.tearDown();
}
public void testAllFullDisplayName() {
- for (final InputMethodSubtype subtype : mSubtypesList) {
+ for (final RichInputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils
- .getSubtypeDisplayNameInSystemLocale(subtype);
- if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
- final String layoutName = SubtypeLocaleUtils
- .getKeyboardLayoutSetDisplayName(subtype);
- assertTrue(subtypeName, subtypeName.contains(layoutName));
+ .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype());
+ final Locale[] locales = subtype.getLocales();
+ if (1 == locales.length) {
+ if (subtype.isNoLanguage()) {
+ final String layoutName = SubtypeLocaleUtils
+ .getKeyboardLayoutSetDisplayName(subtype.getRawSubtype());
+ assertTrue(subtypeName, subtypeName.contains(layoutName));
+ } else {
+ final String languageName = SubtypeLocaleUtils
+ .getSubtypeLocaleDisplayNameInSystemLocale(locales[0].toString());
+ assertTrue(subtypeName, subtypeName.contains(languageName));
+ }
} else {
- final String languageName = SubtypeLocaleUtils
- .getSubtypeLocaleDisplayNameInSystemLocale(subtype.getLocale());
- assertTrue(subtypeName, subtypeName.contains(languageName));
+ // TODO: test multi-lingual subtype spacebar display
}
}
}
@@ -128,6 +173,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
assertEquals("fr_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CH));
assertEquals("de", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE));
assertEquals("de_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_CH));
+ assertEquals("hi", "hindi", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI));
+ assertEquals("sr", "south_slavic", SubtypeLocaleUtils.getKeyboardLayoutSetName(SR));
assertEquals("zz", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ));
assertEquals("de qwerty", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_QWERTY));
@@ -140,27 +187,46 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getKeyboardLayoutSetName(ES_US_COLEMAK));
assertEquals("zz azerty", "azerty",
SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ_AZERTY));
+
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN != null) {
+ assertEquals("hi_ZZ", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_LATN));
+ assertEquals("hi_ZZ dvorak", "dvorak",
+ SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_LATN_DVORAK));
+ }
+ if (SR_LATN != null) {
+ assertEquals("sr_ZZ", "serbian_qwertz",
+ SubtypeLocaleUtils.getKeyboardLayoutSetName(SR_LATN));
+ assertEquals("sr_ZZ qwerty", "qwerty",
+ SubtypeLocaleUtils.getKeyboardLayoutSetName(SR_LATN_QWERTY));
+ }
}
// InputMethodSubtype's display name in system locale (en_US).
- // isAdditionalSubtype (T=true, F=false)
- // locale layout | display name
- // ------ ------- - ----------------------
- // en_US qwerty F English (US) exception
- // en_GB qwerty F English (UK) exception
- // es_US spanish F Spanish (US) exception
- // fr azerty F French
- // fr_CA qwerty F French (Canada)
- // fr_CH swiss F French (Switzerland)
- // de qwertz F German
- // de_CH swiss F German (Switzerland)
- // zz qwerty F Alphabet (QWERTY)
- // fr qwertz T French (QWERTZ)
- // de qwerty T German (QWERTY)
- // en_US azerty T English (US) (AZERTY) exception
- // en_UK dvorak T English (UK) (Dvorak) exception
- // es_US colemak T Spanish (US) (Colemak) exception
- // zz pc T Alphabet (PC)
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ -------------- - ----------------------
+ // en_US qwerty F English (US) exception
+ // en_GB qwerty F English (UK) exception
+ // es_US spanish F Spanish (US) exception
+ // fr azerty F French
+ // fr_CA qwerty F French (Canada)
+ // fr_CH swiss F French (Switzerland)
+ // de qwertz F German
+ // de_CH swiss F German (Switzerland)
+ // hi hindi F Hindi
+ // hi_ZZ qwerty F Hinglish exception
+ // sr south_slavic F Serbian
+ // sr_ZZ serbian_qwertz F Serbian (Latin) exception
+ // zz qwerty F Alphabet (QWERTY)
+ // fr qwertz T French (QWERTZ)
+ // de qwerty T German (QWERTY)
+ // en_US azerty T English (US) (AZERTY) exception
+ // en_UK dvorak T English (UK) (Dvorak) exception
+ // es_US colemak T Spanish (US) (Colemak) exception
+ // hi_ZZ dvorak T Hinglish (Dvorka) exception
+ // sr_ZZ qwerty T Serbian (QWERTY) exception
+ // zz pc T Alphabet (PC)
public void testPredefinedSubtypesInEnglishSystemLocale() {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@@ -182,8 +248,21 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE));
assertEquals("de_CH", "German (Switzerland)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH));
+ assertEquals("hi", "Hindi",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI));
+ assertEquals("sr", "Serbian",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR));
assertEquals("zz", "Alphabet (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ));
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN != null) {
+ assertEquals("hi_ZZ", "Hinglish",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN));
+ }
+ if (SR_LATN != null) {
+ assertEquals("sr_ZZ", "Serbian (Latin)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN));
+ }
return null;
}
};
@@ -208,6 +287,15 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY));
assertEquals("zz pc", "Alphabet (PC)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN_DVORAK != null) {
+ assertEquals("hi_ZZ", "Hinglish (Dvorak)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK));
+ }
+ if (SR_LATN_QWERTY != null) {
+ assertEquals("sr_ZZ", "Serbian (QWERTY)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY));
+ }
return null;
}
};
@@ -218,21 +306,27 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
// isAdditionalSubtype (T=true, F=false)
// locale layout | display name
// ------ ------- - ----------------------
- // en_US qwerty F Anglais (États-Unis) exception
- // en_GB qwerty F Anglais (Royaume-Uni) exception
- // es_US spanish F Espagnol (États-Unis) exception
- // fr azerty F Français
- // fr_CA qwerty F Français (Canada)
- // fr_CH swiss F Français (Suisse)
- // de qwertz F Allemand
- // de_CH swiss F Allemand (Suisse)
- // zz qwerty F Alphabet latin (QWERTY)
- // fr qwertz T Français (QWERTZ)
- // de qwerty T Allemand (QWERTY)
- // en_US azerty T Anglais (États-Unis) (AZERTY) exception
- // en_UK dvorak T Anglais (Royaume-Uni) (Dvorak) exception
- // es_US colemak T Espagnol (États-Unis) (Colemak) exception
- // zz pc T Alphabet latin (PC)
+ // en_US qwerty F Anglais (États-Unis) exception
+ // en_GB qwerty F Anglais (Royaume-Uni) exception
+ // es_US spanish F Espagnol (États-Unis) exception
+ // fr azerty F Français
+ // fr_CA qwerty F Français (Canada)
+ // fr_CH swiss F Français (Suisse)
+ // de qwertz F Allemand
+ // de_CH swiss F Allemand (Suisse)
+ // hi hindi F Hindi exception
+ // hi_ZZ qwerty F Hindi/Anglais exception
+ // sr south_slavic F Serbe exception
+ // sr_ZZ serbian_qwertz F Serbe (latin) exception
+ // zz qwerty F Alphabet latin (QWERTY)
+ // fr qwertz T Français (QWERTZ)
+ // de qwerty T Allemand (QWERTY)
+ // en_US azerty T Anglais (États-Unis) (AZERTY) exception
+ // en_UK dvorak T Anglais (Royaume-Uni) (Dvorak) exception
+ // es_US colemak T Espagnol (États-Unis) (Colemak) exception
+ // hi_ZZ dvorak T Hindi/Anglais (Dvorka) exception
+ // sr_ZZ qwerty T Serbe (QWERTY) exception
+ // zz pc T Alphabet latin (PC)
public void testPredefinedSubtypesInFrenchSystemLocale() {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@@ -254,8 +348,21 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE));
assertEquals("de_CH", "Allemand (Suisse)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH));
+ assertEquals("hi", "Hindi",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI));
+ assertEquals("sr", "Serbe",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR));
assertEquals("zz", "Alphabet latin (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ));
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN != null) {
+ assertEquals("hi_ZZ", "Hindi/Anglais",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN));
+ }
+ if (SR_LATN != null) {
+ assertEquals("sr_ZZ", "Serbe (latin)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN));
+ }
return null;
}
};
@@ -280,12 +387,83 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY));
assertEquals("zz pc", "Alphabet latin (PC)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN_DVORAK != null) {
+ assertEquals("hi_ZZ", "Hindi/Anglais (Dvorak)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK));
+ }
+ if (SR_LATN_QWERTY != null) {
+ assertEquals("sr_ZZ", "Serbe (QWERTY)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY));
+ }
return null;
}
};
tests.runInLocale(mRes, Locale.FRENCH);
}
+ // InputMethodSubtype's display name in system locale (hi).
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ ------- - ----------------------
+ // hi hindi F हिन्दी
+ // hi_ZZ qwerty F हिंग्लिश
+ // hi_ZZ dvorak T हिंग्लिश (Dvorak)
+
+ public void testHinglishSubtypesInHindiSystemLocale() {
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job (final Resources res) {
+ assertEquals("hi", "हिन्दी",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI));
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN != null) {
+ // TODO: Uncommented because of the current translation of these strings
+ // in Hindi are described in Latin script.
+ // assertEquals("hi_ZZ", "हिंग्लिश",
+ // SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN));
+ // assertEquals("hi_ZZ", "हिंग्लिश (Dvorak)",
+ // SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK));
+ // TODO: Remove these tests once the translation of these strings in Hindi
+ // are described in Devanagari script.
+ assertEquals("hi_ZZ", "Hinglish",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN));
+ assertEquals("hi_ZZ", "Hinglish (Dvorak)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK));
+ }
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, new Locale("hi"));
+ }
+
+ // InputMethodSubtype's display name in system locale (sr).
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ -------------- - ----------------------
+ // sr south_slavic F Српски
+ // sr_ZZ serbian_qwertz F Српски (латиница)
+ // sr_ZZ qwerty T Српски (QWERTY)
+
+ public void testSerbianLatinSubtypesInSerbianSystemLocale() {
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job (final Resources res) {
+ assertEquals("sr", "Српски",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR));
+ // These are preliminary subtypes and may not exist.
+ if (SR_LATN != null) {
+ assertEquals("sr_ZZ", "Српски (латиница)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN));
+ assertEquals("sr_ZZ", "Српски (QWERTY)",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY));
+ }
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, new Locale("sr"));
+ }
+
public void testIsRtlLanguage() {
// Known Right-to-Left language subtypes.
final InputMethodSubtype ARABIC = mRichImm
@@ -298,13 +476,15 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
.findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew");
assertNotNull("Hebrew", HEBREW);
- for (final InputMethodSubtype subtype : mSubtypesList) {
+ for (final RichInputMethodSubtype subtype : mSubtypesList) {
+ final InputMethodSubtype rawSubtype = subtype.getRawSubtype();
final String subtypeName = SubtypeLocaleUtils
- .getSubtypeDisplayNameInSystemLocale(subtype);
- if (subtype.equals(ARABIC) || subtype.equals(FARSI) || subtype.equals(HEBREW)) {
- assertTrue(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype));
+ .getSubtypeDisplayNameInSystemLocale(rawSubtype);
+ if (rawSubtype.equals(ARABIC) || rawSubtype.equals(FARSI)
+ || rawSubtype.equals(HEBREW)) {
+ assertTrue(subtypeName, subtype.isRtlSubtype());
} else {
- assertFalse(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype));
+ assertFalse(subtypeName, subtype.isRtlSubtype());
}
}
}