diff options
author | 2013-07-15 23:56:14 -0700 | |
---|---|---|
committer | 2013-07-15 23:56:14 -0700 | |
commit | f9b175b6c1bd84365719cc13aaa2d32aa0bd0b07 (patch) | |
tree | dc9bc5b40f857367029117b508b1923122f3af82 /tests/src | |
parent | 0a951d55a0acaf5edb3df43e28bd90586cce6475 (diff) | |
parent | 3bf996f936d75589d3591689d65ee9d794eb1392 (diff) | |
download | latinime-f9b175b6c1bd84365719cc13aaa2d32aa0bd0b07.tar.gz latinime-f9b175b6c1bd84365719cc13aaa2d32aa0bd0b07.tar.xz latinime-f9b175b6c1bd84365719cc13aaa2d32aa0bd0b07.zip |
am 3bf996f9: Merge "Add a test for user history for switching languages."
* commit '3bf996f936d75589d3591689d65ee9d794eb1392':
Add a test for user history for switching languages.
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java index 93befd7bf..e0a0863ae 100644 --- a/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/UserHistoryDictionaryTests.java @@ -82,7 +82,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { File dictFile = null; try { Log.d(TAG, "This test can be used for profiling."); - Log.d(TAG, "Usage: please set UserHisotoryDictionary.PROFILE_SAVE_RESTORE to true."); + Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); final int numberOfWords = 1000; final Random random = new Random(123456); List<String> words = generateWords(numberOfWords, random); @@ -118,4 +118,54 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } } } + + public void testStressTestForSwitchingLanguagesAndAddingWords() { + final int numberOfLanguages = 2; + final int numberOfLanguageSwitching = 100; + final int numberOfWordsIntertedForEachLanguageSwitch = 100; + + final File dictFiles[] = new File[numberOfLanguages]; + try { + final Random random = new Random(123456); + + // Create locales for this test. + String locales[] = new String[numberOfLanguages]; + for (int i = 0; i < numberOfLanguages; i++) { + locales[i] = "testSwitchingLanguages" + i; + final String fileName = "UserHistoryDictionary." + locales[i] + ".dict"; + dictFiles[i] = new File(getContext().getFilesDir(), fileName); + } + + final long now = System.currentTimeMillis(); + + for (int i = 0; i < numberOfLanguageSwitching; i++) { + final int index = i % numberOfLanguages; + // Switch languages to locales[index]. + final UserHistoryDictionary dict = UserHistoryDictionary.getInstance(getContext(), + locales[index], mPrefs); + final List<String> words = generateWords( + numberOfWordsIntertedForEachLanguageSwitch, random); + // Add random words to the user history dictionary. + addToDict(dict, words); + // write to file + dict.close(); + } + + final long end = System.currentTimeMillis(); + Log.d(TAG, "testStressTestForSwitchingLanguageAndAddingWords took " + + (end - now) + " ms"); + try { + Log.d(TAG, "waiting for writing ..."); + Thread.sleep(5000); + } catch (InterruptedException e) { + Log.d(TAG, "InterruptedException: " + e); + } + } finally { + for (final File file : dictFiles) { + if (file != null) { + file.delete(); + } + } + } + } } |