diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/utils')
4 files changed, 297 insertions, 470 deletions
diff --git a/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java b/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java deleted file mode 100644 index 7519becbc..000000000 --- a/tests/src/com/android/inputmethod/latin/utils/ResizableIntArrayTests.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.latin.utils; - -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import java.util.Arrays; - -@SmallTest -public class ResizableIntArrayTests extends AndroidTestCase { - private static final int DEFAULT_CAPACITY = 48; - - public void testNewInstance() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int[] array = src.getPrimitiveArray(); - assertEquals("new instance length", 0, src.getLength()); - assertNotNull("new instance array", array); - assertEquals("new instance array length", DEFAULT_CAPACITY, array.length); - } - - public void testAdd() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int[] array = src.getPrimitiveArray(); - int[] array2 = null, array3 = null; - final int limit = DEFAULT_CAPACITY * 2 + 10; - for (int i = 0; i < limit; i++) { - final int value = i; - src.add(value); - assertEquals("length after add " + i, i + 1, src.getLength()); - if (i == DEFAULT_CAPACITY) { - array2 = src.getPrimitiveArray(); - } - if (i == DEFAULT_CAPACITY * 2) { - array3 = src.getPrimitiveArray(); - } - if (i < DEFAULT_CAPACITY) { - assertSame("array after add " + i, array, src.getPrimitiveArray()); - } else if (i < DEFAULT_CAPACITY * 2) { - assertSame("array after add " + i, array2, src.getPrimitiveArray()); - } else if (i < DEFAULT_CAPACITY * 3) { - assertSame("array after add " + i, array3, src.getPrimitiveArray()); - } - } - for (int i = 0; i < limit; i++) { - final int value = i; - assertEquals("value at " + i, value, src.get(i)); - } - } - - public void testAddAt() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2; - for (int i = 0; i < limit; i += step) { - final int value = i; - src.addAt(i, value); - assertEquals("length after add at " + i, i + 1, src.getLength()); - } - for (int i = 0; i < limit; i += step) { - final int value = i; - assertEquals("value at " + i, value, src.get(i)); - } - } - - public void testGet() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - try { - src.get(0); - fail("get(0) shouldn't succeed"); - } catch (ArrayIndexOutOfBoundsException e) { - // success - } - try { - src.get(DEFAULT_CAPACITY); - fail("get(DEFAULT_CAPACITY) shouldn't succeed"); - } catch (ArrayIndexOutOfBoundsException e) { - // success - } - - final int index = DEFAULT_CAPACITY / 2; - final int valueAddAt = 100; - src.addAt(index, valueAddAt); - assertEquals("legth after add at " + index, index + 1, src.getLength()); - assertEquals("value after add at " + index, valueAddAt, src.get(index)); - assertEquals("value after add at 0", 0, src.get(0)); - try { - src.get(src.getLength()); - fail("get(length) shouldn't succeed"); - } catch (ArrayIndexOutOfBoundsException e) { - // success - } - } - - public void testReset() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int[] array = src.getPrimitiveArray(); - for (int i = 0; i < DEFAULT_CAPACITY; i++) { - final int value = i; - src.add(value); - assertEquals("length after add " + i, i + 1, src.getLength()); - } - - final int smallerLength = DEFAULT_CAPACITY / 2; - src.reset(smallerLength); - final int[] array2 = src.getPrimitiveArray(); - assertEquals("length after reset", 0, src.getLength()); - assertNotSame("array after reset", array, array2); - - int[] array3 = null; - for (int i = 0; i < DEFAULT_CAPACITY; i++) { - final int value = i; - src.add(value); - assertEquals("length after add " + i, i + 1, src.getLength()); - if (i == smallerLength) { - array3 = src.getPrimitiveArray(); - } - if (i < smallerLength) { - assertSame("array after add " + i, array2, src.getPrimitiveArray()); - } else if (i < smallerLength * 2) { - assertSame("array after add " + i, array3, src.getPrimitiveArray()); - } - } - } - - public void testSetLength() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int[] array = src.getPrimitiveArray(); - for (int i = 0; i < DEFAULT_CAPACITY; i++) { - final int value = i; - src.add(value); - assertEquals("length after add " + i, i + 1, src.getLength()); - } - - final int largerLength = DEFAULT_CAPACITY * 2; - src.setLength(largerLength); - final int[] array2 = src.getPrimitiveArray(); - assertEquals("length after larger setLength", largerLength, src.getLength()); - assertNotSame("array after larger setLength", array, array2); - assertEquals("array length after larger setLength", largerLength, array2.length); - for (int i = 0; i < largerLength; i++) { - final int value = i; - if (i < DEFAULT_CAPACITY) { - assertEquals("value at " + i, value, src.get(i)); - } else { - assertEquals("value at " + i, 0, src.get(i)); - } - } - - final int smallerLength = DEFAULT_CAPACITY / 2; - src.setLength(smallerLength); - final int[] array3 = src.getPrimitiveArray(); - assertEquals("length after smaller setLength", smallerLength, src.getLength()); - assertSame("array after smaller setLength", array2, array3); - assertEquals("array length after smaller setLength", largerLength, array3.length); - for (int i = 0; i < smallerLength; i++) { - final int value = i; - assertEquals("value at " + i, value, src.get(i)); - } - } - - public void testSet() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int limit = DEFAULT_CAPACITY * 2 + 10; - for (int i = 0; i < limit; i++) { - final int value = i; - src.add(value); - } - - final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY); - dst.set(src); - assertEquals("length after set", dst.getLength(), src.getLength()); - assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray()); - } - - public void testCopy() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - for (int i = 0; i < DEFAULT_CAPACITY; i++) { - final int value = i; - src.add(value); - } - - final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY); - final int[] array = dst.getPrimitiveArray(); - dst.copy(src); - assertEquals("length after copy", dst.getLength(), src.getLength()); - assertSame("array after copy", array, dst.getPrimitiveArray()); - assertNotSame("array after copy", dst.getPrimitiveArray(), src.getPrimitiveArray()); - assertIntArrayEquals("values after copy", - dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength()); - - final int smallerLength = DEFAULT_CAPACITY / 2; - dst.reset(smallerLength); - final int[] array2 = dst.getPrimitiveArray(); - dst.copy(src); - final int[] array3 = dst.getPrimitiveArray(); - assertEquals("length after copy to smaller", dst.getLength(), src.getLength()); - assertNotSame("array after copy to smaller", array2, array3); - assertNotSame("array after copy to smaller", array3, src.getPrimitiveArray()); - assertIntArrayEquals("values after copy to smaller", - dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength()); - } - - public void testAppend() { - final int srcLength = DEFAULT_CAPACITY; - final ResizableIntArray src = new ResizableIntArray(srcLength); - for (int i = 0; i < srcLength; i++) { - final int value = i; - src.add(value); - } - final ResizableIntArray dst = new ResizableIntArray(DEFAULT_CAPACITY * 2); - final int[] array = dst.getPrimitiveArray(); - final int dstLength = DEFAULT_CAPACITY / 2; - for (int i = 0; i < dstLength; i++) { - final int value = -i - 1; - dst.add(value); - } - final ResizableIntArray dstCopy = new ResizableIntArray(dst.getLength()); - dstCopy.copy(dst); - - final int startPos = 0; - dst.append(src, startPos, 0 /* length */); - assertEquals("length after append zero", dstLength, dst.getLength()); - assertSame("array after append zero", array, dst.getPrimitiveArray()); - assertIntArrayEquals("values after append zero", dstCopy.getPrimitiveArray(), startPos, - dst.getPrimitiveArray(), startPos, dstLength); - - dst.append(src, startPos, srcLength); - assertEquals("length after append", dstLength + srcLength, dst.getLength()); - assertSame("array after append", array, dst.getPrimitiveArray()); - assertTrue("primitive length after append", - dst.getPrimitiveArray().length >= dstLength + srcLength); - assertIntArrayEquals("original values after append", dstCopy.getPrimitiveArray(), startPos, - dst.getPrimitiveArray(), startPos, dstLength); - assertIntArrayEquals("appended values after append", src.getPrimitiveArray(), startPos, - dst.getPrimitiveArray(), dstLength, srcLength); - - dst.append(src, startPos, srcLength); - assertEquals("length after 2nd append", dstLength + srcLength * 2, dst.getLength()); - assertNotSame("array after 2nd append", array, dst.getPrimitiveArray()); - assertTrue("primitive length after 2nd append", - dst.getPrimitiveArray().length >= dstLength + srcLength * 2); - assertIntArrayEquals("original values after 2nd append", - dstCopy.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), startPos, - dstLength); - assertIntArrayEquals("appended values after 2nd append", - src.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), dstLength, - srcLength); - assertIntArrayEquals("appended values after 2nd append", - src.getPrimitiveArray(), startPos, dst.getPrimitiveArray(), dstLength + srcLength, - srcLength); - } - - public void testFill() { - final int srcLength = DEFAULT_CAPACITY; - final ResizableIntArray src = new ResizableIntArray(srcLength); - for (int i = 0; i < srcLength; i++) { - final int value = i; - src.add(value); - } - final int[] array = src.getPrimitiveArray(); - - final int startPos = srcLength / 3; - final int length = srcLength / 3; - final int endPos = startPos + length; - assertTrue(startPos >= 1); - final int fillValue = 123; - try { - src.fill(fillValue, -1 /* startPos */, length); - fail("fill from -1 shouldn't succeed"); - } catch (IllegalArgumentException e) { - // success - } - try { - src.fill(fillValue, startPos, -1 /* length */); - fail("fill negative length shouldn't succeed"); - } catch (IllegalArgumentException e) { - // success - } - - src.fill(fillValue, startPos, length); - assertEquals("length after fill", srcLength, src.getLength()); - assertSame("array after fill", array, src.getPrimitiveArray()); - for (int i = 0; i < srcLength; i++) { - final int value = i; - if (i >= startPos && i < endPos) { - assertEquals("new values after fill at " + i, fillValue, src.get(i)); - } else { - assertEquals("unmodified values after fill at " + i, value, src.get(i)); - } - } - - final int length2 = srcLength * 2 - startPos; - final int largeEnd = startPos + length2; - assertTrue(largeEnd > srcLength); - final int fillValue2 = 456; - src.fill(fillValue2, startPos, length2); - assertEquals("length after large fill", largeEnd, src.getLength()); - assertNotSame("array after large fill", array, src.getPrimitiveArray()); - for (int i = 0; i < largeEnd; i++) { - final int value = i; - if (i >= startPos && i < largeEnd) { - assertEquals("new values after large fill at " + i, fillValue2, src.get(i)); - } else { - assertEquals("unmodified values after large fill at " + i, value, src.get(i)); - } - } - - final int startPos2 = largeEnd + length2; - final int endPos2 = startPos2 + length2; - final int fillValue3 = 789; - src.fill(fillValue3, startPos2, length2); - assertEquals("length after disjoint fill", endPos2, src.getLength()); - for (int i = 0; i < endPos2; i++) { - final int value = i; - if (i >= startPos2 && i < endPos2) { - assertEquals("new values after disjoint fill at " + i, fillValue3, src.get(i)); - } else if (i >= startPos && i < largeEnd) { - assertEquals("unmodified values after disjoint fill at " + i, - fillValue2, src.get(i)); - } else if (i < startPos) { - assertEquals("unmodified values after disjoint fill at " + i, value, src.get(i)); - } else { - assertEquals("gap values after disjoint fill at " + i, 0, src.get(i)); - } - } - } - - private static void assertIntArrayEquals(final String message, final int[] expecteds, - final int expectedPos, final int[] actuals, final int actualPos, final int length) { - if (expecteds == actuals) { - return; - } - if (expecteds == null || actuals == null) { - assertEquals(message, Arrays.toString(expecteds), Arrays.toString(actuals)); - return; - } - if (expecteds.length < expectedPos + length || actuals.length < actualPos + length) { - fail(message + ": insufficient length: expecteds=" + Arrays.toString(expecteds) - + " actuals=" + Arrays.toString(actuals)); - return; - } - for (int i = 0; i < length; i++) { - assertEquals(message + " [" + i + "]", - expecteds[i + expectedPos], actuals[i + actualPos]); - } - } - - public void testShift() { - final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); - final int limit = DEFAULT_CAPACITY * 10; - final int shiftAmount = 20; - for (int i = 0; i < limit; ++i) { - final int value = i; - src.addAt(i, value); - assertEquals("length after add at " + i, i + 1, src.getLength()); - } - src.shift(shiftAmount); - for (int i = 0; i < limit - shiftAmount; ++i) { - final int oldValue = i + shiftAmount; - assertEquals("value at " + i, oldValue, src.get(i)); - } - } -} diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java index e6131cf65..83afd782d 100644 --- a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtilsTests.java @@ -23,6 +23,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; +import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodSubtype; @@ -36,6 +37,7 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { private RichInputMethodManager mRichImm; private Resources mRes; + private InputMethodSubtype mSavedAddtionalSubtypes[]; RichInputMethodSubtype EN_US; RichInputMethodSubtype EN_GB; @@ -45,6 +47,8 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { RichInputMethodSubtype FR_CH; RichInputMethodSubtype DE; RichInputMethodSubtype DE_CH; + RichInputMethodSubtype HI; + RichInputMethodSubtype SR; RichInputMethodSubtype ZZ; RichInputMethodSubtype DE_QWERTY; RichInputMethodSubtype FR_QWERTZ; @@ -54,17 +58,27 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { RichInputMethodSubtype ZZ_AZERTY; RichInputMethodSubtype ZZ_PC; - // This is a preliminary subtype and may not exist. - RichInputMethodSubtype HI_LATN; + // These are preliminary subtypes and may not exist. + RichInputMethodSubtype HI_LATN; // Hinglish + RichInputMethodSubtype SR_LATN; // Serbian Latin + RichInputMethodSubtype HI_LATN_DVORAK; + RichInputMethodSubtype SR_LATN_QWERTY; @Override protected void setUp() throws Exception { super.setUp(); final Context context = getContext(); + mRes = context.getResources(); RichInputMethodManager.init(context); mRichImm = RichInputMethodManager.getInstance(); - mRes = context.getResources(); - SubtypeLocaleUtils.init(context); + + // Save and reset additional subtypes + mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes(context); + final InputMethodSubtype[] predefinedAddtionalSubtypes = + AdditionalSubtypeUtils.createAdditionalSubtypesArray( + AdditionalSubtypeUtils.createPrefSubtypes( + mRes.getStringArray(R.array.predefined_subtypes))); + mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes); final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme(); final int subtypeCount = imi.getSubtypeCount(); @@ -89,6 +103,10 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { Locale.GERMAN.toString(), "qwertz")); DE_CH = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( "de_CH", "swiss")); + HI = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "hi", "hindi")); + SR = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "sr", "south_slavic")); ZZ = new RichInputMethodSubtype(mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocaleUtils.NO_LANGUAGE, "qwerty")); DE_QWERTY = new RichInputMethodSubtype( @@ -117,9 +135,27 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { "hi_ZZ", "qwerty"); if (hiLatn != null) { HI_LATN = new RichInputMethodSubtype(hiLatn); + HI_LATN_DVORAK = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "hi_ZZ", "dvorak")); + } + final InputMethodSubtype srLatn = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "sr_ZZ", "serbian_qwertz"); + if (srLatn != null) { + SR_LATN = new RichInputMethodSubtype(srLatn); + SR_LATN_QWERTY = new RichInputMethodSubtype( + AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "sr_ZZ", "qwerty")); } } + @Override + protected void tearDown() throws Exception { + // Restore additional subtypes. + mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes); + super.tearDown(); + } + public void testAllFullDisplayNameForSpacebar() { for (final RichInputMethodSubtype subtype : mSubtypesList) { final String subtypeName = SubtypeLocaleUtils @@ -150,10 +186,11 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { continue; } final Locale locale = locales[0]; - if (SubtypeLocaleUtils.sExceptionalLocaleDisplayedInRootLocale.contains( - locale.toString())) { + final Locale displayLocale = SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale( + locale.toString()); + if (Locale.ROOT.equals(displayLocale)) { // Skip test because the language part of this locale string doesn't represent - // the locale to be displayed on the spacebar (for example hi_ZZ and Hinglish). + // the locale to be displayed on the spacebar (for example Hinglish). continue; } final String spacebarText = subtype.getMiddleDisplayName(); @@ -162,30 +199,36 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { subtype.getRawSubtype()), spacebarText); } else { assertEquals(subtypeName, - SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()), + SubtypeLocaleUtils.getSubtypeLanguageDisplayName(locale.toString()), spacebarText); } } } // InputMethodSubtype's display name for spacebar text in its locale. - // isAdditionalSubtype (T=true, F=false) - // locale layout | Middle Full - // ------ ------- - --------- ---------------------- - // en_US qwerty F English English (US) exception - // en_GB qwerty F English English (UK) exception - // es_US spanish F Español Español (EE.UU.) exception - // fr azerty F Français Français - // fr_CA qwerty F Français Français (Canada) - // fr_CH swiss F Français Français (Suisse) - // de qwertz F Deutsch Deutsch - // de_CH swiss F Deutsch Deutsch (Schweiz) - // hi_ZZ qwerty F Hinglish Hinglish - // zz qwerty F QWERTY QWERTY - // fr qwertz T Français Français - // de qwerty T Deutsch Deutsch - // en_US azerty T English English (US) - // zz azerty T AZERTY AZERTY + // isAdditionalSubtype (T=true, F=false) + // locale layout | Middle Full + // ------ -------------- - --------- ---------------------- + // en_US qwerty F English English (US) exception + // en_GB qwerty F English English (UK) exception + // es_US spanish F Español Español (EE.UU.) exception + // fr azerty F Français Français + // fr_CA qwerty F Français Français (Canada) + // fr_CH swiss F Français Français (Suisse) + // de qwertz F Deutsch Deutsch + // de_CH swiss F Deutsch Deutsch (Schweiz) + // hi hindi F हिन्दी हिन्दी + // hi_ZZ qwerty F Hinglish Hinglish exception + // sr south_slavic F Српски Српски + // sr_ZZ serbian_qwertz F Srpski Srpski exception + // zz qwerty F QWERTY QWERTY + // fr qwertz T Français Français + // de qwerty T Deutsch Deutsch + // en_US azerty T English English (US) + // en_GB dvorak T English English (UK) + // hi_ZZ dvorak T Hinglish Hinglish exception + // sr_ZZ qwerty T Srpski Srpski exception + // zz azerty T AZERTY AZERTY private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() { @Override @@ -198,11 +241,9 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { assertEquals("fr_CH", "Français (Suisse)", FR_CH.getFullDisplayName()); assertEquals("de", "Deutsch", DE.getFullDisplayName()); assertEquals("de_CH", "Deutsch (Schweiz)", DE_CH.getFullDisplayName()); + assertEquals("hi", "हिन्दी", HI.getFullDisplayName()); + assertEquals("sr", "Српски", SR.getFullDisplayName()); assertEquals("zz", "QWERTY", ZZ.getFullDisplayName()); - // This is a preliminary subtype and may not exist. - if (HI_LATN != null) { - assertEquals("hi_ZZ", "Hinglish", HI_LATN.getFullDisplayName()); - } assertEquals("en_US", "English", EN_US.getMiddleDisplayName()); assertEquals("en_GB", "English", EN_GB.getMiddleDisplayName()); @@ -213,10 +254,16 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { assertEquals("de", "Deutsch", DE.getMiddleDisplayName()); assertEquals("de_CH", "Deutsch", DE_CH.getMiddleDisplayName()); assertEquals("zz", "QWERTY", ZZ.getMiddleDisplayName()); - // This is a preliminary subtype and may not exist. + + // These are preliminary subtypes and may not exist. if (HI_LATN != null) { + assertEquals("hi_ZZ", "Hinglish", HI_LATN.getFullDisplayName()); assertEquals("hi_ZZ", "Hinglish", HI_LATN.getMiddleDisplayName()); } + if (SR_LATN != null) { + assertEquals("sr_ZZ", "Srpski", SR_LATN.getFullDisplayName()); + assertEquals("sr_ZZ", "Srpski", SR_LATN.getMiddleDisplayName()); + } return null; } }; @@ -239,6 +286,16 @@ public class SpacebarLanguageUtilsTests extends AndroidTestCase { assertEquals("es_US colemak", "Español", ES_US_COLEMAK.getMiddleDisplayName()); assertEquals("zz azerty", "AZERTY", ZZ_AZERTY.getMiddleDisplayName()); assertEquals("zz pc", "PC", ZZ_PC.getMiddleDisplayName()); + + // These are preliminary subtypes and may not exist. + if (HI_LATN_DVORAK != null) { + assertEquals("hi_ZZ dvorak", "Hinglish", HI_LATN_DVORAK.getFullDisplayName()); + assertEquals("hi_ZZ dvorak", "Hinglish", HI_LATN_DVORAK.getMiddleDisplayName()); + } + if (SR_LATN_QWERTY != null) { + assertEquals("sr_ZZ qwerty", "Srpski", SR_LATN_QWERTY.getFullDisplayName()); + assertEquals("sr_ZZ qwerty", "Srpski", SR_LATN_QWERTY.getMiddleDisplayName()); + } return null; } }; diff --git a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java index 7d9d39959..0389fefb0 100644 --- a/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/StringAndJsonUtilsTests.java @@ -23,6 +23,8 @@ import android.text.Spanned; import android.text.SpannedString; import com.android.inputmethod.latin.common.Constants; +import com.android.inputmethod.latin.common.StringUtils; +import com.android.inputmethod.latin.utils.SpannableStringUtils; import java.util.Arrays; import java.util.List; @@ -375,9 +377,9 @@ public class StringAndJsonUtilsTests extends AndroidTestCase { spannableString.setSpan(span1, 0, 7, SPAN1_FLAGS); spannableString.setSpan(span2, 0, 5, SPAN2_FLAGS); spannableString.setSpan(span3, 12, 13, SPAN3_FLAGS); - final CharSequence[] charSequencesFromSpanned = StringUtils.split( + final CharSequence[] charSequencesFromSpanned = SpannableStringUtils.split( spannableString, " ", true /* preserveTrailingEmptySegmengs */); - final CharSequence[] charSequencesFromString = StringUtils.split( + final CharSequence[] charSequencesFromString = SpannableStringUtils.split( spannableString.toString(), " ", true /* preserveTrailingEmptySegmengs */); @@ -456,44 +458,44 @@ public class StringAndJsonUtilsTests extends AndroidTestCase { } public void testSplitCharSequencePreserveTrailingEmptySegmengs() { - assertEquals(1, StringUtils.split("", " ", + assertEquals(1, SpannableStringUtils.split("", " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(1, StringUtils.split(new SpannedString(""), " ", + assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(1, StringUtils.split("", " ", + assertEquals(1, SpannableStringUtils.split("", " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(1, StringUtils.split(new SpannedString(""), " ", + assertEquals(1, SpannableStringUtils.split(new SpannedString(""), " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(0, StringUtils.split(" ", " ", + assertEquals(0, SpannableStringUtils.split(" ", " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(0, StringUtils.split(new SpannedString(" "), " ", + assertEquals(0, SpannableStringUtils.split(new SpannedString(" "), " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(2, StringUtils.split(" ", " ", + assertEquals(2, SpannableStringUtils.split(" ", " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(2, StringUtils.split(new SpannedString(" "), " ", + assertEquals(2, SpannableStringUtils.split(new SpannedString(" "), " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(3, StringUtils.split("a b c ", " ", + assertEquals(3, SpannableStringUtils.split("a b c ", " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(3, StringUtils.split(new SpannedString("a b c "), " ", + assertEquals(3, SpannableStringUtils.split(new SpannedString("a b c "), " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(5, StringUtils.split("a b c ", " ", + assertEquals(5, SpannableStringUtils.split("a b c ", " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(5, StringUtils.split(new SpannedString("a b c "), " ", + assertEquals(5, SpannableStringUtils.split(new SpannedString("a b c "), " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(6, StringUtils.split("a b ", " ", + assertEquals(6, SpannableStringUtils.split("a b ", " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(6, StringUtils.split(new SpannedString("a b "), " ", + assertEquals(6, SpannableStringUtils.split(new SpannedString("a b "), " ", false /* preserveTrailingEmptySegmengs */).length); - assertEquals(7, StringUtils.split("a b ", " ", + assertEquals(7, SpannableStringUtils.split("a b ", " ", true /* preserveTrailingEmptySegmengs */).length); - assertEquals(7, StringUtils.split(new SpannedString("a b "), " ", + assertEquals(7, SpannableStringUtils.split(new SpannedString("a b "), " ", true /* preserveTrailingEmptySegmengs */).length); } } diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java index dfc3fecfd..54f478f5a 100644 --- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java @@ -23,6 +23,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; +import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodSubtype; @@ -36,6 +37,7 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { private RichInputMethodManager mRichImm; private Resources mRes; + private InputMethodSubtype mSavedAddtionalSubtypes[]; InputMethodSubtype EN_US; InputMethodSubtype EN_GB; @@ -45,6 +47,8 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { InputMethodSubtype FR_CH; InputMethodSubtype DE; InputMethodSubtype DE_CH; + InputMethodSubtype HI; + InputMethodSubtype SR; InputMethodSubtype ZZ; InputMethodSubtype DE_QWERTY; InputMethodSubtype FR_QWERTZ; @@ -54,17 +58,27 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { InputMethodSubtype ZZ_AZERTY; InputMethodSubtype ZZ_PC; - // This is a preliminary subtype and may not exist. - InputMethodSubtype HI_LATN; + // These are preliminary subtypes and may not exist. + InputMethodSubtype HI_LATN; // Hinglish + InputMethodSubtype SR_LATN; // Serbian Latin + InputMethodSubtype HI_LATN_DVORAK; // Hinglis Dvorak + InputMethodSubtype SR_LATN_QWERTY; // Serbian Latin Qwerty @Override protected void setUp() throws Exception { super.setUp(); final Context context = getContext(); + mRes = context.getResources(); RichInputMethodManager.init(context); mRichImm = RichInputMethodManager.getInstance(); - mRes = context.getResources(); - SubtypeLocaleUtils.init(context); + + // Save and reset additional subtypes + mSavedAddtionalSubtypes = mRichImm.getAdditionalSubtypes(context); + final InputMethodSubtype[] predefinedAddtionalSubtypes = + AdditionalSubtypeUtils.createAdditionalSubtypesArray( + AdditionalSubtypeUtils.createPrefSubtypes( + mRes.getStringArray(R.array.predefined_subtypes))); + mRichImm.setAdditionalInputMethodSubtypes(predefinedAddtionalSubtypes); final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme(); final int subtypeCount = imi.getSubtypeCount(); @@ -89,6 +103,10 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { Locale.GERMAN.toString(), "qwertz"); DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( "de_CH", "swiss"); + HI = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "hi", "hindi"); + SR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( + "sr", "south_slavic"); ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocaleUtils.NO_LANGUAGE, "qwerty"); DE_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( @@ -107,6 +125,22 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty"); HI_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("hi_ZZ", "qwerty"); + if (HI_LATN != null) { + HI_LATN_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "hi_ZZ", "dvorak"); + } + SR_LATN = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("sr_ZZ", "serbian_qwertz"); + if (SR_LATN != null) { + SR_LATN_QWERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype( + "sr_ZZ", "qwerty"); + } + } + + @Override + protected void tearDown() throws Exception { + // Restore additional subtypes. + mRichImm.setAdditionalInputMethodSubtypes(mSavedAddtionalSubtypes); + super.tearDown(); } public void testAllFullDisplayName() { @@ -139,11 +173,9 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { assertEquals("fr_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CH)); assertEquals("de", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE)); assertEquals("de_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_CH)); + assertEquals("hi", "hindi", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI)); + assertEquals("sr", "south_slavic", SubtypeLocaleUtils.getKeyboardLayoutSetName(SR)); assertEquals("zz", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ)); - // This is a preliminary subtype and may not exist. - if (HI_LATN != null) { - assertEquals("hi_ZZ", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_LATN)); - } assertEquals("de qwerty", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_QWERTY)); assertEquals("fr qwertz", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_QWERTZ)); @@ -155,28 +187,46 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getKeyboardLayoutSetName(ES_US_COLEMAK)); assertEquals("zz azerty", "azerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ_AZERTY)); + + // These are preliminary subtypes and may not exist. + if (HI_LATN != null) { + assertEquals("hi_ZZ", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_LATN)); + assertEquals("hi_ZZ dvorak", "dvorak", + SubtypeLocaleUtils.getKeyboardLayoutSetName(HI_LATN_DVORAK)); + } + if (SR_LATN != null) { + assertEquals("sr_ZZ", "serbian_qwertz", + SubtypeLocaleUtils.getKeyboardLayoutSetName(SR_LATN)); + assertEquals("sr_ZZ qwerty", "qwerty", + SubtypeLocaleUtils.getKeyboardLayoutSetName(SR_LATN_QWERTY)); + } } // InputMethodSubtype's display name in system locale (en_US). - // isAdditionalSubtype (T=true, F=false) - // locale layout | display name - // ------ ------- - ---------------------- - // en_US qwerty F English (US) exception - // en_GB qwerty F English (UK) exception - // es_US spanish F Spanish (US) exception - // fr azerty F French - // fr_CA qwerty F French (Canada) - // fr_CH swiss F French (Switzerland) - // de qwertz F German - // de_CH swiss F German (Switzerland) - // hi_ZZ qwerty F Hinglish - // zz qwerty F Alphabet (QWERTY) - // fr qwertz T French (QWERTZ) - // de qwerty T German (QWERTY) - // en_US azerty T English (US) (AZERTY) exception - // en_UK dvorak T English (UK) (Dvorak) exception - // es_US colemak T Spanish (US) (Colemak) exception - // zz pc T Alphabet (PC) + // isAdditionalSubtype (T=true, F=false) + // locale layout | display name + // ------ -------------- - ---------------------- + // en_US qwerty F English (US) exception + // en_GB qwerty F English (UK) exception + // es_US spanish F Spanish (US) exception + // fr azerty F French + // fr_CA qwerty F French (Canada) + // fr_CH swiss F French (Switzerland) + // de qwertz F German + // de_CH swiss F German (Switzerland) + // hi hindi F Hindi + // hi_ZZ qwerty F Hinglish exception + // sr south_slavic F Serbian + // sr_ZZ serbian_qwertz F Serbian (Latin) exception + // zz qwerty F Alphabet (QWERTY) + // fr qwertz T French (QWERTZ) + // de qwerty T German (QWERTY) + // en_US azerty T English (US) (AZERTY) exception + // en_UK dvorak T English (UK) (Dvorak) exception + // es_US colemak T Spanish (US) (Colemak) exception + // hi_ZZ dvorak T Hinglish (Dvorka) exception + // sr_ZZ qwerty T Serbian (QWERTY) exception + // zz pc T Alphabet (PC) public void testPredefinedSubtypesInEnglishSystemLocale() { final RunInLocale<Void> tests = new RunInLocale<Void>() { @@ -198,13 +248,21 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE)); assertEquals("de_CH", "German (Switzerland)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH)); + assertEquals("hi", "Hindi", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI)); + assertEquals("sr", "Serbian", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR)); assertEquals("zz", "Alphabet (QWERTY)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ)); - // This is a preliminary subtype and may not exist. + // These are preliminary subtypes and may not exist. if (HI_LATN != null) { assertEquals("hi_ZZ", "Hinglish", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN)); } + if (SR_LATN != null) { + assertEquals("sr_ZZ", "Serbian (Latin)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN)); + } return null; } }; @@ -229,6 +287,15 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY)); assertEquals("zz pc", "Alphabet (PC)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC)); + // These are preliminary subtypes and may not exist. + if (HI_LATN_DVORAK != null) { + assertEquals("hi_ZZ", "Hinglish (Dvorak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK)); + } + if (SR_LATN_QWERTY != null) { + assertEquals("sr_ZZ", "Serbian (QWERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY)); + } return null; } }; @@ -239,22 +306,27 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { // isAdditionalSubtype (T=true, F=false) // locale layout | display name // ------ ------- - ---------------------- - // en_US qwerty F Anglais (États-Unis) exception - // en_GB qwerty F Anglais (Royaume-Uni) exception - // es_US spanish F Espagnol (États-Unis) exception - // fr azerty F Français - // fr_CA qwerty F Français (Canada) - // fr_CH swiss F Français (Suisse) - // de qwertz F Allemand - // de_CH swiss F Allemand (Suisse) - // hi_ZZ qwerty F Hinglish - // zz qwerty F Alphabet latin (QWERTY) - // fr qwertz T Français (QWERTZ) - // de qwerty T Allemand (QWERTY) - // en_US azerty T Anglais (États-Unis) (AZERTY) exception - // en_UK dvorak T Anglais (Royaume-Uni) (Dvorak) exception - // es_US colemak T Espagnol (États-Unis) (Colemak) exception - // zz pc T Alphabet latin (PC) + // en_US qwerty F Anglais (États-Unis) exception + // en_GB qwerty F Anglais (Royaume-Uni) exception + // es_US spanish F Espagnol (États-Unis) exception + // fr azerty F Français + // fr_CA qwerty F Français (Canada) + // fr_CH swiss F Français (Suisse) + // de qwertz F Allemand + // de_CH swiss F Allemand (Suisse) + // hi hindi F Hindi exception + // hi_ZZ qwerty F Hindi/Anglais exception + // sr south_slavic F Serbe exception + // sr_ZZ serbian_qwertz F Serbe (latin) exception + // zz qwerty F Alphabet latin (QWERTY) + // fr qwertz T Français (QWERTZ) + // de qwerty T Allemand (QWERTY) + // en_US azerty T Anglais (États-Unis) (AZERTY) exception + // en_UK dvorak T Anglais (Royaume-Uni) (Dvorak) exception + // es_US colemak T Espagnol (États-Unis) (Colemak) exception + // hi_ZZ dvorak T Hindi/Anglais (Dvorka) exception + // sr_ZZ qwerty T Serbe (QWERTY) exception + // zz pc T Alphabet latin (PC) public void testPredefinedSubtypesInFrenchSystemLocale() { final RunInLocale<Void> tests = new RunInLocale<Void>() { @@ -276,13 +348,21 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE)); assertEquals("de_CH", "Allemand (Suisse)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH)); + assertEquals("hi", "Hindi", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI)); + assertEquals("sr", "Serbe", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR)); assertEquals("zz", "Alphabet latin (QWERTY)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ)); - // This is a preliminary subtype and may not exist. + // These are preliminary subtypes and may not exist. if (HI_LATN != null) { assertEquals("hi_ZZ", "Hindi/Anglais", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN)); } + if (SR_LATN != null) { + assertEquals("sr_ZZ", "Serbe (latin)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN)); + } return null; } }; @@ -307,12 +387,77 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase { SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY)); assertEquals("zz pc", "Alphabet latin (PC)", SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC)); + // These are preliminary subtypes and may not exist. + if (HI_LATN_DVORAK != null) { + assertEquals("hi_ZZ", "Hindi/Anglais (Dvorak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK)); + } + if (SR_LATN_QWERTY != null) { + assertEquals("sr_ZZ", "Serbe (QWERTY)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY)); + } return null; } }; tests.runInLocale(mRes, Locale.FRENCH); } + // InputMethodSubtype's display name in system locale (hi). + // isAdditionalSubtype (T=true, F=false) + // locale layout | display name + // ------ ------- - ---------------------- + // hi hindi F हिन्दी + // hi_ZZ qwerty F हिंग्लिश + // hi_ZZ dvorak T हिंग्लिश (Dvorak) + + public void testHinglishSubtypesInHindiSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job (final Resources res) { + assertEquals("hi", "हिन्दी", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI)); + // These are preliminary subtypes and may not exist. + if (HI_LATN != null) { + assertEquals("hi_ZZ", "हिंग्लिश", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN)); + assertEquals("hi_ZZ", "हिंग्लिश (Dvorak)", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(HI_LATN_DVORAK)); + } + return null; + } + }; + tests.runInLocale(mRes, new Locale("hi")); + } + + // InputMethodSubtype's display name in system locale (sr). + // isAdditionalSubtype (T=true, F=false) + // locale layout | display name + // ------ -------------- - ---------------------- + // sr south_slavic F Српски + // sr_ZZ serbian_qwertz F српски (латиница) + // sr_ZZ qwerty T српски (QWERTY) + + public void testSerbianLatinSubtypesInSerbianSystemLocale() { + final RunInLocale<Void> tests = new RunInLocale<Void>() { + @Override + protected Void job (final Resources res) { + assertEquals("sr", "Српски", + SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR)); + // These are preliminary subtypes and may not exist. + if (SR_LATN != null) { + // TODO: Uncommented because of the current translation of these strings + // in Seriban are described in Latin script. +// assertEquals("sr_ZZ", "српски (латиница)", +// SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN)); +// assertEquals("sr_ZZ", "српски (QWERTY)", +// SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(SR_LATN_QWERTY)); + } + return null; + } + }; + tests.runInLocale(mRes, new Locale("sr")); + } + public void testIsRtlLanguage() { // Known Right-to-Left language subtypes. final InputMethodSubtype ARABIC = mRichImm |