aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-09-04 14:40:30 +0900
committerJean Chalard <jchalard@google.com>2012-09-04 17:19:26 +0900
commit5d96585a388a0af8bf0e37fc38ed3d2630733ab9 (patch)
tree5a3bbe6e98cd79935782e558789133f98293b41d /tests/src
parentd34dd5bb6bb01666171a37e9cefe46bb20d04e93 (diff)
downloadlatinime-5d96585a388a0af8bf0e37fc38ed3d2630733ab9.tar.gz
latinime-5d96585a388a0af8bf0e37fc38ed3d2630733ab9.tar.xz
latinime-5d96585a388a0af8bf0e37fc38ed3d2630733ab9.zip
Add a first test for the spell checker
Bug: 6981919 Change-Id: Idd34150cec70e71bde652428f1631693bbc4a9ff
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/InputTestsBase.java17
-rw-r--r--tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java43
2 files changed, 58 insertions, 2 deletions
diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
index ffd95f57a..dfb83fa24 100644
--- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java
@@ -51,7 +51,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
protected LatinIME mLatinIME;
protected Keyboard mKeyboard;
- protected TextView mTextView;
+ protected MyTextView mTextView;
protected InputConnection mInputConnection;
private final HashMap<String, InputMethodSubtype> mSubtypeMap =
new HashMap<String, InputMethodSubtype>();
@@ -86,6 +86,19 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
return (mSpan instanceof SuggestionSpan) &&
0 != (SuggestionSpan.FLAG_AUTO_CORRECTION & ((SuggestionSpan)mSpan).getFlags());
}
+ public String[] getSuggestions() {
+ return ((SuggestionSpan)mSpan).getSuggestions();
+ }
+ }
+
+ // A helper class to increase control over the TextView
+ public static class MyTextView extends TextView {
+ public MyTextView(final Context c) {
+ super(c);
+ }
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ }
}
public InputTestsBase() {
@@ -112,7 +125,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
@Override
protected void setUp() throws Exception {
super.setUp();
- mTextView = new TextView(getContext());
+ mTextView = new MyTextView(getContext());
mTextView.setInputType(InputType.TYPE_CLASS_TEXT);
mTextView.setEnabled(true);
setupService();
diff --git a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java
new file mode 100644
index 000000000..11624e122
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin.spellcheck;
+
+import android.text.SpannableStringBuilder;
+import android.text.style.CharacterStyle;
+import android.text.style.SuggestionSpan;
+
+import com.android.inputmethod.latin.InputTestsBase;
+
+public class AndroidSpellCheckerServiceTest extends InputTestsBase {
+ public void testSpellchecker() {
+ mTextView.onAttachedToWindow();
+ mTextView.setText("tgis");
+ type(" ");
+ sleep(1000);
+ runMessages();
+ sleep(1000);
+
+ final SpanGetter span = new SpanGetter(mTextView.getText(), SuggestionSpan.class);
+ // If no span, the following will crash
+ final String[] suggestions = span.getSuggestions();
+ // For this test we consider "tgis" should yield at least 2 suggestions (at this moment
+ // it yields 5).
+ assertTrue(suggestions.length >= 2);
+ // We also assume the top suggestion should be "this".
+ assertEquals("", "this", suggestions[0]);
+ }
+}