• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import com.android.inputmethod.latin.R;
22 
23 @LargeTest
24 public class PunctuationTests extends InputTestsBase {
25 
26     final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
27 
testWordThenSpaceThenPunctuationFromStripTwice()28     public void testWordThenSpaceThenPunctuationFromStripTwice() {
29         final String WORD_TO_TYPE = "this ";
30         final String PUNCTUATION_FROM_STRIP = "!";
31         final String EXPECTED_RESULT = "this!! ";
32         final boolean defaultNextWordPredictionOption =
33                 mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
34         final boolean previousNextWordPredictionOption =
35                 setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
36                         defaultNextWordPredictionOption);
37         try {
38             mLatinIME.loadSettings();
39             type(WORD_TO_TYPE);
40             sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
41             runMessages();
42             assertTrue("type word then type space should display punctuation strip",
43                     mLatinIME.isShowingPunctuationList());
44             pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
45             pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
46             assertEquals("type word then type space then punctuation from strip twice",
47                     EXPECTED_RESULT, mEditText.getText().toString());
48         } finally {
49             setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
50                     defaultNextWordPredictionOption);
51         }
52     }
53 
testWordThenSpaceThenPunctuationFromKeyboardTwice()54     public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {
55         final String WORD_TO_TYPE = "this !!";
56         final String EXPECTED_RESULT = "this !!";
57         type(WORD_TO_TYPE);
58         assertEquals("manual pick then space then punctuation from keyboard twice", EXPECTED_RESULT,
59                 mEditText.getText().toString());
60     }
61 
testManualPickThenPunctuationFromStripTwiceThenType()62     public void testManualPickThenPunctuationFromStripTwiceThenType() {
63         final String WORD1_TO_TYPE = "this";
64         final String WORD2_TO_TYPE = "is";
65         final String PUNCTUATION_FROM_STRIP = "!";
66         final String EXPECTED_RESULT = "this!! is";
67         type(WORD1_TO_TYPE);
68         pickSuggestionManually(0, WORD1_TO_TYPE);
69         pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
70         pickSuggestionManually(0, PUNCTUATION_FROM_STRIP);
71         type(WORD2_TO_TYPE);
72         assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT,
73                 mEditText.getText().toString());
74     }
75 
testManualPickThenManualPickWithPunctAtStart()76     public void testManualPickThenManualPickWithPunctAtStart() {
77         final String WORD1_TO_TYPE = "this";
78         final String WORD2_TO_PICK = "!is";
79         final String EXPECTED_RESULT = "this!is";
80         type(WORD1_TO_TYPE);
81         pickSuggestionManually(0, WORD1_TO_TYPE);
82         pickSuggestionManually(1, WORD2_TO_PICK);
83         assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT,
84                 mEditText.getText().toString());
85     }
86 
testManuallyPickedWordThenColon()87     public void testManuallyPickedWordThenColon() {
88         final String WORD_TO_TYPE = "this";
89         final String PUNCTUATION = ":";
90         final String EXPECTED_RESULT = "this:";
91         type(WORD_TO_TYPE);
92         pickSuggestionManually(0, WORD_TO_TYPE);
93         type(PUNCTUATION);
94         assertEquals("manually pick word then colon",
95                 EXPECTED_RESULT, mEditText.getText().toString());
96     }
97 
testManuallyPickedWordThenOpenParen()98     public void testManuallyPickedWordThenOpenParen() {
99         final String WORD_TO_TYPE = "this";
100         final String PUNCTUATION = "(";
101         final String EXPECTED_RESULT = "this (";
102         type(WORD_TO_TYPE);
103         pickSuggestionManually(0, WORD_TO_TYPE);
104         type(PUNCTUATION);
105         assertEquals("manually pick word then open paren",
106                 EXPECTED_RESULT, mEditText.getText().toString());
107     }
108 
testManuallyPickedWordThenCloseParen()109     public void testManuallyPickedWordThenCloseParen() {
110         final String WORD_TO_TYPE = "this";
111         final String PUNCTUATION = ")";
112         final String EXPECTED_RESULT = "this)";
113         type(WORD_TO_TYPE);
114         pickSuggestionManually(0, WORD_TO_TYPE);
115         type(PUNCTUATION);
116         assertEquals("manually pick word then close paren",
117                 EXPECTED_RESULT, mEditText.getText().toString());
118     }
119 
testManuallyPickedWordThenSmiley()120     public void testManuallyPickedWordThenSmiley() {
121         final String WORD_TO_TYPE = "this";
122         final String SPECIAL_KEY = ":-)";
123         final String EXPECTED_RESULT = "this :-)";
124         type(WORD_TO_TYPE);
125         pickSuggestionManually(0, WORD_TO_TYPE);
126         mLatinIME.onTextInput(SPECIAL_KEY);
127         assertEquals("manually pick word then press the smiley key",
128                 EXPECTED_RESULT, mEditText.getText().toString());
129     }
130 
testManuallyPickedWordThenDotCom()131     public void testManuallyPickedWordThenDotCom() {
132         final String WORD_TO_TYPE = "this";
133         final String SPECIAL_KEY = ".com";
134         final String EXPECTED_RESULT = "this.com";
135         type(WORD_TO_TYPE);
136         pickSuggestionManually(0, WORD_TO_TYPE);
137         mLatinIME.onTextInput(SPECIAL_KEY);
138         assertEquals("manually pick word then press the .com key",
139                 EXPECTED_RESULT, mEditText.getText().toString());
140     }
141 
testTypeWordTypeDotThenPressDotCom()142     public void testTypeWordTypeDotThenPressDotCom() {
143         final String WORD_TO_TYPE = "this.";
144         final String SPECIAL_KEY = ".com";
145         final String EXPECTED_RESULT = "this.com";
146         type(WORD_TO_TYPE);
147         mLatinIME.onTextInput(SPECIAL_KEY);
148         assertEquals("type word type dot then press the .com key",
149                 EXPECTED_RESULT, mEditText.getText().toString());
150     }
151 
testAutoCorrectionWithSingleQuoteInside()152     public void testAutoCorrectionWithSingleQuoteInside() {
153         final String WORD_TO_TYPE = "you'f ";
154         final String EXPECTED_RESULT = "you'd ";
155         type(WORD_TO_TYPE);
156         assertEquals("auto-correction with single quote inside",
157                 EXPECTED_RESULT, mEditText.getText().toString());
158     }
159 
testAutoCorrectionWithSingleQuotesAround()160     public void testAutoCorrectionWithSingleQuotesAround() {
161         final String WORD_TO_TYPE = "'tgis' ";
162         final String EXPECTED_RESULT = "'this' ";
163         type(WORD_TO_TYPE);
164         assertEquals("auto-correction with single quotes around",
165                 EXPECTED_RESULT, mEditText.getText().toString());
166     }
167 }
168