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.java8
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java24
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java85
-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/RecapitalizeStatusTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java377
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java318
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java251
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java7
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java40
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java276
15 files changed, 947 insertions, 830 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..131865ab2 100644
--- a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java
@@ -39,10 +39,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 +57,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..4646a823d 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
@@ -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..dc4e2e4bb
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
@@ -0,0 +1,85 @@
+/*
+ * 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.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/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/SpacebarLanguageUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java
new file mode 100644
index 000000000..83afd782d
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java
@@ -0,0 +1,318 @@
+/*
+ * 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.R;
+import com.android.inputmethod.latin.RichInputMethodManager;
+import com.android.inputmethod.latin.RichInputMethodSubtype;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+@SmallTest
+public class SpacebarLanguageUtilsTests extends AndroidTestCase {
+ // All input method subtypes of LatinIME.
+ private final ArrayList<RichInputMethodSubtype> mSubtypesList = new ArrayList<>();
+
+ private RichInputMethodManager mRichImm;
+ private Resources mRes;
+ private InputMethodSubtype mSavedAddtionalSubtypes[];
+
+ RichInputMethodSubtype EN_US;
+ RichInputMethodSubtype EN_GB;
+ RichInputMethodSubtype ES_US;
+ RichInputMethodSubtype FR;
+ RichInputMethodSubtype FR_CA;
+ RichInputMethodSubtype FR_CH;
+ RichInputMethodSubtype DE;
+ RichInputMethodSubtype DE_CH;
+ RichInputMethodSubtype HI;
+ RichInputMethodSubtype SR;
+ RichInputMethodSubtype ZZ;
+ RichInputMethodSubtype DE_QWERTY;
+ RichInputMethodSubtype FR_QWERTZ;
+ RichInputMethodSubtype EN_US_AZERTY;
+ RichInputMethodSubtype EN_UK_DVORAK;
+ RichInputMethodSubtype ES_US_COLEMAK;
+ RichInputMethodSubtype ZZ_AZERTY;
+ RichInputMethodSubtype ZZ_PC;
+
+ // These are preliminary subtypes and may not exist.
+ RichInputMethodSubtype HI_LATN; // Hinglish
+ RichInputMethodSubtype SR_LATN; // Serbian Latin
+ RichInputMethodSubtype HI_LATN_DVORAK;
+ RichInputMethodSubtype SR_LATN_QWERTY;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final Context context = getContext();
+ mRes = context.getResources();
+ RichInputMethodManager.init(context);
+ mRichImm = RichInputMethodManager.getInstance();
+
+ // Save and reset additional subtypes
+ mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes(context);
+ 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(new RichInputMethodSubtype(subtype));
+ }
+
+ EN_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.US.toString(), "qwerty"));
+ EN_GB = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.UK.toString(), "qwerty"));
+ ES_US = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "es_US", "spanish"));
+ FR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.FRENCH.toString(), "azerty"));
+ FR_CA = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.CANADA_FRENCH.toString(), "qwerty"));
+ FR_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "fr_CH", "swiss"));
+ DE = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ Locale.GERMAN.toString(), "qwertz"));
+ DE_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "de_CH", "swiss"));
+ HI = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "hi", "hindi"));
+ SR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "sr", "south_slavic"));
+ ZZ = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"));
+ DE_QWERTY = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ Locale.GERMAN.toString(), "qwerty"));
+ FR_QWERTZ = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ Locale.FRENCH.toString(), "qwertz"));
+ EN_US_AZERTY = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ Locale.US.toString(), "azerty"));
+ EN_UK_DVORAK = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ Locale.UK.toString(), "dvorak"));
+ ES_US_COLEMAK = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ "es_US", "colemak"));
+ ZZ_AZERTY = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ SubtypeLocaleUtils.NO_LANGUAGE, "azerty"));
+ ZZ_PC = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty"));
+
+ final InputMethodSubtype hiLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "hi_ZZ", "qwerty");
+ if (hiLatn != null) {
+ HI_LATN = new RichInputMethodSubtype(hiLatn);
+ HI_LATN_DVORAK = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ "hi_ZZ", "dvorak"));
+ }
+ final InputMethodSubtype srLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ "sr_ZZ", "serbian_qwertz");
+ if (srLatn != null) {
+ SR_LATN = new RichInputMethodSubtype(srLatn);
+ SR_LATN_QWERTY = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
+ "sr_ZZ", "qwerty"));
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Restore additional subtypes.
+ mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes);
+ super.tearDown();
+ }
+
+ public void testAllFullDisplayNameForSpacebar() {
+ for (final RichInputMethodSubtype subtype : mSubtypesList) {
+ final String subtypeName = SubtypeLocaleUtils
+ .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype());
+ final String spacebarText = subtype.getFullDisplayName();
+ final Locale[] locales = subtype.getLocales();
+ if (1 == locales.length) {
+ final String languageName = SubtypeLocaleUtils
+ .getSubtypeLocaleDisplayName(locales[0].toString());
+ if (subtype.isNoLanguage()) {
+ assertFalse(subtypeName, spacebarText.contains(languageName));
+ } else {
+ assertTrue(subtypeName, spacebarText.contains(languageName));
+ }
+ } else {
+ // TODO: test multi-lingual subtype spacebar display
+ }
+ }
+ }
+
+ public void testAllMiddleDisplayNameForSpacebar() {
+ for (final RichInputMethodSubtype subtype : mSubtypesList) {
+ final String subtypeName = SubtypeLocaleUtils
+ .getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype());
+ final Locale[] locales = subtype.getLocales();
+ if (locales.length > 1) {
+ // TODO: test multi-lingual subtype spacebar display
+ continue;
+ }
+ final Locale locale = locales[0];
+ final Locale displayLocale = SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale(
+ locale.toString());
+ if (Locale.ROOT.equals(displayLocale)) {
+ // Skip test because the language part of this locale string doesn't represent
+ // the locale to be displayed on the spacebar (for example Hinglish).
+ continue;
+ }
+ final String spacebarText = subtype.getMiddleDisplayName();
+ if (subtype.isNoLanguage()) {
+ assertEquals(subtypeName, SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(
+ subtype.getRawSubtype()), spacebarText);
+ } else {
+ assertEquals(subtypeName,
+ SubtypeLocaleUtils.getSubtypeLanguageDisplayName(locale.toString()),
+ 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)
+ // hi hindi F हिन्दी हिन्दी
+ // hi_ZZ qwerty F Hinglish Hinglish exception
+ // sr south_slavic F Српски Српски
+ // sr_ZZ serbian_qwertz F Srpski Srpski exception
+ // zz qwerty F QWERTY QWERTY
+ // fr qwertz T Français Français
+ // de qwerty T Deutsch Deutsch
+ // en_US azerty T English English (US)
+ // en_GB dvorak T English English (UK)
+ // hi_ZZ dvorak T Hinglish Hinglish exception
+ // sr_ZZ qwerty T Srpski Srpski exception
+ // 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)", EN_US.getFullDisplayName());
+ assertEquals("en_GB", "English (UK)", EN_GB.getFullDisplayName());
+ assertEquals("es_US", "Español (EE.UU.)", ES_US.getFullDisplayName());
+ assertEquals("fr", "Français", FR.getFullDisplayName());
+ assertEquals("fr_CA", "Français (Canada)", FR_CA.getFullDisplayName());
+ assertEquals("fr_CH", "Français (Suisse)", FR_CH.getFullDisplayName());
+ assertEquals("de", "Deutsch", DE.getFullDisplayName());
+ assertEquals("de_CH", "Deutsch (Schweiz)", DE_CH.getFullDisplayName());
+ assertEquals("hi", "हिन्दी", HI.getFullDisplayName());
+ assertEquals("sr", "Српски", SR.getFullDisplayName());
+ assertEquals("zz", "QWERTY", ZZ.getFullDisplayName());
+
+ assertEquals("en_US", "English", EN_US.getMiddleDisplayName());
+ assertEquals("en_GB", "English", EN_GB.getMiddleDisplayName());
+ assertEquals("es_US", "Español", ES_US.getMiddleDisplayName());
+ assertEquals("fr", "Français", FR.getMiddleDisplayName());
+ assertEquals("fr_CA", "Français", FR_CA.getMiddleDisplayName());
+ assertEquals("fr_CH", "Français", FR_CH.getMiddleDisplayName());
+ assertEquals("de", "Deutsch", DE.getMiddleDisplayName());
+ assertEquals("de_CH", "Deutsch", DE_CH.getMiddleDisplayName());
+ assertEquals("zz", "QWERTY", ZZ.getMiddleDisplayName());
+
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN != null) {
+ assertEquals("hi_ZZ", "Hinglish", HI_LATN.getFullDisplayName());
+ assertEquals("hi_ZZ", "Hinglish", HI_LATN.getMiddleDisplayName());
+ }
+ if (SR_LATN != null) {
+ assertEquals("sr_ZZ", "Srpski", SR_LATN.getFullDisplayName());
+ assertEquals("sr_ZZ", "Srpski", SR_LATN.getMiddleDisplayName());
+ }
+ return null;
+ }
+ };
+
+ private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() {
+ @Override
+ protected Void job(final Resources res) {
+ assertEquals("fr qwertz", "Français", FR_QWERTZ.getFullDisplayName());
+ assertEquals("de qwerty", "Deutsch", DE_QWERTY.getFullDisplayName());
+ assertEquals("en_US azerty", "English (US)", EN_US_AZERTY.getFullDisplayName());
+ assertEquals("en_UK dvorak", "English (UK)", EN_UK_DVORAK.getFullDisplayName());
+ assertEquals("es_US colemak", "Español (EE.UU.)", ES_US_COLEMAK.getFullDisplayName());
+ assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getFullDisplayName());
+ assertEquals("zz pc", "PC", ZZ_PC.getFullDisplayName());
+
+ assertEquals("fr qwertz", "Français", FR_QWERTZ.getMiddleDisplayName());
+ assertEquals("de qwerty", "Deutsch", DE_QWERTY.getMiddleDisplayName());
+ assertEquals("en_US azerty", "English", EN_US_AZERTY.getMiddleDisplayName());
+ assertEquals("en_UK dvorak", "English", EN_UK_DVORAK.getMiddleDisplayName());
+ assertEquals("es_US colemak", "Español", ES_US_COLEMAK.getMiddleDisplayName());
+ assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getMiddleDisplayName());
+ assertEquals("zz pc", "PC", ZZ_PC.getMiddleDisplayName());
+
+ // These are preliminary subtypes and may not exist.
+ if (HI_LATN_DVORAK != null) {
+ assertEquals("hi_ZZ dvorak", "Hinglish", HI_LATN_DVORAK.getFullDisplayName());
+ assertEquals("hi_ZZ dvorak", "Hinglish", HI_LATN_DVORAK.getMiddleDisplayName());
+ }
+ if (SR_LATN_QWERTY != null) {
+ assertEquals("sr_ZZ qwerty", "Srpski", SR_LATN_QWERTY.getFullDisplayName());
+ assertEquals("sr_ZZ qwerty", "Srpski", SR_LATN_QWERTY.getMiddleDisplayName());
+ }
+ 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/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..11d10aa2f 100644
--- a/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/SpannableStringUtilsTests.java
@@ -21,7 +21,6 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.text.style.SuggestionSpan;
import android.text.style.URLSpan;
import android.text.SpannableStringBuilder;
-import android.text.Spannable;
import android.text.Spanned;
@SmallTest
@@ -34,8 +33,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,7 +50,7 @@ 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);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
index 637ae10ee..0389fefb0 100644
--- a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java
@@ -22,7 +22,9 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.SpannedString;
-import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
+import com.android.inputmethod.latin.utils.SpannableStringUtils;
import java.util.Arrays;
import java.util.List;
@@ -375,9 +377,9 @@ public class StringAndJsonUtilsTests extends AndroidTestCase {
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(
+ final CharSequence[] charSequencesFromSpanned = SpannableStringUtils.split(
spannableString, " ", true /* preserveTrailingEmptySegmengs */);
- final CharSequence[] charSequencesFromString = StringUtils.split(
+ final CharSequence[] charSequencesFromString = SpannableStringUtils.split(
spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */);
@@ -456,44 +458,44 @@ public class StringAndJsonUtilsTests extends AndroidTestCase {
}
public void testSplitCharSequencePreserveTrailingEmptySegmengs() {
- assertEquals(1, StringUtils.split("", " ",
+ assertEquals(1, SpannableStringUtils.split("", " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(1, StringUtils.split(new SpannedString(""), " ",
+ assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(1, StringUtils.split("", " ",
+ assertEquals(1, SpannableStringUtils.split("", " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(1, StringUtils.split(new SpannedString(""), " ",
+ assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(0, StringUtils.split(" ", " ",
+ assertEquals(0, SpannableStringUtils.split(" ", " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(0, StringUtils.split(new SpannedString(" "), " ",
+ assertEquals(0, SpannableStringUtils.split(new SpannedString(" "), " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(2, StringUtils.split(" ", " ",
+ assertEquals(2, SpannableStringUtils.split(" ", " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(2, StringUtils.split(new SpannedString(" "), " ",
+ assertEquals(2, SpannableStringUtils.split(new SpannedString(" "), " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(3, StringUtils.split("a b c ", " ",
+ assertEquals(3, SpannableStringUtils.split("a b c ", " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(3, StringUtils.split(new SpannedString("a b c "), " ",
+ assertEquals(3, SpannableStringUtils.split(new SpannedString("a b c "), " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(5, StringUtils.split("a b c ", " ",
+ assertEquals(5, SpannableStringUtils.split("a b c ", " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(5, StringUtils.split(new SpannedString("a b c "), " ",
+ assertEquals(5, SpannableStringUtils.split(new SpannedString("a b c "), " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(6, StringUtils.split("a b ", " ",
+ assertEquals(6, SpannableStringUtils.split("a b ", " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(6, StringUtils.split(new SpannedString("a b "), " ",
+ assertEquals(6, SpannableStringUtils.split(new SpannedString("a b "), " ",
false /* preserveTrailingEmptySegmengs */).length);
- assertEquals(7, StringUtils.split("a b ", " ",
+ assertEquals(7, SpannableStringUtils.split("a b ", " ",
true /* preserveTrailingEmptySegmengs */).length);
- assertEquals(7, StringUtils.split(new SpannedString("a b "), " ",
+ assertEquals(7, SpannableStringUtils.split(new SpannedString("a b "), " ",
true /* preserveTrailingEmptySegmengs */).length);
}
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java
index ce3df7dd6..54f478f5a 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(context);
+ 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,77 @@ 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) {
+ assertEquals("hi_ZZ", "हिंग्लिश",
+ SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN));
+ assertEquals("hi_ZZ", "हिंग्लिश (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) {
+ // TODO: Uncommented because of the current translation of these strings
+ // in Seriban are described in Latin script.
+// 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 +470,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());
}
}
}