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