diff options
author | 2014-10-03 07:55:59 +0000 | |
---|---|---|
committer | 2014-10-03 07:55:59 +0000 | |
commit | fb051c3957ae17061204b06258aec3b2e0f05034 (patch) | |
tree | 4447b4568d9cd50ec4e0e81cc90f9103027da653 /tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | |
parent | a4244df846d055f1c95a68565478e2183871e489 (diff) | |
parent | f51d3667fcaaaebec28ca5376e0027d0ee4c79de (diff) | |
download | latinime-fb051c3957ae17061204b06258aec3b2e0f05034.tar.gz latinime-fb051c3957ae17061204b06258aec3b2e0f05034.tar.xz latinime-fb051c3957ae17061204b06258aec3b2e0f05034.zip |
Merge changes I3c1f5ac1,I269c9aa8
* changes:
Switch code point table
Test for code point table (dicttool test)
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index a96b3fd0a..215c9ddc7 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -304,6 +304,39 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { "unigram with various code points")); } + public void testCharacterTableIsPresent() throws IOException, UnsupportedFormatException { + final String[] wordSource = {"words", "used", "for", "testing", "a", "code point", "table"}; + final List<String> words = Arrays.asList(wordSource); + final String correctCodePointTable = "eotdsanirfg bclwup"; + final String dictName = "codePointTableTest"; + final String dictVersion = Long.toString(System.currentTimeMillis()); + final String codePointTableAttribute = DictionaryHeader.CODE_POINT_TABLE_KEY; + final File file = new File(dictName); + + // Write a test dictionary + final DictEncoder dictEncoder = new Ver2DictEncoder(file, + Ver2DictEncoder.CODE_POINT_TABLE_ON); + final FormatSpec.FormatOptions formatOptions = + new FormatSpec.FormatOptions( + FormatSpec.MINIMUM_SUPPORTED_VERSION_OF_CODE_POINT_TABLE); + final FusionDictionary sourcedict = new FusionDictionary(new PtNodeArray(), + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion, formatOptions)); + addUnigrams(words.size(), sourcedict, words, null /* shortcutMap */); + dictEncoder.writeDictionary(sourcedict, formatOptions); + + // Read the dictionary + final DictDecoder dictDecoder = BinaryDictIOUtils.getDictDecoder(file, 0, file.length(), + DictDecoder.USE_BYTEARRAY); + final DictionaryHeader fileHeader = dictDecoder.readHeader(); + // Check if codePointTable is present + assertTrue("codePointTable is not present", + fileHeader.mDictionaryOptions.mAttributes.containsKey(codePointTableAttribute)); + final String codePointTable = + fileHeader.mDictionaryOptions.mAttributes.get(codePointTableAttribute); + // Check if codePointTable is correct + assertEquals("codePointTable is incorrect", codePointTable, correctCodePointTable); + } + // Unit test for CharEncoding.readString and CharEncoding.writeString. public void testCharEncoding() { // the max length of a word in sWords is less than 50. |