diff options
author | 2013-08-22 22:43:20 +0900 | |
---|---|---|
committer | 2013-08-23 20:29:25 +0900 | |
commit | e9a10ff0f026b5ec458f116afc7a75806574cbcd (patch) | |
tree | b50ff7fc7e7b4a71db9410bfea829905f00817fb /tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | |
parent | b64157bf4720dfc2aa40ad8e6806459012f81082 (diff) | |
download | latinime-e9a10ff0f026b5ec458f116afc7a75806574cbcd.tar.gz latinime-e9a10ff0f026b5ec458f116afc7a75806574cbcd.tar.xz latinime-e9a10ff0f026b5ec458f116afc7a75806574cbcd.zip |
Add DictDecoder.readDictionaryBinary.
Bug: 10434720
Change-Id: I14690a6e0f922ed1bab3a4b6c9a457ae84d4c1a4
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 5bf9143ed..6d4c05e09 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -33,7 +33,6 @@ import com.android.inputmethod.latin.utils.CollectionUtils; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -133,17 +132,15 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { // Utilities for test /** - * Makes new DictBuffer according to BUFFER_TYPE. + * Makes new DictDecoder according to BUFFER_TYPE. */ - private void getDictBuffer(final Ver3DictDecoder dictDecoder, final int bufferType) - throws FileNotFoundException, IOException { + private Ver3DictDecoder getDictDecoder(final File file, final int bufferType) { if (bufferType == USE_BYTE_BUFFER) { - dictDecoder.openDictBuffer( - new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory()); - } else if (bufferType == USE_BYTE_ARRAY) { - dictDecoder.openDictBuffer( - new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); + return new Ver3DictDecoder(file, DictDecoder.USE_READONLY_BYTEBUFFER); + } else if (bufferType == USE_BYTE_ARRAY) { + return new Ver3DictDecoder(file, DictDecoder.USE_BYTEARRAY); } + return null; } /** @@ -284,14 +281,14 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final SparseArray<List<Integer>> bigrams, final Map<String, List<String>> shortcutMap, final int bufferType) { long now, diff = -1; - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); FusionDictionary dict = null; try { - getDictBuffer(dictDecoder, bufferType); + final Ver3DictDecoder dictDecoder = getDictDecoder(file, bufferType); + dictDecoder.openDictBuffer(); assertNotNull(dictDecoder.getDictBuffer()); now = System.currentTimeMillis(); - dict = BinaryDictDecoderUtils.readDictionaryBinary(dictDecoder, null); + dict = dictDecoder.readDictionaryBinary(null); diff = System.currentTimeMillis() - now; } catch (IOException e) { Log.e(TAG, "IOException while reading dictionary", e); @@ -444,9 +441,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final Map<Integer, Integer> resultFreqs = CollectionUtils.newTreeMap(); long now = -1, diff = -1; - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); try { - getDictBuffer(dictDecoder, bufferType); + final Ver3DictDecoder dictDecoder = getDictDecoder(file, bufferType); + dictDecoder.openDictBuffer(); assertNotNull("Can't get buffer.", dictDecoder.getDictBuffer()); now = System.currentTimeMillis(); BinaryDictIOUtils.readUnigramsAndBigramsBinary(dictDecoder, resultWords, resultFreqs, @@ -587,10 +584,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, DictDecoder.USE_BYTEARRAY); try { - dictDecoder.openDictBuffer( - new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); + dictDecoder.openDictBuffer(); } catch (IOException e) { // ignore Log.e(TAG, "IOException while opening the buffer", e); @@ -648,10 +644,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); timeWritingDictToFile(file, dict, VERSION3_WITH_DYNAMIC_UPDATE); - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file); + final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, DictDecoder.USE_BYTEARRAY); try { - dictDecoder.openDictBuffer( - new Ver3DictDecoder.DictionaryBufferFromByteArrayFactory()); + dictDecoder.openDictBuffer(); } catch (IOException e) { // ignore Log.e(TAG, "IOException while opening the buffer", e); |