1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.latin.spellcheck;
18 
19 import android.test.suitebuilder.annotation.LargeTest;
20 import android.text.style.SuggestionSpan;
21 
22 import com.android.inputmethod.latin.InputTestsBase;
23 
24 @LargeTest
25 public class AndroidSpellCheckerServiceTest extends InputTestsBase {
testSpellchecker()26     public void testSpellchecker() {
27         changeLanguage("en_US");
28         mEditText.setText("tgis ");
29         mEditText.setSelection(mEditText.getText().length());
30         mEditText.onAttachedToWindow();
31         sleep(1000);
32         runMessages();
33         sleep(1000);
34 
35         final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
36         // If no span, the following will crash
37         final String[] suggestions = span.getSuggestions();
38         // For this test we consider "tgis" should yield at least 2 suggestions (at this moment
39         // it yields 5).
40         assertTrue(suggestions.length >= 2);
41         // We also assume the top suggestion should be "this".
42         assertEquals("Test basic spell checking", "this", suggestions[0]);
43     }
44 
testRussianSpellchecker()45     public void testRussianSpellchecker() {
46         changeLanguage("ru");
47         mEditText.onAttachedToWindow();
48         mEditText.setText("годп ");
49         mEditText.setSelection(mEditText.getText().length());
50         mEditText.onAttachedToWindow();
51         sleep(1000);
52         runMessages();
53         sleep(1000);
54 
55         final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
56         // We don't ship with Russian LM
57         assertNull(span.getSpan());
58     }
59 
testSpellcheckWithPeriods()60     public void testSpellcheckWithPeriods() {
61         changeLanguage("en_US");
62         mEditText.setText("I'm.sure ");
63         mEditText.setSelection(mEditText.getText().length());
64         mEditText.onAttachedToWindow();
65         sleep(1000);
66         runMessages();
67         sleep(1000);
68 
69         final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
70         // If no span, the following will crash
71         final String[] suggestions = span.getSuggestions();
72         // The first suggestion should be "I'm sure".
73         assertEquals("Test spell checking of mistyped period for space", "I'm sure",
74                 suggestions[0]);
75     }
76 }
77