Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
Tadashi G. Takaoka | ce6bcdd | 2013-02-12 16:15:47 +0900 | [diff] [blame] | 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 |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 7 | * |
Tadashi G. Takaoka | ce6bcdd | 2013-02-12 16:15:47 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
Tadashi G. Takaoka | ce6bcdd | 2013-02-12 16:15:47 +0900 | [diff] [blame] | 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. |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.inputmethod.keyboard; |
| 18 | |
| 19 | import android.content.Context; |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 20 | import android.content.res.Resources; |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 21 | import android.test.AndroidTestCase; |
Tadashi G. Takaoka | b4598f7 | 2013-02-04 15:25:24 -0800 | [diff] [blame] | 22 | import android.test.suitebuilder.annotation.SmallTest; |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 23 | import android.view.inputmethod.InputMethodSubtype; |
| 24 | |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 25 | import com.android.inputmethod.latin.AdditionalSubtype; |
Tadashi G. Takaoka | 5f282ea | 2012-08-21 16:34:55 +0900 | [diff] [blame] | 26 | import com.android.inputmethod.latin.CollectionUtils; |
Tadashi G. Takaoka | 6fbbab3 | 2012-11-09 18:21:41 +0900 | [diff] [blame] | 27 | import com.android.inputmethod.latin.RichInputMethodManager; |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 28 | import com.android.inputmethod.latin.StringUtils; |
| 29 | import com.android.inputmethod.latin.SubtypeLocale; |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 30 | import com.android.inputmethod.latin.LocaleUtils.RunInLocale; |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 31 | |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.Locale; |
| 34 | |
Tadashi G. Takaoka | b4598f7 | 2013-02-04 15:25:24 -0800 | [diff] [blame] | 35 | @SmallTest |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 36 | public class SpacebarTextTests extends AndroidTestCase { |
| 37 | // Locale to subtypes list. |
Tadashi G. Takaoka | 5f282ea | 2012-08-21 16:34:55 +0900 | [diff] [blame] | 38 | private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList(); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 39 | |
Tadashi G. Takaoka | 6fbbab3 | 2012-11-09 18:21:41 +0900 | [diff] [blame] | 40 | private RichInputMethodManager mRichImm; |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 41 | 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 54 | |
| 55 | @Override |
| 56 | protected void setUp() throws Exception { |
| 57 | super.setUp(); |
| 58 | final Context context = getContext(); |
Tadashi G. Takaoka | f90fc10 | 2013-01-07 18:40:59 +0900 | [diff] [blame] | 59 | RichInputMethodManager.init(context); |
Tadashi G. Takaoka | 6fbbab3 | 2012-11-09 18:21:41 +0900 | [diff] [blame] | 60 | mRichImm = RichInputMethodManager.getInstance(); |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 61 | mRes = context.getResources(); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 62 | SubtypeLocale.init(context); |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 63 | |
| 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | public void testAllFullDisplayName() { |
| 83 | for (final InputMethodSubtype subtype : mSubtypesList) { |
Tadashi G. Takaoka | 4b3cae9 | 2013-01-23 16:23:11 +0900 | [diff] [blame] | 84 | final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype); |
| 85 | final String spacebarText = MainKeyboardView.getFullDisplayName(subtype); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 86 | 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. Takaoka | 4b3cae9 | 2013-01-23 16:23:11 +0900 | [diff] [blame] | 98 | final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype); |
Tadashi G. Takaoka | c8e45dd | 2012-07-23 10:27:14 +0900 | [diff] [blame] | 99 | final String spacebarText = MainKeyboardView.getMiddleDisplayName(subtype); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 100 | 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. Takaoka | 4b3cae9 | 2013-01-23 16:23:11 +0900 | [diff] [blame] | 113 | final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 114 | final Locale locale = SubtypeLocale.getSubtypeLocale(subtype); |
Tadashi G. Takaoka | c8e45dd | 2012-07-23 10:27:14 +0900 | [diff] [blame] | 115 | final String spacebarText = MainKeyboardView.getShortDisplayName(subtype); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 116 | 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. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 127 | // 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 140 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 141 | 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 151 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 152 | 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 159 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 160 | 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 170 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 171 | 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. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 204 | public void testAdditionalSubtypeInEnglish() { |
| 205 | testsAdditionalSubtypes.runInLocale(mRes, Locale.ENGLISH); |
| 206 | } |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 207 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 208 | public void testPredefinedSubtypesInFrench() { |
| 209 | testsPredefinedSubtypes.runInLocale(mRes, Locale.FRENCH); |
| 210 | } |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 211 | |
Tadashi G. Takaoka | 8630cd9 | 2013-01-25 13:11:51 +0900 | [diff] [blame] | 212 | public void testAdditionalSubtypeInFrench() { |
| 213 | testsAdditionalSubtypes.runInLocale(mRes, Locale.FRENCH); |
Tadashi G. Takaoka | 27b42ce | 2012-04-25 14:17:49 +0900 | [diff] [blame] | 214 | } |
| 215 | } |