am 9ab71eda: Fix tests.
* commit '9ab71eda83c756d9d551fc757d07b6b81f6dfb1e': Fix tests.main
commit
7db1ac2667
|
@ -379,6 +379,15 @@ public final class FormatSpec {
|
||||||
mHeaderSize = headerSize;
|
mHeaderSize = headerSize;
|
||||||
mDictionaryOptions = dictionaryOptions;
|
mDictionaryOptions = dictionaryOptions;
|
||||||
mFormatOptions = formatOptions;
|
mFormatOptions = formatOptions;
|
||||||
|
if (null == getLocaleString()) {
|
||||||
|
throw new RuntimeException("Cannot create a FileHeader without a locale");
|
||||||
|
}
|
||||||
|
if (null == getVersion()) {
|
||||||
|
throw new RuntimeException("Cannot create a FileHeader without a version");
|
||||||
|
}
|
||||||
|
if (null == getId()) {
|
||||||
|
throw new RuntimeException("Cannot create a FileHeader without an ID");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to get the locale as a String
|
// Helper method to get the locale as a String
|
||||||
|
|
|
@ -140,8 +140,10 @@ public class Ver4DictUpdater extends Ver4DictDecoder implements DictUpdater {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteWord(final String word) throws IOException, UnsupportedFormatException {
|
public void deleteWord(final String word) throws IOException, UnsupportedFormatException {
|
||||||
if (mDictBuffer == null) openDictBuffer();
|
if (mDictBuffer == null) {
|
||||||
readHeader();
|
openDictBuffer();
|
||||||
|
readHeader();
|
||||||
|
}
|
||||||
final int wordPos = getTerminalPosition(word);
|
final int wordPos = getTerminalPosition(word);
|
||||||
if (wordPos != FormatSpec.NOT_VALID_WORD) {
|
if (wordPos != FormatSpec.NOT_VALID_WORD) {
|
||||||
mDictBuffer.position(wordPos);
|
mDictBuffer.position(wordPos);
|
||||||
|
|
|
@ -265,7 +265,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
||||||
getContext().getCacheDir());
|
getContext().getCacheDir());
|
||||||
|
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(dictName, dictVersion));
|
BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion));
|
||||||
addUnigrams(words.size(), dict, words, shortcuts);
|
addUnigrams(words.size(), dict, words, shortcuts);
|
||||||
addBigrams(dict, words, bigrams);
|
addBigrams(dict, words, bigrams);
|
||||||
checkDictionary(dict, words, bigrams, shortcuts);
|
checkDictionary(dict, words, bigrams, shortcuts);
|
||||||
|
@ -444,7 +444,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
||||||
|
|
||||||
// making the dictionary from lists of words.
|
// making the dictionary from lists of words.
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(dictName, dictVersion));
|
BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion));
|
||||||
addUnigrams(words.size(), dict, words, null /* shortcutMap */);
|
addUnigrams(words.size(), dict, words, null /* shortcutMap */);
|
||||||
addBigrams(dict, words, bigrams);
|
addBigrams(dict, words, bigrams);
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
||||||
getContext().getCacheDir());
|
getContext().getCacheDir());
|
||||||
|
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(dictName, dictVersion));
|
BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion));
|
||||||
addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
|
addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
|
||||||
addBigrams(dict, words, bigrams);
|
addBigrams(dict, words, bigrams);
|
||||||
timeWritingDictToFile(file, dict, formatOptions);
|
timeWritingDictToFile(file, dict, formatOptions);
|
||||||
|
@ -649,8 +649,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
||||||
getContext().getCacheDir());
|
getContext().getCacheDir());
|
||||||
|
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
new FusionDictionary.DictionaryOptions(
|
BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion));
|
||||||
new HashMap<String, String>(), false, false));
|
|
||||||
addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
|
addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */);
|
||||||
timeWritingDictToFile(file, dict, formatOptions);
|
timeWritingDictToFile(file, dict, formatOptions);
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
|
|
||||||
// set an initial dictionary.
|
// set an initial dictionary.
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(testName, version));
|
BinaryDictUtils.makeDictionaryOptions(testName, version));
|
||||||
dict.add("abcd", 10, null, false);
|
dict.add("abcd", 10, null, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -301,7 +301,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
|
|
||||||
// set an initial dictionary.
|
// set an initial dictionary.
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(testName, version));
|
BinaryDictUtils.makeDictionaryOptions(testName, version));
|
||||||
dict.add("abcd", 10, null, false);
|
dict.add("abcd", 10, null, false);
|
||||||
dict.add("efgh", 15, null, false);
|
dict.add("efgh", 15, null, false);
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
|
||||||
|
|
||||||
// set an initial dictionary.
|
// set an initial dictionary.
|
||||||
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
|
||||||
BinaryDictUtils.getDictionaryOptions(testName, version));
|
BinaryDictUtils.makeDictionaryOptions(testName, version));
|
||||||
dict.add("initial", 10, null, false);
|
dict.add("initial", 10, null, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.makedict;
|
package com.android.inputmethod.latin.makedict;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
|
||||||
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
|
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
|
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
|
||||||
|
|
||||||
|
@ -41,11 +42,12 @@ public class BinaryDictUtils {
|
||||||
new FormatSpec.FormatOptions(4, true /* supportsDynamicUpdate */,
|
new FormatSpec.FormatOptions(4, true /* supportsDynamicUpdate */,
|
||||||
true /* hasTimestamp */);
|
true /* hasTimestamp */);
|
||||||
|
|
||||||
public static DictionaryOptions getDictionaryOptions(final String id, final String version) {
|
public static DictionaryOptions makeDictionaryOptions(final String id, final String version) {
|
||||||
final DictionaryOptions options = new DictionaryOptions(new HashMap<String, String>(),
|
final DictionaryOptions options = new DictionaryOptions(new HashMap<String, String>(),
|
||||||
false /* germanUmlautProcessing */, false /* frenchLigatureProcessing */);
|
false /* germanUmlautProcessing */, false /* frenchLigatureProcessing */);
|
||||||
options.mAttributes.put("dictionary", id);
|
options.mAttributes.put(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, "en_US");
|
||||||
options.mAttributes.put("version", version);
|
options.mAttributes.put(FileHeader.DICTIONARY_ID_ATTRIBUTE, id);
|
||||||
|
options.mAttributes.put(FileHeader.DICTIONARY_VERSION_ATTRIBUTE, version);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue