diff options
Diffstat (limited to 'tests/src')
10 files changed, 74 insertions, 95 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java index 9e43bd4d2..8e26e7fc7 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java @@ -33,7 +33,7 @@ public final class KeySpecParserTests extends KeySpecParserTestsBase { final String actualLabel = KeySpecParser.getLabel(keySpecResolved); final String actualOutputText = KeySpecParser.getOutputText(keySpecResolved); final int actualIcon = KeySpecParser.getIconId(keySpecResolved); - final int actualCode = KeySpecParser.getCode(keySpecResolved, mCodesSet); + final int actualCode = KeySpecParser.getCode(keySpecResolved); assertEquals(message + " [label]", expectedLabel, actualLabel); assertEquals(message + " [ouptputText]", expectedOutputText, actualOutputText); assertEquals(message + " [icon]", diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java index edeb6a6c2..c342533c8 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java @@ -32,7 +32,6 @@ import java.util.Locale; abstract class KeySpecParserTestsBase extends AndroidTestCase { private final static Locale TEST_LOCALE = Locale.ENGLISH; - protected final KeyboardCodesSet mCodesSet = new KeyboardCodesSet(); protected final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); private static final String CODE_SETTINGS_NAME = "key_settings"; @@ -52,7 +51,6 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); - mCodesSet.setLocale(TEST_LOCALE); mTextsSet.setLocale(TEST_LOCALE); final Context context = getContext(); new RunInLocale<Void>() { @@ -63,8 +61,8 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase { } }.runInLocale(context.getResources(), TEST_LOCALE); - mCodeSettings = mCodesSet.getCode(CODE_SETTINGS_NAME); - mCodeActionNext = mCodesSet.getCode("key_action_next"); + mCodeSettings = KeyboardCodesSet.getCode(CODE_SETTINGS_NAME); + mCodeActionNext = KeyboardCodesSet.getCode("key_action_next"); mSettingsIconId = KeyboardIconsSet.getIconId(ICON_SETTINGS_NAME); } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java index ea25bcf37..6c0d74941 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecTests.java @@ -33,8 +33,8 @@ public final class MoreKeySpecTests extends KeySpecParserTestsBase { final String expectedLabel, final String expectedOutputText, final int expectedIconId, final int expectedCode) { final String labelResolved = mTextsSet.resolveTextReference(moreKeySpec); - final MoreKeySpec spec = new MoreKeySpec(labelResolved, false /* needsToUpperCase */, - Locale.US, mCodesSet); + final MoreKeySpec spec = new MoreKeySpec( + labelResolved, false /* needsToUpperCase */, Locale.US); assertEquals(message + " [label]", expectedLabel, spec.mLabel); assertEquals(message + " [ouptputText]", expectedOutputText, spec.mOutputText); assertEquals(message + " [icon]", diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index 7d664c825..5702a62f4 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -55,8 +55,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { @Override protected void tearDown() throws Exception { - super.tearDown(); stopTestModeInNativeCode(); + super.tearDown(); } private void addUnigramWord(final BinaryDictionary binaryDictionary, final String word, diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index 13700418f..c1adf6557 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -43,16 +43,6 @@ public class BinaryDictionaryTests extends AndroidTestCase { private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_LOCALE = "test"; - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - private File createEmptyDictionaryAndGetFile(final String dictId, final int formatVersion) throws IOException { if (formatVersion == FormatSpec.VERSION4) { diff --git a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java index cdd8f6b85..6e894decf 100644 --- a/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java +++ b/tests/src/com/android/inputmethod/latin/BlueUnderlineTests.java @@ -50,8 +50,7 @@ public class BlueUnderlineTests extends InputTestsBase { final SpanGetter spanBefore = new SpanGetter(mEditText.getText(), SuggestionSpan.class); assertEquals("extend blue underline, span start", EXPECTED_SPAN_START, spanBefore.mStart); assertEquals("extend blue underline, span end", EXPECTED_SPAN_END, spanBefore.mEnd); - assertEquals("extend blue underline, span color", true, - spanBefore.isAutoCorrectionIndicator()); + assertTrue("extend blue underline, span color", spanBefore.isAutoCorrectionIndicator()); sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); // Now we have been able to re-evaluate the word, there shouldn't be an auto-correction span @@ -80,8 +79,8 @@ public class BlueUnderlineTests extends InputTestsBase { sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class); - assertEquals("show no blue underline after backspace, span start should be -1", - EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart); + assertFalse("show no blue underline after backspace, span should not be the auto-" + + "correction indicator", suggestionSpan.isAutoCorrectionIndicator()); final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class); assertEquals("should be composing, so should have an underline span", EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); @@ -107,7 +106,8 @@ public class BlueUnderlineTests extends InputTestsBase { sleep(DELAY_TO_WAIT_FOR_UNDERLINE); runMessages(); final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class); - assertNull("blue underline removed when cursor is moved", span.mSpan); + assertFalse("blue underline removed when cursor is moved", + span.isAutoCorrectionIndicator()); } public void testComposingStopsOnSpace() { diff --git a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java index 0b7fcbbe8..ffec20ab2 100644 --- a/tests/src/com/android/inputmethod/latin/EditDistanceTests.java +++ b/tests/src/com/android/inputmethod/latin/EditDistanceTests.java @@ -21,16 +21,6 @@ import android.test.suitebuilder.annotation.SmallTest; @SmallTest public class EditDistanceTests extends AndroidTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - /* * dist(kitten, sitting) == 3 * diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index b267bc5da..06b64b439 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -38,6 +38,8 @@ import android.widget.FrameLayout; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.settings.DebugSettings; +import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -47,8 +49,6 @@ import java.util.concurrent.TimeUnit; public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { private static final String TAG = InputTestsBase.class.getSimpleName(); - private static final String PREF_DEBUG_MODE = "debug_mode"; - private static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; // Default value for auto-correction threshold. This is the string representation of the // index in the resources array of auto-correction threshold settings. private static final String DEFAULT_AUTO_CORRECTION_THRESHOLD = "1"; @@ -65,6 +65,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected View mInputView; protected InputConnection mInputConnection; private boolean mPreviousDebugSetting; + private boolean mPreviousBigramPredictionSettings; private String mPreviousAutoCorrectSetting; // A helper class to ease span tests @@ -163,7 +164,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { // returns the previous setting value protected boolean setDebugMode(final boolean value) { - return setBooleanPreference(PREF_DEBUG_MODE, value, false); + return setBooleanPreference(DebugSettings.PREF_DEBUG_MODE, value, false); } protected EditorInfo enrichEditorInfo(final EditorInfo ei) { @@ -184,7 +185,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); mPreviousDebugSetting = setDebugMode(true); - mPreviousAutoCorrectSetting = setStringPreference(PREF_AUTO_CORRECTION_THRESHOLD, + mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, + true, true /* defaultValue */); + mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); mLatinIME.onCreate(); EditorInfo ei = new EditorInfo(); @@ -202,16 +205,21 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mInputConnection = ic; changeLanguage("en_US"); // Run messages to avoid the messages enqueued by startInputView() and its friends - // to run on a later call and ruin things. + // to run on a later call and ruin things. We need to wait first because some of them + // can be posted with a delay (notably, MSG_RESUME_SUGGESTIONS) + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS); runMessages(); } @Override - protected void tearDown() { + protected void tearDown() throws Exception { mLatinIME.mHandler.removeAllMessages(); - setStringPreference(PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, + true /* defaultValue */); + setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, DEFAULT_AUTO_CORRECTION_THRESHOLD); setDebugMode(mPreviousDebugSetting); + super.tearDown(); } // We need to run the messages added to the handler from LatinIME. The only way to do diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 75a1aa3ca..141730de9 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -115,9 +115,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { @Override protected void tearDown() throws Exception { - super.tearDown(); // Quit test mode. BinaryDictionary.setCurrentTimeForTest(-1); + super.tearDown(); } private void generateWords(final int number, final Random random) { diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index a629773f6..dff5a77d7 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -22,6 +22,7 @@ import android.util.Log; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.utils.CollectionUtils; +import com.android.inputmethod.latin.utils.FileUtils; import java.io.File; import java.util.ArrayList; @@ -46,7 +47,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { /** * Generates a random word. */ - private String generateWord(final int value) { + private static String generateWord(final int value) { final int lengthOfChars = CHARACTERS.length; StringBuilder builder = new StringBuilder(); long lvalue = Math.abs((long)value); @@ -57,7 +58,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { return builder.toString(); } - private List<String> generateWords(final int number, final Random random) { + private static List<String> generateWords(final int number, final Random random) { final Set<String> wordSet = CollectionUtils.newHashSet(); while (wordSet.size() < number) { wordSet.add(generateWord(random.nextInt())); @@ -65,7 +66,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { return new ArrayList<String>(wordSet); } - private void addToDict(final UserHistoryDictionary dict, final List<String> words) { + private static void addToDict(final UserHistoryDictionary dict, final List<String> words) { String prevWord = null; for (String word : words) { dict.addToDictionary(prevWord, word, true, @@ -78,12 +79,11 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { * @param checkContents if true, checks whether written words are actually in the dictionary * or not. */ - private void addAndWriteRandomWords(final String testFilenameSuffix, final int numberOfWords, + private void addAndWriteRandomWords(final Locale locale, final int numberOfWords, final Random random, final boolean checkContents) { final List<String> words = generateWords(numberOfWords, random); - final UserHistoryDictionary dict = - PersonalizationHelper.getUserHistoryDictionary(getContext(), - new Locale(testFilenameSuffix)); + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + mContext, locale); // Add random words to the user history dictionary. addToDict(dict, words); if (checkContents) { @@ -99,12 +99,11 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { /** * Clear all entries in the user history dictionary. - * @param testFilenameSuffix file name suffix used for testing. + * @param locale dummy locale for testing. */ - private void clearHistory(final String testFilenameSuffix) { - final UserHistoryDictionary dict = - PersonalizationHelper.getUserHistoryDictionary(getContext(), - new Locale(testFilenameSuffix)); + private void clearHistory(final Locale locale) { + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + mContext, locale); dict.waitAllTasksForTests(); dict.clearAndFlushDictionary(); dict.close(); @@ -113,37 +112,35 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { /** * Shut down executer and wait until all operations of user history are done. - * @param testFilenameSuffix file name suffix used for testing. + * @param locale dummy locale for testing. */ - private void waitForWriting(final String testFilenameSuffix) { - final UserHistoryDictionary dict = - PersonalizationHelper.getUserHistoryDictionary(getContext(), - new Locale(testFilenameSuffix)); + private void waitForWriting(final Locale locale) { + final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( + mContext, locale); dict.waitAllTasksForTests(); } 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 String testFilenameSuffix = "test_random_words" + System.currentTimeMillis(); - final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix - + ExpandableBinaryDictionary.DICT_FILE_EXTENSION; + final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); + final String dictName = ExpandableBinaryDictionary.getDictName( + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); + final File dictFile = ExpandableBinaryDictionary.getDictFile( + mContext, dictName, null /* dictFile */); final int numberOfWords = 1000; final Random random = new Random(123456); try { - clearHistory(testFilenameSuffix); - addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random, + clearHistory(dummyLocale); + addAndWriteRandomWords(dummyLocale, numberOfWords, random, true /* checksContents */); } finally { Log.d(TAG, "waiting for writing ..."); - waitForWriting(testFilenameSuffix); - final File dictFile = new File(getContext().getFilesDir(), fileName); - if (dictFile != null) { - assertTrue(dictFile.exists()); - dictFile.delete(); - } + waitForWriting(dummyLocale); + assertTrue("check exisiting of " + dictFile, dictFile.exists()); + FileUtils.deleteRecursively(dictFile); } } @@ -153,17 +150,18 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final int numberOfWordsInsertedForEachLanguageSwitch = 100; final File dictFiles[] = new File[numberOfLanguages]; - final String testFilenameSuffixes[] = new String[numberOfLanguages]; + final Locale dummyLocales[] = new Locale[numberOfLanguages]; try { final Random random = new Random(123456); // Create filename suffixes for this test. for (int i = 0; i < numberOfLanguages; i++) { - testFilenameSuffixes[i] = "test_switching_languages" + i; - final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffixes[i] - + ExpandableBinaryDictionary.DICT_FILE_EXTENSION; - dictFiles[i] = new File(getContext().getFilesDir(), fileName); - clearHistory(testFilenameSuffixes[i]); + dummyLocales[i] = new Locale("test_switching_languages" + i); + final String dictName = ExpandableBinaryDictionary.getDictName( + UserHistoryDictionary.NAME, dummyLocales[i], null /* dictFile */); + dictFiles[i] = ExpandableBinaryDictionary.getDictFile( + mContext, dictName, null /* dictFile */); + clearHistory(dummyLocales[i]); } final long start = System.currentTimeMillis(); @@ -171,7 +169,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { for (int i = 0; i < numberOfLanguageSwitching; i++) { final int index = i % numberOfLanguages; // Switch languages to testFilenameSuffixes[index]. - addAndWriteRandomWords(testFilenameSuffixes[index], + addAndWriteRandomWords(dummyLocales[index], numberOfWordsInsertedForEachLanguageSwitch, random, false /* checksContents */); } @@ -182,36 +180,31 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } finally { Log.d(TAG, "waiting for writing ..."); for (int i = 0; i < numberOfLanguages; i++) { - waitForWriting(testFilenameSuffixes[i]); + waitForWriting(dummyLocales[i]); } - for (final File file : dictFiles) { - if (file != null) { - assertTrue(file.exists()); - file.delete(); - } + for (final File dictFile : dictFiles) { + assertTrue("check exisiting of " + dictFile, dictFile.exists()); + FileUtils.deleteRecursively(dictFile); } } } public void testAddManyWords() { - final String testFilenameSuffix = "test_random_words" + System.currentTimeMillis(); + final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); + final String dictName = ExpandableBinaryDictionary.getDictName( + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); + final File dictFile = ExpandableBinaryDictionary.getDictFile( + mContext, dictName, null /* dictFile */); final int numberOfWords = 10000; final Random random = new Random(123456); - clearHistory(testFilenameSuffix); + clearHistory(dummyLocale); try { - addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random, - true /* checksContents */); + addAndWriteRandomWords(dummyLocale, numberOfWords, random, true /* checksContents */); } finally { Log.d(TAG, "waiting for writing ..."); - waitForWriting(testFilenameSuffix); - final String fileName = UserHistoryDictionary.NAME + "." + testFilenameSuffix - + ExpandableBinaryDictionary.DICT_FILE_EXTENSION; - final File dictFile = new File(getContext().getFilesDir(), fileName); - if (dictFile != null) { - assertTrue(dictFile.exists()); - dictFile.delete(); - } + waitForWriting(dummyLocale); + assertTrue("check exisiting of " + dictFile, dictFile.exists()); + FileUtils.deleteRecursively(dictFile); } } - } |