blob: 1398db97c1c97835633dc39fff31b938a6d3bea4 [file] [log] [blame]
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +09001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
Tadashi G. Takaokace6bcdd2013-02-12 16:15:47 +09004 * 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
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +09007 *
Tadashi G. Takaokace6bcdd2013-02-12 16:15:47 +09008 * http://www.apache.org/licenses/LICENSE-2.0
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +09009 *
10 * Unless required by applicable law or agreed to in writing, software
Tadashi G. Takaokace6bcdd2013-02-12 16:15:47 +090011 * 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.
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090015 */
16
17package com.android.inputmethod.keyboard;
18
19import android.content.Context;
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +090020import android.content.res.Resources;
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090021import android.test.AndroidTestCase;
Tadashi G. Takaokab4598f72013-02-04 15:25:24 -080022import android.test.suitebuilder.annotation.SmallTest;
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090023import android.view.inputmethod.InputMethodSubtype;
24
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090025import com.android.inputmethod.latin.AdditionalSubtype;
Tadashi G. Takaoka5f282ea2012-08-21 16:34:55 +090026import com.android.inputmethod.latin.CollectionUtils;
Tadashi G. Takaoka6fbbab32012-11-09 18:21:41 +090027import com.android.inputmethod.latin.RichInputMethodManager;
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090028import com.android.inputmethod.latin.StringUtils;
29import com.android.inputmethod.latin.SubtypeLocale;
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +090030import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090031
32import java.util.ArrayList;
33import java.util.Locale;
34
Tadashi G. Takaokab4598f72013-02-04 15:25:24 -080035@SmallTest
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090036public class SpacebarTextTests extends AndroidTestCase {
37 // Locale to subtypes list.
Tadashi G. Takaoka5f282ea2012-08-21 16:34:55 +090038 private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090039
Tadashi G. Takaoka6fbbab32012-11-09 18:21:41 +090040 private RichInputMethodManager mRichImm;
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +090041 private Resources mRes;
42
43 InputMethodSubtype EN_US;
44 InputMethodSubtype EN_GB;
45 InputMethodSubtype ES_US;
46 InputMethodSubtype FR;
47 InputMethodSubtype FR_CA;
48 InputMethodSubtype DE;
49 InputMethodSubtype ZZ;
50 InputMethodSubtype DE_QWERTY;
51 InputMethodSubtype FR_QWERTZ;
52 InputMethodSubtype US_AZERTY;
53 InputMethodSubtype ZZ_AZERTY;
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090054
55 @Override
56 protected void setUp() throws Exception {
57 super.setUp();
58 final Context context = getContext();
Tadashi G. Takaokaf90fc102013-01-07 18:40:59 +090059 RichInputMethodManager.init(context);
Tadashi G. Takaoka6fbbab32012-11-09 18:21:41 +090060 mRichImm = RichInputMethodManager.getInstance();
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +090061 mRes = context.getResources();
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090062 SubtypeLocale.init(context);
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +090063
64 EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.US.toString(), "qwerty");
65 EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.UK.toString(), "qwerty");
66 ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("es_US", "spanish");
67 FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.FRENCH.toString(), "azerty");
68 FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
69 Locale.CANADA_FRENCH.toString(), "qwerty");
70 DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.GERMAN.toString(), "qwertz");
71 ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(SubtypeLocale.NO_LANGUAGE, "qwerty");
72 DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
73 Locale.GERMAN.toString(), "qwerty", null);
74 FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
75 Locale.FRENCH.toString(), "qwertz", null);
76 US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
77 Locale.US.toString(), "azerty", null);
78 ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
79 SubtypeLocale.NO_LANGUAGE, "azerty", null);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090080 }
81
82 public void testAllFullDisplayName() {
83 for (final InputMethodSubtype subtype : mSubtypesList) {
Tadashi G. Takaoka4b3cae92013-01-23 16:23:11 +090084 final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
85 final String spacebarText = MainKeyboardView.getFullDisplayName(subtype);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +090086 final String languageName =
87 SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale());
88 if (SubtypeLocale.isNoLanguage(subtype)) {
89 assertFalse(subtypeName, spacebarText.contains(languageName));
90 } else {
91 assertTrue(subtypeName, spacebarText.contains(languageName));
92 }
93 }
94 }
95
96 public void testAllMiddleDisplayName() {
97 for (final InputMethodSubtype subtype : mSubtypesList) {
Tadashi G. Takaoka4b3cae92013-01-23 16:23:11 +090098 final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
Tadashi G. Takaokac8e45dd2012-07-23 10:27:14 +090099 final String spacebarText = MainKeyboardView.getMiddleDisplayName(subtype);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900100 if (SubtypeLocale.isNoLanguage(subtype)) {
101 assertEquals(subtypeName,
102 SubtypeLocale.getKeyboardLayoutSetName(subtype), spacebarText);
103 } else {
104 assertEquals(subtypeName,
105 SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale()),
106 spacebarText);
107 }
108 }
109 }
110
111 public void testAllShortDisplayName() {
112 for (final InputMethodSubtype subtype : mSubtypesList) {
Tadashi G. Takaoka4b3cae92013-01-23 16:23:11 +0900113 final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900114 final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
Tadashi G. Takaokac8e45dd2012-07-23 10:27:14 +0900115 final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900116 final String languageCode = StringUtils.toTitleCase(locale.getLanguage(), locale);
117 if (SubtypeLocale.isNoLanguage(subtype)) {
118 assertEquals(subtypeName, "", spacebarText);
119 } else {
120 assertEquals(subtypeName, languageCode, spacebarText);
121 }
122 }
123 }
124
125 // InputMethodSubtype's display name for spacebar text in its locale.
126 // isAdditionalSubtype (T=true, F=false)
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900127 // locale layout | Short Middle Full
128 // ------ ------- - ---- --------- ----------------------
129 // en_US qwerty F En English English (US) exception
130 // en_GB qwerty F En English English (UK) exception
131 // es_US spanish F Es Español Español (EE.UU.) exception
132 // fr azerty F Fr Français Français
133 // fr_CA qwerty F Fr Français Français (Canada)
134 // de qwertz F De Deutsch Deutsch
135 // zz qwerty F QWERTY QWERTY
136 // fr qwertz T Fr Français Français
137 // de qwerty T De Deutsch Deutsch
138 // en_US azerty T En English English (US)
139 // zz azerty T AZERTY AZERTY
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900140
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900141 private final RunInLocale<Void> testsPredefinedSubtypes = new RunInLocale<Void>() {
142 @Override
143 protected Void job(Resources res) {
144 assertEquals("en_US", "English (US)", MainKeyboardView.getFullDisplayName(EN_US));
145 assertEquals("en_GB", "English (UK)", MainKeyboardView.getFullDisplayName(EN_GB));
146 assertEquals("es_US", "Español (EE.UU.)", MainKeyboardView.getFullDisplayName(ES_US));
147 assertEquals("fr ", "Français", MainKeyboardView.getFullDisplayName(FR));
148 assertEquals("fr_CA", "Français (Canada)", MainKeyboardView.getFullDisplayName(FR_CA));
149 assertEquals("de ", "Deutsch", MainKeyboardView.getFullDisplayName(DE));
150 assertEquals("zz ", "QWERTY", MainKeyboardView.getFullDisplayName(ZZ));
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900151
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900152 assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
153 assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
154 assertEquals("es_US", "Español", MainKeyboardView.getMiddleDisplayName(ES_US));
155 assertEquals("fr ", "Français", MainKeyboardView.getMiddleDisplayName(FR));
156 assertEquals("fr_CA", "Français", MainKeyboardView.getMiddleDisplayName(FR_CA));
157 assertEquals("de ", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE));
158 assertEquals("zz ", "QWERTY", MainKeyboardView.getMiddleDisplayName(ZZ));
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900159
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900160 assertEquals("en_US", "En", MainKeyboardView.getShortDisplayName(EN_US));
161 assertEquals("en_GB", "En", MainKeyboardView.getShortDisplayName(EN_GB));
162 assertEquals("es_US", "Es", MainKeyboardView.getShortDisplayName(ES_US));
163 assertEquals("fr ", "Fr", MainKeyboardView.getShortDisplayName(FR));
164 assertEquals("fr_CA", "Fr", MainKeyboardView.getShortDisplayName(FR_CA));
165 assertEquals("de ", "De", MainKeyboardView.getShortDisplayName(DE));
166 assertEquals("zz ", "", MainKeyboardView.getShortDisplayName(ZZ));
167 return null;
168 }
169 };
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900170
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900171 private final RunInLocale<Void> testsAdditionalSubtypes = new RunInLocale<Void>() {
172 @Override
173 protected Void job(Resources res) {
174 assertEquals("fr qwertz", "Français",
175 MainKeyboardView.getFullDisplayName(FR_QWERTZ));
176 assertEquals("de qwerty", "Deutsch",
177 MainKeyboardView.getFullDisplayName(DE_QWERTY));
178 assertEquals("en_US azerty", "English (US)",
179 MainKeyboardView.getFullDisplayName(US_AZERTY));
180 assertEquals("zz azerty", "AZERTY",
181 MainKeyboardView.getFullDisplayName(ZZ_AZERTY));
182
183 assertEquals("fr qwertz", "Français",
184 MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
185 assertEquals("de qwerty", "Deutsch",
186 MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
187 assertEquals("en_US azerty", "English",
188 MainKeyboardView.getMiddleDisplayName(US_AZERTY));
189 assertEquals("zz azerty", "AZERTY",
190 MainKeyboardView.getMiddleDisplayName(ZZ_AZERTY));
191
192 assertEquals("fr qwertz", "Fr", MainKeyboardView.getShortDisplayName(FR_QWERTZ));
193 assertEquals("de qwerty", "De", MainKeyboardView.getShortDisplayName(DE_QWERTY));
194 assertEquals("en_US azerty", "En", MainKeyboardView.getShortDisplayName(US_AZERTY));
195 assertEquals("zz azerty", "", MainKeyboardView.getShortDisplayName(ZZ_AZERTY));
196 return null;
197 }
198 };
199
200 public void testPredefinedSubtypesInEnglish() {
201 testsPredefinedSubtypes.runInLocale(mRes, Locale.ENGLISH);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900202 }
203
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900204 public void testAdditionalSubtypeInEnglish() {
205 testsAdditionalSubtypes.runInLocale(mRes, Locale.ENGLISH);
206 }
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900207
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900208 public void testPredefinedSubtypesInFrench() {
209 testsPredefinedSubtypes.runInLocale(mRes, Locale.FRENCH);
210 }
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900211
Tadashi G. Takaoka8630cd92013-01-25 13:11:51 +0900212 public void testAdditionalSubtypeInFrench() {
213 testsAdditionalSubtypes.runInLocale(mRes, Locale.FRENCH);
Tadashi G. Takaoka27b42ce2012-04-25 14:17:49 +0900214 }
215}