aboutsummaryrefslogtreecommitdiffstats
path: root/tools/dicttool/tests
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-10 21:52:38 +0900
committerJean Chalard <jchalard@google.com>2013-12-16 15:40:45 +0900
commit3df617323e1e0035344f66de28db34ccfdc2d557 (patch)
tree6476cacc2197e988b634d099f8904cfa6800ac78 /tools/dicttool/tests
parent2c25c7c9e1c98feaa3fc739244badacfa0719576 (diff)
downloadlatinime-3df617323e1e0035344f66de28db34ccfdc2d557.tar.gz
latinime-3df617323e1e0035344f66de28db34ccfdc2d557.tar.xz
latinime-3df617323e1e0035344f66de28db34ccfdc2d557.zip
Make the bad header a checked exception and fix dicttool test
Change-Id: If780a2a1cb722aee83d910904c0a6315add9552d
Diffstat (limited to 'tools/dicttool/tests')
-rw-r--r--tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java17
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
index 9e397f19d..0c11f868e 100644
--- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
@@ -42,9 +42,16 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
private static final int TEST_FREQ = 37; // Some arbitrary value unlikely to happen by chance
public void testGetRawDictWorks() throws IOException, UnsupportedFormatException {
+ final String VERSION = "1";
+ final String LOCALE = "test";
+ final String ID = "main:test";
+
// Create a thrice-compressed dictionary file.
- final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
- new DictionaryOptions(new HashMap<String, String>()));
+ final DictionaryOptions testOptions = new DictionaryOptions(new HashMap<String, String>());
+ testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE, VERSION);
+ testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, LOCALE);
+ testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, ID);
+ final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), testOptions);
dict.add("foo", TEST_FREQ, null, false /* isNotAWord */);
dict.add("fta", 1, null, false /* isNotAWord */);
dict.add("ftb", 1, null, false /* isNotAWord */);
@@ -72,6 +79,12 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
final FusionDictionary resultDict = dictDecoder.readDictionaryBinary(
null /* dict : an optional dictionary to add words to, or null */,
false /* deleteDictIfBroken */);
+ assertEquals("Wrong version attribute", VERSION, resultDict.mOptions.mAttributes.get(
+ FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE));
+ assertEquals("Wrong locale attribute", LOCALE, resultDict.mOptions.mAttributes.get(
+ FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE));
+ assertEquals("Wrong id attribute", ID, resultDict.mOptions.mAttributes.get(
+ FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE));
assertEquals("Dictionary can't be read back correctly",
FusionDictionary.findWordInTree(resultDict.mRootNodeArray, "foo").getFrequency(),
TEST_FREQ);