aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin')
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java136
-rw-r--r--tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java144
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java215
3 files changed, 390 insertions, 105 deletions
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
index a84df28c9..d83c4a55b 100644
--- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java
@@ -25,15 +25,11 @@ import android.util.Log;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.NgramContext.WordInfo;
-import com.android.inputmethod.latin.common.FileUtils;
import com.android.inputmethod.latin.settings.LocalSettingsConstants;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import com.android.inputmethod.latin.utils.DistracterFilter;
import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
@@ -48,34 +44,13 @@ import javax.annotation.Nullable;
public class UserHistoryDictionaryTests extends AndroidTestCase {
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000;
- private static final String TEST_LOCALE_PREFIX = "test_";
private static final String TEST_ACCOUNT = "account@example.com";
- private static final String[] CHARACTERS = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
- };
-
private int mCurrentTime = 0;
private SharedPreferences mPrefs;
private String mLastKnownAccount = null;
- private void removeAllTestDictFiles() {
- final Locale dummyLocale = new Locale(TEST_LOCALE_PREFIX);
- final String dictName = UserHistoryDictionary.getUserHistoryDictName(
- UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext());
- final File dictFile = ExpandableBinaryDictionary.getDictFile(
- mContext, dictName, null /* dictFile */);
- final FilenameFilter filenameFilter = new FilenameFilter() {
- @Override
- public boolean accept(final File dir, final String filename) {
- return filename.startsWith(UserHistoryDictionary.NAME + "." + TEST_LOCALE_PREFIX);
- }
- };
- FileUtils.deleteFilteredFiles(dictFile.getParentFile(), filenameFilter);
- }
-
private static void printAllFiles(final File dir) {
Log.d(TAG, dir.getAbsolutePath());
for (final File file : dir.listFiles()) {
@@ -83,7 +58,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
}
}
- private static void checkExistenceAndRemoveDictFile(final UserHistoryDictionary dict,
+ private static void assertDictionaryExists(final UserHistoryDictionary dict,
final File dictFile) {
Log.d(TAG, "waiting for writing ...");
dict.waitAllTasksForTests();
@@ -97,12 +72,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
Log.e(TAG, "Interrupted during waiting for writing the dict file.");
}
}
- assertTrue("check exisiting of " + dictFile, dictFile.exists());
- FileUtils.deleteRecursively(dictFile);
- }
-
- private static Locale getDummyLocale(final String name) {
- return new Locale(TEST_LOCALE_PREFIX + name + System.currentTimeMillis());
+ assertTrue("Following dictionary file doesn't exist: " + dictFile, dictFile.exists());
}
@Override
@@ -115,12 +85,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
updateAccountName(TEST_ACCOUNT);
resetCurrentTimeForTestMode();
- removeAllTestDictFiles();
+ UserHistoryDictionaryTestsHelper.removeAllTestDictFiles(
+ UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext);
}
@Override
protected void tearDown() throws Exception {
- removeAllTestDictFiles();
+ UserHistoryDictionaryTestsHelper.removeAllTestDictFiles(
+ UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext);
stopTestModeInNativeCode();
// Restore the account that was present before running the test.
@@ -165,58 +137,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
}
/**
- * Generates a random word.
- */
- private static String generateWord(final int value) {
- final int lengthOfChars = CHARACTERS.length;
- final StringBuilder builder = new StringBuilder();
- long lvalue = Math.abs((long)value);
- while (lvalue > 0) {
- builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]);
- lvalue /= lengthOfChars;
- }
- return builder.toString();
- }
-
- private static List<String> generateWords(final int number, final Random random) {
- final HashSet<String> wordSet = new HashSet<>();
- while (wordSet.size() < number) {
- wordSet.add(generateWord(random.nextInt()));
- }
- return new ArrayList<>(wordSet);
- }
-
- private static void addToDict(final UserHistoryDictionary dict, final List<String> words,
- final int timestamp) {
- NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
- for (final String word : words) {
- UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp,
- DistracterFilter.EMPTY_DISTRACTER_FILTER);
- ngramContext = ngramContext.getNextNgramContext(new WordInfo(word));
- }
- }
-
- /**
- * @param checkContents if true, checks whether written words are actually in the dictionary
- * or not.
- */
- private void addAndWriteRandomWords(final UserHistoryDictionary dict,
- final int numberOfWords, final Random random, final boolean checkContents) {
- final List<String> words = generateWords(numberOfWords, random);
- // Add random words to the user history dictionary.
- addToDict(dict, words, mCurrentTime);
- if (checkContents) {
- dict.waitAllTasksForTests();
- for (int i = 0; i < numberOfWords; ++i) {
- final String word = words.get(i);
- assertTrue(dict.isInDictionary(word));
- }
- }
- // write to file.
- dict.close();
- }
-
- /**
* Clear all entries in the user history dictionary.
* @param dict the user history dictionary.
*/
@@ -230,19 +150,19 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
public void testRandomWords() {
Log.d(TAG, "This test can be used for profiling.");
Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true.");
- final Locale dummyLocale = getDummyLocale("random_words");
+ final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("random_words");
final String dictName = UserHistoryDictionary.getUserHistoryDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext());
final File dictFile = ExpandableBinaryDictionary.getDictFile(
mContext, dictName, null /* dictFile */);
final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(
getContext(), dummyLocale, TEST_ACCOUNT);
-
+ clearHistory(dict);
final int numberOfWords = 1000;
final Random random = new Random(123456);
- clearHistory(dict);
- addAndWriteRandomWords(dict, numberOfWords, random, true /* checksContents */);
- checkExistenceAndRemoveDictFile(dict, dictFile);
+ assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(
+ dict, numberOfWords, random, true /* checksContents */, mCurrentTime));
+ assertDictionaryExists(dict, dictFile);
}
public void testStressTestForSwitchingLanguagesAndAddingWords() {
@@ -258,7 +178,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
// Create filename suffixes for this test.
for (int i = 0; i < numberOfLanguages; i++) {
- final Locale dummyLocale = getDummyLocale("switching_languages" + i);
+ final Locale dummyLocale =
+ UserHistoryDictionaryTestsHelper.getDummyLocale("switching_languages" + i);
final String dictName = UserHistoryDictionary.getUserHistoryDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext());
dictFiles[i] = ExpandableBinaryDictionary.getDictFile(
@@ -273,8 +194,11 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
for (int i = 0; i < numberOfLanguageSwitching; i++) {
final int index = i % numberOfLanguages;
// Switch to dicts[index].
- addAndWriteRandomWords(dicts[index], numberOfWordsInsertedForEachLanguageSwitch,
- random, false /* checksContents */);
+ assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(dicts[index],
+ numberOfWordsInsertedForEachLanguageSwitch,
+ random,
+ false /* checksContents */,
+ mCurrentTime));
}
final long end = System.currentTimeMillis();
@@ -282,13 +206,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
+ (end - start) + " ms");
} finally {
for (int i = 0; i < numberOfLanguages; i++) {
- checkExistenceAndRemoveDictFile(dicts[i], dictFiles[i]);
+ assertDictionaryExists(dicts[i], dictFiles[i]);
}
}
}
public void testAddManyWords() {
- final Locale dummyLocale = getDummyLocale("many_random_words");
+ final Locale dummyLocale =
+ UserHistoryDictionaryTestsHelper.getDummyLocale("many_random_words");
final String dictName = UserHistoryDictionary.getUserHistoryDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext());
final File dictFile = ExpandableBinaryDictionary.getDictFile(
@@ -298,23 +223,23 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(
getContext(), dummyLocale, TEST_ACCOUNT);
clearHistory(dict);
- try {
- addAndWriteRandomWords(dict, numberOfWords, random, true /* checksContents */);
- } finally {
- checkExistenceAndRemoveDictFile(dict, dictFile);
- }
+ assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(dict,
+ numberOfWords, random, true /* checksContents */, mCurrentTime));
+ assertDictionaryExists(dict, dictFile);
}
public void testDecaying() {
- final Locale dummyLocale = getDummyLocale("decaying");
+ final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("decaying");
final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(
getContext(), dummyLocale, TEST_ACCOUNT);
- final int numberOfWords = 5000;
- final Random random = new Random(123456);
resetCurrentTimeForTestMode();
clearHistory(dict);
- final List<String> words = generateWords(numberOfWords, random);
dict.waitAllTasksForTests();
+
+ final int numberOfWords = 5000;
+ final Random random = new Random(123456);
+ final List<String> words = UserHistoryDictionaryTestsHelper.generateWords(numberOfWords,
+ random);
NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
for (final String word : words) {
UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, mCurrentTime,
@@ -329,6 +254,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
for (final String word : words) {
assertTrue(dict.isInDictionary(word));
}
+ // Long term decay results in words removed from the dictionary.
forcePassingLongTime();
dict.runGCIfRequired();
dict.waitAllTasksForTests();
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
new file mode 100644
index 000000000..d394c0faa
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTestsHelper.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.personalization;
+
+import android.content.Context;
+
+import com.android.inputmethod.latin.NgramContext;
+import com.android.inputmethod.latin.NgramContext.WordInfo;
+import com.android.inputmethod.latin.common.FileUtils;
+import com.android.inputmethod.latin.utils.DistracterFilter;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+
+/**
+ * Utility class for helping while running tests involving {@link UserHistoryDictionary}.
+ */
+public class UserHistoryDictionaryTestsHelper {
+
+ /**
+ * Locale prefix for generating dummy locales for tests.
+ */
+ public static final String TEST_LOCALE_PREFIX = "test-";
+
+ /**
+ * Characters for generating random words.
+ */
+ private static final String[] CHARACTERS = {
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
+ };
+
+ /**
+ * Remove all the test dictionary files created for the given locale.
+ */
+ public static void removeAllTestDictFiles(final String filter, final Context context) {
+ final FilenameFilter filenameFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String filename) {
+ return filename.startsWith(UserHistoryDictionary.NAME + "." + filter);
+ }
+ };
+ FileUtils.deleteFilteredFiles(context.getFilesDir(), filenameFilter);
+ }
+
+ /**
+ * Generates and writes random words to dictionary. Caller can be assured
+ * that the write tasks would be finished; and its success would be reflected
+ * in the returned boolean.
+ *
+ * @param dict {@link UserHistoryDictionary} to which words should be added.
+ * @param numberOfWords number of words to be added.
+ * @param random helps generate random words.
+ * @param checkContents if true, checks whether written words are actually in the dictionary.
+ * @param currentTime timestamp that would be used for adding the words.
+ * @returns true if all words have been written to dictionary successfully.
+ */
+ public static boolean addAndWriteRandomWords(final UserHistoryDictionary dict,
+ final int numberOfWords, final Random random, final boolean checkContents,
+ final int currentTime) {
+ final List<String> words = generateWords(numberOfWords, random);
+ // Add random words to the user history dictionary.
+ addWordsToDictionary(dict, words, currentTime);
+ boolean success = true;
+ if (checkContents) {
+ dict.waitAllTasksForTests();
+ for (int i = 0; i < numberOfWords; ++i) {
+ final String word = words.get(i);
+ if (!dict.isInDictionary(word)) {
+ success = false;
+ break;
+ }
+ }
+ }
+ // write to file.
+ dict.close();
+ dict.waitAllTasksForTests();
+ return success;
+ }
+
+ private static void addWordsToDictionary(final UserHistoryDictionary dict,
+ final List<String> words, final int timestamp) {
+ NgramContext ngramContext = NgramContext.EMPTY_PREV_WORDS_INFO;
+ for (final String word : words) {
+ UserHistoryDictionary.addToDictionary(dict, ngramContext, word, true, timestamp,
+ DistracterFilter.EMPTY_DISTRACTER_FILTER);
+ ngramContext = ngramContext.getNextNgramContext(new WordInfo(word));
+ }
+ }
+
+ /**
+ * Creates unique test locale for using within tests.
+ */
+ public static Locale getDummyLocale(final String name) {
+ return new Locale(TEST_LOCALE_PREFIX + name + System.currentTimeMillis());
+ }
+
+ /**
+ * Generates random words.
+ *
+ * @param numberOfWords number of words to generate.
+ * @param random salt used for generating random words.
+ */
+ public static List<String> generateWords(final int numberOfWords, final Random random) {
+ final HashSet<String> wordSet = new HashSet<>();
+ while (wordSet.size() < numberOfWords) {
+ wordSet.add(generateWord(random.nextInt()));
+ }
+ return new ArrayList<>(wordSet);
+ }
+
+ /**
+ * Generates a random word.
+ */
+ private static String generateWord(final int value) {
+ final int lengthOfChars = CHARACTERS.length;
+ final StringBuilder builder = new StringBuilder();
+ long lvalue = Math.abs((long)value);
+ while (lvalue > 0) {
+ builder.append(CHARACTERS[(int)(lvalue % lengthOfChars)]);
+ lvalue /= lengthOfChars;
+ }
+ return builder.toString();
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java
new file mode 100644
index 000000000..7f7f493b1
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/utils/LanguageOnSpacebarUtilsTests.java
@@ -0,0 +1,215 @@
+/*
+ * 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 static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_FULL_LOCALE;
+import static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_LANGUAGE_ONLY;
+import static com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils.FORMAT_TYPE_NONE;
+
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.inputmethod.InputMethodSubtype;
+
+import com.android.inputmethod.latin.RichInputMethodManager;
+import com.android.inputmethod.latin.RichInputMethodSubtype;
+import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
+import com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils;
+import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+import javax.annotation.Nonnull;
+
+@SmallTest
+public class LanguageOnSpacebarUtilsTests extends AndroidTestCase {
+ private RichInputMethodManager mRichImm;
+
+ RichInputMethodSubtype EN_US_QWERTY;
+ RichInputMethodSubtype EN_GB_QWERTY;
+ RichInputMethodSubtype FR_AZERTY;
+ RichInputMethodSubtype FR_CA_QWERTY;
+ RichInputMethodSubtype FR_CH_SWISS;
+ RichInputMethodSubtype FR_CH_QWERTY;
+ RichInputMethodSubtype FR_CH_QWERTZ;
+ RichInputMethodSubtype IW_HEBREW;
+ RichInputMethodSubtype ZZ_QWERTY;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final Context context = getContext();
+ RichInputMethodManager.init(context);
+ mRichImm = RichInputMethodManager.getInstance();
+
+ EN_US_QWERTY = findSubtypeOf(Locale.US.toString(), "qwerty");
+ EN_GB_QWERTY = findSubtypeOf(Locale.UK.toString(), "qwerty");
+ FR_AZERTY = findSubtypeOf(Locale.FRENCH.toString(), "azerty");
+ FR_CA_QWERTY = findSubtypeOf(Locale.CANADA_FRENCH.toString(), "qwerty");
+ FR_CH_SWISS = findSubtypeOf("fr_CH", "swiss");
+ FR_CH_QWERTZ = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwertz"));
+ FR_CH_QWERTY = new RichInputMethodSubtype(
+ AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype("fr_CH", "qwerty"));
+ IW_HEBREW = findSubtypeOf("iw", "hebrew");
+ ZZ_QWERTY = findSubtypeOf(SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
+ }
+
+ @Nonnull
+ private RichInputMethodSubtype findSubtypeOf(final String localeString,
+ final String keyboardLayoutSetName) {
+ final InputMethodSubtype subtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
+ localeString, keyboardLayoutSetName);
+ if (subtype == null) {
+ throw new RuntimeException("Can't find subtype of " + localeString + " with "
+ + keyboardLayoutSetName);
+ }
+ return new RichInputMethodSubtype(subtype);
+ }
+
+ private static void enableSubtypes(final RichInputMethodSubtype ... subtypes) {
+ final ArrayList<InputMethodSubtype> enabledSubtypes = new ArrayList<>();
+ for (final RichInputMethodSubtype subtype : subtypes) {
+ enabledSubtypes.add(subtype.getRawSubtype());
+ }
+ LanguageOnSpacebarUtils.setEnabledSubtypes(enabledSubtypes);
+ }
+
+ private static void assertFormatType(final RichInputMethodSubtype subtype,
+ final boolean implicitlyEnabledSubtype, final Locale systemLocale,
+ final int expectedFormat) {
+ LanguageOnSpacebarUtils.onSubtypeChanged(subtype, implicitlyEnabledSubtype, systemLocale);
+ assertEquals(subtype.getLocales()[0] + " implicitly=" + implicitlyEnabledSubtype
+ + " in " + systemLocale, expectedFormat,
+ LanguageOnSpacebarUtils.getLanguageOnSpacebarFormatType(subtype));
+ }
+
+ public void testOneSubtypeImplicitlyEnabled() {
+ enableSubtypes(EN_US_QWERTY);
+ assertFormatType(EN_US_QWERTY, true, Locale.US, FORMAT_TYPE_NONE);
+
+ enableSubtypes(EN_GB_QWERTY);
+ assertFormatType(EN_GB_QWERTY, true, Locale.UK, FORMAT_TYPE_NONE);
+
+ enableSubtypes(FR_AZERTY);
+ assertFormatType(FR_AZERTY, true, Locale.FRANCE, FORMAT_TYPE_NONE);
+
+ enableSubtypes(FR_CA_QWERTY);
+ assertFormatType(FR_CA_QWERTY, true, Locale.CANADA_FRENCH, FORMAT_TYPE_NONE);
+ }
+
+ public void testOneSubtypeExplicitlyEnabled() {
+ enableSubtypes(EN_US_QWERTY);
+ assertFormatType(EN_US_QWERTY, false, Locale.UK, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ enableSubtypes(EN_GB_QWERTY);
+ assertFormatType(EN_GB_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(EN_GB_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ enableSubtypes(FR_AZERTY);
+ assertFormatType(FR_AZERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ enableSubtypes(FR_CA_QWERTY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ }
+
+ public void testOneSubtypeImplicitlyEnabledWithNoLanguageSubtype() {
+ final Locale Locale_IW = new Locale("iw");
+ enableSubtypes(IW_HEBREW, ZZ_QWERTY);
+ // TODO: Should this be FORMAT_TYPE_NONE?
+ assertFormatType(IW_HEBREW, true, Locale_IW, FORMAT_TYPE_LANGUAGE_ONLY);
+ // TODO: Should this be FORMAT_TYPE_NONE?
+ assertFormatType(ZZ_QWERTY, true, Locale_IW, FORMAT_TYPE_FULL_LOCALE);
+ }
+
+ public void testTwoSubtypesExplicitlyEnabled() {
+ enableSubtypes(EN_US_QWERTY, FR_AZERTY);
+ assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_AZERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(EN_US_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ enableSubtypes(EN_US_QWERTY, ZZ_QWERTY);
+ assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(ZZ_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(EN_US_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(ZZ_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE);
+
+ }
+
+ public void testMultiSubtypeWithSameLanuageAndSameLayout() {
+ // Explicitly enable en_US, en_GB, fr_FR, and no language keyboards.
+ enableSubtypes(EN_US_QWERTY, EN_GB_QWERTY, FR_CA_QWERTY, ZZ_QWERTY);
+
+ assertFormatType(EN_US_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(EN_GB_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CA_QWERTY, false, Locale.US, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(ZZ_QWERTY, false, Locale.US, FORMAT_TYPE_FULL_LOCALE);
+
+ assertFormatType(EN_US_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(EN_GB_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(ZZ_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
+ }
+
+ public void testMultiSubtypesWithSameLanguageButHaveDifferentLayout() {
+ enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTZ);
+
+ assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_SWISS, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_SWISS, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_SWISS, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ }
+
+ public void testMultiSubtypesWithSameLanguageAndMayHaveSameLayout() {
+ enableSubtypes(FR_AZERTY, FR_CA_QWERTY, FR_CH_SWISS, FR_CH_QWERTY, FR_CH_QWERTZ);
+
+ assertFormatType(FR_AZERTY, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_SWISS, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTY, false, Locale.FRANCE, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.FRANCE, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ assertFormatType(FR_AZERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_SWISS, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTY, false, Locale.CANADA_FRENCH, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.CANADA_FRENCH, FORMAT_TYPE_LANGUAGE_ONLY);
+
+ assertFormatType(FR_AZERTY, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CA_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_SWISS, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ assertFormatType(FR_CH_QWERTY, false, Locale.JAPAN, FORMAT_TYPE_FULL_LOCALE);
+ assertFormatType(FR_CH_QWERTZ, false, Locale.JAPAN, FORMAT_TYPE_LANGUAGE_ONLY);
+ }
+}