diff options
author | 2011-02-28 14:54:04 -0800 | |
---|---|---|
committer | 2011-02-28 15:08:04 -0800 | |
commit | 6f4eba814a7f8426617db61f928a965209ebf359 (patch) | |
tree | 31ed66c19404aeebbcc241ba1eba3bb89e18fd4b /java/src | |
parent | 654db88d35d3aee1bbbf5f606be5827372c2dff7 (diff) | |
download | latinime-6f4eba814a7f8426617db61f928a965209ebf359.tar.gz latinime-6f4eba814a7f8426617db61f928a965209ebf359.tar.xz latinime-6f4eba814a7f8426617db61f928a965209ebf359.zip |
Add test entry for BinaryDictionary class
Bug: 3414081
Change-Id: I1a3d60698795bf28c477086838e726d498fb6de0
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionary.java | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 55cd0848a..e207c33bd 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.ProximityInfo; @@ -93,8 +94,7 @@ public class BinaryDictionary extends Dictionary { return sInstance; } - // For unit test - /* package */ static BinaryDictionary initDictionary(File dictionary, long startOffset, + /* package for test */ static BinaryDictionary initDictionary(File dictionary, long startOffset, long length, int dicTypeId) { synchronized (sInstance) { sInstance.closeInternal(); @@ -166,11 +166,32 @@ public class BinaryDictionary extends Dictionary { @Override public void getWords(final WordComposer codes, final WordCallback callback) { - if (mNativeDict == 0) return; + final int count = getSuggestions(codes, mKeyboardSwitcher.getLatinKeyboard()); + + for (int j = 0; j < count; ++j) { + if (mFrequencies[j] < 1) break; + final int start = j * MAX_WORD_LENGTH; + int len = 0; + while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) { + ++len; + } + if (len > 0) { + callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId, + DataType.UNIGRAM); + } + } + } + + /* package for test */ boolean isValidDictionary() { + return mNativeDict != 0; + } + + /* package for test */ int getSuggestions(final WordComposer codes, final Keyboard keyboard) { + if (!isValidDictionary()) return -1; final int codesSize = codes.size(); // Won't deal with really long words. - if (codesSize > MAX_WORD_LENGTH - 1) return; + if (codesSize > MAX_WORD_LENGTH - 1) return -1; Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE); for (int i = 0; i < codesSize; i++) { @@ -181,23 +202,10 @@ public class BinaryDictionary extends Dictionary { Arrays.fill(mOutputChars, (char) 0); Arrays.fill(mFrequencies, 0); - int count = getSuggestionsNative( - mNativeDict, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), + return getSuggestionsNative( + mNativeDict, keyboard.getProximityInfo(), codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize, mOutputChars, mFrequencies); - - for (int j = 0; j < count; ++j) { - if (mFrequencies[j] < 1) break; - final int start = j * MAX_WORD_LENGTH; - int len = 0; - while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) { - ++len; - } - if (len > 0) { - callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId, - DataType.UNIGRAM); - } - } } @Override |