Home | History | Annotate | Download | only in spellcheck
      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 {
     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 
     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         // If no span, the following will crash
     57         final String[] suggestions = span.getSuggestions();
     58         // For this test we consider "" should yield at least 2 suggestions (at this moment
     59         // it yields 5).
     60         assertTrue(suggestions.length >= 2);
     61         // We also assume the top suggestion should be "", which is the top word in the
     62         // Russian dictionary.
     63         assertEquals("", "", suggestions[0]);
     64     }
     65 
     66     public void testSpellcheckWithPeriods() {
     67         changeLanguage("en_US");
     68         mEditText.setText("I'm.sure ");
     69         mEditText.setSelection(mEditText.getText().length());
     70         mEditText.onAttachedToWindow();
     71         sleep(1000);
     72         runMessages();
     73         sleep(1000);
     74 
     75         final SpanGetter span = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
     76         // If no span, the following will crash
     77         final String[] suggestions = span.getSuggestions();
     78         // The first suggestion should be "I'm sure".
     79         assertEquals("Test spell checking of mistyped period for space", "I'm sure",
     80                 suggestions[0]);
     81     }
     82 }
     83