aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2010-04-28 18:12:58 -0700
committerAmith Yamasani <yamasani@google.com>2010-05-07 13:40:20 -0700
commite4e1130d003a75e3b5cbea1678755d2b71d7cb1d (patch)
tree7a55da5d4c9923c0392438237561026fe347f765 /java
parentf53d0da540d4aca9c0b78938094e13a828ab1bd6 (diff)
downloadlatinime-e4e1130d003a75e3b5cbea1678755d2b71d7cb1d.tar.gz
latinime-e4e1130d003a75e3b5cbea1678755d2b71d7cb1d.tar.xz
latinime-e4e1130d003a75e3b5cbea1678755d2b71d7cb1d.zip
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.
Diffstat (limited to 'java')
-rw-r--r--java/proguard.flags5
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java20
-rwxr-xr-xjava/src/com/android/inputmethod/latin/Suggest.java21
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java2
4 files changed, 40 insertions, 8 deletions
diff --git a/java/proguard.flags b/java/proguard.flags
index 0a5d2dda9..829a096c0 100644
--- a/java/proguard.flags
+++ b/java/proguard.flags
@@ -1,3 +1,8 @@
-keep class com.android.inputmethod.latin.BinaryDictionary {
int mDictLength;
+ <init>(...);
+}
+
+-keep class com.android.inputmethod.latin.Suggest {
+ <init>(...);
}
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);
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index a70bea003..010913d6d 100755
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -16,18 +16,17 @@
package com.android.inputmethod.latin;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import android.content.Context;
import android.text.AutoText;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import com.android.inputmethod.latin.WordComposer;
-
/**
* This class loads a dictionary and provides a list of suggestions for a given sequence of
* characters. This includes corrections and completions.
@@ -69,9 +68,17 @@ public class Suggest implements Dictionary.WordCallback {
private int mCorrectionMode = CORRECTION_BASIC;
-
public Suggest(Context context, int dictionaryResId) {
mMainDict = new BinaryDictionary(context, dictionaryResId);
+ initPool();
+ }
+
+ public Suggest(Context context, ByteBuffer byteBuffer) {
+ mMainDict = new BinaryDictionary(context, byteBuffer);
+ initPool();
+ }
+
+ private void initPool() {
for (int i = 0; i < mPrefMaxSuggestions; i++) {
StringBuilder sb = new StringBuilder(32);
mStringPool.add(sb);
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 19f714ae7..2547aa133 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -44,7 +44,7 @@ public class WordComposer {
*/
private boolean mIsCapitalized;
- WordComposer() {
+ public WordComposer() {
mCodes = new ArrayList<int[]>(12);
mTypedWord = new StringBuilder(20);
}