diff options
Diffstat (limited to 'tests/src')
5 files changed, 25 insertions, 21 deletions
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index c63193aeb..d76a55283 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -22,6 +22,7 @@ import android.util.Pair; import com.android.inputmethod.latin.makedict.CodePointUtils; import com.android.inputmethod.latin.makedict.FormatSpec; +import com.android.inputmethod.latin.utils.FileUtils; import java.io.File; import java.io.IOException; @@ -102,7 +103,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { private File createEmptyDictionaryAndGetFile(final String dictId, final int formatVersion) throws IOException { - if (formatVersion == 4) { + if (formatVersion == FormatSpec.VERSION4) { return createEmptyVer4DictionaryAndGetFile(dictId); } else { throw new IOException("Dictionary format version " + formatVersion @@ -112,7 +113,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { private File createEmptyVer4DictionaryAndGetFile(final String dictId) throws IOException { final File file = File.createTempFile(dictId, TEST_DICT_FILE_EXTENSION, getContext().getCacheDir()); - file.delete(); + FileUtils.deleteRecursively(file); file.mkdir(); Map<String, String> attributeMap = new HashMap<String, String>(); attributeMap.put(FormatSpec.FileHeader.SUPPORTS_DYNAMIC_UPDATE_ATTRIBUTE, @@ -123,10 +124,10 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); if (BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(), FormatSpec.VERSION4, attributeMap)) { - return new File(file, FormatSpec.TRIE_FILE_EXTENSION); + return new File(file, FormatSpec.HEADER_FILE_EXTENSION); } else { throw new IOException("Empty dictionary " + file.getAbsolutePath() + " " - + FormatSpec.TRIE_FILE_EXTENSION + " cannot be created."); + + FormatSpec.HEADER_FILE_EXTENSION + " cannot be created."); } } @@ -140,11 +141,11 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { binaryDictionary.getPropertyForTests(query); } - public void testControllCurrentTime() { - testControllCurrentTime(FormatSpec.VERSION4); + public void testControlCurrentTime() { + testControlCurrentTime(FormatSpec.VERSION4); } - private void testControllCurrentTime(final int formatVersion) { + private void testControlCurrentTime(final int formatVersion) { final int TEST_COUNT = 1000; final long seed = System.currentTimeMillis(); final Random random = new Random(seed); diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index 7fa52e902..c14840258 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -72,10 +72,10 @@ public class BinaryDictionaryTests extends AndroidTestCase { FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); if (BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(), FormatSpec.VERSION4, attributeMap)) { - return new File(file, FormatSpec.TRIE_FILE_EXTENSION); + return new File(file, FormatSpec.HEADER_FILE_EXTENSION); } else { throw new IOException("Empty dictionary " + file.getAbsolutePath() + " " - + FormatSpec.TRIE_FILE_EXTENSION + " cannot be created."); + + FormatSpec.HEADER_FILE_EXTENSION + " cannot be created."); } } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 05de37d4c..e3ec2eca9 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -523,7 +523,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { return null; } if (fileHeader == null) return null; - return BinaryDictDecoderUtils.getWordAtPosition(dictDecoder, fileHeader.mHeaderSize, + return BinaryDictDecoderUtils.getWordAtPosition(dictDecoder, fileHeader.mBodyOffset, address, fileHeader.mFormatOptions).mWord; } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java index da217cea6..308919499 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java @@ -216,7 +216,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file); final FileHeader fileHeader = dictDecoder.readHeader(); assertEquals(word, - BinaryDictDecoderUtils.getWordAtPosition(dictDecoder, fileHeader.mHeaderSize, + BinaryDictDecoderUtils.getWordAtPosition(dictDecoder, fileHeader.mBodyOffset, position, fileHeader.mFormatOptions).mWord); } catch (IOException e) { Log.e(TAG, "Raised an IOException while looking up a word", e); diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java index 8b1521a6c..ad17a7118 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java @@ -29,17 +29,18 @@ public class BinaryDictUtils { public static final String TEST_DICT_FILE_EXTENSION = ".testDict"; - public static final FormatSpec.FormatOptions VERSION2 = new FormatSpec.FormatOptions(2); + public static final FormatSpec.FormatOptions VERSION2 = + new FormatSpec.FormatOptions(FormatSpec.VERSION2); public static final FormatSpec.FormatOptions VERSION3_WITHOUT_DYNAMIC_UPDATE = - new FormatSpec.FormatOptions(3, false /* supportsDynamicUpdate */); + new FormatSpec.FormatOptions(FormatSpec.VERSION3, false /* supportsDynamicUpdate */); public static final FormatSpec.FormatOptions VERSION3_WITH_DYNAMIC_UPDATE = - new FormatSpec.FormatOptions(3, true /* supportsDynamicUpdate */); + new FormatSpec.FormatOptions(FormatSpec.VERSION3, true /* supportsDynamicUpdate */); public static final FormatSpec.FormatOptions VERSION4_WITHOUT_DYNAMIC_UPDATE = - new FormatSpec.FormatOptions(4, false /* supportsDynamicUpdate */); + new FormatSpec.FormatOptions(FormatSpec.VERSION4, false /* supportsDynamicUpdate */); public static final FormatSpec.FormatOptions VERSION4_WITH_DYNAMIC_UPDATE = - new FormatSpec.FormatOptions(4, true /* supportsDynamicUpdate */); + new FormatSpec.FormatOptions(FormatSpec.VERSION4, true /* supportsDynamicUpdate */); public static final FormatSpec.FormatOptions VERSION4_WITH_DYNAMIC_UPDATE_AND_TIMESTAMP = - new FormatSpec.FormatOptions(4, true /* supportsDynamicUpdate */, + new FormatSpec.FormatOptions(FormatSpec.VERSION4, true /* supportsDynamicUpdate */, true /* hasTimestamp */); public static DictionaryOptions makeDictionaryOptions(final String id, final String version) { @@ -53,9 +54,10 @@ public class BinaryDictUtils { public static File getDictFile(final String name, final String version, final FormatOptions formatOptions, final File directory) { - if (formatOptions.mVersion == 2 || formatOptions.mVersion == 3) { + if (formatOptions.mVersion == FormatSpec.VERSION2 + || formatOptions.mVersion == FormatSpec.VERSION3) { return new File(directory, name + "." + version + TEST_DICT_FILE_EXTENSION); - } else if (formatOptions.mVersion == 4) { + } else if (formatOptions.mVersion == FormatSpec.VERSION4) { return new File(directory, name + "." + version); } else { throw new RuntimeException("the format option has a wrong version : " @@ -67,7 +69,8 @@ public class BinaryDictUtils { final File cacheDir) { if (formatOptions.mVersion == FormatSpec.VERSION4) { return new Ver4DictEncoder(cacheDir); - } else if (formatOptions.mVersion == 3 || formatOptions.mVersion == 2) { + } else if (formatOptions.mVersion == FormatSpec.VERSION3 + || formatOptions.mVersion == FormatSpec.VERSION2) { return new Ver3DictEncoder(file); } else { throw new RuntimeException("The format option has a wrong version : " @@ -79,7 +82,7 @@ public class BinaryDictUtils { throws UnsupportedFormatException { if (formatOptions.mVersion == FormatSpec.VERSION4) { return new Ver4DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); - } else if (formatOptions.mVersion == 3) { + } else if (formatOptions.mVersion == FormatSpec.VERSION3) { return new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); } else { throw new UnsupportedFormatException("The format option has a wrong version : " |