Merge "Remove all test dictionary files before and after unit test."

main
Keisuke Kuroyanagi 2014-08-13 07:51:03 +00:00 committed by Android (Google) Code Review
commit 24cb234778
1 changed files with 26 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import com.android.inputmethod.latin.utils.DistracterFilter;
import com.android.inputmethod.latin.utils.FileUtils; import com.android.inputmethod.latin.utils.FileUtils;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -42,6 +43,7 @@ import java.util.concurrent.TimeUnit;
public class UserHistoryDictionaryTests extends AndroidTestCase { public class UserHistoryDictionaryTests extends AndroidTestCase {
private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName(); private static final String TAG = UserHistoryDictionaryTests.class.getSimpleName();
private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000; private static final int WAIT_FOR_WRITING_FILE_IN_MILLISECONDS = 3000;
private static final String TEST_LOCALE_PREFIX = "test_";
private static final String[] CHARACTERS = { private static final String[] CHARACTERS = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
@ -50,14 +52,31 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
private int mCurrentTime = 0; private int mCurrentTime = 0;
private void removeAllTestDictFiles() {
final Locale dummyLocale = new Locale(TEST_LOCALE_PREFIX);
final String dictName = ExpandableBinaryDictionary.getDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */);
final File dictFile = ExpandableBinaryDictionary.getDictFile(
mContext, dictName, null /* dictFile */);
final FilenameFilter filenameFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.startsWith(UserHistoryDictionary.NAME + "." + TEST_LOCALE_PREFIX);
}
};
FileUtils.deleteFilteredFiles(dictFile.getParentFile(), filenameFilter);
}
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
resetCurrentTimeForTestMode(); resetCurrentTimeForTestMode();
removeAllTestDictFiles();
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
removeAllTestDictFiles();
stopTestModeInNativeCode(); stopTestModeInNativeCode();
super.tearDown(); super.tearDown();
} }
@ -169,7 +188,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
public void testRandomWords() { public void testRandomWords() {
Log.d(TAG, "This test can be used for profiling."); Log.d(TAG, "This test can be used for profiling.");
Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true.");
final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); final Locale dummyLocale =
new Locale(TEST_LOCALE_PREFIX + "random_words" + System.currentTimeMillis());
final String dictName = ExpandableBinaryDictionary.getDictName( final String dictName = ExpandableBinaryDictionary.getDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */);
final File dictFile = ExpandableBinaryDictionary.getDictFile( final File dictFile = ExpandableBinaryDictionary.getDictFile(
@ -202,7 +222,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
// Create filename suffixes for this test. // Create filename suffixes for this test.
for (int i = 0; i < numberOfLanguages; i++) { for (int i = 0; i < numberOfLanguages; i++) {
dummyLocales[i] = new Locale("test_switching_languages" + i); dummyLocales[i] = new Locale(TEST_LOCALE_PREFIX + "switching_languages" + i);
final String dictName = ExpandableBinaryDictionary.getDictName( final String dictName = ExpandableBinaryDictionary.getDictName(
UserHistoryDictionary.NAME, dummyLocales[i], null /* dictFile */); UserHistoryDictionary.NAME, dummyLocales[i], null /* dictFile */);
dictFiles[i] = ExpandableBinaryDictionary.getDictFile( dictFiles[i] = ExpandableBinaryDictionary.getDictFile(
@ -236,7 +256,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
} }
public void testAddManyWords() { public void testAddManyWords() {
final Locale dummyLocale = new Locale("test_random_words" + System.currentTimeMillis()); final Locale dummyLocale =
new Locale(TEST_LOCALE_PREFIX + "random_words" + System.currentTimeMillis());
final String dictName = ExpandableBinaryDictionary.getDictName( final String dictName = ExpandableBinaryDictionary.getDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */);
final File dictFile = ExpandableBinaryDictionary.getDictFile( final File dictFile = ExpandableBinaryDictionary.getDictFile(
@ -264,7 +285,8 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
} }
public void testDecaying() { public void testDecaying() {
final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis()); final Locale dummyLocale =
new Locale(TEST_LOCALE_PREFIX + "decaying" + System.currentTimeMillis());
final int numberOfWords = 5000; final int numberOfWords = 5000;
final Random random = new Random(123456); final Random random = new Random(123456);
resetCurrentTimeForTestMode(); resetCurrentTimeForTestMode();