diff options
author | 2013-09-30 11:42:52 +0900 | |
---|---|---|
committer | 2013-10-03 20:16:34 +0900 | |
commit | d6e307a4b7933ad5efebc6b0d3b775c5ab5c0e6e (patch) | |
tree | 719e0b159c2c886f31dd7829931af9630faf1693 /tests/src | |
parent | 7e6e97014d7d031f233267220a627b3dfdfd26dc (diff) | |
download | latinime-d6e307a4b7933ad5efebc6b0d3b775c5ab5c0e6e.tar.gz latinime-d6e307a4b7933ad5efebc6b0d3b775c5ab5c0e6e.tar.xz latinime-d6e307a4b7933ad5efebc6b0d3b775c5ab5c0e6e.zip |
Add DictUpdater.
Change-Id: Ic586e46e5a9f59de53d53e59886d635345940974
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | 22 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java | 25 |
2 files changed, 12 insertions, 35 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 0cf4ef9f1..aa1658301 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -657,27 +657,21 @@ 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, DictDecoder.USE_BYTEARRAY); - try { - dictDecoder.openDictBuffer(); - } catch (IOException e) { - // ignore - Log.e(TAG, "IOException while opening the buffer", e); - } - assertTrue("Can't get the buffer", dictDecoder.isDictBufferOpen()); + final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, + DictDecoder.USE_WRITABLE_BYTEBUFFER); try { MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, - dictDecoder.getTerminalPosition(sWords.get(0))); - DynamicBinaryDictIOUtils.deleteWord(dictDecoder, sWords.get(0)); + dictUpdater.getTerminalPosition(sWords.get(0))); + dictUpdater.deleteWord(sWords.get(0)); assertEquals(FormatSpec.NOT_VALID_WORD, - dictDecoder.getTerminalPosition(sWords.get(0))); + dictUpdater.getTerminalPosition(sWords.get(0))); MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, - dictDecoder.getTerminalPosition(sWords.get(5))); - DynamicBinaryDictIOUtils.deleteWord(dictDecoder, sWords.get(5)); + dictUpdater.getTerminalPosition(sWords.get(5))); + dictUpdater.deleteWord(sWords.get(5)); assertEquals(FormatSpec.NOT_VALID_WORD, - dictDecoder.getTerminalPosition(sWords.get(5))); + dictUpdater.getTerminalPosition(sWords.get(5))); } catch (IOException e) { } catch (UnsupportedFormatException e) { } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java index a83749499..acd65856c 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java @@ -27,9 +27,7 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.utils.CollectionUtils; -import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -186,46 +184,31 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { private long insertAndCheckWord(final File file, final String word, final int frequency, final boolean exist, final ArrayList<WeightedString> bigrams, final ArrayList<WeightedString> shortcuts) { - BufferedOutputStream outStream = null; long amountOfTime = -1; try { - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, + final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); - dictDecoder.openDictBuffer(); - outStream = new BufferedOutputStream(new FileOutputStream(file, true)); if (!exist) { assertEquals(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word)); } final long now = System.nanoTime(); - DynamicBinaryDictIOUtils.insertWord(dictDecoder, outStream, word, frequency, bigrams, - shortcuts, false, false); + dictUpdater.insertWord(word, frequency, bigrams, shortcuts, false, false); amountOfTime = System.nanoTime() - now; - outStream.flush(); MoreAsserts.assertNotEqual(FormatSpec.NOT_VALID_WORD, getWordPosition(file, word)); - outStream.close(); } catch (IOException e) { Log.e(TAG, "Raised an IOException while inserting a word", e); } catch (UnsupportedFormatException e) { Log.e(TAG, "Raised an UnsupportedFormatException error while inserting a word", e); - } finally { - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - Log.e(TAG, "Failed to close the output stream", e); - } - } } return amountOfTime; } private void deleteWord(final File file, final String word) { try { - final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, + final Ver3DictUpdater dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); - dictDecoder.openDictBuffer(); - DynamicBinaryDictIOUtils.deleteWord(dictDecoder, word); + dictUpdater.deleteWord(word); } catch (IOException e) { } catch (UnsupportedFormatException e) { } |