diff options
author | 2014-10-03 07:59:15 +0000 | |
---|---|---|
committer | 2014-10-03 07:59:15 +0000 | |
commit | f3bcb22c8e6636608375cc209fbaeebe2d4f52ee (patch) | |
tree | 51bbc8357cf08e5c335753a2de543f488fd72c3b | |
parent | d780b1a19ba2e5aa467cbde4baac24618f2c40af (diff) | |
parent | fb051c3957ae17061204b06258aec3b2e0f05034 (diff) | |
download | latinime-f3bcb22c8e6636608375cc209fbaeebe2d4f52ee.tar.gz latinime-f3bcb22c8e6636608375cc209fbaeebe2d4f52ee.tar.xz latinime-f3bcb22c8e6636608375cc209fbaeebe2d4f52ee.zip |
am fb051c39: Merge changes I3c1f5ac1,I269c9aa8
* commit 'fb051c3957ae17061204b06258aec3b2e0f05034':
Switch code point table
Test for code point table (dicttool test)
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java | 33 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java | 7 |
2 files changed, 37 insertions, 3 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. diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java index eabde4620..2c2152be7 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictEncoder.java @@ -137,10 +137,11 @@ public class Ver2DictEncoder implements DictEncoder { // Make code point conversion table ordered by occurrence of code points // Version 201 or later have codePointTable final CodePointTable codePointTable; - if (formatOptions.mVersion >= FormatSpec.MINIMUM_SUPPORTED_VERSION_OF_CODE_POINT_TABLE) { - codePointTable = makeCodePointTable(dict); - } else { + if (mCodePointTableMode == CODE_POINT_TABLE_OFF || formatOptions.mVersion + < FormatSpec.MINIMUM_SUPPORTED_VERSION_OF_CODE_POINT_TABLE) { codePointTable = new CodePointTable(); + } else { + codePointTable = makeCodePointTable(dict); } BinaryDictEncoderUtils.writeDictionaryHeader(mOutStream, dict, formatOptions, |