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

* commit 'f61999caba1fa720c6817da8b6fc129d16b9a954':
  Make it easy to open several dictionaries from tests
This commit is contained in:
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 * 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. * 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 String mFilename;
public final long mOffset; public final long mOffset;
public final long mLength; public final long mLength;

View file

@ -21,6 +21,8 @@ import android.content.res.AssetFileDescriptor;
import android.content.res.Resources; import android.content.res.Resources;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; 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. * Create a dictionary from passed data. This is intended for unit tests only.
* @param dictionary the file to read * @param dictionaryList the list of files to read, with their offsets and lengths
* @param startOffset the offset in the file where the data starts
* @param length the length of the data
* @param useFullEditDistance whether to use the full edit distance in suggestions * @param useFullEditDistance whether to use the full edit distance in suggestions
* @return the created dictionary, or null. * @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) { final boolean useFullEditDistance, Locale locale) {
if (dictionary.isFile()) { final DictionaryCollection dictionaryCollection =
return new BinaryDictionary(dictionary.getAbsolutePath(), startOffset, length, new DictionaryCollection(Dictionary.TYPE_MAIN);
useFullEditDistance, locale, Dictionary.TYPE_MAIN); for (final AssetFileAddress address : dictionaryList) {
} else { final BinaryDictionary binaryDictionary = new BinaryDictionary(address.mFilename,
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath()); address.mOffset, address.mLength, useFullEditDistance, locale,
return null; 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.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
@ -77,9 +76,9 @@ public final class Suggest {
} }
@UsedForTesting @UsedForTesting
Suggest(final File dictionary, final long startOffset, final long length, final Locale locale) { Suggest(final AssetFileAddress[] dictionaryList, final Locale locale) {
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionary, final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionaryList,
startOffset, length /* useFullEditDistance */, false, locale); false /* useFullEditDistance */, locale);
mLocale = locale; mLocale = locale;
mMainDictionary = mainDict; mMainDictionary = mainDict;
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict);