Make it easy to open several dictionaries from tests
Bug: 9127175 Change-Id: I3f1840ee73b364df26dfddb5acb10001e0f2cb61
This commit is contained in:
parent
e6125db98d
commit
1562fc91f0
3 changed files with 17 additions and 15 deletions
|
@ -24,7 +24,7 @@ import java.io.File;
|
|||
* the package file. Open it correctly thus requires the name of the package it is in, but
|
||||
* also the offset in the file and the length of this data. This class encapsulates these three.
|
||||
*/
|
||||
final class AssetFileAddress {
|
||||
public final class AssetFileAddress {
|
||||
public final String mFilename;
|
||||
public final long mOffset;
|
||||
public final long mLength;
|
||||
|
|
|
@ -21,6 +21,8 @@ import android.content.res.AssetFileDescriptor;
|
|||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.annotations.UsedForTesting;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
|
@ -126,21 +128,22 @@ public final class DictionaryFactory {
|
|||
|
||||
/**
|
||||
* Create a dictionary from passed data. This is intended for unit tests only.
|
||||
* @param dictionary the file to read
|
||||
* @param startOffset the offset in the file where the data starts
|
||||
* @param length the length of the data
|
||||
* @param dictionaryList the list of files to read, with their offsets and lengths
|
||||
* @param useFullEditDistance whether to use the full edit distance in suggestions
|
||||
* @return the created dictionary, or null.
|
||||
*/
|
||||
public static Dictionary createDictionaryForTest(File dictionary, long startOffset, long length,
|
||||
@UsedForTesting
|
||||
public static Dictionary createDictionaryForTest(final AssetFileAddress[] dictionaryList,
|
||||
final boolean useFullEditDistance, Locale locale) {
|
||||
if (dictionary.isFile()) {
|
||||
return new BinaryDictionary(dictionary.getAbsolutePath(), startOffset, length,
|
||||
useFullEditDistance, locale, Dictionary.TYPE_MAIN);
|
||||
} else {
|
||||
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath());
|
||||
return null;
|
||||
final DictionaryCollection dictionaryCollection =
|
||||
new DictionaryCollection(Dictionary.TYPE_MAIN);
|
||||
for (final AssetFileAddress address : dictionaryList) {
|
||||
final BinaryDictionary binaryDictionary = new BinaryDictionary(address.mFilename,
|
||||
address.mOffset, address.mLength, useFullEditDistance, locale,
|
||||
Dictionary.TYPE_MAIN);
|
||||
dictionaryCollection.addDictionary(binaryDictionary);
|
||||
}
|
||||
return dictionaryCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,6 @@ import com.android.inputmethod.annotations.UsedForTesting;
|
|||
import com.android.inputmethod.keyboard.ProximityInfo;
|
||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
|
@ -77,9 +76,9 @@ public final class Suggest {
|
|||
}
|
||||
|
||||
@UsedForTesting
|
||||
Suggest(final File dictionary, final long startOffset, final long length, final Locale locale) {
|
||||
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionary,
|
||||
startOffset, length /* useFullEditDistance */, false, locale);
|
||||
Suggest(final AssetFileAddress[] dictionaryList, final Locale locale) {
|
||||
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionaryList,
|
||||
false /* useFullEditDistance */, locale);
|
||||
mLocale = locale;
|
||||
mMainDictionary = mainDict;
|
||||
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict);
|
||||
|
|
Loading…
Reference in a new issue