diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputTestsBase.java | 7 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | 23 |
2 files changed, 25 insertions, 5 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 0a1c4e963..da1fb6f0d 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -44,10 +44,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { private static final String PREF_DEBUG_MODE = "debug_mode"; - // The message that sets the underline is posted with a 100 ms delay + // The message that sets the underline is posted with a 200 ms delay protected static final int DELAY_TO_WAIT_FOR_UNDERLINE = 200; - // The message that sets predictions is posted with a 100 ms delay + // The message that sets predictions is posted with a 200 ms delay protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200; + // The message that sets auto-corrections is posted within a 100 ms delay. + protected static final int DELAY_TO_WAIT_FOR_AUTOCORRECTION = 100; protected LatinIME mLatinIME; protected Keyboard mKeyboard; @@ -221,6 +223,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected void type(final String stringToType) { for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) { type(stringToType.codePointAt(i)); + sleep(DELAY_TO_WAIT_FOR_AUTOCORRECTION); } } diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index 1fd1b8a81..1a20ec52d 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -82,14 +82,29 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } } + /** + * @param checksContents if true, checks whether written words are actually in the dictionary + * or not. + */ private void addAndWriteRandomWords(final String testFilenameSuffix, final int numberOfWords, - final Random random) { + final Random random, final boolean checksContents) { final List<String> words = generateWords(numberOfWords, random); final UserHistoryPredictionDictionary dict = PersonalizationHelper.getUserHistoryPredictionDictionary(getContext(), testFilenameSuffix /* locale */, mPrefs); // Add random words to the user history dictionary. addToDict(dict, words); + if (checksContents) { + try { + Thread.sleep(TimeUnit.MILLISECONDS.convert(5L, TimeUnit.SECONDS)); + } catch (InterruptedException e) { + } + for (int i = 0; i < 10 && i < numberOfWords; ++i) { + final String word = words.get(i); + // This may fail as long as we use tryLock on inserting the bigram words + assertTrue(dict.isInDictionaryForTests(word)); + } + } // write to file. dict.close(); } @@ -103,7 +118,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final Random random = new Random(123456); try { - addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random); + addAndWriteRandomWords(testFilenameSuffix, numberOfWords, random, + true /* checksContents */); } finally { try { Log.d(TAG, "waiting for writing ..."); @@ -148,7 +164,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final int index = i % numberOfLanguages; // Switch languages to testFilenameSuffixes[index]. addAndWriteRandomWords(testFilenameSuffixes[index], - numberOfWordsInsertedForEachLanguageSwitch, random); + numberOfWordsInsertedForEachLanguageSwitch, random, + false /* checksContents */); } final long end = System.currentTimeMillis(); |