From e4e1130d003a75e3b5cbea1678755d2b71d7cb1d Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 28 Apr 2010 18:12:58 -0700 Subject: Tests and some new constructors to help in testing. Added tests for the dictionary lookup and correction logic on the primary dictionary. This exercises part of the Suggest class and the native dictionary lookup code. --- .../android/inputmethod/latin/BinaryDictionary.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionary.java') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 4901b210b..6473f4558 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -68,6 +68,26 @@ public class BinaryDictionary extends Dictionary { } } + /** + * Create a dictionary from a byte buffer. This is used for testing. + * @param context application context for reading resources + * @param resId the resource containing the raw binary dictionary + */ + public BinaryDictionary(Context context, ByteBuffer byteBuffer) { + if (byteBuffer != null) { + if (byteBuffer.isDirect()) { + mNativeDictDirectBuffer = byteBuffer; + } else { + mNativeDictDirectBuffer = ByteBuffer.allocateDirect(byteBuffer.capacity()); + byteBuffer.rewind(); + mNativeDictDirectBuffer.put(byteBuffer); + } + mDictLength = byteBuffer.capacity(); + mNativeDict = openNative(mNativeDictDirectBuffer, + TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER); + } + } + private native int openNative(ByteBuffer bb, int typedLetterMultiplier, int fullWordMultiplier); private native void closeNative(int dict); private native boolean isValidWordNative(int nativeData, char[] word, int wordLength); -- cgit v1.2.3-83-g751a