am f61999ca: Merge "Make it easy to open several dictionaries from tests"

* commit 'f61999caba1fa720c6817da8b6fc129d16b9a954':
  Make it easy to open several dictionaries from tests
main
Jean Chalard 2013-05-31 04:23:33 -07:00 committed by Android Git Automerger
commit fcdb85b37a
3 changed files with 17 additions and 15 deletions

View File

@ -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;

View File

@ -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;
}
/**

View File

@ -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);