From 72bc9ad37ed3d89ccea253542b867221a1d9a129 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 8 Oct 2013 14:00:57 +0900 Subject: [PATCH] Add Ime language switching test. Change-Id: I6a96dc5fdd533899353d537382608c2759faff1c --- .../inputmethod/latin/InputTestsBase.java | 6 +- .../latin/LatinImeStressTests.java | 61 +++++++++++++++++++ .../latin/makedict/CodePointUtils.java | 36 +++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/src/com/android/inputmethod/latin/LatinImeStressTests.java diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 234bb1b31..b9b52a6f3 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -238,12 +238,16 @@ public class InputTestsBase extends ServiceTestCase { } protected void changeLanguage(final String locale) { + changeLanguageWithoutWait(locale); + waitForDictionaryToBeLoaded(); + } + + protected void changeLanguageWithoutWait(final String locale) { mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); SubtypeSwitcher.getInstance().forceLocale(mEditText.mCurrentLocale); mLatinIME.loadKeyboard(); runMessages(); mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); - waitForDictionaryToBeLoaded(); } protected void changeKeyboardLocaleAndDictLocale(final String keyboardLocale, diff --git a/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java new file mode 100644 index 000000000..5e98cdf8d --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2013 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; + +import android.test.suitebuilder.annotation.LargeTest; + +import com.android.inputmethod.latin.makedict.CodePointUtils; + +import java.util.Random; + +@LargeTest +public class LatinImeStressTests extends InputTestsBase { + public void testSwitchLanguagesAndInputLatinRandomCodePoints() { + final String[] locales = {"en_US", "de", "el", "es", "fi", "it", "nl", "pt", "ru"}; + final int switchCount = 50; + final int maxWordCountToTypeInEachIteration = 20; + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final int codePointSetSize = 30; + final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER; + for (int i = 0; i < switchCount; ++i) { + changeLanguageWithoutWait(locales[random.nextInt(locales.length)]); + final int wordCount = random.nextInt(maxWordCountToTypeInEachIteration); + for (int j = 0; j < wordCount; ++j) { + final String word = CodePointUtils.generateWord(random, codePointSet); + type(word); + } + } + } + public void testSwitchLanguagesAndInputRandamCodePoints() { + final String[] locales = {"en_US", "de", "el", "es", "fi", "it", "nl", "pt", "ru"}; + final int switchCount = 50; + final int maxWordCountToTypeInEachIteration = 20; + final long seed = System.currentTimeMillis(); + final Random random = new Random(seed); + final int codePointSetSize = 30; + final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); + for (int i = 0; i < switchCount; ++i) { + changeLanguageWithoutWait(locales[random.nextInt(locales.length)]); + final int wordCount = random.nextInt(maxWordCountToTypeInEachIteration); + for (int j = 0; j < wordCount; ++j) { + final String word = CodePointUtils.generateWord(random, codePointSet); + type(word); + } + } + } +} diff --git a/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java b/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java index 36b958af8..a270ee774 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/CodePointUtils.java @@ -24,6 +24,42 @@ public class CodePointUtils { // This utility class is not publicly instantiable. } + public static final int[] LATIN_ALPHABETS_LOWER = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 0x00E0 /* LATIN SMALL LETTER A WITH GRAVE */, + 0x00E1 /* LATIN SMALL LETTER A WITH ACUTE */, + 0x00E2 /* LATIN SMALL LETTER A WITH CIRCUMFLEX */, + 0x00E3 /* LATIN SMALL LETTER A WITH TILDE */, + 0x00E4 /* LATIN SMALL LETTER A WITH DIAERESIS */, + 0x00E5 /* LATIN SMALL LETTER A WITH RING ABOVE */, + 0x00E6 /* LATIN SMALL LETTER AE */, + 0x00E7 /* LATIN SMALL LETTER C WITH CEDILLA */, + 0x00E8 /* LATIN SMALL LETTER E WITH GRAVE */, + 0x00E9 /* LATIN SMALL LETTER E WITH ACUTE */, + 0x00EA /* LATIN SMALL LETTER E WITH CIRCUMFLEX */, + 0x00EB /* LATIN SMALL LETTER E WITH DIAERESIS */, + 0x00EC /* LATIN SMALL LETTER I WITH GRAVE */, + 0x00ED /* LATIN SMALL LETTER I WITH ACUTE */, + 0x00EE /* LATIN SMALL LETTER I WITH CIRCUMFLEX */, + 0x00EF /* LATIN SMALL LETTER I WITH DIAERESIS */, + 0x00F0 /* LATIN SMALL LETTER ETH */, + 0x00F1 /* LATIN SMALL LETTER N WITH TILDE */, + 0x00F2 /* LATIN SMALL LETTER O WITH GRAVE */, + 0x00F3 /* LATIN SMALL LETTER O WITH ACUTE */, + 0x00F4 /* LATIN SMALL LETTER O WITH CIRCUMFLEX */, + 0x00F5 /* LATIN SMALL LETTER O WITH TILDE */, + 0x00F6 /* LATIN SMALL LETTER O WITH DIAERESIS */, + 0x00F7 /* LATIN SMALL LETTER O WITH STROKE */, + 0x00F9 /* LATIN SMALL LETTER U WITH GRAVE */, + 0x00FA /* LATIN SMALL LETTER U WITH ACUTE */, + 0x00FB /* LATIN SMALL LETTER U WITH CIRCUMFLEX */, + 0x00FC /* LATIN SMALL LETTER U WITH DIAERESIS */, + 0x00FD /* LATIN SMALL LETTER Y WITH ACUTE */, + 0x00FE /* LATIN SMALL LETTER THORN */, + 0x00FF /* LATIN SMALL LETTER Y WITH DIAERESIS */ + }; + public static int[] generateCodePointSet(final int codePointSetSize, final Random random) { final int[] codePointSet = new int[codePointSetSize]; for (int i = codePointSet.length - 1; i >= 0; ) {