From 5d96585a388a0af8bf0e37fc38ed3d2630733ab9 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 4 Sep 2012 14:40:30 +0900 Subject: Add a first test for the spell checker Bug: 6981919 Change-Id: Idd34150cec70e71bde652428f1631693bbc4a9ff --- .../spellcheck/AndroidSpellCheckerServiceTest.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java (limited to 'tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java') 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]); + } +} -- cgit v1.2.3-83-g751a From c61bed6860cf047e4ef7fd851ae82727ac230440 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 4 Sep 2012 17:44:19 +0900 Subject: Add a preliminary test for basic Russian spell check Bug: 6981919 Change-Id: I5ec6a6468cb616e7a4369c79b4dbfc84f3d8de59 --- .../android/inputmethod/latin/InputTestsBase.java | 10 ++++++++++ .../spellcheck/AndroidSpellCheckerServiceTest.java | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java') diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index dfb83fa24..fe58cb84e 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -41,6 +41,7 @@ import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import java.util.HashMap; +import java.util.Locale; public class InputTestsBase extends ServiceTestCase { @@ -93,12 +94,20 @@ public class InputTestsBase extends ServiceTestCase { // A helper class to increase control over the TextView public static class MyTextView extends TextView { + public Locale mCurrentLocale; public MyTextView(final Context c) { super(c); } public void onAttachedToWindow() { super.onAttachedToWindow(); } + public Locale getTextServicesLocale() { + // This method is necessary because TextView is asking this method for the language + // to check the spell in. If we don't override this, the spell checker will run in + // whatever language the keyboard is currently set on the test device, ignoring any + // settings we do inside the tests. + return mCurrentLocale; + } } public InputTestsBase() { @@ -261,6 +270,7 @@ public class InputTestsBase extends ServiceTestCase { protected void changeLanguage(final String locale) { final InputMethodSubtype subtype = mSubtypeMap.get(locale); + mTextView.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); if (subtype == null) { fail("InputMethodSubtype for locale " + locale + " is not enabled"); } diff --git a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java index 11624e122..21406d370 100644 --- a/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java +++ b/tests/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerServiceTest.java @@ -40,4 +40,24 @@ public class AndroidSpellCheckerServiceTest extends InputTestsBase { // We also assume the top suggestion should be "this". assertEquals("", "this", suggestions[0]); } + + public void testRussianSpellchecker() { + changeLanguage("ru"); + mTextView.onAttachedToWindow(); + mTextView.setText("годп"); + 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 "годп" should yield at least 2 suggestions (at this moment + // it yields 5). + assertTrue(suggestions.length >= 2); + // We also assume the top suggestion should be "года", which is the top word in the + // Russian dictionary. + assertEquals("", "года", suggestions[0]); + } } -- cgit v1.2.3-83-g751a