InputLogicTestsNonEnglish.java revision dfbe2bfe089b301819039e9b3a7d2c307e6beac7
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
17package com.android.inputmethod.latin;
18
19import android.test.suitebuilder.annotation.LargeTest;
20
21import com.android.inputmethod.latin.suggestions.SuggestionStripView;
22
23@LargeTest
24public class InputLogicTestsNonEnglish extends InputTestsBase {
25    final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
26
27    public void testAutoCorrectForFrench() {
28        final String STRING_TO_TYPE = "irq ";
29        final String EXPECTED_RESULT = "ira ";
30        changeLanguage("fr");
31        type(STRING_TO_TYPE);
32        assertEquals("simple auto-correct for French", EXPECTED_RESULT,
33                mEditText.getText().toString());
34    }
35
36    public void testManualPickThenSeparatorForFrench() {
37        final String WORD1_TO_TYPE = "test";
38        final String WORD2_TO_TYPE = "!";
39        final String EXPECTED_RESULT = "test !";
40        changeLanguage("fr");
41        type(WORD1_TO_TYPE);
42        pickSuggestionManually(0, WORD1_TO_TYPE);
43        type(WORD2_TO_TYPE);
44        assertEquals("manual pick then separator for French", EXPECTED_RESULT,
45                mEditText.getText().toString());
46    }
47
48    public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() {
49        final String WORD_TO_TYPE = "test ";
50        final String PUNCTUATION_FROM_STRIP = "!";
51        final String EXPECTED_RESULT = "test !!";
52        final boolean defaultNextWordPredictionOption =
53                mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
54        final boolean previousNextWordPredictionOption =
55                setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
56                        defaultNextWordPredictionOption);
57        try {
58            changeLanguage("fr");
59            type(WORD_TO_TYPE);
60            sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
61            runMessages();
62            assertTrue("type word then type space should display punctuation strip",
63                    mLatinIME.isShowingPunctuationList());
64            pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
65            pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
66            assertEquals("type word then type space then punctuation from strip twice for French",
67                    EXPECTED_RESULT, mEditText.getText().toString());
68        } finally {
69            setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
70                    defaultNextWordPredictionOption);
71        }
72    }
73
74    public void testWordThenSpaceDisplaysPredictions() {
75        final String WORD_TO_TYPE = "beaujolais ";
76        final String EXPECTED_RESULT = "nouveau";
77        final boolean defaultNextWordPredictionOption =
78                mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
79        final boolean previousNextWordPredictionOption =
80                setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true,
81                        defaultNextWordPredictionOption);
82        try {
83            changeLanguage("fr");
84            type(WORD_TO_TYPE);
85            sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
86            runMessages();
87            final SuggestedWords suggestedWords = mLatinIME.getSuggestedWords();
88            assertEquals("type word then type space yields predictions for French",
89                    EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
90        } finally {
91            setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
92                    defaultNextWordPredictionOption);
93        }
94    }
95
96    public void testAutoCorrectForGerman() {
97        final String STRING_TO_TYPE = "unf ";
98        final String EXPECTED_RESULT = "und ";
99        changeLanguage("de");
100        type(STRING_TO_TYPE);
101        assertEquals("simple auto-correct for German", EXPECTED_RESULT,
102                mEditText.getText().toString());
103    }
104
105    public void testAutoCorrectWithUmlautForGerman() {
106        final String STRING_TO_TYPE = "ueber ";
107        final String EXPECTED_RESULT = "über ";
108        changeLanguage("de");
109        type(STRING_TO_TYPE);
110        assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT,
111                mEditText.getText().toString());
112    }
113}
114